changeset 32220:be14cf8a4c91

Make the current variant a property.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 24 Sep 2011 21:15:29 +0000
parents 2571b01e849c
children 5cf6c4a8dcab
files pidgin/gtkconv-theme.c
diffstat 1 files changed, 53 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv-theme.c	Sat Sep 24 17:04:09 2011 +0000
+++ b/pidgin/gtkconv-theme.c	Sat Sep 24 21:15:29 2011 +0000
@@ -37,6 +37,8 @@
 #define PIDGIN_CONV_THEME_GET_PRIVATE(Gobject) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((Gobject), PIDGIN_TYPE_CONV_THEME, PidginConvThemePrivate))
 
+static void _set_variant(PidginConvTheme *theme, const char *variant);
+
 /******************************************************************************
  * Structs
  *****************************************************************************/
@@ -68,21 +70,24 @@
 } PidginConvThemePrivate;
 
 /******************************************************************************
- * Globals
- *****************************************************************************/
-
-static GObjectClass *parent_class = NULL;
-
-/******************************************************************************
  * Enums
  *****************************************************************************/
 
 enum {
 	PROP_ZERO = 0,
 	PROP_INFO,
+	PROP_VARIANT,
+	PROP_LAST
 };
 
 /******************************************************************************
+ * Globals
+ *****************************************************************************/
+
+static GObjectClass *parent_class = NULL;
+static GParamSpec *properties[PROP_LAST];
+
+/******************************************************************************
  * GObject Stuff
  *****************************************************************************/
 
@@ -96,6 +101,11 @@
 		case PROP_INFO:
 			g_value_set_boxed(value, (gpointer)pidgin_conversation_theme_get_info(theme));
 			break;
+
+		case PROP_VARIANT:
+			g_value_set_string(value, pidgin_conversation_theme_get_variant(theme));
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
 			break;
@@ -112,6 +122,11 @@
 		case PROP_INFO:
 			pidgin_conversation_theme_set_info(theme, g_value_get_boxed(value));
 			break;
+
+		case PROP_VARIANT:
+			_set_variant(theme, g_value_get_string(value));
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
 			break;
@@ -176,6 +191,14 @@
 			G_TYPE_HASH_TABLE,
 			G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 	g_object_class_install_property(obj_class, PROP_INFO, pspec);
+	properties[PROP_INFO] = pspec;
+
+	/* VARIANT */
+	pspec = g_param_spec_string("variant", "Variant",
+			"The current variant for this theme",
+			NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+	g_object_class_install_property(obj_class, PROP_VARIANT, pspec);
+	properties[PROP_VARIANT] = pspec;
 
 }
 
@@ -490,6 +513,28 @@
 	return priv->outgoing_next_context_html;
 }
 
+static void
+_set_variant(PidginConvTheme *theme, const char *variant)
+{
+	PidginConvThemePrivate *priv;
+	const GValue *val;
+	char *prefname;
+
+	g_return_if_fail(theme != NULL);
+	g_return_if_fail(variant != NULL);
+
+	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
+
+	g_free(priv->variant);
+	priv->variant = g_strdup(variant);
+
+	val = get_key(priv, "CFBundleIdentifier", FALSE);
+	prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s/variant",
+	                           g_value_get_string(val));
+	purple_prefs_set_string(prefname, variant);
+	g_free(prefname);
+}
+
 /*****************************************************************************
  * Public API functions
  *****************************************************************************/
@@ -628,23 +673,8 @@
 void
 pidgin_conversation_theme_set_variant(PidginConvTheme *theme, const char *variant)
 {
-	PidginConvThemePrivate *priv;
-	const GValue *val;
-	char *prefname;
-
-	g_return_if_fail(theme != NULL);
-	g_return_if_fail(variant != NULL);
-
-	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
-
-	g_free(priv->variant);
-	priv->variant = g_strdup(variant);
-
-	val = get_key(priv, "CFBundleIdentifier", FALSE);
-	prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s/variant",
-	                           g_value_get_string(val));
-	purple_prefs_set_string(prefname, variant);
-	g_free(prefname);
+	_set_variant(theme, variant);
+	g_object_notify_by_pspec(G_OBJECT(theme), properties[PROP_VARIANT]);
 }
 
 const GList *