pidgin/pidginstock.c

changeset 41154
862153de4f30
parent 41153
5f034a5261c3
child 41155
922c9e70900c
equal deleted inserted replaced
41153:5f034a5261c3 41154:862153de4f30
1 /* pidgin
2 *
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.
6 *
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.
11 *
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.
16 *
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
20 *
21 */
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include <glib/gi18n-lib.h>
27
28 #include <purple.h>
29
30 #include "pidginstock.h"
31
32 #include "gtkicon-theme-loader.h"
33 #include "pidgincore.h"
34
35 #warning GtkStock is deprecated. Port usage of PidginStock to GtkIconTheme \
36 and friends.
37
38 /**************************************************************************
39 * Globals
40 **************************************************************************/
41
42 static gboolean stock_initted = FALSE;
43 static GtkIconSize microscopic, extra_small, small, medium, large, huge;
44
45 /**************************************************************************
46 * Structures
47 **************************************************************************/
48
49 /*****************************************************************************
50 * Public API functions
51 *****************************************************************************/
52
53 void
54 pidgin_stock_load_status_icon_theme(PidginStatusIconTheme *theme)
55 {
56 if (theme != NULL) {
57 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme",
58 purple_theme_get_name(PURPLE_THEME(theme)));
59 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir",
60 purple_theme_get_dir(PURPLE_THEME(theme)));
61 }
62 else {
63 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
64 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
65 }
66 }
67
68 void
69 pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme)
70 {
71 if (theme != NULL) {
72 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme",
73 purple_theme_get_name(PURPLE_THEME(theme)));
74 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir",
75 purple_theme_get_dir(PURPLE_THEME(theme)));
76 }
77 else {
78 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
79 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
80 }
81 }
82
83 void
84 pidgin_stock_init(void)
85 {
86 PidginIconThemeLoader *loader, *stockloader;
87 const gchar *path = NULL;
88
89 if (stock_initted)
90 return;
91
92 stock_initted = TRUE;
93
94 /* Setup the status icon theme */
95 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL);
96 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader));
97 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/status");
98 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", "");
99 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", "");
100
101 stockloader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "stock-icon", NULL);
102 purple_theme_manager_register_type(PURPLE_THEME_LOADER(stockloader));
103 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/stock");
104 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", "");
105 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", "");
106
107 /* register custom icon sizes */
108 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
109 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11);
110 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16);
111 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22);
112 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32);
113 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48);
114 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64);
115 G_GNUC_END_IGNORE_DEPRECATIONS
116
117 pidgin_stock_load_stock_icon_theme(NULL);
118
119 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/
120 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/status/icon-theme") &&
121 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) {
122
123 PidginStatusIconTheme *theme = PIDGIN_STATUS_ICON_THEME(purple_theme_loader_build(PURPLE_THEME_LOADER(loader), path));
124 pidgin_stock_load_status_icon_theme(theme);
125 if (theme)
126 g_object_unref(G_OBJECT(theme));
127
128 }
129 else
130 pidgin_stock_load_status_icon_theme(NULL);
131 }
132
133 static void
134 pidgin_stock_icon_theme_class_init(PidginStockIconThemeClass *klass)
135 {
136 }
137
138 GType
139 pidgin_stock_icon_theme_get_type(void)
140 {
141 static GType type = 0;
142 if (type == 0) {
143 static const GTypeInfo info = {
144 sizeof (PidginStockIconThemeClass),
145 NULL, /* base_init */
146 NULL, /* base_finalize */
147 (GClassInitFunc)pidgin_stock_icon_theme_class_init, /* class_init */
148 NULL, /* class_finalize */
149 NULL, /* class_data */
150 sizeof (PidginStockIconTheme),
151 0, /* n_preallocs */
152 NULL,
153 NULL, /* value table */
154 };
155 type = g_type_register_static(PIDGIN_TYPE_ICON_THEME,
156 "PidginStockIconTheme", &info, 0);
157 }
158 return type;
159 }

mercurial