| 1 /** |
|
| 2 * @file gtkstock.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 "gtkgaim.h" |
|
| 28 |
|
| 29 #include "gtkstock.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 { GAIM_STOCK_ABOUT, "buttons", "about_menu.png" }, |
|
| 40 { GAIM_STOCK_ACCOUNTS, "buttons", "accounts.png" }, |
|
| 41 { GAIM_STOCK_ACTION, NULL, GTK_STOCK_EXECUTE }, |
|
| 42 #if GTK_CHECK_VERSION(2,6,0) |
|
| 43 { GAIM_STOCK_ALIAS, NULL, GTK_STOCK_EDIT }, |
|
| 44 #else |
|
| 45 { GAIM_STOCK_ALIAS, "buttons", "edit.png" }, |
|
| 46 #endif |
|
| 47 { GAIM_STOCK_BGCOLOR, "buttons", "change-bgcolor-small.png" }, |
|
| 48 { GAIM_STOCK_BLOCK, NULL, GTK_STOCK_STOP }, |
|
| 49 { GAIM_STOCK_CHAT, NULL, GTK_STOCK_JUMP_TO }, |
|
| 50 { GAIM_STOCK_CLEAR, NULL, GTK_STOCK_CLEAR }, |
|
| 51 { GAIM_STOCK_CLOSE_TABS, NULL, GTK_STOCK_CLOSE }, |
|
| 52 #if GTK_CHECK_VERSION(2,6,0) |
|
| 53 { GAIM_STOCK_CONNECT, NULL, GTK_STOCK_CONNECT }, |
|
| 54 #else |
|
| 55 { GAIM_STOCK_CONNECT, "icons", "stock_connect_16.png" }, |
|
| 56 #endif |
|
| 57 { GAIM_STOCK_DEBUG, NULL, GTK_STOCK_PROPERTIES }, |
|
| 58 { GAIM_STOCK_DOWNLOAD, NULL, GTK_STOCK_GO_DOWN }, |
|
| 59 { GAIM_STOCK_DIALOG_AUTH, "dialogs", "gaim_auth.png" }, |
|
| 60 { GAIM_STOCK_DIALOG_COOL, "dialogs", "gaim_cool.png" }, |
|
| 61 { GAIM_STOCK_DIALOG_ERROR, "dialogs", "gaim_error.png" }, |
|
| 62 { GAIM_STOCK_DIALOG_INFO, "dialogs", "gaim_info.png" }, |
|
| 63 { GAIM_STOCK_DIALOG_QUESTION, "dialogs", "gaim_question.png" }, |
|
| 64 { GAIM_STOCK_DIALOG_WARNING, "dialogs", "gaim_warning.png" }, |
|
| 65 #if GTK_CHECK_VERSION(2,6,0) |
|
| 66 { GAIM_STOCK_DISCONNECT, NULL, GTK_STOCK_DISCONNECT }, |
|
| 67 #else |
|
| 68 { GAIM_STOCK_DISCONNECT, "icons", "stock_disconnect_16.png" }, |
|
| 69 #endif |
|
| 70 { GAIM_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" }, |
|
| 71 #if GTK_CHECK_VERSION(2,6,0) |
|
| 72 { GAIM_STOCK_EDIT, NULL, GTK_STOCK_EDIT }, |
|
| 73 #else |
|
| 74 { GAIM_STOCK_EDIT, "buttons", "edit.png" }, |
|
| 75 #endif |
|
| 76 { GAIM_STOCK_FILE_CANCELED, NULL, GTK_STOCK_CANCEL }, |
|
| 77 { GAIM_STOCK_FILE_DONE, NULL, GTK_STOCK_APPLY }, |
|
| 78 { GAIM_STOCK_FILE_TRANSFER, NULL, GTK_STOCK_REVERT_TO_SAVED }, |
|
| 79 { GAIM_STOCK_ICON_AWAY, "icons", "away.png" }, |
|
| 80 { GAIM_STOCK_ICON_AWAY_MSG, "icons", "msgpend.png" }, |
|
| 81 { GAIM_STOCK_ICON_CONNECT, "icons", "connect.png" }, |
|
| 82 { GAIM_STOCK_ICON_OFFLINE, "icons", "offline.png" }, |
|
| 83 { GAIM_STOCK_ICON_ONLINE, "icons", "online.png" }, |
|
| 84 { GAIM_STOCK_ICON_ONLINE_MSG, "icons", "msgunread.png" }, |
|
| 85 { GAIM_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR }, |
|
| 86 { GAIM_STOCK_IM, "buttons", "send-im.png" }, |
|
| 87 { GAIM_STOCK_IMAGE, "buttons", "insert-image-small.png" }, |
|
| 88 #if GTK_CHECK_VERSION(2,8,0) |
|
| 89 { GAIM_STOCK_INFO, NULL, GTK_STOCK_INFO }, |
|
| 90 #else |
|
| 91 { GAIM_STOCK_INFO, "buttons", "info.png" }, |
|
| 92 #endif |
|
| 93 { GAIM_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO }, |
|
| 94 { GAIM_STOCK_LINK, "buttons", "insert-link-small.png" }, |
|
| 95 { GAIM_STOCK_LOG, NULL, GTK_STOCK_DND_MULTIPLE }, |
|
| 96 { GAIM_STOCK_MODIFY, NULL, GTK_STOCK_PREFERENCES }, |
|
| 97 #if GTK_CHECK_VERSION(2,6,0) |
|
| 98 { GAIM_STOCK_PAUSE, NULL, GTK_STOCK_MEDIA_PAUSE }, |
|
| 99 #else |
|
| 100 { GAIM_STOCK_PAUSE, "buttons", "pause.png" }, |
|
| 101 #endif |
|
| 102 { GAIM_STOCK_PENDING, "buttons", "send-im.png" }, |
|
| 103 #if GTK_CHECK_VERSION(2,6,0) |
|
| 104 { GAIM_STOCK_PLUGIN, NULL, GTK_STOCK_DISCONNECT }, |
|
| 105 #else |
|
| 106 { GAIM_STOCK_PLUGIN, "icons", "stock_disconnect_16.png" }, |
|
| 107 #endif |
|
| 108 { GAIM_STOCK_POUNCE, NULL, GTK_STOCK_REDO }, |
|
| 109 { GAIM_STOCK_OPEN_MAIL, NULL, GTK_STOCK_JUMP_TO }, |
|
| 110 { GAIM_STOCK_SEND, "buttons", "send-im.png" }, |
|
| 111 { GAIM_STOCK_SIGN_ON, NULL, GTK_STOCK_EXECUTE }, |
|
| 112 { GAIM_STOCK_SIGN_OFF, NULL, GTK_STOCK_CLOSE }, |
|
| 113 { GAIM_STOCK_SMILEY, "buttons", "insert-smiley-small.png" }, |
|
| 114 { GAIM_STOCK_TEXT_BIGGER, "buttons", "text_bigger.png" }, |
|
| 115 { GAIM_STOCK_TEXT_NORMAL, "buttons", "text_normal.png" }, |
|
| 116 { GAIM_STOCK_TEXT_SMALLER, "buttons", "text_smaller.png" }, |
|
| 117 { GAIM_STOCK_TYPED, "gaim", "typed.png" }, |
|
| 118 { GAIM_STOCK_TYPING, "gaim", "typing.png" }, |
|
| 119 { GAIM_STOCK_VOICE_CHAT, "gaim", "phone.png" }, |
|
| 120 { GAIM_STOCK_STATUS_ONLINE, "gaim", "status-online.png" }, |
|
| 121 { GAIM_STOCK_STATUS_OFFLINE, "gaim", "status-offline.png" }, |
|
| 122 { GAIM_STOCK_STATUS_AWAY, "gaim", "status-away.png" }, |
|
| 123 { GAIM_STOCK_STATUS_INVISIBLE,"gaim", "status-invisible.png" }, |
|
| 124 { GAIM_STOCK_STATUS_TYPING0, "gaim", "status-typing0.png" }, |
|
| 125 { GAIM_STOCK_STATUS_TYPING1, "gaim", "status-typing1.png" }, |
|
| 126 { GAIM_STOCK_STATUS_TYPING2, "gaim", "status-typing2.png" }, |
|
| 127 { GAIM_STOCK_STATUS_TYPING3, "gaim", "status-typing3.png" }, |
|
| 128 { GAIM_STOCK_STATUS_CONNECT0, "gaim", "status-connect0.png" }, |
|
| 129 { GAIM_STOCK_STATUS_CONNECT1, "gaim", "status-connect1.png" }, |
|
| 130 { GAIM_STOCK_STATUS_CONNECT2, "gaim", "status-connect2.png" }, |
|
| 131 { GAIM_STOCK_STATUS_CONNECT3, "gaim", "status-connect3.png" }, |
|
| 132 { GAIM_STOCK_UPLOAD, NULL, GTK_STOCK_GO_UP } |
|
| 133 }; |
|
| 134 |
|
| 135 static const GtkStockItem stock_items[] = |
|
| 136 { |
|
| 137 { GAIM_STOCK_ALIAS, N_("_Alias"), 0, 0, NULL }, |
|
| 138 { GAIM_STOCK_CHAT, N_("_Join"), 0, 0, NULL }, |
|
| 139 { GAIM_STOCK_CLOSE_TABS, N_("Close _tabs"), 0, 0, NULL }, |
|
| 140 { GAIM_STOCK_IM, N_("I_M"), 0, 0, NULL }, |
|
| 141 { GAIM_STOCK_INFO, N_("_Get Info"), 0, 0, NULL }, |
|
| 142 { GAIM_STOCK_INVITE, N_("_Invite"), 0, 0, NULL }, |
|
| 143 { GAIM_STOCK_MODIFY, N_("_Modify"), 0, 0, NULL }, |
|
| 144 { GAIM_STOCK_OPEN_MAIL, N_("_Open Mail"), 0, 0, NULL }, |
|
| 145 { GAIM_STOCK_PAUSE, N_("_Pause"), 0, 0, NULL }, |
|
| 146 }; |
|
| 147 |
|
| 148 static gchar * |
|
| 149 find_file(const char *dir, const char *base) |
|
| 150 { |
|
| 151 char *filename; |
|
| 152 |
|
| 153 if (base == NULL) |
|
| 154 return NULL; |
|
| 155 |
|
| 156 if (!strcmp(dir, "gaim")) |
|
| 157 filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL); |
|
| 158 else |
|
| 159 { |
|
| 160 filename = g_build_filename(DATADIR, "pixmaps", "gaim", dir, |
|
| 161 base, NULL); |
|
| 162 } |
|
| 163 |
|
| 164 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
|
| 165 { |
|
| 166 g_critical("Unable to load stock pixmap %s\n", base); |
|
| 167 |
|
| 168 g_free(filename); |
|
| 169 |
|
| 170 return NULL; |
|
| 171 } |
|
| 172 |
|
| 173 return filename; |
|
| 174 } |
|
| 175 |
|
| 176 void |
|
| 177 gaim_gtk_stock_init(void) |
|
| 178 { |
|
| 179 static gboolean stock_initted = FALSE; |
|
| 180 GtkIconFactory *icon_factory; |
|
| 181 size_t i; |
|
| 182 GtkWidget *win; |
|
| 183 |
|
| 184 if (stock_initted) |
|
| 185 return; |
|
| 186 |
|
| 187 stock_initted = TRUE; |
|
| 188 |
|
| 189 /* Setup the icon factory. */ |
|
| 190 icon_factory = gtk_icon_factory_new(); |
|
| 191 |
|
| 192 gtk_icon_factory_add_default(icon_factory); |
|
| 193 |
|
| 194 /* Er, yeah, a hack, but it works. :) */ |
|
| 195 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
|
| 196 gtk_widget_realize(win); |
|
| 197 |
|
| 198 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) |
|
| 199 { |
|
| 200 GdkPixbuf *pixbuf; |
|
| 201 GtkIconSet *iconset; |
|
| 202 gchar *filename; |
|
| 203 |
|
| 204 if (stock_icons[i].dir == NULL) |
|
| 205 { |
|
| 206 /* GTK+ Stock icon */ |
|
| 207 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), |
|
| 208 stock_icons[i].filename); |
|
| 209 } |
|
| 210 else |
|
| 211 { |
|
| 212 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); |
|
| 213 |
|
| 214 if (filename == NULL) |
|
| 215 continue; |
|
| 216 |
|
| 217 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); |
|
| 218 |
|
| 219 g_free(filename); |
|
| 220 |
|
| 221 iconset = gtk_icon_set_new_from_pixbuf(pixbuf); |
|
| 222 |
|
| 223 g_object_unref(G_OBJECT(pixbuf)); |
|
| 224 } |
|
| 225 |
|
| 226 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); |
|
| 227 |
|
| 228 gtk_icon_set_unref(iconset); |
|
| 229 } |
|
| 230 |
|
| 231 gtk_widget_destroy(win); |
|
| 232 |
|
| 233 /* register custom icon sizes */ |
|
| 234 gtk_icon_size_register(GAIM_ICON_SIZE_LOGO, 330, 90); |
|
| 235 gtk_icon_size_register(GAIM_ICON_SIZE_DIALOG_COOL, 40, 60); |
|
| 236 gtk_icon_size_register(GAIM_ICON_SIZE_STATUS, 30, 30); |
|
| 237 gtk_icon_size_register(GAIM_ICON_SIZE_STATUS_TWO_LINE, 30, 30); |
|
| 238 gtk_icon_size_register(GAIM_ICON_SIZE_STATUS_SMALL, 16, 16); |
|
| 239 gtk_icon_size_register(GAIM_ICON_SIZE_STATUS_SMALL_TWO_LINE, 24, 24); |
|
| 240 |
|
| 241 g_object_unref(G_OBJECT(icon_factory)); |
|
| 242 |
|
| 243 /* Register the stock items. */ |
|
| 244 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); |
|
| 245 } |
|