[Xfce4-commits] <xfdesktop:jannis/port-to-gio> Add xfdesktop_file_icon_update_file_info().

Jannis Pohlmann noreply at xfce.org
Sun Oct 17 19:34:01 CEST 2010


Updating branch refs/heads/jannis/port-to-gio
         to d6fcc540bf3c942e165fcf097b1da3ad5d72d351 (commit)
       from 73affaebdc509dd7ac80cdb2385b892347e41df0 (commit)

commit d6fcc540bf3c942e165fcf097b1da3ad5d72d351
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sun Oct 17 19:12:30 2010 +0200

    Add xfdesktop_file_icon_update_file_info().
    
    This is the GIO alternative to xfdesktop_file_icon_update_info() which
    takes a ThunarVfsInfo.

 src/xfdesktop-file-icon.c         |   14 ++++++++++++++
 src/xfdesktop-file-icon.h         |    3 +++
 src/xfdesktop-regular-file-icon.c |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/src/xfdesktop-file-icon.c b/src/xfdesktop-file-icon.c
index 124e178..d79f32c 100644
--- a/src/xfdesktop-file-icon.c
+++ b/src/xfdesktop-file-icon.c
@@ -238,6 +238,20 @@ xfdesktop_file_icon_update_info(XfdesktopFileIcon *icon,
        klass->update_info(icon, info);
 }
 
+void
+xfdesktop_file_icon_update_file_info(XfdesktopFileIcon *icon,
+                                     GFileInfo *info)
+{
+    XfdesktopFileIconClass *klass;
+    
+    g_return_if_fail(XFDESKTOP_IS_FILE_ICON(icon));
+    
+    klass = XFDESKTOP_FILE_ICON_GET_CLASS(icon);
+    
+    if(klass->update_file_info)
+       klass->update_file_info(icon, info);
+}
+
 gboolean
 xfdesktop_file_icon_can_rename_file(XfdesktopFileIcon *icon)
 {
diff --git a/src/xfdesktop-file-icon.h b/src/xfdesktop-file-icon.h
index 515fc5a..b3b51d4 100644
--- a/src/xfdesktop-file-icon.h
+++ b/src/xfdesktop-file-icon.h
@@ -58,6 +58,7 @@ struct _XfdesktopFileIconClass
     GFileInfo *(*peek_filesystem_info)(XfdesktopFileIcon *icon);
     GFile *(*peek_file)(XfdesktopFileIcon *icon);
     void (*update_info)(XfdesktopFileIcon *icon, ThunarVfsInfo *info);
+    void (*update_file_info)(XfdesktopFileIcon *icon, GFileInfo *info);
     
     gboolean (*can_rename_file)(XfdesktopFileIcon *icon);
     gboolean (*rename_file)(XfdesktopFileIcon *icon, const gchar *new_name);
@@ -74,6 +75,8 @@ GFileInfo *xfdesktop_file_icon_peek_filesystem_info(XfdesktopFileIcon *icon);
 GFile *xfdesktop_file_icon_peek_file(XfdesktopFileIcon *icon);
 void xfdesktop_file_icon_update_info(XfdesktopFileIcon *icon,
                                      ThunarVfsInfo *info);
+void xfdesktop_file_icon_update_file_info(XfdesktopFileIcon *icon,
+                                          GFileInfo *info);
 
 gboolean xfdesktop_file_icon_can_rename_file(XfdesktopFileIcon *icon);
 gboolean xfdesktop_file_icon_rename_file(XfdesktopFileIcon *icon,
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index 8a09ca3..be52c28 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -89,6 +89,8 @@ static GFileInfo *xfdesktop_regular_file_icon_peek_filesystem_info(XfdesktopFile
 static GFile *xfdesktop_regular_file_icon_peek_file(XfdesktopFileIcon *icon);
 static void xfdesktop_regular_file_icon_update_info(XfdesktopFileIcon *icon,
                                                     ThunarVfsInfo *info);
+static void xfdesktop_regular_file_icon_update_file_info(XfdesktopFileIcon *icon,
+                                                         GFileInfo *info);
 static gboolean xfdesktop_regular_file_can_write_parent(XfdesktopFileIcon *icon);
 static gboolean xfdesktop_regular_file_icon_rename_file(XfdesktopFileIcon *icon,
                                                         const gchar *new_name);
@@ -140,6 +142,7 @@ xfdesktop_regular_file_icon_class_init(XfdesktopRegularFileIconClass *klass)
     file_icon_class->peek_filesystem_info = xfdesktop_regular_file_icon_peek_filesystem_info;
     file_icon_class->peek_file = xfdesktop_regular_file_icon_peek_file;
     file_icon_class->update_info = xfdesktop_regular_file_icon_update_info;
+    file_icon_class->update_file_info = xfdesktop_regular_file_icon_update_file_info;
     file_icon_class->can_rename_file = xfdesktop_regular_file_can_write_parent;
     file_icon_class->rename_file = xfdesktop_regular_file_icon_rename_file;
     file_icon_class->can_delete_file = xfdesktop_regular_file_can_write_parent;
@@ -693,6 +696,39 @@ xfdesktop_regular_file_icon_update_info(XfdesktopFileIcon *icon,
     xfdesktop_icon_pixbuf_changed(XFDESKTOP_ICON(icon));
 }
 
+static void
+xfdesktop_regular_file_icon_update_file_info(XfdesktopFileIcon *icon,
+                                             GFileInfo *info)
+{
+    XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon);
+    const gchar *old_display_name, *new_display_name;
+    gboolean label_changed = FALSE;
+    
+    g_return_if_fail(XFDESKTOP_IS_REGULAR_FILE_ICON(icon));
+    g_return_if_fail(G_IS_FILE_INFO(info));
+
+    if(regular_file_icon->priv->file_info) { 
+        old_display_name = g_file_info_get_attribute_string(regular_file_icon->priv->file_info,
+                                                            G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+        new_display_name = g_file_info_get_attribute_string(info,
+                                                            G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+
+        label_changed = (g_strcmp0(old_display_name, new_display_name) != 0);
+
+        /* release the old file info */
+        g_object_unref(regular_file_icon->priv->file_info);
+        regular_file_icon->priv->file_info = NULL;
+    }
+
+    regular_file_icon->priv->info = g_object_ref(info);
+    
+    if(label_changed)
+        xfdesktop_icon_label_changed(XFDESKTOP_ICON(icon));
+    
+    /* not really easy to check if this changed or not, so just invalidate it */
+    xfdesktop_regular_file_icon_invalidate_pixbuf(regular_file_icon);
+    xfdesktop_icon_pixbuf_changed(XFDESKTOP_ICON(icon));
+}
 
 
 /* public API */



More information about the Xfce4-commits mailing list