pidgin/gtksmiley-theme.c

changeset 35705
3203e0f1b1bd
parent 35704
aa22dcef8913
child 35706
6a0bbe6adc4a
equal deleted inserted replaced
35704:aa22dcef8913 35705:3203e0f1b1bd
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 */ 20 */
21 21
22 #include "gtksmiley-theme.h" 22 #include "gtksmiley-theme.h"
23 23
24 #include <glib/gstdio.h>
25
24 #define PIDGIN_SMILEY_THEME_GET_PRIVATE(obj) \ 26 #define PIDGIN_SMILEY_THEME_GET_PRIVATE(obj) \
25 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_SMILEY_THEME, \ 27 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_SMILEY_THEME, \
26 PurpleSmileyThemePrivate)) 28 PidginSmileyThemePrivate))
27 29
28 typedef struct 30 typedef struct
29 { 31 {
30 } PurpleSmileyThemePrivate; 32 gchar *path;
33 } PidginSmileyThemePrivate;
31 34
32 static GObjectClass *parent_class; 35 static GObjectClass *parent_class;
36
37 static gchar **probe_dirs;
38 static GList *smiley_themes = NULL;
39
40 /*******************************************************************************
41 * Theme loading
42 ******************************************************************************/
43
44 static void
45 pidgin_smiley_theme_load(const gchar *theme_path)
46 {
47 PidginSmileyTheme *theme;
48 PidginSmileyThemePrivate *priv;
49 GList *it;
50 gchar *index_path;
51
52 /* it's not super-efficient, but we don't expect huge amount of
53 * installed themes */
54 for (it = smiley_themes; it; it = g_list_next(it)) {
55 PidginSmileyThemePrivate *priv =
56 PIDGIN_SMILEY_THEME_GET_PRIVATE(it->data);
57
58 /* theme is already loaded */
59 if (g_strcmp0(priv->path, theme_path) == 0)
60 return;
61 }
62
63 index_path = g_build_filename(theme_path, "theme", NULL);
64
65 theme = g_object_new(PIDGIN_TYPE_SMILEY_THEME, NULL);
66 priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
67
68 priv->path = g_strdup(theme_path);
69
70 /* TODO: parse index_path */
71
72 g_free(index_path);
73 }
74
75 static void
76 pidgin_smiley_theme_probe(void)
77 {
78 GList *it, *next;
79 int i;
80
81 /* remove non-existing themes */
82 for (it = smiley_themes; it; it = next) {
83 PidginSmileyTheme *theme = it->data;
84 PidginSmileyThemePrivate *priv =
85 PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
86
87 next = g_list_next(it);
88
89 if (g_file_test(priv->path, G_FILE_TEST_EXISTS))
90 continue;
91 smiley_themes = g_list_remove_link(smiley_themes, it);
92 g_object_unref(theme);
93 }
94
95 /* scan for themes */
96 for (i = 0; probe_dirs[i]; i++) {
97 GDir *dir = g_dir_open(probe_dirs[i], 0, NULL);
98 const gchar *theme_dir_name;
99
100 if (!dir)
101 continue;
102
103 while ((theme_dir_name = g_dir_read_name(dir))) {
104 gchar *theme_path = g_build_filename(
105 probe_dirs[i], theme_dir_name, NULL);
106
107 if (g_file_test(theme_path, G_FILE_TEST_IS_DIR))
108 pidgin_smiley_theme_load(theme_path);
109
110 g_free(theme_path);
111 }
112
113 g_dir_close(dir);
114 }
115 }
116
33 117
34 /******************************************************************************* 118 /*******************************************************************************
35 * API implementation 119 * API implementation
36 ******************************************************************************/ 120 ******************************************************************************/
37 121
42 } 126 }
43 127
44 void 128 void
45 pidgin_smiley_theme_init(void) 129 pidgin_smiley_theme_init(void)
46 { 130 {
47 } 131 const gchar *user_smileys_dir;
48 132
133 probe_dirs = g_new0(gchar*, 3);
134 probe_dirs[0] = g_build_filename(
135 DATADIR, "pixmaps", "pidgin", "emotes", NULL);
136 user_smileys_dir = probe_dirs[1] = g_build_filename(
137 purple_user_dir(), "smileys", NULL);
138
139 if (!g_file_test(user_smileys_dir, G_FILE_TEST_IS_DIR))
140 g_mkdir(user_smileys_dir, S_IRUSR | S_IWUSR | S_IXUSR);
141 }
142
143 void
144 pidgin_smiley_theme_uninit(void)
145 {
146 g_strfreev(probe_dirs);
147 }
148
149 GList *
150 pidgin_smiley_theme_get_all(void)
151 {
152 pidgin_smiley_theme_probe();
153
154 return NULL;
155 }
49 156
50 /******************************************************************************* 157 /*******************************************************************************
51 * Object stuff 158 * Object stuff
52 ******************************************************************************/ 159 ******************************************************************************/
53 160
54 static void 161 static void
55 pidgin_smiley_theme_finalize(GObject *obj) 162 pidgin_smiley_theme_finalize(GObject *obj)
56 { 163 {
164 PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(obj);
165
166 g_free(priv->path);
167
57 G_OBJECT_CLASS(parent_class)->finalize(obj); 168 G_OBJECT_CLASS(parent_class)->finalize(obj);
58 } 169 }
59 170
60 static void 171 static void
61 pidgin_smiley_theme_class_init(PurpleSmileyListClass *klass) 172 pidgin_smiley_theme_class_init(PurpleSmileyListClass *klass)
63 GObjectClass *gobj_class = G_OBJECT_CLASS(klass); 174 GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
64 PurpleSmileyThemeClass *pst_class = PURPLE_SMILEY_THEME_CLASS(klass); 175 PurpleSmileyThemeClass *pst_class = PURPLE_SMILEY_THEME_CLASS(klass);
65 176
66 parent_class = g_type_class_peek_parent(klass); 177 parent_class = g_type_class_peek_parent(klass);
67 178
68 g_type_class_add_private(klass, sizeof(PurpleSmileyThemePrivate)); 179 g_type_class_add_private(klass, sizeof(PidginSmileyThemePrivate));
69 180
70 gobj_class->finalize = pidgin_smiley_theme_finalize; 181 gobj_class->finalize = pidgin_smiley_theme_finalize;
71 182
72 pst_class->get_smileys = pidgin_smiley_theme_get_smileys_impl; 183 pst_class->get_smileys = pidgin_smiley_theme_get_smileys_impl;
73 } 184 }

mercurial