pidgin/pidginstock.c

changeset 15883
969b74a3e27a
parent 15834
ba09306a7b0a
child 15884
4de1981757fc
child 15889
8997bafe667b
equal deleted inserted replaced
15882:1dbd5756b7bf 15883:969b74a3e27a
1 /**
2 * @file gaimstock.c GTK+ Stock resources
3 * @ingroup gtkui
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26 #include "internal.h"
27 #include "pidgin.h"
28
29 #include "pidginstock.h"
30
31 static struct StockIcon
32 {
33 const char *name;
34 const char *dir;
35 const char *filename;
36
37 } const stock_icons[] =
38 {
39 { PIDGIN_STOCK_ABOUT, "buttons", "about_menu.png" },
40 { PIDGIN_STOCK_ACTION, NULL, GTK_STOCK_EXECUTE },
41 #if GTK_CHECK_VERSION(2,6,0)
42 { PIDGIN_STOCK_ALIAS, NULL, GTK_STOCK_EDIT },
43 #else
44 { PIDGIN_STOCK_ALIAS, "buttons", "edit.png" },
45 #endif
46 { PIDGIN_STOCK_BLOCK, NULL, GTK_STOCK_STOP },
47 { PIDGIN_STOCK_UNBLOCK, NULL, GTK_STOCK_STOP /* XXX: */ },
48 { PIDGIN_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO },
49 { PIDGIN_STOCK_CLEAR, NULL, GTK_STOCK_CLEAR },
50 { PIDGIN_STOCK_CLOSE_TABS, NULL, GTK_STOCK_CLOSE },
51 #if GTK_CHECK_VERSION(2,6,0)
52 { PIDGIN_STOCK_CONNECT, NULL, GTK_STOCK_CONNECT },
53 #else
54 { PIDGIN_STOCK_CONNECT, "icons", "stock_connect_16.png" },
55 #endif
56 { PIDGIN_STOCK_DEBUG, NULL, GTK_STOCK_PROPERTIES },
57 { PIDGIN_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN },
58 #if GTK_CHECK_VERSION(2,6,0)
59 { PIDGIN_STOCK_DISCONNECT, NULL, GTK_STOCK_DISCONNECT },
60 #else
61 { PIDGIN_STOCK_DISCONNECT, "icons", "stock_disconnect_16.png" },
62 #endif
63 { PIDGIN_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" },
64 #if GTK_CHECK_VERSION(2,6,0)
65 { PIDGIN_STOCK_EDIT, NULL, GTK_STOCK_EDIT },
66 #else
67 { PIDGIN_STOCK_EDIT, "buttons", "edit.png" },
68 #endif
69 { PIDGIN_STOCK_FILE_CANCELED, NULL, GTK_STOCK_CANCEL },
70 { PIDGIN_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY },
71 { PIDGIN_STOCK_FILE_TRANSFER, NULL, GTK_STOCK_REVERT_TO_SAVED },
72 { PIDGIN_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR },
73 { PIDGIN_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO },
74 { PIDGIN_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES },
75 #if GTK_CHECK_VERSION(2,6,0)
76 { PIDGIN_STOCK_PAUSE, NULL, GTK_STOCK_MEDIA_PAUSE },
77 #else
78 { PIDGIN_STOCK_PAUSE, "buttons", "pause.png" },
79 #endif
80 { PIDGIN_STOCK_POUNCE, NULL, GTK_STOCK_REDO },
81 { PIDGIN_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO },
82 { PIDGIN_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE },
83 { PIDGIN_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE },
84 { PIDGIN_STOCK_TYPED, "gaim", "typed.png" },
85 { PIDGIN_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP },
86 };
87
88 static const GtkStockItem stock_items[] =
89 {
90 { PIDGIN_STOCK_ALIAS, N_("_Alias"), 0, 0, NULL },
91 { PIDGIN_STOCK_CHAT, N_("_Join"), 0, 0, NULL },
92 { PIDGIN_STOCK_CLOSE_TABS, N_("Close _tabs"), 0, 0, NULL },
93 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, N_("I_M"), 0, 0, NULL },
94 { PIDGIN_STOCK_TOOLBAR_USER_INFO, N_("_Get Info"), 0, 0, NULL },
95 { PIDGIN_STOCK_INVITE, N_("_Invite"), 0, 0, NULL },
96 { PIDGIN_STOCK_MODIFY, N_("_Modify"), 0, 0, NULL },
97 { PIDGIN_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, NULL },
98 { PIDGIN_STOCK_PAUSE, N_("_Pause"), 0, 0, NULL },
99 };
100
101 static struct SizedStockIcon {
102 const char *name;
103 const char *dir;
104 const char *filename;
105 gboolean extra_small;
106 gboolean small;
107 gboolean medium;
108 gboolean large;
109 gboolean huge;
110 gboolean rtl;
111 } const sized_stock_icons [] = {
112 { PIDGIN_STOCK_STATUS_AVAILABLE, "status", "available.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
113 { PIDGIN_STOCK_STATUS_AVAILABLE_I, "status", "available_i.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
114 { PIDGIN_STOCK_STATUS_AWAY, "status", "away.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
115 { PIDGIN_STOCK_STATUS_AWAY_I, "status", "away_i.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
116 { PIDGIN_STOCK_STATUS_BUSY, "status", "busy.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
117 { PIDGIN_STOCK_STATUS_BUSY_I, "status", "busy_i.png", TRUE, FALSE, FALSE, FALSE, FALSE,FALSE },
118 { PIDGIN_STOCK_STATUS_CHAT, "status", "chat.png", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE },
119 { PIDGIN_STOCK_STATUS_XA, "status", "extended-away.png", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE },
120 { PIDGIN_STOCK_STATUS_XA_I, "status", "extended-away_i.png",TRUE, FALSE, FALSE, FALSE, FALSE, TRUE },
121 { PIDGIN_STOCK_STATUS_LOGIN, "status", "log-in.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
122 { PIDGIN_STOCK_STATUS_LOGOUT, "status", "log-out.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
123 { PIDGIN_STOCK_STATUS_OFFLINE, "status", "offline.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
124 { PIDGIN_STOCK_STATUS_PERSON, "status", "person.png", TRUE, TRUE, TRUE, TRUE, FALSE, FALSE },
125 { PIDGIN_STOCK_STATUS_MESSAGE, "status", "message-pending.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
126
127 { PIDGIN_STOCK_STATUS_IGNORED, "emblems", "blocked.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
128 { PIDGIN_STOCK_STATUS_FOUNDER, "emblems", "founder.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
129 { PIDGIN_STOCK_STATUS_OPERATOR, "emblems", "operator.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
130 { PIDGIN_STOCK_STATUS_HALFOP, "emblems", "half-operator.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
131 { PIDGIN_STOCK_STATUS_VOICE, "emblems", "voice.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
132
133 { PIDGIN_STOCK_DIALOG_AUTH, "dialogs", "auth.png", TRUE, FALSE, FALSE, FALSE, TRUE, FALSE },
134 { PIDGIN_STOCK_DIALOG_COOL, "dialogs", "cool.png", FALSE, FALSE, FALSE, FALSE, TRUE, FALSE },
135 { PIDGIN_STOCK_DIALOG_ERROR, "dialogs", "error.png", TRUE, FALSE, FALSE, FALSE, TRUE, FALSE },
136 { PIDGIN_STOCK_DIALOG_INFO, "dialogs", "info.png", TRUE, FALSE, FALSE, FALSE, TRUE, FALSE },
137 { PIDGIN_STOCK_DIALOG_MAIL, "dialogs", "mail.png", TRUE, FALSE, FALSE, FALSE, TRUE, FALSE },
138 { PIDGIN_STOCK_DIALOG_QUESTION, "dialogs", "question.png", TRUE, FALSE, FALSE, FALSE, TRUE, FALSE },
139 { PIDGIN_STOCK_DIALOG_WARNING, "dialogs", "warning.png", FALSE, FALSE, FALSE, FALSE, TRUE, FALSE },
140
141 { PIDGIN_STOCK_ANIMATION_CONNECT0, "animations", "connect0.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
142 { PIDGIN_STOCK_ANIMATION_CONNECT1, "animations", "connect1.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
143 { PIDGIN_STOCK_ANIMATION_CONNECT2, "animations", "connect2.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
144 { PIDGIN_STOCK_ANIMATION_CONNECT3, "animations", "connect3.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
145 { PIDGIN_STOCK_ANIMATION_CONNECT4, "animations", "connect4.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
146 { PIDGIN_STOCK_ANIMATION_CONNECT5, "animations", "connect5.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
147 { PIDGIN_STOCK_ANIMATION_CONNECT6, "animations", "connect6.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
148 { PIDGIN_STOCK_ANIMATION_CONNECT7, "animations", "connect7.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
149 { PIDGIN_STOCK_ANIMATION_CONNECT8, "animations", "connect8.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
150 { PIDGIN_STOCK_ANIMATION_TYPING0, "animations", "typing0.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
151 { PIDGIN_STOCK_ANIMATION_TYPING1, "animations", "typing1.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
152 { PIDGIN_STOCK_ANIMATION_TYPING2, "animations", "typing2.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
153 { PIDGIN_STOCK_ANIMATION_TYPING3, "animations", "typing3.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
154 { PIDGIN_STOCK_ANIMATION_TYPING4, "animations", "typing4.png",TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
155
156 { PIDGIN_STOCK_TOOLBAR_ACCOUNTS, "toolbar", "accounts.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
157 { PIDGIN_STOCK_TOOLBAR_BGCOLOR, "toolbar", "change-bgcolor.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
158 { PIDGIN_STOCK_TOOLBAR_FGCOLOR, "toolbar", "change-fgcolor.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
159 { PIDGIN_STOCK_TOOLBAR_SMILEY, "toolbar", "emote-select.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
160 { PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER, "toolbar", "font-size-down.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
161 { PIDGIN_STOCK_TOOLBAR_TEXT_LARGER, "toolbar", "font-size-up.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
162 { PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, "toolbar", "insert-image.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
163 { PIDGIN_STOCK_TOOLBAR_INSERT_LINK, "toolbar", "insert-link.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
164 { PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, "toolbar", "message-new.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
165 { PIDGIN_STOCK_TOOLBAR_PLUGINS, "toolbar", "plugins.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
166 { PIDGIN_STOCK_TOOLBAR_TYPING, "toolbar", "typing.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
167 { PIDGIN_STOCK_TOOLBAR_PENDING, "status", "message-pending.png", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
168
169 { PIDGIN_STOCK_TRAY_AVAILABLE, "tray", "tray-online.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
170 { PIDGIN_STOCK_TRAY_AWAY, "tray", "tray-away.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
171 { PIDGIN_STOCK_TRAY_BUSY, "tray", "tray-busy.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
172 { PIDGIN_STOCK_TRAY_XA, "tray", "tray-extended-away.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
173 { PIDGIN_STOCK_TRAY_OFFLINE, "tray", "tray-offline.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
174 { PIDGIN_STOCK_TRAY_CONNECT, "tray", "tray-connecting.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE },
175 { PIDGIN_STOCK_TRAY_PENDING, "tray", "tray-message.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE }
176 };
177
178 static gchar *
179 find_file(const char *dir, const char *base)
180 {
181 char *filename;
182
183 if (base == NULL)
184 return NULL;
185
186 if (!strcmp(dir, "gaim"))
187 filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL);
188 else
189 {
190 filename = g_build_filename(DATADIR, "pixmaps", "gaim", dir,
191 base, NULL);
192 }
193
194 return filename;
195 }
196
197 static void
198 add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, const char *dir,
199 gboolean rtl, const char *size, const char *file)
200 {
201 char *filename;
202 GtkIconSource *source;
203
204 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, file, NULL);
205 source = gtk_icon_source_new();
206 gtk_icon_source_set_filename(source, filename);
207 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR);
208 gtk_icon_source_set_direction_wildcarded(source, !rtl);
209 gtk_icon_source_set_size(source, sizeid);
210 gtk_icon_source_set_size_wildcarded(source, FALSE);
211 gtk_icon_source_set_state_wildcarded(source, TRUE);
212 gtk_icon_set_add_source(iconset, source);
213 gtk_icon_source_free(source);
214
215 if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) {
216 source = gtk_icon_source_new();
217 gtk_icon_source_set_filename(source, filename);
218 gtk_icon_source_set_direction_wildcarded(source, TRUE);
219 gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);
220 gtk_icon_source_set_size_wildcarded(source, FALSE);
221 gtk_icon_source_set_state_wildcarded(source, TRUE);
222 gtk_icon_set_add_source(iconset, source);
223 gtk_icon_source_free(source);
224 }
225 g_free(filename);
226
227 if (rtl) {
228 filename = g_build_filename(DATADIR, "pixmaps", "pidgin", dir, size, "rtl", file, NULL);
229 source = gtk_icon_source_new();
230 gtk_icon_source_set_filename(source, filename);
231 gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL);
232 gtk_icon_source_set_size(source, sizeid);
233 gtk_icon_source_set_size_wildcarded(source, FALSE);
234 gtk_icon_source_set_state_wildcarded(source, TRUE);
235 gtk_icon_set_add_source(iconset, source);
236 g_free(filename);
237 gtk_icon_source_free(source);
238 }
239
240
241 }
242
243 void
244 pidgin_stock_init(void)
245 {
246 static gboolean stock_initted = FALSE;
247 GtkIconFactory *icon_factory;
248 size_t i;
249 GtkWidget *win;
250 GtkIconSize extra_small, small, medium, large, huge;
251
252 if (stock_initted)
253 return;
254
255 stock_initted = TRUE;
256
257 /* Setup the icon factory. */
258 icon_factory = gtk_icon_factory_new();
259
260 gtk_icon_factory_add_default(icon_factory);
261
262 /* Er, yeah, a hack, but it works. :) */
263 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
264 gtk_widget_realize(win);
265
266 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++)
267 {
268 GtkIconSource *source;
269 GtkIconSet *iconset;
270 gchar *filename;
271
272 if (stock_icons[i].dir == NULL)
273 {
274 /* GTK+ Stock icon */
275 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win),
276 stock_icons[i].filename);
277 }
278 else
279 {
280 filename = find_file(stock_icons[i].dir, stock_icons[i].filename);
281
282 if (filename == NULL)
283 continue;
284
285 source = gtk_icon_source_new();
286 gtk_icon_source_set_filename(source, filename);
287 gtk_icon_source_set_direction_wildcarded(source, TRUE);
288 gtk_icon_source_set_size_wildcarded(source, TRUE);
289 gtk_icon_source_set_state_wildcarded(source, TRUE);
290
291
292 iconset = gtk_icon_set_new();
293 gtk_icon_set_add_source(iconset, source);
294
295 gtk_icon_source_free(source);
296 g_free(filename);
297 }
298
299 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);
300
301 gtk_icon_set_unref(iconset);
302 }
303
304 /* register custom icon sizes */
305 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16);
306 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22);
307 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32);
308 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48);
309 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64);
310
311 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++)
312 {
313 GtkIconSet *iconset;
314
315 iconset = gtk_icon_set_new();
316 if (sized_stock_icons[i].extra_small)
317 add_sized_icon(iconset, extra_small,
318 sized_stock_icons[i].dir, sized_stock_icons[i].rtl,
319 "16", sized_stock_icons[i].filename);
320 if (sized_stock_icons[i].small)
321 add_sized_icon(iconset, small,
322 sized_stock_icons[i].dir, sized_stock_icons[i].rtl,
323 "22", sized_stock_icons[i].filename);
324 if (sized_stock_icons[i].medium)
325 add_sized_icon(iconset, medium,
326 sized_stock_icons[i].dir, sized_stock_icons[i].rtl,
327 "32", sized_stock_icons[i].filename);
328 if (sized_stock_icons[i].large)
329 add_sized_icon(iconset, large,
330 sized_stock_icons[i].dir, sized_stock_icons[i].rtl,
331 "48", sized_stock_icons[i].filename);
332 if (sized_stock_icons[i].huge)
333 add_sized_icon(iconset, huge,
334 sized_stock_icons[i].dir, sized_stock_icons[i].rtl,
335 "64", sized_stock_icons[i].filename);
336
337 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset);
338 gtk_icon_set_unref(iconset);
339 }
340
341 gtk_widget_destroy(win);
342 g_object_unref(G_OBJECT(icon_factory));
343
344 /* Register the stock items. */
345 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items));
346 }

mercurial