Commit b226fcd3 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

Add panel_make_menu_icon, which exposes the pixbuf loading function from

Wed Feb 20 19:13:33 2002  George Lebl <jirka@5z.com>

	* menu.[ch], applet.c, foobar-widget.c, gnome-run.c:  Add
	  panel_make_menu_icon, which exposes the pixbuf loading function
	  from the menu icon cache so that we can use it in other places,
	  such as the run box.

	* button-widget.c: use the desktop-item icon finding function for
	  icon finding

	* launcher.c: when getting the best launcher icon look for 48x48 and
	  not 20x20
parent c29ce7ae
Wed Feb 20 19:13:33 2002 George Lebl <jirka@5z.com>
* menu.[ch], applet.c, foobar-widget.c, gnome-run.c: Add
panel_make_menu_icon, which exposes the pixbuf loading function
from the menu icon cache so that we can use it in other places,
such as the run box.
* button-widget.c: use the desktop-item icon finding function for
icon finding
* launcher.c: when getting the best launcher icon look for 48x48 and
not 20x20
Wed Feb 20 18:15:38 2002 George Lebl <jirka@5z.com> Wed Feb 20 18:15:38 2002 George Lebl <jirka@5z.com>
* menu-fentry.c: sure_string the fullname before making a collation * menu-fentry.c: sure_string the fullname before making a collation
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "logout.h" #include "logout.h"
#include "menu-properties.h" #include "menu-properties.h"
#include "menu-util.h" #include "menu-util.h"
#include "menu.h"
#include "panel-config.h" #include "panel-config.h"
#include "panel-gconf.h" #include "panel-gconf.h"
#include "panel-config-global.h" #include "panel-config-global.h"
...@@ -521,36 +522,24 @@ applet_setup_panel_menu (gboolean is_basep) ...@@ -521,36 +522,24 @@ applet_setup_panel_menu (gboolean is_basep)
{ {
GtkWidget *menuitem; GtkWidget *menuitem;
GtkWidget *panel_menu; GtkWidget *panel_menu;
gchar *pixmap_path; GdkPixbuf *pixbuf;
menuitem = gtk_image_menu_item_new (); menuitem = gtk_image_menu_item_new ();
pixmap_path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP, pixbuf = panel_make_menu_icon ("gnome-panel.png",
"gnome-panel.png", TRUE, NULL); NULL /* fallback */,
if (pixmap_path) { SMALL_ICON_SIZE /* size */,
GdkPixbuf *pixbuf, *scaled_pixbuf = NULL; NULL /* long_operation */);
if (pixbuf != NULL) {
GtkWidget *image = NULL; GtkWidget *image = NULL;
pixbuf = gdk_pixbuf_new_from_file (pixmap_path, NULL); image = gtk_image_new_from_pixbuf (pixbuf);
g_object_unref (pixbuf);
if (pixbuf != NULL) {
scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
SMALL_ICON_SIZE,
SMALL_ICON_SIZE,
GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
}
if (scaled_pixbuf != NULL) {
image = gtk_image_new_from_pixbuf (scaled_pixbuf);
g_object_unref (scaled_pixbuf);
}
setup_menuitem (menuitem, setup_menuitem (menuitem,
image, image,
_("Panel")); _("Panel"));
g_free (pixmap_path);
} else { } else {
g_message (_("Cannot find pixmap file %s"), "gnome-panel.png"); g_message (_("Cannot find pixmap file %s"), "gnome-panel.png");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libgnome/gnome-i18n.h> #include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h> #include <libgnome/gnome-util.h>
#include <libgnome/gnome-desktop-item.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include "button-widget.h" #include "button-widget.h"
#include "panel-widget.h" #include "panel-widget.h"
...@@ -287,14 +288,14 @@ loadup_file(const char *file) ...@@ -287,14 +288,14 @@ loadup_file(const char *file)
if (string_empty (file)) if (string_empty (file))
return NULL; return NULL;
if (!g_path_is_absolute (file)) { if ( ! g_path_is_absolute (file)) {
char *f; char *full = gnome_desktop_item_find_icon (file,
48 /* desired size */,
0 /* flags */);
f = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP, if (full != NULL) {
file, TRUE, NULL); pb = gdk_pixbuf_new_from_file (full, NULL);
if (f) { g_free (full);
pb = gdk_pixbuf_new_from_file (f, NULL);
g_free (f);
} }
} else { } else {
pb = gdk_pixbuf_new_from_file (file, NULL); pb = gdk_pixbuf_new_from_file (file, NULL);
......
...@@ -666,25 +666,12 @@ get_default_image (void) ...@@ -666,25 +666,12 @@ get_default_image (void)
static GdkPixbuf *pixbuf = NULL; static GdkPixbuf *pixbuf = NULL;
static gboolean looked = FALSE; static gboolean looked = FALSE;
if (! looked) { if ( ! looked) {
GdkPixbuf *pb = NULL, *scaled = NULL; pixbuf = panel_make_menu_icon ("gnome-tasklist.png",
char *name = panel_pixmap_discovery ("gnome-tasklist.png", FALSE /* fallback */); /* evil fallback huh? */
if (name == NULL) "apple-red.png",
/* evil fallback huh? */ 20 /* size */,
name = panel_pixmap_discovery ("apple-red.png", FALSE /* fallback */); NULL /* long_operation */);
if (name != NULL) {
pb = gdk_pixbuf_new_from_file (name, NULL);
g_free (name);
}
if (pb != NULL) {
scaled = gdk_pixbuf_scale_simple (pb, 20, 20,
GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pb));
pixbuf = scaled;
}
looked = TRUE; looked = TRUE;
} }
......
...@@ -774,31 +774,13 @@ fill_list (GtkWidget *list) ...@@ -774,31 +774,13 @@ fill_list (GtkWidget *list)
GtkTreeIter iter; GtkTreeIter iter;
FileRec *fr; FileRec *fr;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
char *icon;
fr = tmp->data; fr = tmp->data;
icon = gnome_desktop_item_find_icon (fr->icon, pixbuf = panel_make_menu_icon (fr->icon,
ICON_SIZE /* desired size */, NULL /* fallback */,
0 /* flags */); ICON_SIZE,
if (icon != NULL) { NULL /* long_operation */);
pixbuf = gdk_pixbuf_new_from_file (icon, NULL);
g_free (icon);
} else {
pixbuf = NULL;
}
if (pixbuf != NULL &&
(gdk_pixbuf_get_width (pixbuf) != ICON_SIZE ||
gdk_pixbuf_get_height (pixbuf) != ICON_SIZE)) {
GdkPixbuf *scaled;
scaled = gdk_pixbuf_scale_simple (pixbuf,
ICON_SIZE,
ICON_SIZE,
GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pixbuf));
pixbuf = scaled;
}
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
......
...@@ -789,7 +789,7 @@ ditem_set_icon (GnomeDesktopItem *ditem, const char *icon) ...@@ -789,7 +789,7 @@ ditem_set_icon (GnomeDesktopItem *ditem, const char *icon)
if (icon != NULL && if (icon != NULL &&
icon[0] != G_DIR_SEPARATOR) { icon[0] != G_DIR_SEPARATOR) {
char *full = gnome_desktop_item_find_icon (icon, char *full = gnome_desktop_item_find_icon (icon,
20 /* desired size */, 48 /* desired size */,
0 /* flags */); 0 /* flags */);
if (full != NULL) { if (full != NULL) {
gnome_desktop_item_set_string (ditem, gnome_desktop_item_set_string (ditem,
......
...@@ -768,54 +768,39 @@ remove_pixmap_from_loaded (gpointer data, GObject *where_the_object_was) ...@@ -768,54 +768,39 @@ remove_pixmap_from_loaded (gpointer data, GObject *where_the_object_was)
g_free (key); g_free (key);
} }
static gboolean GdkPixbuf *
load_icons_handler (gpointer data) panel_make_menu_icon (const char *icon,
const char *fallback,
int size,
gboolean *long_operation)
{ {
GtkImage *pixmap;
GdkPixbuf *pb; GdkPixbuf *pb;
IconToLoad *icon;
char *file, *key; char *file, *key;
gboolean loaded; gboolean loaded;
load_icons_handler_again: if (long_operation != NULL)
*long_operation = TRUE;
if (icons_to_load == NULL) {
load_icons_id = 0;
return FALSE;
}
icon = icons_to_load->data;
icons_to_load = g_list_remove (icons_to_load, icon);
/* if not visible anymore, just ignore */
if ( ! GTK_WIDGET_VISIBLE (icon->pixmap)) {
icon_to_load_free (icon);
/* we didn't do anything long/hard, so just do this again,
* this is fun, don't go back to main loop */
goto load_icons_handler_again;
}
file = gnome_desktop_item_find_icon (icon->image, file = gnome_desktop_item_find_icon (icon,
icon->size /* desired size */, size /* desired size */,
0 /* flags */); 0 /* flags */);
if (file == NULL) if (file == NULL && fallback != NULL)
file = gnome_desktop_item_find_icon (icon->fallback_image, file = gnome_desktop_item_find_icon (fallback,
icon->size /* desired size */, size /* desired size */,
0 /* flags */); 0 /* flags */);
if (file == NULL) { if (file == NULL) {
icon_to_load_free (icon); /* we didn't do anything long/hard */
/* we didn't do anything long/hard, so just do this again, if (long_operation != NULL)
* this is fun, don't go back to main loop */ *long_operation = FALSE;
goto load_icons_handler_again; return NULL;
} }
pb = NULL; pb = NULL;
loaded = FALSE; loaded = FALSE;
pixmap = NULL;
key = g_strdup_printf ("%d:%s", icon->size, file); key = g_strdup_printf ("%d:%s", size, file);
if (loaded_icons != NULL && if (loaded_icons != NULL &&
(pb = g_hash_table_lookup (loaded_icons, key)) != NULL) { (pb = g_hash_table_lookup (loaded_icons, key)) != NULL) {
...@@ -833,24 +818,19 @@ load_icons_handler_again: ...@@ -833,24 +818,19 @@ load_icons_handler_again:
if (pb == NULL) { if (pb == NULL) {
g_free (file); g_free (file);
g_free (key); g_free (key);
icon_to_load_free (icon); return NULL;
/* this may have been a long operation so jump back to
* the main loop for a while */
return TRUE;
} }
if (gdk_pixbuf_get_width (pb) != icon->size || if (loaded &&
gdk_pixbuf_get_height (pb) != icon->size) { (gdk_pixbuf_get_width (pb) != size ||
gdk_pixbuf_get_height (pb) != size)) {
GdkPixbuf *pb2; GdkPixbuf *pb2;
pb2 = gdk_pixbuf_scale_simple (pb, icon->size, icon->size, pb2 = gdk_pixbuf_scale_simple (pb, size, size,
GDK_INTERP_BILINEAR); GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pb)); g_object_unref (G_OBJECT (pb));
pb = pb2; pb = pb2;
} }
gtk_image_set_from_pixbuf (GTK_IMAGE (icon->pixmap), pb);
g_object_unref (G_OBJECT (pb));
if (loaded) { if (loaded) {
if (loaded_icons == NULL) if (loaded_icons == NULL)
loaded_icons = g_hash_table_new_full loaded_icons = g_hash_table_new_full
...@@ -864,19 +844,70 @@ load_icons_handler_again: ...@@ -864,19 +844,70 @@ load_icons_handler_again:
(GWeakNotify) remove_pixmap_from_loaded, (GWeakNotify) remove_pixmap_from_loaded,
g_strdup (key)); g_strdup (key));
} else { } else {
g_free (file); /* we didn't load from disk */
g_free (key); if (long_operation != NULL)
icon_to_load_free (icon); *long_operation = FALSE;
}
/* we didn't load from disk, so just do this again, g_free (file);
g_free (key);
return pb;
}
static gboolean
load_icons_handler (gpointer data)
{
GdkPixbuf *pb;
IconToLoad *icon;
gboolean long_operation;
load_icons_handler_again:
if (icons_to_load == NULL) {
load_icons_id = 0;
return FALSE;
}
icon = icons_to_load->data;
icons_to_load = g_list_remove (icons_to_load, icon);
/* if not visible anymore, just ignore */
if ( ! GTK_WIDGET_VISIBLE (icon->pixmap)) {
icon_to_load_free (icon);
/* we didn't do anything long/hard, so just do this again,
* this is fun, don't go back to main loop */ * this is fun, don't go back to main loop */
goto load_icons_handler_again; goto load_icons_handler_again;
} }
g_free (file); pb = panel_make_menu_icon (icon->image,
g_free (key); icon->fallback_image,
icon->size,
&long_operation);
if (pb == NULL) {
icon_to_load_free (icon);
if (long_operation) {
/* this may have been a long operation so jump back to
* the main loop for a while */
return TRUE;
} else {
/* we didn't do anything long/hard, so just do this again,
* this is fun, don't go back to main loop */
goto load_icons_handler_again;
}
}
gtk_image_set_from_pixbuf (GTK_IMAGE (icon->pixmap), pb);
g_object_unref (G_OBJECT (pb));
icon_to_load_free (icon); icon_to_load_free (icon);
if ( ! long_operation) {
/* we didn't do anything long/hard, so just do this again,
* this is fun, don't go back to main loop */
goto load_icons_handler_again;
}
/* if still more we'll come back */ /* if still more we'll come back */
return TRUE; return TRUE;
} }
......
...@@ -136,6 +136,11 @@ void panel_load_menu_image_deferred (GtkWidget *image_menu_item, ...@@ -136,6 +136,11 @@ void panel_load_menu_image_deferred (GtkWidget *image_menu_item,
/* Note, bind the following on 'show' or some such */ /* Note, bind the following on 'show' or some such */
void panel_make_sure_menu_within_screen (GtkMenu *menu); void panel_make_sure_menu_within_screen (GtkMenu *menu);
GdkPixbuf * panel_make_menu_icon (const char *icon,
const char *fallback,
int size,
gboolean *long_operation);
G_END_DECLS G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment