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>
* menu-fentry.c: sure_string the fullname before making a collation
......
......@@ -20,6 +20,7 @@
#include "logout.h"
#include "menu-properties.h"
#include "menu-util.h"
#include "menu.h"
#include "panel-config.h"
#include "panel-gconf.h"
#include "panel-config-global.h"
......@@ -521,36 +522,24 @@ applet_setup_panel_menu (gboolean is_basep)
{
GtkWidget *menuitem;
GtkWidget *panel_menu;
gchar *pixmap_path;
GdkPixbuf *pixbuf;
menuitem = gtk_image_menu_item_new ();
pixmap_path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP,
"gnome-panel.png", TRUE, NULL);
if (pixmap_path) {
GdkPixbuf *pixbuf, *scaled_pixbuf = NULL;
pixbuf = panel_make_menu_icon ("gnome-panel.png",
NULL /* fallback */,
SMALL_ICON_SIZE /* size */,
NULL /* long_operation */);
if (pixbuf != NULL) {
GtkWidget *image = NULL;
pixbuf = gdk_pixbuf_new_from_file (pixmap_path, NULL);
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);
}
image = gtk_image_new_from_pixbuf (pixbuf);
g_object_unref (pixbuf);
setup_menuitem (menuitem,
image,
_("Panel"));
g_free (pixmap_path);
} else {
g_message (_("Cannot find pixmap file %s"), "gnome-panel.png");
......
......@@ -5,6 +5,7 @@
#include <gtk/gtk.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnome/gnome-desktop-item.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "button-widget.h"
#include "panel-widget.h"
......@@ -287,14 +288,14 @@ loadup_file(const char *file)
if (string_empty (file))
return NULL;
if (!g_path_is_absolute (file)) {
char *f;
if ( ! g_path_is_absolute (file)) {
char *full = gnome_desktop_item_find_icon (file,
48 /* desired size */,
0 /* flags */);
f = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP,
file, TRUE, NULL);
if (f) {
pb = gdk_pixbuf_new_from_file (f, NULL);
g_free (f);
if (full != NULL) {
pb = gdk_pixbuf_new_from_file (full, NULL);
g_free (full);
}
} else {
pb = gdk_pixbuf_new_from_file (file, NULL);
......
......@@ -666,25 +666,12 @@ get_default_image (void)
static GdkPixbuf *pixbuf = NULL;
static gboolean looked = FALSE;
if (! looked) {
GdkPixbuf *pb = NULL, *scaled = NULL;
char *name = panel_pixmap_discovery ("gnome-tasklist.png", FALSE /* fallback */);
if (name == NULL)
/* evil fallback huh? */
name = panel_pixmap_discovery ("apple-red.png", FALSE /* fallback */);
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;
}
if ( ! looked) {
pixbuf = panel_make_menu_icon ("gnome-tasklist.png",
/* evil fallback huh? */
"apple-red.png",
20 /* size */,
NULL /* long_operation */);
looked = TRUE;
}
......
......@@ -774,31 +774,13 @@ fill_list (GtkWidget *list)
GtkTreeIter iter;
FileRec *fr;
GdkPixbuf *pixbuf;
char *icon;
fr = tmp->data;
icon = gnome_desktop_item_find_icon (fr->icon,
ICON_SIZE /* desired size */,
0 /* flags */);
if (icon != NULL) {
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;
}
pixbuf = panel_make_menu_icon (fr->icon,
NULL /* fallback */,
ICON_SIZE,
NULL /* long_operation */);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
......
......@@ -789,7 +789,7 @@ ditem_set_icon (GnomeDesktopItem *ditem, const char *icon)
if (icon != NULL &&
icon[0] != G_DIR_SEPARATOR) {
char *full = gnome_desktop_item_find_icon (icon,
20 /* desired size */,
48 /* desired size */,
0 /* flags */);
if (full != NULL) {
gnome_desktop_item_set_string (ditem,
......
......@@ -768,54 +768,39 @@ remove_pixmap_from_loaded (gpointer data, GObject *where_the_object_was)
g_free (key);
}
static gboolean
load_icons_handler (gpointer data)
GdkPixbuf *
panel_make_menu_icon (const char *icon,
const char *fallback,
int size,
gboolean *long_operation)
{
GtkImage *pixmap;
GdkPixbuf *pb;
IconToLoad *icon;
char *file, *key;
gboolean loaded;
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 */
goto load_icons_handler_again;
}
if (long_operation != NULL)
*long_operation = TRUE;
file = gnome_desktop_item_find_icon (icon->image,
icon->size /* desired size */,
file = gnome_desktop_item_find_icon (icon,
size /* desired size */,
0 /* flags */);
if (file == NULL)
file = gnome_desktop_item_find_icon (icon->fallback_image,
icon->size /* desired size */,
if (file == NULL && fallback != NULL)
file = gnome_desktop_item_find_icon (fallback,
size /* desired size */,
0 /* flags */);
if (file == NULL) {
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;
/* we didn't do anything long/hard */
if (long_operation != NULL)
*long_operation = FALSE;
return NULL;
}
pb = NULL;
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 &&
(pb = g_hash_table_lookup (loaded_icons, key)) != NULL) {
......@@ -833,24 +818,19 @@ load_icons_handler_again:
if (pb == NULL) {
g_free (file);
g_free (key);
icon_to_load_free (icon);
/* this may have been a long operation so jump back to
* the main loop for a while */
return TRUE;
return NULL;
}
if (gdk_pixbuf_get_width (pb) != icon->size ||
gdk_pixbuf_get_height (pb) != icon->size) {
if (loaded &&
(gdk_pixbuf_get_width (pb) != size ||
gdk_pixbuf_get_height (pb) != size)) {
GdkPixbuf *pb2;
pb2 = gdk_pixbuf_scale_simple (pb, icon->size, icon->size,
pb2 = gdk_pixbuf_scale_simple (pb, size, size,
GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (pb));
pb = pb2;
}
gtk_image_set_from_pixbuf (GTK_IMAGE (icon->pixmap), pb);
g_object_unref (G_OBJECT (pb));
if (loaded) {
if (loaded_icons == NULL)
loaded_icons = g_hash_table_new_full
......@@ -864,19 +844,70 @@ load_icons_handler_again:
(GWeakNotify) remove_pixmap_from_loaded,
g_strdup (key));
} else {
g_free (file);
g_free (key);
icon_to_load_free (icon);
/* we didn't load from disk */
if (long_operation != NULL)
*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 */
goto load_icons_handler_again;
}
g_free (file);
g_free (key);
pb = panel_make_menu_icon (icon->image,
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);
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 */
return TRUE;
}
......
......@@ -136,6 +136,11 @@ void panel_load_menu_image_deferred (GtkWidget *image_menu_item,
/* Note, bind the following on 'show' or some such */
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
......
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