# HG changeset patch # User Justin Rodriguez # Date 1218182850 0 # Node ID f29e173320a7335059add88f26a578aae40d263b # Parent 2d419a0fc0e4b9888968a152e2ec5e0e1252cbd0 Add the icon theme files, and re-work some things diff -r 2d419a0fc0e4 -r f29e173320a7 pidgin/gtkicon-loader.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkicon-loader.c Fri Aug 08 08:07:30 2008 +0000 @@ -0,0 +1,127 @@ +/* + * PidginIconThemeLoader for Pidgin + * + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + */ + +#include "gtkicon-loader.h" +#include "gtkicon-theme.h" + +#include "xmlnode.h" + + +/****************************************************************************** + * Globals + *****************************************************************************/ +/***************************************************************************** + * Sound Theme Builder + *****************************************************************************/ + +static gpointer +pidgin_icon_loader_build(const gchar *dir) +{ + xmlnode *root_node, *sub_node; + gchar *filename, *filename_full, *data; + GDir *gdir; + PidginIconTheme *theme = NULL; + + /* Find the theme file */ + gdir = g_dir_open(dir, 0, NULL); + g_return_val_if_fail(gdir != NULL, NULL); + + while ((filename = g_strdup(g_dir_read_name(gdir))) != NULL && ! g_str_has_suffix(filename, ".xml")) + g_free(filename); + + g_return_val_if_fail(filename != NULL, NULL); + + /* Build the xml tree */ + filename_full = g_build_filename(dir, filename, NULL); + + root_node = xmlnode_from_file(dir, filename, "icon themes", "icon-loader"); + g_return_val_if_fail(root_node != NULL, NULL); + + /* Parse the tree */ + sub_node = xmlnode_get_child(root_node, "description"); + data = xmlnode_get_data(sub_node); + + if (xmlnode_get_attrib(root_node, "name") != NULL) { + theme = g_object_new(PIDGIN_TYPE_ICON_THEME, + "type", "icon", + "name", xmlnode_get_attrib(root_node, "name"), + "author", xmlnode_get_attrib(root_node, "author"), + "image", xmlnode_get_attrib(root_node, "image"), + "directory", dir, + "description", data, NULL); + + xmlnode_free(sub_node); + + while ((sub_node = xmlnode_get_child(root_node, "icon")) != NULL){ + pidgin_icon_theme_set_file(theme, + xmlnode_get_attrib(sub_node, "id"), + xmlnode_get_attrib(sub_node, "file")); + xmlnode_free(sub_node); + } + } + + xmlnode_free(root_node); + g_dir_close(gdir); + g_free(filename_full); + g_free(data); + return theme; +} + +/****************************************************************************** + * GObject Stuff + *****************************************************************************/ + +static void +pidgin_icon_theme_loader_class_init (PidginIconThemeLoaderClass *klass) +{ + PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass); + + loader_klass->purple_theme_loader_build = pidgin_icon_loader_build; +} + + +GType +pidgin_icon_theme_loader_get_type (void) +{ + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (PidginIconThemeLoaderClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)pidgin_icon_theme_loader_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PidginIconThemeLoader), + 0, /* n_preallocs */ + NULL, /* instance_init */ + NULL, /* value table */ + }; + type = g_type_register_static (PURPLE_TYPE_THEME_LOADER, + "PidginIconThemeLoader", + &info, 0); + } + return type; +} + + diff -r 2d419a0fc0e4 -r f29e173320a7 pidgin/gtkicon-loader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkicon-loader.h Fri Aug 08 08:07:30 2008 +0000 @@ -0,0 +1,71 @@ +/** + * @file gtkicon-loader.h Pidgin Icon Theme Loader Class API + */ + +/* purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#ifndef _PIDGIN_ICON_THEME_LOADER_H_ +#define _PIDGIN_ICON_THEME_LOADER_H_ + +#include +#include +#include "theme-loader.h" + +/** + * A pidgin icon theme loader. Extends PurpleThemeLoader (theme-loader.h) + * This is a class designed to build icon themes + * + * PidginIconThemeLoader is a GObject. + */ +typedef struct _PidginIconThemeLoader PidginIconThemeLoader; +typedef struct _PidginIconThemeLoaderClass PidginIconThemeLoaderClass; + +#define PIDGIN_TYPE_ICON_THEME_LOADER (pidgin_icon_theme_loader_get_type ()) +#define PIDGIN_ICON_THEME_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIDGIN_TYPE_ICON_THEME_LOADER, PidginIconThemeLoader)) +#define PIDGIN_ICON_THEME_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIDGIN_TYPE_ICON_THEME_LOADER, PidginIconThemeLoaderClass)) +#define PIDGIN_IS_ICON_THEME_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIDGIN_TYPE_ICON_THEME_LOADER)) +#define PIDGIN_IS_ICON_THEME_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIDGIN_TYPE_ICON_THEME_LOADER)) +#define PIDGIN_ICON_THEME_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIDGIN_TYPE_ICON_THEME_LOADER, PidginIconThemeLoaderClass)) + +struct _PidginIconThemeLoader +{ + PurpleThemeLoader parent; +}; + +struct _PidginIconThemeLoaderClass +{ + PurpleThemeLoaderClass parent_class; +}; + +/**************************************************************************/ +/** @name Pidgin Icon Theme-Loader API */ +/**************************************************************************/ +G_BEGIN_DECLS + +/** + * GObject foo. + * @internal. + */ +GType pidgin_icon_theme_loader_get_type(void); + +G_END_DECLS +#endif /* _PIDGIN_ICON_THEME_LOADER_H_ */ diff -r 2d419a0fc0e4 -r f29e173320a7 pidgin/gtkicon-theme.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkicon-theme.c Fri Aug 08 08:07:30 2008 +0000 @@ -0,0 +1,181 @@ +/* + * Icon Themes for Pidgin + * + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + */ + +#include "gtkicon-theme.h" +#include "pidginstock.h" + +#include + +#define PIDGIN_ICON_THEME_GET_PRIVATE(Gobject) \ + ((PidginIconThemePrivate *) ((PIDGIN_ICON_THEME(Gobject))->priv)) + + +/****************************************************************************** + * Structs + *****************************************************************************/ +typedef struct { + /* used to store filenames of diffrent icons */ + GHashTable *icon_files; +} PidginIconThemePrivate; + +/****************************************************************************** + * Globals + *****************************************************************************/ + +static GObjectClass *parent_class = NULL; + +static const GtkStockItem stock_icons[] = +{ + { PIDGIN_STOCK_TRAY_AVAILABLE, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_INVISIBLE, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_AWAY, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_BUSY, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_XA, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_OFFLINE, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_CONNECT, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_PENDING, "", 0, 0, NULL }, + { PIDGIN_STOCK_TRAY_EMAIL, "", 0, 0, NULL }, + + { PIDGIN_STOCK_STATUS_AVAILABLE, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_AVAILABLE_I, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_AWAY, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_AWAY_I, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_BUSY, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_BUSY_I, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_CHAT, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_INVISIBLE, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_XA, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_XA_I, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_LOGIN, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_LOGOUT, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_OFFLINE, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_OFFLINE_I, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_PERSON, "", 0, 0, NULL }, + { PIDGIN_STOCK_STATUS_MESSAGE, "", 0, 0, NULL } +}; + + + +/****************************************************************************** + * Enums + *****************************************************************************/ + +/****************************************************************************** + * GObject Stuff + *****************************************************************************/ + +static void +pidgin_icon_theme_init(GTypeInstance *instance, + gpointer klass) +{ + PidginIconThemePrivate *priv; + + (PIDGIN_ICON_THEME(instance))->priv = g_new0(PidginIconThemePrivate, 1); + + priv = PIDGIN_ICON_THEME_GET_PRIVATE(instance); + + priv->icon_files = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); +} + +static void +pidgin_icon_theme_finalize (GObject *obj) +{ + PidginIconThemePrivate *priv; + + priv = PIDGIN_ICON_THEME_GET_PRIVATE(obj); + + g_hash_table_destroy(priv->icon_files); + + parent_class->finalize (obj); +} + +static void +pidgin_icon_theme_class_init (PidginIconThemeClass *klass) +{ + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + + parent_class = g_type_class_peek_parent (klass); + + obj_class->finalize = pidgin_icon_theme_finalize; +} + +GType +pidgin_icon_theme_get_type (void) +{ + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (PidginIconThemeClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)pidgin_icon_theme_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PidginIconTheme), + 0, /* n_preallocs */ + pidgin_icon_theme_init, /* instance_init */ + NULL, /* value table */ + }; + type = g_type_register_static (PURPLE_TYPE_THEME, + "PidginIconTheme", + &info, 0 /*G_TYPE_FLAG_ABSTRACT*/); + } + return type; +} + + +/***************************************************************************** + * Public API functions + *****************************************************************************/ + +const gchar * +pidgin_icon_theme_get_file(PidginIconTheme *theme, + const gchar *id) +{ + PidginIconThemePrivate *priv; + + g_return_val_if_fail(PIDGIN_IS_ICON_THEME(theme), NULL); + + priv = PIDGIN_ICON_THEME_GET_PRIVATE(theme); + + return g_hash_table_lookup(priv->icon_files, id); +} + +void +pidgin_icon_theme_set_file(PidginIconTheme *theme, + const gchar *id, + const gchar *filename) +{ + PidginIconThemePrivate *priv; + g_return_if_fail(PIDGIN_IS_ICON_THEME(theme)); + + priv = PIDGIN_ICON_THEME_GET_PRIVATE(theme); + + if (filename != NULL)g_hash_table_replace(priv->icon_files, + g_strdup(id), + g_strdup(filename)); + else g_hash_table_remove(priv->icon_files, id); +} diff -r 2d419a0fc0e4 -r f29e173320a7 pidgin/gtkicon-theme.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/gtkicon-theme.h Fri Aug 08 08:07:30 2008 +0000 @@ -0,0 +1,92 @@ +/** + * @file icon-theme.h Pidgin Icon Theme Class API + */ + +/* pidgin + * + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#ifndef _PIDGIN_ICON_THEME_H_ +#define _PIDGIN_ICON_THEME_H_ + +#include +#include +#include "theme.h" + +/** + * extends PurpleTheme (theme.h) + * A pidgin icon theme. + * This object represents a Pidgin icon theme. + * + * PidginIconTheme is a PurpleTheme Object. + */ +typedef struct _PidginIconTheme PidginIconTheme; +typedef struct _PidginIconThemeClass PidginIconThemeClass; + +#define PIDGIN_TYPE_ICON_THEME (pidgin_icon_theme_get_type ()) +#define PIDGIN_ICON_THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIDGIN_TYPE_ICON_THEME, PidginIconTheme)) +#define PIDGIN_ICON_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIDGIN_TYPE_ICON_THEME, PidginIconThemeClass)) +#define PIDGIN_IS_ICON_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIDGIN_TYPE_ICON_THEME)) +#define PIDGIN_IS_ICON_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIDGIN_TYPE_ICON_THEME)) +#define PIDGIN_ICON_THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIDGIN_TYPE_ICON_THEME, PidginIconThemeClass)) + +struct _PidginIconTheme +{ + PurpleTheme parent; + gpointer priv; +}; + +struct _PidginIconThemeClass +{ + PurpleThemeClass parent_class; +}; + +/**************************************************************************/ +/** @name Pidgin Icon Theme API */ +/**************************************************************************/ +G_BEGIN_DECLS + +/** + * GObject foo. + * @internal. + */ +GType pidgin_icon_theme_get_type(void); + +/** + * Returns a copy of the filename for the icon event + * + * @param event the pidgin icon event to look up + * + * @returns the filename of the icon event + */ +const gchar *pidgin_icon_theme_get_file(PidginIconTheme *theme, + const gchar *event); +/** + * Sets the filename for a given icon id + * + * @param icon_id a string representing what the icon is to be used for + * @param filename the name of the file to be used for the given id + */ +void pidgin_icon_theme_set_file(PidginIconTheme *theme, + const gchar *icon_id, + const gchar *filename); + +G_END_DECLS +#endif /* _PIDGIN_ICON_THEME_H_ */ diff -r 2d419a0fc0e4 -r f29e173320a7 pidgin/pidginstock.c --- a/pidgin/pidginstock.c Fri Aug 08 01:42:46 2008 +0000 +++ b/pidgin/pidginstock.c Fri Aug 08 08:07:30 2008 +0000 @@ -225,55 +225,10 @@ return filename; } -static void -add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, const char *dir, - gboolean rtl, const char *size, const char *file) -{ - char *filename; - GtkIconSource *source; - - filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, file, NULL); - source = gtk_icon_source_new(); - gtk_icon_source_set_filename(source, filename); - gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR); - gtk_icon_source_set_direction_wildcarded(source, !rtl); - gtk_icon_source_set_size(source, sizeid); - gtk_icon_source_set_size_wildcarded(source, FALSE); - gtk_icon_source_set_state_wildcarded(source, TRUE); - gtk_icon_set_add_source(iconset, source); - gtk_icon_source_free(source); - - if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) { - source = gtk_icon_source_new(); - gtk_icon_source_set_filename(source, filename); - gtk_icon_source_set_direction_wildcarded(source, TRUE); - gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU); - gtk_icon_source_set_size_wildcarded(source, FALSE); - gtk_icon_source_set_state_wildcarded(source, TRUE); - gtk_icon_set_add_source(iconset, source); - gtk_icon_source_free(source); - } - g_free(filename); - - if (rtl) { - filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, "rtl", file, NULL); - source = gtk_icon_source_new(); - gtk_icon_source_set_filename(source, filename); - gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL); - gtk_icon_source_set_size(source, sizeid); - gtk_icon_source_set_size_wildcarded(source, FALSE); - gtk_icon_source_set_state_wildcarded(source, TRUE); - gtk_icon_set_add_source(iconset, source); - g_free(filename); - gtk_icon_source_free(source); - } - - -} /* Altered from do_colorshift in gnome-panel */ static void -do_alphashift (GdkPixbuf *dest, GdkPixbuf *src) +do_alphashift(GdkPixbuf *dest, GdkPixbuf *src) { gint i, j; gint width, height, has_alpha, srcrowstride, destrowstride; @@ -307,25 +262,49 @@ } } -/* TODO: This is almost certainly not the best way to do this, but it's late, I'm tired, - * we're a few hours from getting this thing out, and copy/paste is EASY. - */ +static gchar * +find_icon_file(PidginIconTheme *theme, const gchar *size, SizedStockIcon sized_icon, gboolean rtl) +{ + const gchar *file, *dir; + gchar *file_full = NULL; + + if (theme != NULL) { + file = pidgin_icon_theme_get_file(theme, sized_icon.name); + dir = purple_theme_get_dir(PURPLE_THEME(theme)); + + if (rtl) + file_full = g_build_filename(dir, size, "rtl", file, NULL); + else file_full = g_build_filename(dir, size, file, NULL); + + if (g_file_test(file_full, G_FILE_TEST_IS_REGULAR)) + return file_full; + + g_free(file_full); + } + + if (rtl) + return g_build_filename(DATADIR, "pixmaps", "pidgin", sized_icon.dir, size, sized_icon.filename, NULL); + else return g_build_filename(DATADIR, "pixmaps", "pidgin", sized_icon.dir, size, sized_icon.filename, NULL); +} + static void -add_translucent_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, const char *dir, - gboolean rtl, const char *size, const char *file) +add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme, + const char *size, SizedStockIcon sized_icon, gboolean translucent) { char *filename; GtkIconSource *source; GdkPixbuf *pixbuf; - filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, file, NULL); + filename = find_icon_file(theme, size, sized_icon, FALSE); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); - do_alphashift(pixbuf, pixbuf); source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(source, pixbuf); + if (translucent) { + do_alphashift(pixbuf, pixbuf); + gtk_icon_source_set_pixbuf(source, pixbuf); + } else gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR); - gtk_icon_source_set_direction_wildcarded(source, !rtl); + gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl); gtk_icon_source_set_size(source, sizeid); gtk_icon_source_set_size_wildcarded(source, FALSE); gtk_icon_source_set_state_wildcarded(source, TRUE); @@ -334,7 +313,9 @@ if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) { source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(source, pixbuf); + if (translucent) + gtk_icon_source_set_pixbuf(source, pixbuf); + else gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction_wildcarded(source, TRUE); gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU); gtk_icon_source_set_size_wildcarded(source, FALSE); @@ -345,12 +326,14 @@ g_free(filename); g_object_unref(pixbuf); - if (rtl) { - filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, "rtl", file, NULL); + if (sized_icon.rtl) { + filename = find_icon_file(theme, size, sized_icon, TRUE); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); - do_alphashift(pixbuf, pixbuf); source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(source, pixbuf); + if (translucent) { + do_alphashift(pixbuf, pixbuf); + gtk_icon_source_set_pixbuf(source, pixbuf); + } else gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL); gtk_icon_source_set_size(source, sizeid); gtk_icon_source_set_size_wildcarded(source, FALSE); @@ -362,33 +345,6 @@ } } -static void -build_sized_icon_sets(GtkIconSet *normal, GtkIconSet *translucent, SizedStockIcon icon, - GtkIconSize size, PidginIconTheme *theme, const gchar *pix) -{ - const gchar *file, *dir; - gchar *file_full; - gboolean use_theme; - - if ((use_theme = theme != NULL)) { - file = pidgin_icon_theme_get_file(theme, icon.name); - dir = purple_theme_get_dir(PURPLE_THEME(theme)); - - file_full = g_build_filename(dir, pix, file, NULL); - use_theme = g_file_test(file_full, G_FILE_TEST_IS_REGULAR); - g_free(file_full); - } - - if (!use_theme) { - file = icon.filename; - dir = icon.dir; - } - - add_sized_icon(normal, size, dir, icon.rtl, pix, file); - if (translucent != NULL) - add_translucent_sized_icon(translucent, size, dir, icon.rtl, pix, file); -} - /***************************************************************************** * Public API functions *****************************************************************************/ @@ -417,23 +373,24 @@ if (sized_status_icons[i].translucent_name) translucent = gtk_icon_set_new(); - if (sized_status_icons[i].microscopic) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], microscopic, theme, "11"); - if (sized_status_icons[i].extra_small) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], extra_small, theme, "16"); - if (sized_status_icons[i].small) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], small, theme, "22"); - if (sized_status_icons[i].medium) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], medium, theme, "32"); - if (sized_status_icons[i].large) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], large, theme, "48"); - if (sized_status_icons[i].huge) - build_sized_icon_sets(normal, translucent, sized_status_icons[i], huge, theme, "64"); +#define ADD_SIZED_ICON(name, size) if (sized_status_icons[i].name) { \ + add_sized_icon(normal, name, theme, size, sized_status_icons[i], FALSE); \ + if (sized_status_icons[i].translucent_name) \ + add_sized_icon(normal, name, theme, size, sized_status_icons[i], TRUE); \ + } + ADD_SIZED_ICON(microscopic, "11"); + ADD_SIZED_ICON(extra_small, "16"); + ADD_SIZED_ICON(small, "22"); + ADD_SIZED_ICON(medium, "32"); + ADD_SIZED_ICON(large, "48"); + ADD_SIZED_ICON(huge, "64"); +#undef ADD_SIZED_ICON gtk_icon_factory_add(icon_factory, sized_status_icons[i].name, normal); gtk_icon_set_unref(normal); if (sized_status_icons[i].translucent_name) { + gtk_icon_factory_add(icon_factory, sized_status_icons[i].translucent_name, translucent); gtk_icon_set_unref(translucent); } @@ -469,6 +426,7 @@ win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_realize(win); + /* All non-sized icons */ for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { GtkIconSource *source; @@ -515,24 +473,20 @@ large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48); huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64); + /* All non-status sized icons */ for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) { - GtkIconSet *iconset; - - iconset = gtk_icon_set_new(); + GtkIconSet *iconset = gtk_icon_set_new(); - if (sized_stock_icons[i].microscopic) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], microscopic, NULL, "11"); - if (sized_stock_icons[i].extra_small) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], extra_small, NULL, "16"); - if (sized_stock_icons[i].small) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], small, NULL, "22"); - if (sized_stock_icons[i].medium) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], medium, NULL, "32"); - if (sized_stock_icons[i].large) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], large, NULL, "48"); - if (sized_stock_icons[i].huge) - build_sized_icon_sets(iconset, NULL, sized_stock_icons[i], huge, NULL, "64"); +#define ADD_SIZED_ICON(name, size) if (sized_stock_icons[i].name) \ + add_sized_icon(iconset, name, NULL, size, sized_stock_icons[i], FALSE); + ADD_SIZED_ICON(microscopic, "11"); + ADD_SIZED_ICON(extra_small, "16"); + ADD_SIZED_ICON(small, "22"); + ADD_SIZED_ICON(medium, "32"); + ADD_SIZED_ICON(large, "48"); + ADD_SIZED_ICON(huge, "64"); +#undef ADD_SIZED_ICON gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); gtk_icon_set_unref(iconset);