changeset 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 2e8721fceaa5
children c26d13e7f52b
files pidgin/gtkconv-theme-loader.c
diffstat 1 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv-theme-loader.c	Mon Sep 19 20:39:09 2011 +0000
+++ b/pidgin/gtkconv-theme-loader.c	Mon Sep 19 21:03:21 2011 +0000
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "pidgin.h"
 #include "gtkconv-theme-loader.h"
 #include "gtkconv-theme.h"
 
@@ -185,8 +186,31 @@
 	g_free(variant_dir);
 
 	if (variants) {
+		char *prefname;
+		const char *default_variant = NULL;
 		const char *file;
-		char *name;
+
+		/* Try user-set variant */
+		prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s/variant",
+		                           CFBundleIdentifier);
+		default_variant = purple_prefs_get_string(prefname);
+		g_free(prefname);
+
+		if (default_variant && *default_variant) {
+			pidgin_conversation_theme_set_variant(theme, default_variant);
+
+		} else {
+			/* Try theme default */
+			val = g_hash_table_lookup(info, "DefaultVariant");
+			if (val && G_VALUE_HOLDS_STRING(val)) {
+				default_variant = g_value_get_string(val);
+				if (default_variant && *default_variant)
+					pidgin_conversation_theme_set_variant(theme, default_variant);
+				else
+					default_variant = NULL;
+			} else
+				default_variant = NULL;
+		}
 
 		while ((file = g_dir_read_name(variants)) != NULL) {
 			const char *end = g_strrstr(file, ".css");
@@ -197,6 +221,12 @@
 
 			name = g_strndup(file, end - file);
 			pidgin_conversation_theme_add_variant(theme, name);
+
+			/* Set variant with first found */
+			if (!default_variant) {
+				pidgin_conversation_theme_set_variant(theme, name);
+				default_variant = name;
+			}
 		}
 
 		g_dir_close(variants);