diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c index 9d92c256..62190f25 100644 --- a/src/fe-gtk/gtkutil.c +++ b/src/fe-gtk/gtkutil.c @@ -250,41 +250,68 @@ gtkutil_menu_icon_theme_variant (void) return theme_variant; } +static char * +gtkutil_menu_icon_resource_path (const char *icon_name, const char *extension) +{ + char *resource_path; + const char *variant; + + if (!icon_name || !extension || !g_str_has_prefix (icon_name, "zc-menu-")) + return NULL; + + variant = gtkutil_menu_icon_theme_variant (); + resource_path = g_strdup_printf ("/icons/menu/%s/%s.%s", variant, + icon_name + strlen ("zc-menu-"), extension); + if (!g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL)) + { + g_free (resource_path); + resource_path = g_strdup_printf ("/icons/menu/light/%s.%s", + icon_name + strlen ("zc-menu-"), extension); + if (!g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL)) + { + g_free (resource_path); + return NULL; + } + } + + return resource_path; +} + +gboolean +gtkutil_menu_icon_exists (const char *icon_name) +{ + char *resource_path; + gboolean found; + + resource_path = gtkutil_menu_icon_resource_path (icon_name, "png"); + if (!resource_path) + resource_path = gtkutil_menu_icon_resource_path (icon_name, "svg"); + + found = resource_path != NULL; + g_free (resource_path); + + return found; +} + static GtkWidget * gtkutil_menu_icon_image_new (const char *icon_name, GtkIconSize size) { GtkWidget *image = NULL; GdkPixbuf *pixbuf = NULL; char *resource_path; - const char *variant; - if (!icon_name || !g_str_has_prefix (icon_name, "zc-menu-")) - return NULL; + resource_path = gtkutil_menu_icon_resource_path (icon_name, "png"); + if (!resource_path) + resource_path = gtkutil_menu_icon_resource_path (icon_name, "svg"); - variant = gtkutil_menu_icon_theme_variant (); - resource_path = g_strdup_printf ("/icons/menu/%s/%s.png", variant, icon_name + strlen ("zc-menu-")); - if (!g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL)) + if (resource_path) { - g_free (resource_path); - resource_path = g_strdup_printf ("/icons/menu/light/%s.png", icon_name + strlen ("zc-menu-")); - } - - pixbuf = gdk_pixbuf_new_from_resource (resource_path, NULL); - if (!pixbuf) - { - g_free (resource_path); - resource_path = g_strdup_printf ("/icons/menu/%s/%s.svg", variant, icon_name + strlen ("zc-menu-")); - if (!g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL)) - { - g_free (resource_path); - resource_path = g_strdup_printf ("/icons/menu/light/%s.svg", icon_name + strlen ("zc-menu-")); - } pixbuf = gdk_pixbuf_new_from_resource (resource_path, NULL); - } - if (pixbuf) - { - image = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); + if (pixbuf) + { + image = gtk_image_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); + } } g_free (resource_path); diff --git a/src/fe-gtk/gtkutil.h b/src/fe-gtk/gtkutil.h index 4c7fd6cd..4d128e59 100644 --- a/src/fe-gtk/gtkutil.h +++ b/src/fe-gtk/gtkutil.h @@ -41,6 +41,7 @@ GtkWidget *gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callbac void *userdata, char *labeltext); GtkWidget *gtkutil_image_new_from_stock (const char *stock, GtkIconSize size); GtkWidget *gtkutil_button_new_from_stock (const char *stock, const char *label); +gboolean gtkutil_menu_icon_exists (const char *icon_name); const char *gtkutil_icon_name_from_stock (const char *stock_name); void gtkutil_label_new (char *text, GtkWidget * box); GtkWidget *gtkutil_entry_new (int max, GtkWidget * box, void *callback, diff --git a/src/fe-gtk/menu.c b/src/fe-gtk/menu.c index 71f598e8..cd827c4a 100644 --- a/src/fe-gtk/menu.c +++ b/src/fe-gtk/menu.c @@ -65,28 +65,6 @@ static GSList *submenu_list; -static gboolean -menu_icon_exists_in_resource (const char *icon_name) -{ - char *resource_path; - gboolean found; - - if (!icon_name || !g_str_has_prefix (icon_name, "zc-menu-")) - return FALSE; - - resource_path = g_strdup_printf ("/icons/menu/light/%s.png", icon_name + strlen ("zc-menu-")); - found = g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL); - if (!found) - { - g_free (resource_path); - resource_path = g_strdup_printf ("/icons/menu/light/%s.svg", icon_name + strlen ("zc-menu-")); - found = g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL); - } - g_free (resource_path); - - return found; -} - static GtkWidget * menu_icon_widget_new (const char *icon) { @@ -112,7 +90,7 @@ menu_icon_widget_new (const char *icon) { char *menu_icon_name = g_strdup_printf ("zc-menu-%s", icon); - if (menu_icon_exists_in_resource (menu_icon_name)) + if (gtkutil_menu_icon_exists (menu_icon_name)) img = gtkutil_image_new_from_stock (menu_icon_name, GTK_ICON_SIZE_MENU); else img = gtkutil_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);