finch: Mark unused variable.
[pidgin-git.git] / pidgin / pidginstock.c
blob6038ecdd9f73b1367afebb0ddbb2bee3f5eedb4c
1 /* pidgin
3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "internal.h"
23 #include "pidgin.h"
24 #include "prefs.h"
26 #include "gtkicon-theme-loader.h"
27 #include "theme-manager.h"
29 #include "pidginstock.h"
31 #warning GtkStock is deprecated. Port usage of PidginStock to GtkIconTheme \
32 and friends.
34 /**************************************************************************
35 * Globals
36 **************************************************************************/
38 static gboolean stock_initted = FALSE;
39 static GtkIconSize microscopic, extra_small, small, medium, large, huge;
41 /**************************************************************************
42 * Structures
43 **************************************************************************/
45 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
46 static struct StockIcon
48 const char *name;
49 const char *dir;
50 const char *filename;
52 } const stock_icons[] = {
54 { PIDGIN_STOCK_ACTION, NULL, GTK_STOCK_EXECUTE },
55 { PIDGIN_STOCK_ALIAS, NULL, GTK_STOCK_EDIT },
56 { PIDGIN_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO },
57 { PIDGIN_STOCK_CLEAR, NULL, GTK_STOCK_CLEAR },
58 { PIDGIN_STOCK_CLOSE_TABS, NULL, GTK_STOCK_CLOSE },
59 { PIDGIN_STOCK_DEBUG, NULL, GTK_STOCK_PROPERTIES },
60 { PIDGIN_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN },
61 { PIDGIN_STOCK_DISCONNECT, NULL, GTK_STOCK_DISCONNECT },
62 { PIDGIN_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" },
63 { PIDGIN_STOCK_EDIT, NULL, GTK_STOCK_EDIT },
64 { PIDGIN_STOCK_FILE_CANCELLED, NULL, GTK_STOCK_CANCEL },
65 { PIDGIN_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY },
66 { PIDGIN_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR },
67 { PIDGIN_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO },
68 { PIDGIN_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES },
69 { PIDGIN_STOCK_ADD, NULL, GTK_STOCK_ADD },
70 { PIDGIN_STOCK_PAUSE, NULL, GTK_STOCK_MEDIA_PAUSE },
71 { PIDGIN_STOCK_POUNCE, NULL, GTK_STOCK_REDO },
72 { PIDGIN_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO },
73 { PIDGIN_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE },
74 { PIDGIN_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE },
75 { PIDGIN_STOCK_TYPED, "pidgin", "typed.png" },
76 { PIDGIN_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP },
77 { PIDGIN_STOCK_INFO, NULL, GTK_STOCK_INFO },
78 { PIDGIN_STOCK_NEXT, NULL, GTK_STOCK_GO_FORWARD },
80 G_GNUC_END_IGNORE_DEPRECATIONS
82 static const GtkStockItem stock_items[] =
84 { PIDGIN_STOCK_ALIAS, N_("_Alias"), 0, 0, PACKAGE },
85 { PIDGIN_STOCK_CHAT, N_("_Join"), 0, 0, PACKAGE },
86 { PIDGIN_STOCK_CLOSE_TABS, N_("Close _tabs"), 0, 0, PACKAGE },
87 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, N_("I_M"), 0, 0, PACKAGE },
88 { PIDGIN_STOCK_TOOLBAR_USER_INFO, N_("_Get Info"), 0, 0, PACKAGE },
89 { PIDGIN_STOCK_INVITE, N_("_Invite"), 0, 0, PACKAGE },
90 { PIDGIN_STOCK_MODIFY, N_("_Modify..."), 0, 0, PACKAGE },
91 { PIDGIN_STOCK_ADD, N_("_Add..."), 0, 0, PACKAGE },
92 { PIDGIN_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, PACKAGE },
93 { PIDGIN_STOCK_PAUSE, N_("_Pause"), 0, 0, PACKAGE },
94 { PIDGIN_STOCK_EDIT, N_("_Edit"), 0, 0, PACKAGE },
95 { PIDGIN_STOCK_NEXT, N_("_Next"), 0, 0, PACKAGE },
98 typedef struct {
99 const char *name;
100 const char *dir;
101 const char *filename;
102 gboolean microscopic;
103 gboolean extra_small;
104 gboolean small;
105 gboolean medium;
106 gboolean large;
107 gboolean huge;
108 gboolean rtl;
109 const char *translucent_name;
110 } SizedStockIcon;
112 const SizedStockIcon sized_stock_icons [] = {
114 { PIDGIN_STOCK_STATUS_IGNORED, "emblems", "emblem-blocked.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
115 { PIDGIN_STOCK_STATUS_FOUNDER, "emblems", "emblem-founder.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
116 { PIDGIN_STOCK_STATUS_OPERATOR, "emblems", "emblem-operator.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
117 { PIDGIN_STOCK_STATUS_HALFOP, "emblems", "emblem-half-operator.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
118 { PIDGIN_STOCK_STATUS_VOICE, "emblems", "emblem-voice.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
120 { PIDGIN_STOCK_ANIMATION_CONNECT0, "animations", "process-working0.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
121 { PIDGIN_STOCK_ANIMATION_CONNECT1, "animations", "process-working1.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
122 { PIDGIN_STOCK_ANIMATION_CONNECT2, "animations", "process-working2.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
123 { PIDGIN_STOCK_ANIMATION_CONNECT3, "animations", "process-working3.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
124 { PIDGIN_STOCK_ANIMATION_CONNECT4, "animations", "process-working4.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
125 { PIDGIN_STOCK_ANIMATION_CONNECT5, "animations", "process-working5.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
126 { PIDGIN_STOCK_ANIMATION_CONNECT6, "animations", "process-working6.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
127 { PIDGIN_STOCK_ANIMATION_CONNECT7, "animations", "process-working7.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
128 { PIDGIN_STOCK_ANIMATION_CONNECT8, "animations", "process-working8.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
129 { PIDGIN_STOCK_ANIMATION_CONNECT9, "animations", "process-working9.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
130 { PIDGIN_STOCK_ANIMATION_CONNECT10, "animations", "process-working10.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
131 { PIDGIN_STOCK_ANIMATION_CONNECT11, "animations", "process-working11.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
132 { PIDGIN_STOCK_ANIMATION_CONNECT12, "animations", "process-working12.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
133 { PIDGIN_STOCK_ANIMATION_CONNECT13, "animations", "process-working13.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
134 { PIDGIN_STOCK_ANIMATION_CONNECT14, "animations", "process-working14.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
135 { PIDGIN_STOCK_ANIMATION_CONNECT15, "animations", "process-working15.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
136 { PIDGIN_STOCK_ANIMATION_CONNECT16, "animations", "process-working16.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
137 { PIDGIN_STOCK_ANIMATION_CONNECT17, "animations", "process-working17.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
138 { PIDGIN_STOCK_ANIMATION_CONNECT18, "animations", "process-working18.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
139 { PIDGIN_STOCK_ANIMATION_CONNECT19, "animations", "process-working19.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
140 { PIDGIN_STOCK_ANIMATION_CONNECT20, "animations", "process-working20.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
141 { PIDGIN_STOCK_ANIMATION_CONNECT21, "animations", "process-working21.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
142 { PIDGIN_STOCK_ANIMATION_CONNECT22, "animations", "process-working22.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
143 { PIDGIN_STOCK_ANIMATION_CONNECT23, "animations", "process-working23.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
144 { PIDGIN_STOCK_ANIMATION_CONNECT24, "animations", "process-working24.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
145 { PIDGIN_STOCK_ANIMATION_CONNECT25, "animations", "process-working25.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
146 { PIDGIN_STOCK_ANIMATION_CONNECT26, "animations", "process-working26.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
147 { PIDGIN_STOCK_ANIMATION_CONNECT27, "animations", "process-working27.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
148 { PIDGIN_STOCK_ANIMATION_CONNECT28, "animations", "process-working28.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
149 { PIDGIN_STOCK_ANIMATION_CONNECT29, "animations", "process-working29.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
150 { PIDGIN_STOCK_ANIMATION_CONNECT30, "animations", "process-working30.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
152 { PIDGIN_STOCK_ANIMATION_TYPING0, "animations", "typing0.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
153 { PIDGIN_STOCK_ANIMATION_TYPING1, "animations", "typing1.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
154 { PIDGIN_STOCK_ANIMATION_TYPING2, "animations", "typing2.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
155 { PIDGIN_STOCK_ANIMATION_TYPING3, "animations", "typing3.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
156 { PIDGIN_STOCK_ANIMATION_TYPING4, "animations", "typing4.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
157 { PIDGIN_STOCK_ANIMATION_TYPING5, "animations", "typing5.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
159 { PIDGIN_STOCK_TOOLBAR_BGCOLOR, "actions", "change-bgcolor.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
160 { PIDGIN_STOCK_TOOLBAR_BLOCK, "emblems", "emblem-blocked.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
161 { PIDGIN_STOCK_TOOLBAR_FGCOLOR, "actions", "change-fgcolor.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
162 { PIDGIN_STOCK_TOOLBAR_SMILEY, "actions", "emote-select.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
163 { PIDGIN_STOCK_TOOLBAR_FONT_FACE, "actions", "font-face.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
164 { PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER, "actions", "font-size-down.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
165 { PIDGIN_STOCK_TOOLBAR_TEXT_LARGER, "actions", "font-size-up.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
166 { PIDGIN_STOCK_TOOLBAR_INSERT, "actions", "insert.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
167 { PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, "actions", "insert-image.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
168 { PIDGIN_STOCK_TOOLBAR_INSERT_SCREENSHOT, "actions", "insert-screenshot.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
169 { PIDGIN_STOCK_TOOLBAR_INSERT_LINK, "actions", "insert-link.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
170 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, "actions", "message-new.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
171 { PIDGIN_STOCK_TOOLBAR_PENDING, "actions", "message-new.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
172 { PIDGIN_STOCK_TOOLBAR_PLUGINS, "actions", "plugins.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
173 { PIDGIN_STOCK_TOOLBAR_UNBLOCK, "actions", "unblock.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
174 { PIDGIN_STOCK_TOOLBAR_SELECT_AVATAR, "actions", "select-avatar.png", FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, NULL },
175 { PIDGIN_STOCK_TOOLBAR_SEND_FILE, "actions", "send-file.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
176 { PIDGIN_STOCK_TOOLBAR_TRANSFER, "actions", "transfer.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
177 #ifdef USE_VV
178 { PIDGIN_STOCK_TOOLBAR_AUDIO_CALL, "actions", "audio-call.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
179 { PIDGIN_STOCK_TOOLBAR_VIDEO_CALL, "actions", "video-call.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
180 { PIDGIN_STOCK_TOOLBAR_AUDIO_VIDEO_CALL, "actions", "audio-video-call.png", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
181 #endif
182 { PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, "actions", "get-attention.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL }
185 const SizedStockIcon sized_status_icons [] = {
187 { PIDGIN_STOCK_STATUS_AVAILABLE, "status", "user-available.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_AVAILABLE_I },
188 { PIDGIN_STOCK_STATUS_AWAY, "status", "user-away.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_AWAY_I },
189 { PIDGIN_STOCK_STATUS_BUSY, "status", "user-busy.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_BUSY_I },
190 { PIDGIN_STOCK_STATUS_CHAT, "status", "chat.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
191 { PIDGIN_STOCK_STATUS_INVISIBLE, "status", "user-invisible.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
192 { PIDGIN_STOCK_STATUS_XA, "status", "user-extended-away.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, PIDGIN_STOCK_STATUS_XA_I },
193 { PIDGIN_STOCK_STATUS_LOGIN, "status", "log-in.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
194 { PIDGIN_STOCK_STATUS_LOGOUT, "status", "log-out.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
195 { PIDGIN_STOCK_STATUS_OFFLINE, "status", "user-offline.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_OFFLINE_I },
196 { PIDGIN_STOCK_STATUS_PERSON, "status", "person.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
197 { PIDGIN_STOCK_STATUS_MESSAGE, "actions", "message-new.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL }
200 const SizedStockIcon sized_tray_icons [] = {
201 #define SIZED_TRAY_ICON(name) \
202 { name, "status", name ".png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL }
203 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_AVAILABLE ),
204 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_INVISIBLE ),
205 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_AWAY ),
206 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_BUSY ),
207 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_XA ),
208 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_OFFLINE ),
209 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_CONNECT ),
210 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_PENDING ),
211 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_EMAIL )
212 #undef SIZED_TRAY_ICON
215 /*****************************************************************************
216 * Private functions
217 *****************************************************************************/
219 static gchar *
220 find_file_common(const char *name)
222 gchar *filename;
223 const gchar *userdir;
224 const gchar * const *sysdirs;
226 userdir = g_get_user_data_dir();
227 filename = g_build_filename(userdir, name, NULL);
228 if (g_file_test(filename, G_FILE_TEST_EXISTS))
229 return filename;
230 g_free(filename);
232 sysdirs = g_get_system_data_dirs();
233 for (; *sysdirs; sysdirs++) {
234 filename = g_build_filename(*sysdirs, name, NULL);
235 if (g_file_test(filename, G_FILE_TEST_EXISTS))
236 return filename;
237 g_free(filename);
239 filename = g_build_filename(PURPLE_DATADIR, name, NULL);
240 if (g_file_test(filename, G_FILE_TEST_EXISTS))
241 return filename;
242 g_free(filename);
243 return NULL;
246 static gchar *
247 find_file(const char *dir, const char *base)
249 char *filename;
250 char *ret;
252 if (base == NULL)
253 return NULL;
255 if (purple_strequal(dir, "pidgin"))
256 filename = g_build_filename("pixmaps", "pidgin", base, NULL);
257 else
258 filename = g_build_filename("pixmaps", "pidgin", dir, base, NULL);
260 ret = find_file_common(filename);
261 g_free(filename);
262 return ret;
266 /* Altered from do_colorshift in gnome-panel */
267 static void
268 do_alphashift(GdkPixbuf *pixbuf)
270 gint i, j;
271 gint width, height, padding;
272 guchar *pixels;
273 guchar a;
275 if (!gdk_pixbuf_get_has_alpha(pixbuf))
276 return;
278 width = gdk_pixbuf_get_width(pixbuf);
279 height = gdk_pixbuf_get_height(pixbuf);
280 padding = gdk_pixbuf_get_rowstride(pixbuf) - width * 4;
281 pixels = gdk_pixbuf_get_pixels(pixbuf);
283 for (i = 0; i < height; i++) {
284 for (j = 0; j < width; j++) {
285 pixels++;
286 pixels++;
287 pixels++;
288 a = *(pixels);
289 *(pixels++) = a / 2;
291 pixels += padding;
295 static gchar *
296 find_icon_file(PidginIconTheme *theme, const gchar *size, SizedStockIcon sized_icon, gboolean rtl)
298 const gchar *file, *dir;
299 gchar *file_full = NULL;
300 gchar *tmp;
302 if (theme != NULL) {
303 file = pidgin_icon_theme_get_icon(PIDGIN_ICON_THEME(theme), sized_icon.name);
304 dir = purple_theme_get_dir(PURPLE_THEME(theme));
306 if (rtl)
307 file_full = g_build_filename(dir, size, "rtl", file, NULL);
308 else
309 file_full = g_build_filename(dir, size, file, NULL);
311 if (g_file_test(file_full, G_FILE_TEST_IS_REGULAR))
312 return file_full;
314 g_free(file_full);
317 if (rtl)
318 tmp = g_build_filename("pixmaps", "pidgin", sized_icon.dir, size, "rtl", sized_icon.filename, NULL);
319 else
320 tmp = g_build_filename("pixmaps", "pidgin", sized_icon.dir, size, sized_icon.filename, NULL);
322 file_full = find_file_common(tmp);
323 g_free(tmp);
325 if (file_full == NULL) {
326 gchar *size_dir = g_strdup_printf("%sx%s", size, size);
328 if (rtl)
329 tmp = g_build_filename("pidgin", "icons", "hicolor",
330 size_dir, sized_icon.dir, "rtl",
331 sized_icon.filename, NULL);
332 else
333 tmp = g_build_filename("pidgin", "icons", "hicolor",
334 size_dir, sized_icon.dir,
335 sized_icon.filename, NULL);
336 g_free(size_dir);
338 file_full = find_file_common(tmp);
339 g_free(tmp);
342 return file_full;
345 static void
346 add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme,
347 const char *size, SizedStockIcon sized_icon, gboolean translucent)
349 char *filename;
350 GtkIconSource *source;
351 GdkPixbuf *pixbuf;
353 filename = find_icon_file(theme, size, sized_icon, FALSE);
354 g_return_if_fail(filename != NULL);
355 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
356 if (translucent)
357 do_alphashift(pixbuf);
359 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
360 source = gtk_icon_source_new();
361 gtk_icon_source_set_pixbuf(source, pixbuf);
362 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR);
363 gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl);
364 gtk_icon_source_set_size(source, sizeid);
365 gtk_icon_source_set_size_wildcarded(source, FALSE);
366 gtk_icon_source_set_state_wildcarded(source, TRUE);
367 gtk_icon_set_add_source(iconset, source);
368 gtk_icon_source_free(source);
370 if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) {
371 source = gtk_icon_source_new();
372 gtk_icon_source_set_pixbuf(source, pixbuf);
373 gtk_icon_source_set_direction_wildcarded(source, TRUE);
374 gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);
375 gtk_icon_source_set_size_wildcarded(source, FALSE);
376 gtk_icon_source_set_state_wildcarded(source, TRUE);
377 gtk_icon_set_add_source(iconset, source);
378 gtk_icon_source_free(source);
380 g_free(filename);
381 g_object_unref(pixbuf);
383 if (sized_icon.rtl) {
384 filename = find_icon_file(theme, size, sized_icon, TRUE);
385 g_return_if_fail(filename != NULL);
386 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
387 if (translucent)
388 do_alphashift(pixbuf);
390 source = gtk_icon_source_new();
391 gtk_icon_source_set_pixbuf(source, pixbuf);
392 gtk_icon_source_set_filename(source, filename);
393 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL);
394 gtk_icon_source_set_size(source, sizeid);
395 gtk_icon_source_set_size_wildcarded(source, FALSE);
396 gtk_icon_source_set_state_wildcarded(source, TRUE);
397 gtk_icon_set_add_source(iconset, source);
398 g_free(filename);
399 g_object_unref(pixbuf);
400 gtk_icon_source_free(source);
402 G_GNUC_END_IGNORE_DEPRECATIONS
405 static void
406 reload_settings(void)
408 gtk_style_context_reset_widgets(gdk_screen_get_default());
411 /*****************************************************************************
412 * Public API functions
413 *****************************************************************************/
415 void
416 pidgin_stock_load_status_icon_theme(PidginStatusIconTheme *theme)
418 GtkIconFactory *icon_factory;
419 gsize i;
420 GtkIconSet *normal;
421 GtkIconSet *translucent = NULL;
422 GtkWidget *win;
424 if (theme != NULL) {
425 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme",
426 purple_theme_get_name(PURPLE_THEME(theme)));
427 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir",
428 purple_theme_get_dir(PURPLE_THEME(theme)));
430 else {
431 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
432 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
435 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
436 icon_factory = gtk_icon_factory_new();
438 gtk_icon_factory_add_default(icon_factory);
439 G_GNUC_END_IGNORE_DEPRECATIONS
441 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
442 gtk_widget_realize(win);
444 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
445 for (i = 0; i < G_N_ELEMENTS(sized_status_icons); i++)
447 normal = gtk_icon_set_new();
448 if (sized_status_icons[i].translucent_name)
449 translucent = gtk_icon_set_new();
451 #define ADD_SIZED_ICON(name, size) \
452 if (sized_status_icons[i].name) { \
453 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE); \
454 if (sized_status_icons[i].translucent_name) \
455 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE); \
457 ADD_SIZED_ICON(microscopic, "11");
458 ADD_SIZED_ICON(extra_small, "16");
459 ADD_SIZED_ICON(small, "22");
460 ADD_SIZED_ICON(medium, "32");
461 ADD_SIZED_ICON(large, "48");
462 ADD_SIZED_ICON(huge, "64");
463 #undef ADD_SIZED_ICON
465 gtk_icon_factory_add(icon_factory, sized_status_icons[i].name, normal);
466 gtk_icon_set_unref(normal);
468 if (sized_status_icons[i].translucent_name) {
469 gtk_icon_factory_add(icon_factory, sized_status_icons[i].translucent_name, translucent);
470 gtk_icon_set_unref(translucent);
474 for (i = 0; i < G_N_ELEMENTS(sized_tray_icons); i++)
476 normal = gtk_icon_set_new();
477 if (sized_tray_icons[i].translucent_name)
478 translucent = gtk_icon_set_new();
480 #define ADD_SIZED_ICON(name, size) \
481 if (sized_tray_icons[i].name) { \
482 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], FALSE); \
483 if (sized_tray_icons[i].translucent_name) \
484 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], TRUE); \
486 ADD_SIZED_ICON(extra_small, "16");
487 ADD_SIZED_ICON(small, "22");
488 ADD_SIZED_ICON(medium, "32");
489 ADD_SIZED_ICON(large, "48");
490 #undef ADD_SIZED_ICON
492 gtk_icon_factory_add(icon_factory, sized_tray_icons[i].name, normal);
493 gtk_icon_set_unref(normal);
495 if (sized_tray_icons[i].translucent_name) {
496 gtk_icon_factory_add(icon_factory, sized_tray_icons[i].translucent_name, translucent);
497 gtk_icon_set_unref(translucent);
500 G_GNUC_END_IGNORE_DEPRECATIONS
502 gtk_widget_destroy(win);
503 g_object_unref(G_OBJECT(icon_factory));
504 reload_settings();
507 void
508 pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme)
510 GtkIconFactory *icon_factory;
511 gsize i;
512 GtkWidget *win;
514 if (theme != NULL) {
515 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme",
516 purple_theme_get_name(PURPLE_THEME(theme)));
517 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir",
518 purple_theme_get_dir(PURPLE_THEME(theme)));
520 else {
521 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
522 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
525 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
526 icon_factory = gtk_icon_factory_new();
528 gtk_icon_factory_add_default(icon_factory);
529 G_GNUC_END_IGNORE_DEPRECATIONS
531 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
532 gtk_widget_realize(win);
534 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
535 /* All non-sized icons */
536 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) {
537 GtkIconSource *source;
538 GtkIconSet *iconset;
539 gchar *filename;
541 if (stock_icons[i].dir == NULL) {
542 /* GTK+ Stock icon */
543 iconset = gtk_style_context_lookup_icon_set(gtk_widget_get_style_context(win),
544 stock_icons[i].filename);
545 } else {
546 filename = find_file(stock_icons[i].dir, stock_icons[i].filename);
548 if (filename == NULL)
549 continue;
551 source = gtk_icon_source_new();
552 gtk_icon_source_set_filename(source, filename);
553 gtk_icon_source_set_direction_wildcarded(source, TRUE);
554 gtk_icon_source_set_size_wildcarded(source, TRUE);
555 gtk_icon_source_set_state_wildcarded(source, TRUE);
557 iconset = gtk_icon_set_new();
558 gtk_icon_set_add_source(iconset, source);
560 gtk_icon_source_free(source);
561 g_free(filename);
564 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);
566 gtk_icon_set_unref(iconset);
569 /* All non-status sized icons */
570 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++)
572 GtkIconSet *iconset = gtk_icon_set_new();
574 #define ADD_SIZED_ICON(name, size) \
575 if (sized_stock_icons[i].name) \
576 add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE);
577 ADD_SIZED_ICON(microscopic, "11");
578 ADD_SIZED_ICON(extra_small, "16");
579 ADD_SIZED_ICON(small, "22");
580 ADD_SIZED_ICON(medium, "32");
581 ADD_SIZED_ICON(large, "48");
582 ADD_SIZED_ICON(huge, "64");
583 #undef ADD_SIZED_ICON
585 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset);
586 gtk_icon_set_unref(iconset);
588 G_GNUC_END_IGNORE_DEPRECATIONS
590 gtk_widget_destroy(win);
591 g_object_unref(G_OBJECT(icon_factory));
592 reload_settings();
595 void
596 pidgin_stock_init(void)
598 PidginIconThemeLoader *loader, *stockloader;
599 const gchar *path = NULL;
601 if (stock_initted)
602 return;
604 stock_initted = TRUE;
606 /* Setup the status icon theme */
607 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL);
608 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader));
609 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/status");
610 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
611 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
613 stockloader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "stock-icon", NULL);
614 purple_theme_manager_register_type(PURPLE_THEME_LOADER(stockloader));
615 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/stock");
616 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
617 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
619 /* register custom icon sizes */
620 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
621 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11);
622 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16);
623 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22);
624 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32);
625 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48);
626 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64);
627 G_GNUC_END_IGNORE_DEPRECATIONS
629 pidgin_stock_load_stock_icon_theme(NULL);
631 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/
632 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/status/icon-theme") &&
633 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) {
635 PidginStatusIconTheme *theme = PIDGIN_STATUS_ICON_THEME(purple_theme_loader_build(PURPLE_THEME_LOADER(loader), path));
636 pidgin_stock_load_status_icon_theme(theme);
637 if (theme)
638 g_object_unref(G_OBJECT(theme));
641 else
642 pidgin_stock_load_status_icon_theme(NULL);
644 /* Register the stock items. */
645 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
646 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items));
647 G_GNUC_END_IGNORE_DEPRECATIONS
650 static void
651 pidgin_stock_icon_theme_class_init(PidginStockIconThemeClass *klass)
655 GType
656 pidgin_stock_icon_theme_get_type(void)
658 static GType type = 0;
659 if (type == 0) {
660 static const GTypeInfo info = {
661 sizeof (PidginStockIconThemeClass),
662 NULL, /* base_init */
663 NULL, /* base_finalize */
664 (GClassInitFunc)pidgin_stock_icon_theme_class_init, /* class_init */
665 NULL, /* class_finalize */
666 NULL, /* class_data */
667 sizeof (PidginStockIconTheme),
668 0, /* n_preallocs */
669 NULL,
670 NULL, /* value table */
672 type = g_type_register_static(PIDGIN_TYPE_ICON_THEME,
673 "PidginStockIconTheme", &info, 0);
675 return type;