Mercurial > pidgin.yaz
changeset 4250:3b884e35e6b5
[gaim-migrate @ 4500]
The docklet now uses an icon factory. Thanks Robot101.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 08 Jan 2003 08:22:16 +0000 |
parents | 9c7fcb211886 |
children | f68c4203d001 |
files | plugins/docklet/docklet.c |
diffstat | 1 files changed, 47 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/docklet/docklet.c Wed Jan 08 08:18:49 2003 +0000 +++ b/plugins/docklet/docklet.c Wed Jan 08 08:22:16 2003 +0000 @@ -57,6 +57,8 @@ static EggTrayIcon *docklet = NULL; static GtkWidget *icon; static enum docklet_status status; +static GtkIconFactory *icon_factory = NULL; +static GtkIconSize icon_size; static void docklet_toggle_mute(GtkWidget *toggle, void *data) { mute_sounds = GTK_CHECK_MENU_ITEM(toggle)->active; @@ -186,48 +188,35 @@ } } -static void docklet_update_icon() { - gchar *filename = NULL; - GdkPixbuf *unscaled; +static void docklet_update_icon() +{ + const gchar *icon_name = NULL; switch (status) { case offline: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "offline.png", NULL); + icon_name = "gaim-docklet-offline"; break; case offline_connecting: case online_connecting: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "connect.png", NULL); + icon_name = "gaim-docklet-connect"; break; case online: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "online.png", NULL); + icon_name = "gaim-docklet-online"; break; case online_pending: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "msgunread.png", NULL); + icon_name = "gaim-docklet-msgunread"; break; case away: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "away.png", NULL); + icon_name = "gaim-docklet-away"; break; case away_pending: - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "msgpend.png", NULL); + icon_name = "gaim-docklet-msgpend"; break; } - unscaled = gdk_pixbuf_new_from_file(filename, NULL); - - if (unscaled) { - GdkPixbuf *scaled; + gtk_image_set_from_stock(GTK_IMAGE(icon), icon_name, icon_size); - scaled = gdk_pixbuf_scale_simple(unscaled, 24, 24, GDK_INTERP_BILINEAR); - gtk_image_set_from_pixbuf(GTK_IMAGE(icon), scaled); - g_object_unref(unscaled); - g_object_unref(scaled); - - debug_printf("Tray Icon: updated icon to %s\n",filename); - } else { - debug_printf("Tray Icon: failed to load icon from %s\n",filename); - } - - g_free(filename); + debug_printf("Tray Icon: updated icon to '%s'\n",icon_name); } static gboolean docklet_update_status() { @@ -356,7 +345,39 @@ static void gaim_new_conversation(char *who, void *data) { } */ +static void docklet_register_icon(const char *name, char *fn) { + gchar *filename; + + filename = g_build_filename(DATADIR, "pixmaps", "gaim", fn, NULL); + gtk_icon_factory_add(icon_factory, name, + gtk_icon_set_new_from_pixbuf(gdk_pixbuf_new_from_file(filename, NULL))); + g_free(filename); +} + +static void docklet_register_icon_factory() { + icon_factory = gtk_icon_factory_new(); + + docklet_register_icon("gaim-docklet-offline", "offline.png"); + docklet_register_icon("gaim-docklet-connect", "connect.png"); + docklet_register_icon("gaim-docklet-online", "online.png"); + docklet_register_icon("gaim-docklet-msgunread", "msgunread.png"); + docklet_register_icon("gaim-docklet-away", "away.png"); + docklet_register_icon("gaim-docklet-msgpend", "msgpend.png"); + + gtk_icon_factory_add_default(icon_factory); + + icon_size = gtk_icon_size_register("gaim-docklet-size", 24, 24); +} + +static void docklet_unregister_icon_factory() { + /* does this actually free anything? it's a moot point seeing as + unloading the docklet crashes gaim, but it needs to be checked */ + gtk_icon_factory_remove_default(icon_factory); +} + char *gaim_plugin_init(GModule *handle) { + docklet_register_icon_factory(); + docklet_create(NULL); gaim_signal_connect(handle, event_signon, gaim_signon, NULL); @@ -385,6 +406,8 @@ g_object_unref(G_OBJECT(docklet)); docklet = NULL; + + docklet_unregister_icon_factory(); debug_printf("Tray Icon: removed\n"); }