[Xfce4-commits] [xfce/libxfce4ui] 01/01: Add two new functions to search for app icons

noreply at xfce.org noreply at xfce.org
Mon Jan 13 23:35:08 CET 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/libxfce4ui.

commit e656667d2ed1ce847cfb8f1019a70b11c698790f
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Jan 13 23:29:19 2020 +0100

    Add two new functions to search for app icons
    
    * xfce_icon_name_from_desktop_id: Returns the value of the "Icon" property
      in the corresponding desktop file (or NULL)
    * xfce_gicon_from_name: Tries to return a GIcon for the app name (or
      NULL)
---
 docs/libxfce4ui-sections.txt     |  4 +-
 libxfce4ui/libxfce4ui.symbols    |  2 +
 libxfce4ui/xfce-gtk-extensions.c | 84 ++++++++++++++++++++++++++++++++++++++++
 libxfce4ui/xfce-gtk-extensions.h |  4 ++
 4 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/docs/libxfce4ui-sections.txt b/docs/libxfce4ui-sections.txt
index 8886c9d..64a6b17 100644
--- a/docs/libxfce4ui-sections.txt
+++ b/docs/libxfce4ui-sections.txt
@@ -32,8 +32,10 @@ xfce_gtk_button_new_mixed
 xfce_gtk_frame_box_new
 xfce_gtk_frame_box_new_with_content
 xfce_gtk_window_center_on_active_screen
-xfce_widget_reparent
 xfce_gtk_menu_popup_until_mapped
+xfce_widget_reparent
+xfce_icon_name_from_desktop_id
+xfce_gicon_from_name
 </SECTION>
 
 <SECTION>
diff --git a/libxfce4ui/libxfce4ui.symbols b/libxfce4ui/libxfce4ui.symbols
index 5453f08..f8b55d5 100644
--- a/libxfce4ui/libxfce4ui.symbols
+++ b/libxfce4ui/libxfce4ui.symbols
@@ -87,6 +87,8 @@ xfce_gtk_frame_box_new_with_content G_GNUC_MALLOC
 xfce_gtk_window_center_on_active_screen
 xfce_gtk_menu_popup_until_mapped
 xfce_widget_reparent
+xfce_icon_name_from_desktop_id
+xfce_gicon_from_name
 #endif
 #endif
 
diff --git a/libxfce4ui/xfce-gtk-extensions.c b/libxfce4ui/xfce-gtk-extensions.c
index 01ee1c7..ad720ab 100644
--- a/libxfce4ui/xfce-gtk-extensions.c
+++ b/libxfce4ui/xfce-gtk-extensions.c
@@ -42,6 +42,7 @@
 #include <libxfce4ui/xfce-gdk-extensions.h>
 #include <libxfce4ui/libxfce4ui-private.h>
 #include <libxfce4ui/libxfce4ui-alias.h>
+#include <libxfce4util/libxfce4util.h>
 
 /* Xfce frame padding */
 #define PADDING (6)
@@ -317,5 +318,88 @@ xfce_widget_reparent (GtkWidget *widget,
   return FALSE;
 }
 
+
+
+/**
+ * xfce_icon_name_from_desktop_id:
+ * @desktop_id : Name of the desktop file.
+ *
+ * Return value: %NULL on error, else the string, which should be freed using
+ *               g_free() when no longer needed.
+ *
+ * Since: 4.16
+ **/
+gchar *
+xfce_icon_name_from_desktop_id (const gchar *desktop_id)
+{
+    const gchar *icon_file;
+    gchar *resource;
+    XfceRc *rcfile;
+
+    resource = g_strdup_printf ("applications%c%s.desktop",
+                                G_DIR_SEPARATOR,
+                                desktop_id);
+    rcfile = xfce_rc_config_open (XFCE_RESOURCE_DATA,
+                                  resource, TRUE);
+    g_free (resource);
+
+    if (rcfile && xfce_rc_has_group (rcfile, "Desktop Entry")) {
+        xfce_rc_set_group (rcfile, "Desktop Entry");
+        icon_file = xfce_rc_read_entry (rcfile, "Icon", NULL);
+        xfce_rc_close (rcfile);
+        return icon_file;
+    }
+    else
+        return NULL;
+}
+
+
+
+/**
+ * xfce_gicon_from_name:
+ * @name : Name of the application.
+ *
+ * This function will first look for a desktop file of @name and if successful
+ * use the value of the "Icon" property to return a #GIcon.
+ * If no desktop file of @name is found it will fallback to returning a #GIcon
+ * based on #g_themed_icon_new_with_default_fallbacks and
+ * #gtk_icon_theme_lookup_by_gicon.
+ *
+ * Return value: a new #GThemedIcon.
+ *
+ * Since: 4.16
+ **/
+GIcon *
+xfce_gicon_from_name (const gchar *name)
+{
+    gchar *icon_name = NULL;
+    GIcon *gicon;
+    GtkIconInfo *icon_info;
+
+    /* Check if there is a desktop file of 'name' */
+    icon_name = xfce_icon_name_from_desktop_id (name);
+    if (icon_name) {
+        gicon = g_themed_icon_new_with_default_fallbacks (icon_name);
+        g_free (icon_name);
+    }
+    else {
+        gicon = g_themed_icon_new_with_default_fallbacks (name);
+    }
+
+    /* As g_themed_icon_new_with_default_fallbacks always returns 'something'
+       check if there's anything that matches in the icon theme */
+    icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+                                                gicon,
+                                                GTK_ICON_SIZE_BUTTON,
+                                                GTK_ICON_LOOKUP_FORCE_REGULAR);
+
+    if (icon_info)
+        return gicon;
+    else
+        return NULL;
+}
+
+
+
 #define __XFCE_GTK_EXTENSIONS_C__
 #include <libxfce4ui/libxfce4ui-aliasdef.c>
diff --git a/libxfce4ui/xfce-gtk-extensions.h b/libxfce4ui/xfce-gtk-extensions.h
index e075375..7ee3810 100644
--- a/libxfce4ui/xfce-gtk-extensions.h
+++ b/libxfce4ui/xfce-gtk-extensions.h
@@ -50,6 +50,10 @@ gboolean   xfce_gtk_menu_popup_until_mapped        (GtkMenu             *menu,
 gboolean   xfce_widget_reparent                    (GtkWidget           *widget,
                                                     GtkWidget           *new_parent);
 
+gchar     *xfce_icon_name_from_desktop_id          (const gchar         *desktop_id);
+
+GIcon     *xfce_gicon_from_name                    (const gchar         *name);
+
 G_END_DECLS
 
 #endif /* !__XFCE_GTK_EXTENSIONS_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list