comparison pidgin/gtkconv-theme-loader.c @ 32651:8716216050ee

Set the default variant when loading the theme. The priorities are value-from-prefs > default-from-theme > first-name-read.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 19 Sep 2011 21:03:21 +0000
parents 1caf13175039
children cc6efa22cdf3
comparison
equal deleted inserted replaced
32650:2e8721fceaa5 32651:8716216050ee
18 * You should have received a copy of the GNU General Public License 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 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 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 */ 21 */
22 22
23 #include "pidgin.h"
23 #include "gtkconv-theme-loader.h" 24 #include "gtkconv-theme-loader.h"
24 #include "gtkconv-theme.h" 25 #include "gtkconv-theme.h"
25 26
26 #include "xmlnode.h" 27 #include "xmlnode.h"
27 #include "debug.h" 28 #include "debug.h"
183 variant_dir = g_build_filename(dir, "Contents", "Resources", "Variants", NULL); 184 variant_dir = g_build_filename(dir, "Contents", "Resources", "Variants", NULL);
184 variants = g_dir_open(variant_dir, 0, NULL); 185 variants = g_dir_open(variant_dir, 0, NULL);
185 g_free(variant_dir); 186 g_free(variant_dir);
186 187
187 if (variants) { 188 if (variants) {
189 char *prefname;
190 const char *default_variant = NULL;
188 const char *file; 191 const char *file;
189 char *name; 192
193 /* Try user-set variant */
194 prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s/variant",
195 CFBundleIdentifier);
196 default_variant = purple_prefs_get_string(prefname);
197 g_free(prefname);
198
199 if (default_variant && *default_variant) {
200 pidgin_conversation_theme_set_variant(theme, default_variant);
201
202 } else {
203 /* Try theme default */
204 val = g_hash_table_lookup(info, "DefaultVariant");
205 if (val && G_VALUE_HOLDS_STRING(val)) {
206 default_variant = g_value_get_string(val);
207 if (default_variant && *default_variant)
208 pidgin_conversation_theme_set_variant(theme, default_variant);
209 else
210 default_variant = NULL;
211 } else
212 default_variant = NULL;
213 }
190 214
191 while ((file = g_dir_read_name(variants)) != NULL) { 215 while ((file = g_dir_read_name(variants)) != NULL) {
192 const char *end = g_strrstr(file, ".css"); 216 const char *end = g_strrstr(file, ".css");
193 char *name; 217 char *name;
194 218
195 if ((end == NULL) || (*(end + 4) != '\0')) 219 if ((end == NULL) || (*(end + 4) != '\0'))
196 continue; 220 continue;
197 221
198 name = g_strndup(file, end - file); 222 name = g_strndup(file, end - file);
199 pidgin_conversation_theme_add_variant(theme, name); 223 pidgin_conversation_theme_add_variant(theme, name);
224
225 /* Set variant with first found */
226 if (!default_variant) {
227 pidgin_conversation_theme_set_variant(theme, name);
228 default_variant = name;
229 }
200 } 230 }
201 231
202 g_dir_close(variants); 232 g_dir_close(variants);
203 } 233 }
204 234