Commit 005db8c3 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels
Browse files

desktop: monitor files for changes

https://launchpad.net/bugs/1875317
parent 2c977e34
...@@ -41,6 +41,8 @@ typedef struct ...@@ -41,6 +41,8 @@ typedef struct
GFile *file; GFile *file;
GFileInfo *info; GFileInfo *info;
GFileMonitor *monitor;
GfIconSize icon_size; GfIconSize icon_size;
guint extra_text_width; guint extra_text_width;
...@@ -1009,6 +1011,69 @@ set_icon_size (GfIcon *self, ...@@ -1009,6 +1011,69 @@ set_icon_size (GfIcon *self,
update_icon (self); update_icon (self);
} }
static void
file_changed_cb (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
GfIcon *self)
{
switch (event_type)
{
case G_FILE_MONITOR_EVENT_CHANGED:
break;
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
icon_refresh (self);
break;
case G_FILE_MONITOR_EVENT_DELETED:
break;
case G_FILE_MONITOR_EVENT_CREATED:
break;
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
gf_icon_update (self);
break;
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
break;
case G_FILE_MONITOR_EVENT_UNMOUNTED:
break;
case G_FILE_MONITOR_EVENT_MOVED:
break;
case G_FILE_MONITOR_EVENT_RENAMED:
break;
case G_FILE_MONITOR_EVENT_MOVED_IN:
break;
case G_FILE_MONITOR_EVENT_MOVED_OUT:
break;
default:
break;
}
}
static void
set_file (GfIcon *self,
GFile *file)
{
GfIconPrivate *priv;
priv = gf_icon_get_instance_private (self);
g_clear_object (&priv->file);
priv->file = g_object_ref (file);
GF_ICON_GET_CLASS (self)->create_file_monitor (self);
}
static void static void
gf_icon_constructed (GObject *object) gf_icon_constructed (GObject *object)
{ {
...@@ -1036,6 +1101,8 @@ gf_icon_dispose (GObject *object) ...@@ -1036,6 +1101,8 @@ gf_icon_dispose (GObject *object)
g_clear_object (&priv->file); g_clear_object (&priv->file);
g_clear_object (&priv->info); g_clear_object (&priv->info);
g_clear_object (&priv->monitor);
g_clear_object (&priv->app_info); g_clear_object (&priv->app_info);
g_clear_object (&priv->thumbnail); g_clear_object (&priv->thumbnail);
...@@ -1112,7 +1179,7 @@ gf_icon_set_property (GObject *object, ...@@ -1112,7 +1179,7 @@ gf_icon_set_property (GObject *object,
case PROP_FILE: case PROP_FILE:
g_assert (priv->file == NULL); g_assert (priv->file == NULL);
priv->file = g_value_dup_object (value); set_file (self, g_value_get_object (value));
break; break;
case PROP_INFO: case PROP_INFO:
...@@ -1154,6 +1221,35 @@ gf_icon_get_preferred_width (GtkWidget *widget, ...@@ -1154,6 +1221,35 @@ gf_icon_get_preferred_width (GtkWidget *widget,
*natural_width += priv->extra_text_width; *natural_width += priv->extra_text_width;
} }
static void
gf_icon_create_file_monitor (GfIcon *self)
{
GfIconPrivate *priv;
GError *error;
priv = gf_icon_get_instance_private (self);
g_clear_object (&priv->monitor);
error = NULL;
priv->monitor = g_file_monitor_file (priv->file,
G_FILE_MONITOR_NONE,
NULL,
&error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
g_signal_connect (priv->monitor,
"changed",
G_CALLBACK (file_changed_cb),
self);
}
static GIcon * static GIcon *
gf_icon_get_icon (GfIcon *self, gf_icon_get_icon (GfIcon *self,
gboolean *is_thumbnail) gboolean *is_thumbnail)
...@@ -1299,6 +1395,7 @@ gf_icon_class_init (GfIconClass *self_class) ...@@ -1299,6 +1395,7 @@ gf_icon_class_init (GfIconClass *self_class)
widget_class->get_preferred_width = gf_icon_get_preferred_width; widget_class->get_preferred_width = gf_icon_get_preferred_width;
self_class->create_file_monitor = gf_icon_create_file_monitor;
self_class->get_icon = gf_icon_get_icon; self_class->get_icon = gf_icon_get_icon;
self_class->get_text = gf_icon_get_text; self_class->get_text = gf_icon_get_text;
self_class->can_delete = gf_icon_can_delete; self_class->can_delete = gf_icon_can_delete;
...@@ -1416,9 +1513,7 @@ gf_icon_set_file (GfIcon *self, ...@@ -1416,9 +1513,7 @@ gf_icon_set_file (GfIcon *self,
g_clear_pointer (&priv->popover, gtk_widget_destroy); g_clear_pointer (&priv->popover, gtk_widget_destroy);
g_clear_object (&priv->file); set_file (self, file);
priv->file = g_object_ref (file);
gf_icon_update (self); gf_icon_update (self);
} }
......
...@@ -29,14 +29,16 @@ struct _GfIconClass ...@@ -29,14 +29,16 @@ struct _GfIconClass
{ {
GtkButtonClass parent_class; GtkButtonClass parent_class;
GIcon * (* get_icon) (GfIcon *self, void (* create_file_monitor) (GfIcon *self);
gboolean *is_thumbnail);
const char * (* get_text) (GfIcon *self); GIcon * (* get_icon) (GfIcon *self,
gboolean *is_thumbnail);
gboolean (* can_delete) (GfIcon *self); const char * (* get_text) (GfIcon *self);
gboolean (* can_rename) (GfIcon *self); gboolean (* can_delete) (GfIcon *self);
gboolean (* can_rename) (GfIcon *self);
}; };
GtkWidget *gf_icon_new (GfIconView *icon_view, GtkWidget *gf_icon_new (GfIconView *icon_view,
......
...@@ -145,29 +145,11 @@ static void ...@@ -145,29 +145,11 @@ static void
gf_trash_icon_constructed (GObject *object) gf_trash_icon_constructed (GObject *object)
{ {
GfTrashIcon *self; GfTrashIcon *self;
GError *error;
self = GF_TRASH_ICON (object); self = GF_TRASH_ICON (object);
G_OBJECT_CLASS (gf_trash_icon_parent_class)->constructed (object); G_OBJECT_CLASS (gf_trash_icon_parent_class)->constructed (object);
error = NULL;
self->monitor = g_file_monitor_directory (gf_icon_get_file (GF_ICON (self)),
G_FILE_MONITOR_WATCH_MOVES,
self->cancellable,
&error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
g_signal_connect (self->monitor, "changed",
G_CALLBACK (trash_changed_cb),
self);
check_if_empty (self); check_if_empty (self);
} }
...@@ -186,6 +168,35 @@ gf_trash_icon_dispose (GObject *object) ...@@ -186,6 +168,35 @@ gf_trash_icon_dispose (GObject *object)
G_OBJECT_CLASS (gf_trash_icon_parent_class)->dispose (object); G_OBJECT_CLASS (gf_trash_icon_parent_class)->dispose (object);
} }
static void
gf_trash_icon_create_file_monitor (GfIcon *icon)
{
GfTrashIcon *self;
GError *error;
self = GF_TRASH_ICON (icon);
g_clear_object (&self->monitor);
error = NULL;
self->monitor = g_file_monitor_directory (gf_icon_get_file (GF_ICON (self)),
G_FILE_MONITOR_WATCH_MOVES,
self->cancellable,
&error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
g_signal_connect (self->monitor,
"changed",
G_CALLBACK (trash_changed_cb),
self);
}
static GIcon * static GIcon *
gf_trash_icon_get_icon (GfIcon *icon, gf_trash_icon_get_icon (GfIcon *icon,
gboolean *is_thumbnail) gboolean *is_thumbnail)
...@@ -222,6 +233,7 @@ gf_trash_icon_class_init (GfTrashIconClass *self_class) ...@@ -222,6 +233,7 @@ gf_trash_icon_class_init (GfTrashIconClass *self_class)
object_class->constructed = gf_trash_icon_constructed; object_class->constructed = gf_trash_icon_constructed;
object_class->dispose = gf_trash_icon_dispose; object_class->dispose = gf_trash_icon_dispose;
icon_class->create_file_monitor = gf_trash_icon_create_file_monitor;
icon_class->get_icon = gf_trash_icon_get_icon; icon_class->get_icon = gf_trash_icon_get_icon;
icon_class->can_delete = gf_trash_icon_can_delete; icon_class->can_delete = gf_trash_icon_can_delete;
icon_class->can_rename = gf_trash_icon_can_rename; icon_class->can_rename = gf_trash_icon_can_rename;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment