| |
1 /* |
| |
2 * Icon Themes for Pidgin |
| |
3 * |
| |
4 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
6 * source distribution. |
| |
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. |
| |
12 * |
| |
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. |
| |
17 * |
| |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| |
21 */ |
| |
22 |
| |
23 #include "gtkicon-theme.h" |
| |
24 #include "pidginstock.h" |
| |
25 |
| |
26 #include <gtk/gtk.h> |
| |
27 |
| |
28 #define PIDGIN_ICON_THEME_GET_PRIVATE(Gobject) \ |
| |
29 ((PidginIconThemePrivate *) ((PIDGIN_ICON_THEME(Gobject))->priv)) |
| |
30 |
| |
31 /****************************************************************************** |
| |
32 * Structs |
| |
33 *****************************************************************************/ |
| |
34 |
| |
35 typedef struct { |
| |
36 /* used to store filenames of diffrent icons */ |
| |
37 GHashTable *icon_files; |
| |
38 } PidginIconThemePrivate; |
| |
39 |
| |
40 /****************************************************************************** |
| |
41 * Globals |
| |
42 *****************************************************************************/ |
| |
43 |
| |
44 static GObjectClass *parent_class = NULL; |
| |
45 |
| |
46 /****************************************************************************** |
| |
47 * GObject Stuff |
| |
48 *****************************************************************************/ |
| |
49 |
| |
50 static void |
| |
51 pidgin_icon_theme_init(GTypeInstance *instance, |
| |
52 gpointer klass) |
| |
53 { |
| |
54 PidginIconThemePrivate *priv; |
| |
55 |
| |
56 (PIDGIN_ICON_THEME(instance))->priv = g_new0(PidginIconThemePrivate, 1); |
| |
57 |
| |
58 priv = PIDGIN_ICON_THEME_GET_PRIVATE(instance); |
| |
59 |
| |
60 priv->icon_files = g_hash_table_new_full(g_str_hash, |
| |
61 g_str_equal, g_free, g_free); |
| |
62 } |
| |
63 |
| |
64 static void |
| |
65 pidgin_icon_theme_finalize(GObject *obj) |
| |
66 { |
| |
67 PidginIconThemePrivate *priv; |
| |
68 |
| |
69 priv = PIDGIN_ICON_THEME_GET_PRIVATE(obj); |
| |
70 |
| |
71 g_hash_table_destroy(priv->icon_files); |
| |
72 g_free(priv); |
| |
73 |
| |
74 parent_class->finalize(obj); |
| |
75 } |
| |
76 |
| |
77 static void |
| |
78 pidgin_icon_theme_class_init(PidginIconThemeClass *klass) |
| |
79 { |
| |
80 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| |
81 |
| |
82 parent_class = g_type_class_peek_parent(klass); |
| |
83 |
| |
84 obj_class->finalize = pidgin_icon_theme_finalize; |
| |
85 } |
| |
86 |
| |
87 GType |
| |
88 pidgin_icon_theme_get_type(void) |
| |
89 { |
| |
90 static GType type = 0; |
| |
91 if (type == 0) { |
| |
92 static const GTypeInfo info = { |
| |
93 sizeof(PidginIconThemeClass), |
| |
94 NULL, /* base_init */ |
| |
95 NULL, /* base_finalize */ |
| |
96 (GClassInitFunc)pidgin_icon_theme_class_init, /* class_init */ |
| |
97 NULL, /* class_finalize */ |
| |
98 NULL, /* class_data */ |
| |
99 sizeof(PidginIconTheme), |
| |
100 0, /* n_preallocs */ |
| |
101 pidgin_icon_theme_init, /* instance_init */ |
| |
102 NULL, /* value table */ |
| |
103 }; |
| |
104 type = g_type_register_static(PURPLE_TYPE_THEME, |
| |
105 "PidginIconTheme", &info, G_TYPE_FLAG_ABSTRACT); |
| |
106 } |
| |
107 return type; |
| |
108 } |
| |
109 |
| |
110 /***************************************************************************** |
| |
111 * Public API functions |
| |
112 *****************************************************************************/ |
| |
113 |
| |
114 const gchar * |
| |
115 pidgin_icon_theme_get_icon(PidginIconTheme *theme, |
| |
116 const gchar *id) |
| |
117 { |
| |
118 PidginIconThemePrivate *priv; |
| |
119 |
| |
120 g_return_val_if_fail(PIDGIN_IS_ICON_THEME(theme), NULL); |
| |
121 |
| |
122 priv = PIDGIN_ICON_THEME_GET_PRIVATE(theme); |
| |
123 |
| |
124 return g_hash_table_lookup(priv->icon_files, id); |
| |
125 } |
| |
126 |
| |
127 void |
| |
128 pidgin_icon_theme_set_icon(PidginIconTheme *theme, |
| |
129 const gchar *id, |
| |
130 const gchar *filename) |
| |
131 { |
| |
132 PidginIconThemePrivate *priv; |
| |
133 g_return_if_fail(PIDGIN_IS_ICON_THEME(theme)); |
| |
134 |
| |
135 priv = PIDGIN_ICON_THEME_GET_PRIVATE(theme); |
| |
136 |
| |
137 if (filename != NULL) |
| |
138 g_hash_table_replace(priv->icon_files, |
| |
139 g_strdup(id), g_strdup(filename)); |
| |
140 else |
| |
141 g_hash_table_remove(priv->icon_files, id); |
| |
142 } |