mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 07:50:19 +00:00
Removed the local menu_icon_exists_in_resource probe from menu.c, so this file no longer carries a hardcoded /icons/menu/light resource check path. menu_icon_widget_new now calls gtkutil_menu_icon_exists for the zc-menu-* candidate check. This keeps the same fallback flow for custom icons: direct readable path first, then config-dir path, then stock/themed lookup.
Added gtkutil_menu_icon_exists to gtkutil.c and declared it in gtkutil.h. The implementation uses a shared helper that resolves menu icon resources with theme-variant-aware lookup (variant first, then light fallback) for both png and svg, so probing behavior now lives in the same subsystem as gtkutil_image_new_from_stock.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user