[Xfce4-commits] <xfdesktop:eric/bugzilla-patches> Comments in .desktop files are displayed in the tooltip (bug 8509)

Eric Koegel noreply at xfce.org
Sat Mar 3 18:10:07 CET 2012


Updating branch refs/heads/eric/bugzilla-patches
         to 2fac2c92ccb2fec0d6b64aa97c1f2315836d3ab1 (commit)
       from d3211fcb34491200bf60d1e38ace87f0ca8ee4c0 (commit)

commit 2fac2c92ccb2fec0d6b64aa97c1f2315836d3ab1
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Fri Mar 2 15:00:36 2012 +0300

    Comments in .desktop files are displayed in the tooltip (bug 8509)

 src/xfdesktop-regular-file-icon.c |   40 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index db6e66b..f42f6d6 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -516,13 +516,27 @@ xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon)
     
     if(!regular_file_icon->priv->tooltip) {
         GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon));
-        const gchar *content_type;
+        const gchar *content_type, *comment = NULL;
         gchar *description, *size_string, *time_string;
         guint64 size, mtime;
+        gboolean is_desktop_file = FALSE;
 
         if(!info)
             return NULL;
 
+        if(g_content_type_equals(g_file_info_get_content_type(info),
+                                 "application/x-desktop"))
+        {
+            is_desktop_file = TRUE;
+        }
+        else
+        {
+          gchar *uri = g_file_get_uri(regular_file_icon->priv->file);
+          if(g_str_has_suffix(uri, ".desktop"))
+              is_desktop_file = TRUE;
+          g_free(uri);
+        }
+
         content_type = g_file_info_get_content_type(info);
         description = g_content_type_get_description(content_type);
 
@@ -534,10 +548,34 @@ xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon)
                                                  G_FILE_ATTRIBUTE_TIME_MODIFIED);
         time_string = xfdesktop_file_utils_format_time_for_display(mtime);
 
+        /* Extract the Comment entry from the .desktop file */
+        if(is_desktop_file)
+        {
+            gchar *path = g_file_get_path(regular_file_icon->priv->file);
+            XfceRc *rcfile = xfce_rc_simple_open(path, TRUE);
+            g_free(path);
+
+            if(rcfile) {
+                xfce_rc_set_group(rcfile, "Desktop Entry");
+                comment = xfce_rc_read_entry(rcfile, "Comment", NULL);
+            }
+
+            xfce_rc_close(rcfile);
+        }
+
         regular_file_icon->priv->tooltip =
             g_strdup_printf(_("Type: %s\nSize: %s\nLast modified: %s"),
                             description, size_string, time_string);
 
+        /* Prepend the comment to the tooltip */
+        if(is_desktop_file && comment != NULL) {
+            gchar *tooltip = regular_file_icon->priv->tooltip;
+            regular_file_icon->priv->tooltip = g_strdup_printf("%s\n%s",
+                                                               comment,
+                                                               tooltip);
+            g_free(tooltip);
+        }
+
         g_free(time_string);
         g_free(size_string);
         g_free(description);


More information about the Xfce4-commits mailing list