[gaim-migrate @ 5479]
[pidgin-git.git] / src / stock.c
blob0fe6d8d1f4537bc5f5405bcdc9a34ea95f05aeca
1 /**
2 * @file stock.c GTK+ Stock resources
4 * gaim
6 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "stock.h"
24 #include "core.h"
25 #include <gtk/gtk.h>
26 #include <string.h>
28 #ifdef _WIN32
29 #include "win32dep.h"
30 #endif
32 static struct StockIcon
34 const char *name;
35 const char *dir;
36 const char *filename;
38 } const stock_icons[] =
40 { GAIM_STOCK_ABOUT, "buttons", "about_menu.png" },
41 { GAIM_STOCK_ACCOUNTS, "buttons", "accounts.png" },
42 { GAIM_STOCK_BGCOLOR, "buttons", "change-bgcolor-small.png" },
43 { GAIM_STOCK_BLOCK, NULL, GTK_STOCK_STOP },
44 { GAIM_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO },
45 { GAIM_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN },
46 { GAIM_STOCK_DIALOG_AUTH, "dialogs", "gaim_auth.png" },
47 { GAIM_STOCK_DIALOG_COOL, "dialogs", "gaim_cool.png" },
48 { GAIM_STOCK_DIALOG_ERROR, "dialogs", "gaim_error.png" },
49 { GAIM_STOCK_DIALOG_INFO, "dialogs", "gaim_info.png" },
50 { GAIM_STOCK_DIALOG_QUESTION, "dialogs", "gaim_question.png" },
51 { GAIM_STOCK_DIALOG_WARNING, "dialogs", "gaim_warning.png" },
52 { GAIM_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" },
53 { GAIM_STOCK_EDIT, "buttons", "edit.png" },
54 { GAIM_STOCK_FILE_CANCELED, NULL, GTK_STOCK_CANCEL },
55 { GAIM_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY },
56 { GAIM_STOCK_FILE_TRANSFER, NULL, GTK_STOCK_REVERT_TO_SAVED },
57 { GAIM_STOCK_ICON_AWAY, "icons", "away.png" },
58 { GAIM_STOCK_ICON_AWAY_MSG, "icons", "msgpend.png" },
59 { GAIM_STOCK_ICON_CONNECT, "icons", "connect.png" },
60 { GAIM_STOCK_ICON_OFFLINE, "icons", "offline.png" },
61 { GAIM_STOCK_ICON_ONLINE, "icons", "online.png" },
62 { GAIM_STOCK_ICON_ONLINE_MSG, "icons", "msgunread.png" },
63 { GAIM_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR },
64 { GAIM_STOCK_IM, NULL, GTK_STOCK_CONVERT },
65 { GAIM_STOCK_IMAGE, "buttons", "insert-image-small.png" },
66 { GAIM_STOCK_INFO, NULL, GTK_STOCK_FIND },
67 { GAIM_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO },
68 { GAIM_STOCK_LINK, "buttons", "insert-link-small.png" },
69 { GAIM_STOCK_LOGO, "gaim", "logo.png" },
70 { GAIM_STOCK_PRIVACY, NULL, GTK_STOCK_PROPERTIES },
71 { GAIM_STOCK_SEND, NULL, GTK_STOCK_CONVERT },
72 { GAIM_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE },
73 { GAIM_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE },
74 { GAIM_STOCK_SMILEY, "buttons", "insert-smiley-small.png" },
75 { GAIM_STOCK_TEXT_BIGGER, "buttons", "text_bigger.png" },
76 { GAIM_STOCK_TEXT_NORMAL, "buttons", "text_normal.png" },
77 { GAIM_STOCK_TEXT_SMALLER, "buttons", "text_smaller.png" },
78 { GAIM_STOCK_TYPED, "gaim", "typed.png" },
79 { GAIM_STOCK_TYPING, "gaim", "typing.png" },
80 { GAIM_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP },
81 { GAIM_STOCK_WARN, NULL, GTK_STOCK_DIALOG_WARNING }
84 static gint stock_icon_count = sizeof(stock_icons) / sizeof(*stock_icons);
86 static gchar *
87 find_file(const char *dir, const char *base)
89 char *filename;
91 if (base == NULL)
92 return NULL;
94 if (!strcmp(dir, "gaim"))
95 filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL);
96 else
97 filename = g_build_filename(DATADIR, "pixmaps", "gaim", dir, base, NULL);
99 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
100 g_critical("Unable to load stock pixmap %s\n", base);
102 g_free(filename);
104 return NULL;
107 return filename;
110 void
111 setup_stock()
113 GtkIconFactory *icon_factory;
114 int i;
115 GtkWidget *win;
117 /* Setup the icon factory. */
118 icon_factory = gtk_icon_factory_new();
120 gtk_icon_factory_add_default(icon_factory);
122 /* Er, yeah, a hack, but it works. :) */
123 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
124 gtk_widget_realize(win);
126 for (i = 0; i < stock_icon_count; i++) {
127 GdkPixbuf *pixbuf;
128 GtkIconSet *iconset;
129 gchar *filename;
131 if (stock_icons[i].dir == NULL) {
133 /* GTK+ Stock icon */
134 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win),
135 stock_icons[i].filename);
137 else {
138 filename = find_file(stock_icons[i].dir, stock_icons[i].filename);
140 if (filename == NULL)
141 continue;
143 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
145 g_free(filename);
147 iconset = gtk_icon_set_new_from_pixbuf(pixbuf);
150 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset);
152 gtk_icon_set_unref(iconset);
155 gtk_widget_destroy(win);
157 /* register logo icon size */
158 gtk_icon_size_register(GAIM_ICON_SIZE_LOGO, 210, 150);
160 g_object_unref(G_OBJECT(icon_factory));