comparison libpurple/theme-manager.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents b276701931d9
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
78 { 78 {
79 return g_str_has_prefix(key, g_strconcat(user_data, "/", NULL)); 79 return g_str_has_prefix(key, g_strconcat(user_data, "/", NULL));
80 } 80 }
81 81
82 static gboolean 82 static gboolean
83 purple_theme_manager_is_theme(gchar *key, 83 check_if_theme_or_loader(gchar *key, gpointer value, GSList **loaders)
84 gpointer value, 84 {
85 gchar *user_data) 85 if (PURPLE_IS_THEME(value))
86 { 86 return TRUE;
87 return PURPLE_IS_THEME(value); 87 else if (PURPLE_IS_THEME_LOADER(value))
88 *loaders = g_slist_prepend(*loaders, value);
89
90 return FALSE;
88 } 91 }
89 92
90 static void 93 static void
91 purple_theme_manager_function_wrapper(gchar *key, 94 purple_theme_manager_function_wrapper(gchar *key,
92 gpointer value, 95 gpointer value,
95 if (PURPLE_IS_THEME(value)) 98 if (PURPLE_IS_THEME(value))
96 (* user_data)(value); 99 (* user_data)(value);
97 } 100 }
98 101
99 static void 102 static void
100 purple_theme_manager_build_dir(const gchar *root) 103 purple_theme_manager_build_dir(GSList *loaders, const gchar *root)
101 { 104 {
102 gchar *purple_dir, *theme_dir; 105 gchar *theme_dir;
103 const gchar *name = NULL, *type = NULL; 106 const gchar *name;
104 GDir *rdir, *tdir; 107 GDir *rdir;
108 GSList *tmp;
105 PurpleThemeLoader *loader; 109 PurpleThemeLoader *loader;
106 110
107 rdir = g_dir_open(root, 0, NULL); 111 rdir = g_dir_open(root, 0, NULL);
108 112
109 if (!rdir) 113 if (!rdir)
110 return; 114 return;
111 115
112 /* Parses directory by root/name/purple/type */
113 while ((name = g_dir_read_name(rdir))) { 116 while ((name = g_dir_read_name(rdir))) {
114 purple_dir = g_build_filename(root, name, "purple", NULL); 117 theme_dir = g_build_filename(root, name, NULL);
115 tdir = g_dir_open(purple_dir, 0, NULL); 118
116 119 for (tmp = loaders; tmp; tmp = g_slist_next(tmp)) {
117 if (!tdir) { 120 loader = PURPLE_THEME_LOADER(tmp->data);
118 g_free(purple_dir); 121
119 122 if (purple_theme_loader_probe(loader, theme_dir)) {
120 continue; 123 PurpleTheme *theme = purple_theme_loader_build(loader, theme_dir);
121 }
122
123 while ((type = g_dir_read_name(tdir))) {
124 if ((loader = g_hash_table_lookup(theme_table, type))) {
125 PurpleTheme *theme = NULL;
126
127 theme_dir = g_build_filename(purple_dir, type, NULL);
128
129 theme = purple_theme_loader_build(loader, theme_dir);
130 g_free(theme_dir);
131
132 if (PURPLE_IS_THEME(theme)) 124 if (PURPLE_IS_THEME(theme))
133 purple_theme_manager_add_theme(theme); 125 purple_theme_manager_add_theme(theme);
134 } 126 }
135 } 127 }
136 128
137 g_dir_close(tdir); 129 g_free(theme_dir);
138 g_free(purple_dir);
139 } 130 }
140 131
141 g_dir_close(rdir); 132 g_dir_close(rdir);
142 } 133 }
143 134
153 } 144 }
154 145
155 void 146 void
156 purple_theme_manager_refresh(void) 147 purple_theme_manager_refresh(void)
157 { 148 {
158 gchar *path = NULL; 149 gchar *path;
159 const gchar *xdg = NULL; 150 const gchar *xdg;
160 gint i = 0; 151 gint i;
161 152 GSList *loaders = NULL;
162 g_hash_table_foreach_remove(theme_table, 153
163 (GHRFunc) purple_theme_manager_is_theme, NULL); 154 g_hash_table_foreach_remove(theme_table, (GHRFunc)check_if_theme_or_loader,
155 &loaders);
164 156
165 /* Add themes from ~/.purple */ 157 /* Add themes from ~/.purple */
166 path = g_build_filename(purple_user_dir(), "themes", NULL); 158 path = g_build_filename(purple_user_dir(), "themes", NULL);
167 purple_theme_manager_build_dir(path); 159 purple_theme_manager_build_dir(loaders, path);
168 g_free(path); 160 g_free(path);
169 161
170 /* look for XDG_DATA_HOME. If we don't have it use ~/.local, and add it */ 162 /* look for XDG_DATA_HOME. If we don't have it use ~/.local, and add it */
171 if ((xdg = g_getenv("XDG_DATA_HOME")) != NULL) 163 if ((xdg = g_getenv("XDG_DATA_HOME")) != NULL)
172 path = g_build_filename(xdg, "themes", NULL); 164 path = g_build_filename(xdg, "themes", NULL);
173 else 165 else
174 path = g_build_filename(purple_home_dir(), ".local", "themes", NULL); 166 path = g_build_filename(purple_home_dir(), ".local", "themes", NULL);
175 167
176 purple_theme_manager_build_dir(path); 168 purple_theme_manager_build_dir(loaders, path);
177 g_free(path); 169 g_free(path);
178 170
179 /* now dig through XDG_DATA_DIRS and add those too */ 171 /* now dig through XDG_DATA_DIRS and add those too */
180 xdg = g_getenv("XDG_DATA_DIRS"); 172 xdg = g_getenv("XDG_DATA_DIRS");
181 if (xdg) { 173 if (xdg) {
182 gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0); 174 gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0);
183 175
184 for (i = 0; xdg_dirs[i]; i++) { 176 for (i = 0; xdg_dirs[i]; i++) {
185 path = g_build_filename(xdg_dirs[i], "themes", NULL); 177 path = g_build_filename(xdg_dirs[i], "themes", NULL);
186 purple_theme_manager_build_dir(path); 178 purple_theme_manager_build_dir(loaders, path);
187 g_free(path); 179 g_free(path);
188 } 180 }
189 181
190 g_strfreev(xdg_dirs); 182 g_strfreev(xdg_dirs);
191 } 183 }
184
185 g_slist_free(loaders);
192 } 186 }
193 187
194 void 188 void
195 purple_theme_manager_uninit(void) 189 purple_theme_manager_uninit(void)
196 { 190 {