Author: jannis Date: 2006-10-03 19:26:37 +0000 (Tue, 03 Oct 2006) New Revision: 23275
Modified: libfrap/trunk/libfrap/menu/ChangeLog libfrap/trunk/libfrap/menu/STATUS libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c Log: * STATUS: Updated the implementation status. * tests/test-display-root-menu.c: Improved loading / displaying of application icons. It's still not perfect, but much better than before. Modified: libfrap/trunk/libfrap/menu/ChangeLog =================================================================== --- libfrap/trunk/libfrap/menu/ChangeLog 2006-10-03 16:34:36 UTC (rev 23274) +++ libfrap/trunk/libfrap/menu/ChangeLog 2006-10-03 19:26:37 UTC (rev 23275) @@ -1,3 +1,10 @@ +2006-10-03 Jannis Pohlmann <[EMAIL PROTECTED]> + + * STATUS: Updated the implementation status. + * tests/test-display-root-menu.c: Improved loading / displaying of + application icons. It's still not perfect, but much better than + before. + 2006-10-01 Jannis Pohlmann <[EMAIL PROTECTED]> * frap-menu-or-rules.c, frap-menu-and-rules.c, frap-menu-not-rules.c: Modified: libfrap/trunk/libfrap/menu/STATUS =================================================================== --- libfrap/trunk/libfrap/menu/STATUS 2006-10-03 16:34:36 UTC (rev 23274) +++ libfrap/trunk/libfrap/menu/STATUS 2006-10-03 19:26:37 UTC (rev 23275) @@ -20,10 +20,7 @@ [x] <DefaultDirectoryDirs> - [-] <Name> - The <Name> is parsed and implemented as a property of XfceMenu - but there are no functions yet to parse menu paths, such as - "/Applications/Graphics". + [x] <Name> [x] <Directory> Modified: libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2006-10-03 16:34:36 UTC (rev 23274) +++ libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2006-10-03 19:26:37 UTC (rev 23275) @@ -32,6 +32,10 @@ +#define ICON_SIZE 22 + + + static FrapMenu *root = NULL; static GtkWidget *window = NULL; @@ -59,6 +63,76 @@ +GdkPixbuf* +create_icon_for_item (FrapMenuItem *item) +{ + GdkPixbuf *pixbuf = NULL; + const gchar *icon_name = frap_menu_item_get_icon_name (item); + const gchar *item_name = frap_menu_item_get_name (item); + + if (icon_name == NULL) + return NULL; + + /* Check if we have an absolute filename */ + if (g_path_is_absolute (icon_name)) + { + pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_name, ICON_SIZE, ICON_SIZE, TRUE, NULL); + } + else + { + /* Try to directly load the icon name first */ + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + + /* Afterwards try removing the filename extension if there is one */ + if (!pixbuf) + { + /* Get basename (just to be sure) */ + gchar *basename = g_path_get_basename (icon_name); + + /* Determine position of the extension */ + gchar *extension = g_utf8_strrchr (basename, -1, '.'); + + /* Make sure we (probably) found an extension */ + if (extension != NULL) + { + /* Remove extension */ + gchar *new_icon_name = g_utf8_strncpy (icon_name, basename, g_utf8_strlen (basename, -1) - g_utf8_strlen (extension, -1)); + + /* Try to load the pixbuf using the new icon name */ + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), new_icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + + /* Free new icon name */ + g_free (new_icon_name); + } + + /* Free basename */ + g_free (basename); + } + + /* Finally, we try to load the icon by lowercase item name */ + if (!pixbuf && item_name != NULL) + { + gchar *new_item_name = g_utf8_strdown (item_name, -1); + + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), new_item_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + + g_free (new_item_name); + } + } + + /* Scale pixbuf (if needed) */ + if (pixbuf) + { + GdkPixbuf *old = pixbuf; + pixbuf = gdk_pixbuf_scale_simple (old, ICON_SIZE, ICON_SIZE, GDK_INTERP_BILINEAR); + gdk_pixbuf_unref (old); + } + + return pixbuf; +} + + + void create_item_widgets_for_menu (const gchar *desktop_id, FrapMenuItem *item, @@ -66,9 +140,16 @@ { GtkWidget *menu_item; GtkWidget *image; + GdkPixbuf *pixbuf; - image = gtk_image_new_from_icon_name (frap_menu_item_get_icon_name (item), GTK_ICON_SIZE_MENU); + /* Try to load the image */ + pixbuf = create_icon_for_item (item); + if (pixbuf) + image = gtk_image_new_from_pixbuf (pixbuf); + else + image = gtk_image_new_from_icon_name ("applications-other", GTK_ICON_SIZE_SMALL_TOOLBAR); + menu_item = gtk_image_menu_item_new_with_label (frap_menu_item_get_name (item)); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image); gtk_menu_shell_append (GTK_MENU_SHELL (widget), menu_item); @@ -101,7 +182,7 @@ continue; /* Create menu icon */ - image = gtk_image_new_from_icon_name (frap_menu_directory_get_icon (directory), GTK_ICON_SIZE_MENU); + image = gtk_image_new_from_icon_name (frap_menu_directory_get_icon (directory), GTK_ICON_SIZE_SMALL_TOOLBAR); /* Create menu item */ menu_item = gtk_image_menu_item_new_with_label (frap_menu_directory_get_name (directory)); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits