Merged pidgin/main into default
[pidgin-git.git] / pidgin / pidginstock.c
blob15a680dfa99494dfffc89ae3e1ff1935e17479f1
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 /**************************************************************************
32 * Globals
33 **************************************************************************/
35 static gboolean stock_initted = FALSE;
36 static GtkIconSize microscopic, extra_small, small, medium, large, huge;
38 /**************************************************************************
39 * Structures
40 **************************************************************************/
42 static struct StockIcon
44 const char *name;
45 const char *dir;
46 const char *filename;
48 } const stock_icons[] = {
50 { PIDGIN_STOCK_ACTION, NULL, GTK_STOCK_EXECUTE },
51 { PIDGIN_STOCK_ALIAS, NULL, GTK_STOCK_EDIT },
52 { PIDGIN_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO },
53 { PIDGIN_STOCK_CLEAR, NULL, GTK_STOCK_CLEAR },
54 { PIDGIN_STOCK_CLOSE_TABS, NULL, GTK_STOCK_CLOSE },
55 { PIDGIN_STOCK_DEBUG, NULL, GTK_STOCK_PROPERTIES },
56 { PIDGIN_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN },
57 { PIDGIN_STOCK_DISCONNECT, NULL, GTK_STOCK_DISCONNECT },
58 { PIDGIN_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" },
59 { PIDGIN_STOCK_EDIT, NULL, GTK_STOCK_EDIT },
60 { PIDGIN_STOCK_FILE_CANCELLED, NULL, GTK_STOCK_CANCEL },
61 { PIDGIN_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY },
62 { PIDGIN_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR },
63 { PIDGIN_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO },
64 { PIDGIN_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES },
65 { PIDGIN_STOCK_ADD, NULL, GTK_STOCK_ADD },
66 { PIDGIN_STOCK_PAUSE, NULL, GTK_STOCK_MEDIA_PAUSE },
67 { PIDGIN_STOCK_POUNCE, NULL, GTK_STOCK_REDO },
68 { PIDGIN_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO },
69 { PIDGIN_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE },
70 { PIDGIN_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE },
71 { PIDGIN_STOCK_TYPED, "pidgin", "typed.png" },
72 { PIDGIN_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP },
73 { PIDGIN_STOCK_INFO, NULL, GTK_STOCK_INFO },
74 { PIDGIN_STOCK_NEXT, NULL, GTK_STOCK_GO_FORWARD },
77 static const GtkStockItem stock_items[] =
79 { PIDGIN_STOCK_ALIAS, N_("_Alias"), 0, 0, PACKAGE },
80 { PIDGIN_STOCK_CHAT, N_("_Join"), 0, 0, PACKAGE },
81 { PIDGIN_STOCK_CLOSE_TABS, N_("Close _tabs"), 0, 0, PACKAGE },
82 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, N_("I_M"), 0, 0, PACKAGE },
83 { PIDGIN_STOCK_TOOLBAR_USER_INFO, N_("_Get Info"), 0, 0, PACKAGE },
84 { PIDGIN_STOCK_INVITE, N_("_Invite"), 0, 0, PACKAGE },
85 { PIDGIN_STOCK_MODIFY, N_("_Modify..."), 0, 0, PACKAGE },
86 { PIDGIN_STOCK_ADD, N_("_Add..."), 0, 0, PACKAGE },
87 { PIDGIN_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, PACKAGE },
88 { PIDGIN_STOCK_PAUSE, N_("_Pause"), 0, 0, PACKAGE },
89 { PIDGIN_STOCK_EDIT, N_("_Edit"), 0, 0, PACKAGE },
90 { PIDGIN_STOCK_NEXT, N_("_Next"), 0, 0, PACKAGE },
93 typedef struct {
94 const char *name;
95 const char *dir;
96 const char *filename;
97 gboolean microscopic;
98 gboolean extra_small;
99 gboolean small;
100 gboolean medium;
101 gboolean large;
102 gboolean huge;
103 gboolean rtl;
104 const char *translucent_name;
105 } SizedStockIcon;
107 const SizedStockIcon sized_stock_icons [] = {
109 { PIDGIN_STOCK_STATUS_IGNORED, "emblems", "blocked.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
110 { PIDGIN_STOCK_STATUS_FOUNDER, "emblems", "founder.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
111 { PIDGIN_STOCK_STATUS_OPERATOR, "emblems", "operator.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
112 { PIDGIN_STOCK_STATUS_HALFOP, "emblems", "half-operator.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
113 { PIDGIN_STOCK_STATUS_VOICE, "emblems", "voice.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
115 { PIDGIN_STOCK_DIALOG_AUTH, "dialogs", "auth.png", FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
116 { PIDGIN_STOCK_DIALOG_COOL, "dialogs", "cool.png", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
117 { PIDGIN_STOCK_DIALOG_ERROR, "dialogs", "error.png", FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
118 { PIDGIN_STOCK_DIALOG_INFO, "dialogs", "info.png", FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
119 { PIDGIN_STOCK_DIALOG_MAIL, "dialogs", "mail.png", FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
120 { PIDGIN_STOCK_DIALOG_QUESTION, "dialogs", "question.png", FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
121 { PIDGIN_STOCK_DIALOG_WARNING, "dialogs", "warning.png", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, NULL },
123 { PIDGIN_STOCK_ANIMATION_CONNECT0, "animations", "process-working0.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
124 { PIDGIN_STOCK_ANIMATION_CONNECT1, "animations", "process-working1.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
125 { PIDGIN_STOCK_ANIMATION_CONNECT2, "animations", "process-working2.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
126 { PIDGIN_STOCK_ANIMATION_CONNECT3, "animations", "process-working3.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
127 { PIDGIN_STOCK_ANIMATION_CONNECT4, "animations", "process-working4.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
128 { PIDGIN_STOCK_ANIMATION_CONNECT5, "animations", "process-working5.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
129 { PIDGIN_STOCK_ANIMATION_CONNECT6, "animations", "process-working6.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
130 { PIDGIN_STOCK_ANIMATION_CONNECT7, "animations", "process-working7.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
131 { PIDGIN_STOCK_ANIMATION_CONNECT8, "animations", "process-working8.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
132 { PIDGIN_STOCK_ANIMATION_CONNECT9, "animations", "process-working9.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
133 { PIDGIN_STOCK_ANIMATION_CONNECT10, "animations", "process-working10.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
134 { PIDGIN_STOCK_ANIMATION_CONNECT11, "animations", "process-working11.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
135 { PIDGIN_STOCK_ANIMATION_CONNECT12, "animations", "process-working12.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
136 { PIDGIN_STOCK_ANIMATION_CONNECT13, "animations", "process-working13.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
137 { PIDGIN_STOCK_ANIMATION_CONNECT14, "animations", "process-working14.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
138 { PIDGIN_STOCK_ANIMATION_CONNECT15, "animations", "process-working15.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
139 { PIDGIN_STOCK_ANIMATION_CONNECT16, "animations", "process-working16.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
140 { PIDGIN_STOCK_ANIMATION_CONNECT17, "animations", "process-working17.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
141 { PIDGIN_STOCK_ANIMATION_CONNECT18, "animations", "process-working18.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
142 { PIDGIN_STOCK_ANIMATION_CONNECT19, "animations", "process-working19.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
143 { PIDGIN_STOCK_ANIMATION_CONNECT20, "animations", "process-working20.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
144 { PIDGIN_STOCK_ANIMATION_CONNECT21, "animations", "process-working21.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
145 { PIDGIN_STOCK_ANIMATION_CONNECT22, "animations", "process-working22.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
146 { PIDGIN_STOCK_ANIMATION_CONNECT23, "animations", "process-working23.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
147 { PIDGIN_STOCK_ANIMATION_CONNECT24, "animations", "process-working24.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
148 { PIDGIN_STOCK_ANIMATION_CONNECT25, "animations", "process-working25.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
149 { PIDGIN_STOCK_ANIMATION_CONNECT26, "animations", "process-working26.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
150 { PIDGIN_STOCK_ANIMATION_CONNECT27, "animations", "process-working27.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
151 { PIDGIN_STOCK_ANIMATION_CONNECT28, "animations", "process-working28.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
152 { PIDGIN_STOCK_ANIMATION_CONNECT29, "animations", "process-working29.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
153 { PIDGIN_STOCK_ANIMATION_CONNECT30, "animations", "process-working30.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
155 { PIDGIN_STOCK_ANIMATION_TYPING0, "animations", "typing0.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
156 { PIDGIN_STOCK_ANIMATION_TYPING1, "animations", "typing1.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
157 { PIDGIN_STOCK_ANIMATION_TYPING2, "animations", "typing2.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
158 { PIDGIN_STOCK_ANIMATION_TYPING3, "animations", "typing3.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
159 { PIDGIN_STOCK_ANIMATION_TYPING4, "animations", "typing4.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
160 { PIDGIN_STOCK_ANIMATION_TYPING5, "animations", "typing5.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
162 { PIDGIN_STOCK_TOOLBAR_BGCOLOR, "toolbar", "change-bgcolor.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
163 { PIDGIN_STOCK_TOOLBAR_BLOCK, "emblems", "blocked.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
164 { PIDGIN_STOCK_TOOLBAR_FGCOLOR, "toolbar", "change-fgcolor.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
165 { PIDGIN_STOCK_TOOLBAR_SMILEY, "toolbar", "emote-select.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
166 { PIDGIN_STOCK_TOOLBAR_FONT_FACE, "toolbar", "font-face.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
167 { PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER, "toolbar", "font-size-down.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
168 { PIDGIN_STOCK_TOOLBAR_TEXT_LARGER, "toolbar", "font-size-up.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
169 { PIDGIN_STOCK_TOOLBAR_INSERT, "toolbar", "insert.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
170 { PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, "toolbar", "insert-image.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
171 { PIDGIN_STOCK_TOOLBAR_INSERT_SCREENSHOT, "toolbar", "insert-screenshot.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
172 { PIDGIN_STOCK_TOOLBAR_INSERT_LINK, "toolbar", "insert-link.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
173 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, "toolbar", "message-new.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
174 { PIDGIN_STOCK_TOOLBAR_PENDING, "toolbar", "message-new.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
175 { PIDGIN_STOCK_TOOLBAR_PLUGINS, "toolbar", "plugins.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
176 { PIDGIN_STOCK_TOOLBAR_UNBLOCK, "toolbar", "unblock.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
177 { PIDGIN_STOCK_TOOLBAR_SELECT_AVATAR, "toolbar", "select-avatar.png", FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, NULL },
178 { PIDGIN_STOCK_TOOLBAR_SEND_FILE, "toolbar", "send-file.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
179 { PIDGIN_STOCK_TOOLBAR_TRANSFER, "toolbar", "transfer.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
180 #ifdef USE_VV
181 { PIDGIN_STOCK_TOOLBAR_AUDIO_CALL, "toolbar", "audio-call.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
182 { PIDGIN_STOCK_TOOLBAR_VIDEO_CALL, "toolbar", "video-call.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
183 { PIDGIN_STOCK_TOOLBAR_AUDIO_VIDEO_CALL, "toolbar", "audio-video-call.png", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
184 #endif
185 { PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, "toolbar", "get-attention.png", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL }
188 const SizedStockIcon sized_status_icons [] = {
190 { PIDGIN_STOCK_STATUS_AVAILABLE, "status", "available.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_AVAILABLE_I },
191 { PIDGIN_STOCK_STATUS_AWAY, "status", "away.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_AWAY_I },
192 { PIDGIN_STOCK_STATUS_BUSY, "status", "busy.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_BUSY_I },
193 { PIDGIN_STOCK_STATUS_CHAT, "status", "chat.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
194 { PIDGIN_STOCK_STATUS_INVISIBLE, "status", "invisible.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
195 { PIDGIN_STOCK_STATUS_XA, "status", "extended-away.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, PIDGIN_STOCK_STATUS_XA_I },
196 { PIDGIN_STOCK_STATUS_LOGIN, "status", "log-in.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
197 { PIDGIN_STOCK_STATUS_LOGOUT, "status", "log-out.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
198 { PIDGIN_STOCK_STATUS_OFFLINE, "status", "offline.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_OFFLINE_I },
199 { PIDGIN_STOCK_STATUS_PERSON, "status", "person.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
200 { PIDGIN_STOCK_STATUS_MESSAGE, "toolbar", "message-new.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL }
203 const SizedStockIcon sized_tray_icons [] = {
204 #define SIZED_TRAY_ICON(name) \
205 { name, "tray/hicolor", "status/" name ".png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL }
206 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_AVAILABLE ),
207 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_INVISIBLE ),
208 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_AWAY ),
209 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_BUSY ),
210 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_XA ),
211 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_OFFLINE ),
212 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_CONNECT ),
213 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_PENDING ),
214 SIZED_TRAY_ICON( PIDGIN_STOCK_TRAY_EMAIL )
215 #undef SIZED_TRAY_ICON
218 /*****************************************************************************
219 * Private functions
220 *****************************************************************************/
222 static gchar *
223 find_file_common(const char *name)
225 gchar *filename;
226 const gchar *userdir;
227 const gchar * const *sysdirs;
229 userdir = g_get_user_data_dir();
230 filename = g_build_filename(userdir, name, NULL);
231 if (g_file_test(filename, G_FILE_TEST_EXISTS))
232 return filename;
233 g_free(filename);
235 sysdirs = g_get_system_data_dirs();
236 for (; *sysdirs; sysdirs++) {
237 filename = g_build_filename(*sysdirs, name, NULL);
238 if (g_file_test(filename, G_FILE_TEST_EXISTS))
239 return filename;
240 g_free(filename);
242 filename = g_build_filename(PURPLE_DATADIR, name, NULL);
243 if (g_file_test(filename, G_FILE_TEST_EXISTS))
244 return filename;
245 g_free(filename);
246 return NULL;
249 static gchar *
250 find_file(const char *dir, const char *base)
252 char *filename;
253 char *ret;
255 if (base == NULL)
256 return NULL;
258 if (!strcmp(dir, "pidgin"))
259 filename = g_build_filename("pixmaps", "pidgin", base, NULL);
260 else
261 filename = g_build_filename("pixmaps", "pidgin", dir, base, NULL);
263 ret = find_file_common(filename);
264 g_free(filename);
265 return ret;
269 /* Altered from do_colorshift in gnome-panel */
270 static void
271 do_alphashift(GdkPixbuf *pixbuf)
273 gint i, j;
274 gint width, height, padding;
275 guchar *pixels;
276 guchar a;
278 if (!gdk_pixbuf_get_has_alpha(pixbuf))
279 return;
281 width = gdk_pixbuf_get_width(pixbuf);
282 height = gdk_pixbuf_get_height(pixbuf);
283 padding = gdk_pixbuf_get_rowstride(pixbuf) - width * 4;
284 pixels = gdk_pixbuf_get_pixels(pixbuf);
286 for (i = 0; i < height; i++) {
287 for (j = 0; j < width; j++) {
288 pixels++;
289 pixels++;
290 pixels++;
291 a = *(pixels);
292 *(pixels++) = a / 2;
294 pixels += padding;
298 static gchar *
299 find_icon_file(PidginIconTheme *theme, const gchar *size, SizedStockIcon sized_icon, gboolean rtl)
301 const gchar *file, *dir;
302 gchar *file_full = NULL;
303 gchar *tmp;
305 if (theme != NULL) {
306 file = pidgin_icon_theme_get_icon(PIDGIN_ICON_THEME(theme), sized_icon.name);
307 dir = purple_theme_get_dir(PURPLE_THEME(theme));
309 if (rtl)
310 file_full = g_build_filename(dir, size, "rtl", file, NULL);
311 else
312 file_full = g_build_filename(dir, size, file, NULL);
314 if (g_file_test(file_full, G_FILE_TEST_IS_REGULAR))
315 return file_full;
317 g_free(file_full);
320 if (rtl)
321 tmp = g_build_filename("pixmaps", "pidgin", sized_icon.dir, size, "rtl", sized_icon.filename, NULL);
322 else
323 tmp = g_build_filename("pixmaps", "pidgin", sized_icon.dir, size, sized_icon.filename, NULL);
325 file_full = find_file_common(tmp);
326 g_free(tmp);
327 return file_full;
330 static void
331 add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme,
332 const char *size, SizedStockIcon sized_icon, gboolean translucent)
334 char *filename;
335 GtkIconSource *source;
336 GdkPixbuf *pixbuf;
338 filename = find_icon_file(theme, size, sized_icon, FALSE);
339 g_return_if_fail(filename != NULL);
340 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
341 if (translucent)
342 do_alphashift(pixbuf);
344 source = gtk_icon_source_new();
345 gtk_icon_source_set_pixbuf(source, pixbuf);
346 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR);
347 gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl);
348 gtk_icon_source_set_size(source, sizeid);
349 gtk_icon_source_set_size_wildcarded(source, FALSE);
350 gtk_icon_source_set_state_wildcarded(source, TRUE);
351 gtk_icon_set_add_source(iconset, source);
352 gtk_icon_source_free(source);
354 if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) {
355 source = gtk_icon_source_new();
356 gtk_icon_source_set_pixbuf(source, pixbuf);
357 gtk_icon_source_set_direction_wildcarded(source, TRUE);
358 gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);
359 gtk_icon_source_set_size_wildcarded(source, FALSE);
360 gtk_icon_source_set_state_wildcarded(source, TRUE);
361 gtk_icon_set_add_source(iconset, source);
362 gtk_icon_source_free(source);
364 g_free(filename);
365 g_object_unref(pixbuf);
367 if (sized_icon.rtl) {
368 filename = find_icon_file(theme, size, sized_icon, TRUE);
369 g_return_if_fail(filename != NULL);
370 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
371 if (translucent)
372 do_alphashift(pixbuf);
374 source = gtk_icon_source_new();
375 gtk_icon_source_set_pixbuf(source, pixbuf);
376 gtk_icon_source_set_filename(source, filename);
377 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL);
378 gtk_icon_source_set_size(source, sizeid);
379 gtk_icon_source_set_size_wildcarded(source, FALSE);
380 gtk_icon_source_set_state_wildcarded(source, TRUE);
381 gtk_icon_set_add_source(iconset, source);
382 g_free(filename);
383 g_object_unref(pixbuf);
384 gtk_icon_source_free(source);
388 static void
389 reload_settings(void)
391 gtk_style_context_reset_widgets(gdk_screen_get_default());
394 /*****************************************************************************
395 * Public API functions
396 *****************************************************************************/
398 void
399 pidgin_stock_load_status_icon_theme(PidginStatusIconTheme *theme)
401 GtkIconFactory *icon_factory;
402 gsize i;
403 GtkIconSet *normal;
404 GtkIconSet *translucent = NULL;
405 GtkWidget *win;
407 if (theme != NULL) {
408 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme",
409 purple_theme_get_name(PURPLE_THEME(theme)));
410 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir",
411 purple_theme_get_dir(PURPLE_THEME(theme)));
413 else {
414 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
415 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
418 icon_factory = gtk_icon_factory_new();
420 gtk_icon_factory_add_default(icon_factory);
422 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
423 gtk_widget_realize(win);
425 for (i = 0; i < G_N_ELEMENTS(sized_status_icons); i++)
427 normal = gtk_icon_set_new();
428 if (sized_status_icons[i].translucent_name)
429 translucent = gtk_icon_set_new();
431 #define ADD_SIZED_ICON(name, size) \
432 if (sized_status_icons[i].name) { \
433 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE); \
434 if (sized_status_icons[i].translucent_name) \
435 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE); \
437 ADD_SIZED_ICON(microscopic, "11");
438 ADD_SIZED_ICON(extra_small, "16");
439 ADD_SIZED_ICON(small, "22");
440 ADD_SIZED_ICON(medium, "32");
441 ADD_SIZED_ICON(large, "48");
442 ADD_SIZED_ICON(huge, "64");
443 #undef ADD_SIZED_ICON
445 gtk_icon_factory_add(icon_factory, sized_status_icons[i].name, normal);
446 gtk_icon_set_unref(normal);
448 if (sized_status_icons[i].translucent_name) {
449 gtk_icon_factory_add(icon_factory, sized_status_icons[i].translucent_name, translucent);
450 gtk_icon_set_unref(translucent);
454 for (i = 0; i < G_N_ELEMENTS(sized_tray_icons); i++)
456 normal = gtk_icon_set_new();
457 if (sized_tray_icons[i].translucent_name)
458 translucent = gtk_icon_set_new();
460 #define ADD_SIZED_ICON(name, size) \
461 if (sized_tray_icons[i].name) { \
462 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], FALSE); \
463 if (sized_tray_icons[i].translucent_name) \
464 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], TRUE); \
466 ADD_SIZED_ICON(extra_small, "16x16");
467 ADD_SIZED_ICON(small, "22x22");
468 ADD_SIZED_ICON(medium, "32x32");
469 ADD_SIZED_ICON(large, "48x48");
470 #undef ADD_SIZED_ICON
472 gtk_icon_factory_add(icon_factory, sized_tray_icons[i].name, normal);
473 gtk_icon_set_unref(normal);
475 if (sized_tray_icons[i].translucent_name) {
476 gtk_icon_factory_add(icon_factory, sized_tray_icons[i].translucent_name, translucent);
477 gtk_icon_set_unref(translucent);
481 gtk_widget_destroy(win);
482 g_object_unref(G_OBJECT(icon_factory));
483 reload_settings();
486 void
487 pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme)
489 GtkIconFactory *icon_factory;
490 gsize i;
491 GtkWidget *win;
493 if (theme != NULL) {
494 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme",
495 purple_theme_get_name(PURPLE_THEME(theme)));
496 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir",
497 purple_theme_get_dir(PURPLE_THEME(theme)));
499 else {
500 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
501 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
504 icon_factory = gtk_icon_factory_new();
506 gtk_icon_factory_add_default(icon_factory);
508 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
509 gtk_widget_realize(win);
511 /* All non-sized icons */
512 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) {
513 GtkIconSource *source;
514 GtkIconSet *iconset;
515 gchar *filename;
517 if (stock_icons[i].dir == NULL) {
518 /* GTK+ Stock icon */
519 iconset = gtk_style_context_lookup_icon_set(gtk_widget_get_style_context(win),
520 stock_icons[i].filename);
521 } else {
522 filename = find_file(stock_icons[i].dir, stock_icons[i].filename);
524 if (filename == NULL)
525 continue;
527 source = gtk_icon_source_new();
528 gtk_icon_source_set_filename(source, filename);
529 gtk_icon_source_set_direction_wildcarded(source, TRUE);
530 gtk_icon_source_set_size_wildcarded(source, TRUE);
531 gtk_icon_source_set_state_wildcarded(source, TRUE);
533 iconset = gtk_icon_set_new();
534 gtk_icon_set_add_source(iconset, source);
536 gtk_icon_source_free(source);
537 g_free(filename);
540 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);
542 gtk_icon_set_unref(iconset);
545 /* All non-status sized icons */
546 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++)
548 GtkIconSet *iconset = gtk_icon_set_new();
550 #define ADD_SIZED_ICON(name, size) \
551 if (sized_stock_icons[i].name) \
552 add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE);
553 ADD_SIZED_ICON(microscopic, "11");
554 ADD_SIZED_ICON(extra_small, "16");
555 ADD_SIZED_ICON(small, "22");
556 ADD_SIZED_ICON(medium, "32");
557 ADD_SIZED_ICON(large, "48");
558 ADD_SIZED_ICON(huge, "64");
559 #undef ADD_SIZED_ICON
561 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset);
562 gtk_icon_set_unref(iconset);
565 gtk_widget_destroy(win);
566 g_object_unref(G_OBJECT(icon_factory));
567 reload_settings();
570 void
571 pidgin_stock_init(void)
573 PidginIconThemeLoader *loader, *stockloader;
574 const gchar *path = NULL;
576 if (stock_initted)
577 return;
579 stock_initted = TRUE;
581 /* Setup the status icon theme */
582 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL);
583 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader));
584 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/status");
585 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
586 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
588 stockloader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "stock-icon", NULL);
589 purple_theme_manager_register_type(PURPLE_THEME_LOADER(stockloader));
590 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/stock");
591 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
592 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
594 /* register custom icon sizes */
595 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11);
596 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16);
597 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22);
598 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32);
599 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48);
600 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64);
602 pidgin_stock_load_stock_icon_theme(NULL);
604 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/
605 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/status/icon-theme") &&
606 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) {
608 PidginStatusIconTheme *theme = PIDGIN_STATUS_ICON_THEME(purple_theme_loader_build(PURPLE_THEME_LOADER(loader), path));
609 pidgin_stock_load_status_icon_theme(theme);
610 if (theme)
611 g_object_unref(G_OBJECT(theme));
614 else
615 pidgin_stock_load_status_icon_theme(NULL);
617 /* Register the stock items. */
618 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items));
621 static void
622 pidgin_stock_icon_theme_class_init(PidginStockIconThemeClass *klass)
626 GType
627 pidgin_stock_icon_theme_get_type(void)
629 static GType type = 0;
630 if (type == 0) {
631 static const GTypeInfo info = {
632 sizeof (PidginStockIconThemeClass),
633 NULL, /* base_init */
634 NULL, /* base_finalize */
635 (GClassInitFunc)pidgin_stock_icon_theme_class_init, /* class_init */
636 NULL, /* class_finalize */
637 NULL, /* class_data */
638 sizeof (PidginStockIconTheme),
639 0, /* n_preallocs */
640 NULL,
641 NULL, /* value table */
643 type = g_type_register_static(PIDGIN_TYPE_ICON_THEME,
644 "PidginStockIconTheme", &info, 0);
646 return type;