[gnome-flashback] desktop: handle "renamed" event
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] desktop: handle "renamed" event
- Date: Fri, 15 Nov 2019 14:38:28 +0000 (UTC)
commit f3f801d8d0a4b9c49965c148c8e917d2da1a3256
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Fri Nov 15 16:37:58 2019 +0200
desktop: handle "renamed" event
gnome-flashback/libdesktop/gf-icon-view.c | 106 +++++++++++++++++++-----------
gnome-flashback/libdesktop/gf-icon.c | 79 ++++++++++++++++++++--
gnome-flashback/libdesktop/gf-icon.h | 3 +
3 files changed, 144 insertions(+), 44 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index 1d924f7..cb36a99 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -421,43 +421,6 @@ resort_icons (GfIconView *self,
remove_and_readd_icons (self);
}
-static void
-file_deleted (GfIconView *self,
- GFile *deleted_file)
-{
- GList *l;
-
- for (l = self->icons; l != NULL; l = l->next)
- {
- GfIconInfo *info;
- GFile *file;
-
- info = (GfIconInfo *) l->data;
-
- file = gf_icon_get_file (GF_ICON (info->icon));
-
- if (!g_file_equal (file, deleted_file))
- continue;
-
- if (info->view != NULL)
- {
- gf_monitor_view_remove_icon (GF_MONITOR_VIEW (info->view), info->icon);
- info->view = NULL;
-
- self->selected_icons = g_list_remove (self->selected_icons, l->data);
- self->rubberband_icons = g_list_remove (self->rubberband_icons, l->data);
- }
-
- self->icons = g_list_remove_link (self->icons, l);
- g_list_free_full (l, gf_icon_info_free);
-
- if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
- remove_and_readd_icons (self);
-
- break;
- }
-}
-
static void
unselect_cb (gpointer data,
gpointer user_data)
@@ -563,11 +526,62 @@ query_info_cb (GObject *object,
add_icons (self);
}
+static GfIconInfo *
+find_icon_info_by_file (GfIconView *self,
+ GFile *file)
+{
+ GList *l;
+
+ for (l = self->icons; l != NULL; l = l->next)
+ {
+ GfIconInfo *info;
+ GFile *icon_file;
+
+ info = (GfIconInfo *) l->data;
+ icon_file = gf_icon_get_file (GF_ICON (info->icon));
+
+ if (g_file_equal (icon_file, file))
+ return info;
+ }
+
+ return NULL;
+}
+
+static void
+file_deleted (GfIconView *self,
+ GFile *deleted_file)
+{
+ GfIconInfo *info;
+
+ info = find_icon_info_by_file (self, deleted_file);
+
+ if (info == NULL)
+ return;
+
+ if (info->view != NULL)
+ {
+ GtkWidget *icon;
+
+ icon = info->icon;
+
+ gf_monitor_view_remove_icon (GF_MONITOR_VIEW (info->view), icon);
+ info->view = NULL;
+
+ self->selected_icons = g_list_remove (self->selected_icons, icon);
+ self->rubberband_icons = g_list_remove (self->rubberband_icons, icon);
+ }
+
+ self->icons = g_list_remove (self->icons, info);
+ gf_icon_info_free (info);
+
+ if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+ remove_and_readd_icons (self);
+}
+
static void
file_created (GfIconView *self,
GFile *created_file)
{
-
char *attributes;
attributes = gf_icon_view_get_file_attributes (self);
@@ -583,6 +597,21 @@ file_created (GfIconView *self,
g_free (attributes);
}
+static void
+file_renamed (GfIconView *self,
+ GFile *old_file,
+ GFile *new_file)
+{
+ GfIconInfo *info;
+
+ info = find_icon_info_by_file (self, old_file);
+
+ if (info == NULL)
+ return;
+
+ gf_icon_set_file (GF_ICON (info->icon), new_file);
+}
+
static void
desktop_changed_cb (GFileMonitor *monitor,
GFile *file,
@@ -619,6 +648,7 @@ desktop_changed_cb (GFileMonitor *monitor,
break;
case G_FILE_MONITOR_EVENT_RENAMED:
+ file_renamed (self, file, other_file);
break;
case G_FILE_MONITOR_EVENT_MOVED_IN:
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index 4854e98..57007d0 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -27,6 +27,8 @@
typedef struct
{
+ GCancellable *cancellable;
+
GtkGesture *multi_press;
GfIconView *icon_view;
@@ -336,19 +338,16 @@ update_text (GfIcon *self)
}
static void
-gf_icon_constructed (GObject *object)
+icon_refresh (GfIcon *self)
{
- GfIcon *self;
GfIconPrivate *priv;
const char *content_type;
- self = GF_ICON (object);
priv = gf_icon_get_instance_private (self);
-
- G_OBJECT_CLASS (gf_icon_parent_class)->constructed (object);
-
content_type = g_file_info_get_content_type (priv->info);
+ g_clear_object (&priv->app_info);
+
if (g_strcmp0 (content_type, "application/x-desktop") == 0)
{
char *path;
@@ -362,6 +361,44 @@ gf_icon_constructed (GObject *object)
update_text (self);
}
+static void
+query_info_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+ GFileInfo *file_info;
+ GfIcon *self;
+ GfIconPrivate *priv;
+
+ error = NULL;
+ file_info = g_file_query_info_finish (G_FILE (object), res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("%s", error->message);
+
+ g_error_free (error);
+ return;
+ }
+
+ self = GF_ICON (user_data);
+ priv = gf_icon_get_instance_private (self);
+
+ g_clear_object (&priv->info);
+ priv->info = file_info;
+
+ icon_refresh (self);
+}
+
+static void
+gf_icon_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (gf_icon_parent_class)->constructed (object);
+ icon_refresh (GF_ICON (object));
+}
+
static void
gf_icon_dispose (GObject *object)
{
@@ -371,6 +408,9 @@ gf_icon_dispose (GObject *object)
self = GF_ICON (object);
priv = gf_icon_get_instance_private (self);
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+
g_clear_object (&priv->multi_press);
g_clear_object (&priv->file);
@@ -586,6 +626,8 @@ gf_icon_init (GfIcon *self)
priv = gf_icon_get_instance_private (self);
+ priv->cancellable = g_cancellable_new ();
+
priv->multi_press = gtk_gesture_multi_press_new (GTK_WIDGET (self));
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multi_press), 0);
@@ -636,6 +678,31 @@ gf_icon_new (GfIconView *icon_view,
NULL);
}
+void
+gf_icon_set_file (GfIcon *self,
+ GFile *file)
+{
+ GfIconPrivate *priv;
+ char *attributes;
+
+ priv = gf_icon_get_instance_private (self);
+
+ g_clear_object (&priv->file);
+ priv->file = g_object_ref (file);
+
+ attributes = gf_icon_view_get_file_attributes (priv->icon_view);
+
+ g_file_query_info_async (file,
+ attributes,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_LOW,
+ priv->cancellable,
+ query_info_cb,
+ self);
+
+ g_free (attributes);
+}
+
GFile *
gf_icon_get_file (GfIcon *self)
{
diff --git a/gnome-flashback/libdesktop/gf-icon.h b/gnome-flashback/libdesktop/gf-icon.h
index 94a1a05..66cb232 100644
--- a/gnome-flashback/libdesktop/gf-icon.h
+++ b/gnome-flashback/libdesktop/gf-icon.h
@@ -34,6 +34,9 @@ GtkWidget *gf_icon_new (GfIconView *icon_view,
GFile *file,
GFileInfo *info);
+void gf_icon_set_file (GfIcon *self,
+ GFile *file);
+
GFile *gf_icon_get_file (GfIcon *self);
const char *gf_icon_get_name (GfIcon *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]