changeset 32224:9d5b87e1a4d0

merge of '246ce23ba85b41bf89269edfa8ec16583ad89fb3' and '7b2b39f29c663a3b1ad776bae1361dcfe6c4db16'
author andrew.victor@mxit.com
date Sat, 24 Sep 2011 22:21:48 +0000
parents 459ffa11348e (diff) 4c64383f05cc (current diff)
children 02a2e8183b1d
files
diffstat 1 files changed, 176 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv-theme.c	Sat Sep 24 22:20:58 2011 +0000
+++ b/pidgin/gtkconv-theme.c	Sat Sep 24 22:21:48 2011 +0000
@@ -68,139 +68,22 @@
 } PidginConvThemePrivate;
 
 /******************************************************************************
- * Globals
- *****************************************************************************/
-
-static GObjectClass *parent_class = NULL;
-
-/******************************************************************************
  * Enums
  *****************************************************************************/
 
 enum {
 	PROP_ZERO = 0,
 	PROP_INFO,
+	PROP_VARIANT,
+	PROP_LAST
 };
 
 /******************************************************************************
- * GObject Stuff
+ * Globals
  *****************************************************************************/
 
-static void
-pidgin_conv_theme_get_property(GObject *obj, guint param_id, GValue *value,
-		GParamSpec *psec)
-{
-	PidginConvTheme *theme = PIDGIN_CONV_THEME(obj);
-
-	switch (param_id) {
-		case PROP_INFO:
-			g_value_set_boxed(value, (gpointer)pidgin_conversation_theme_get_info(theme));
-			break;
-		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
-			break;
-	}
-}
-
-static void
-pidgin_conv_theme_set_property(GObject *obj, guint param_id, const GValue *value,
-		GParamSpec *psec)
-{
-	PidginConvTheme *theme = PIDGIN_CONV_THEME(obj);
-
-	switch (param_id) {
-		case PROP_INFO:
-			pidgin_conversation_theme_set_info(theme, g_value_get_boxed(value));
-			break;
-		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
-			break;
-	}
-}
-
-static void
-pidgin_conv_theme_init(GTypeInstance *instance,
-		gpointer klass)
-{
-	PidginConvThemePrivate *priv;
-
-	priv = PIDGIN_CONV_THEME_GET_PRIVATE(instance);
-}
-
-static void
-pidgin_conv_theme_finalize(GObject *obj)
-{
-	PidginConvThemePrivate *priv;
-
-	priv = PIDGIN_CONV_THEME_GET_PRIVATE(obj);
-
-	g_free(priv->template_html);
-	g_free(priv->header_html);
-	g_free(priv->footer_html);
-	g_free(priv->topic_html);
-	g_free(priv->status_html);
-	g_free(priv->content_html);
-	g_free(priv->incoming_content_html);
-	g_free(priv->outgoing_content_html);
-	g_free(priv->incoming_next_content_html);
-	g_free(priv->outgoing_next_content_html);
-	g_free(priv->incoming_context_html);
-	g_free(priv->outgoing_context_html);
-	g_free(priv->incoming_next_context_html);
-	g_free(priv->outgoing_next_context_html);
-	g_free(priv->basestyle_css);
-
-	if (priv->info)
-		g_hash_table_destroy(priv->info);
-
-	parent_class->finalize(obj);
-}
-
-static void
-pidgin_conv_theme_class_init(PidginConvThemeClass *klass)
-{
-	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
-	GParamSpec *pspec;
-
-	parent_class = g_type_class_peek_parent(klass);
-
-	g_type_class_add_private(klass, sizeof(PidginConvThemePrivate));
-
-	obj_class->get_property = pidgin_conv_theme_get_property;
-	obj_class->set_property = pidgin_conv_theme_set_property;
-	obj_class->finalize = pidgin_conv_theme_finalize;
-
-	/* INFO */
-	pspec = g_param_spec_boxed("info", "Info",
-			"The information about this theme",
-			G_TYPE_HASH_TABLE,
-			G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-	g_object_class_install_property(obj_class, PROP_INFO, pspec);
-
-}
-
-GType
-pidgin_conversation_theme_get_type(void)
-{
-	static GType type = 0;
-	if (type == 0) {
-		static const GTypeInfo info = {
-			sizeof(PidginConvThemeClass),
-			NULL, /* base_init */
-			NULL, /* base_finalize */
-			(GClassInitFunc)pidgin_conv_theme_class_init, /* class_init */
-			NULL, /* class_finalize */
-			NULL, /* class_data */
-			sizeof(PidginConvTheme),
-			0, /* n_preallocs */
-			pidgin_conv_theme_init, /* instance_init */
-			NULL, /* value table */
-		};
-		type = g_type_register_static(PURPLE_TYPE_THEME,
-				"PidginConvTheme", &info, 0);
-	}
-	return type;
-}
+static GObjectClass *parent_class = NULL;
+static GParamSpec *properties[PROP_LAST];
 
 /******************************************************************************
  * Helper Functions
@@ -490,6 +373,174 @@
 	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);
+}
+
+/******************************************************************************
+ * GObject Stuff
+ *****************************************************************************/
+
+static void
+pidgin_conv_theme_get_property(GObject *obj, guint param_id, GValue *value,
+		GParamSpec *psec)
+{
+	PidginConvTheme *theme = PIDGIN_CONV_THEME(obj);
+
+	switch (param_id) {
+		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;
+	}
+}
+
+static void
+pidgin_conv_theme_set_property(GObject *obj, guint param_id, const GValue *value,
+		GParamSpec *psec)
+{
+	PidginConvTheme *theme = PIDGIN_CONV_THEME(obj);
+
+	switch (param_id) {
+		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;
+	}
+}
+
+static void
+pidgin_conv_theme_init(GTypeInstance *instance,
+		gpointer klass)
+{
+	PidginConvThemePrivate *priv;
+
+	priv = PIDGIN_CONV_THEME_GET_PRIVATE(instance);
+}
+
+static void
+pidgin_conv_theme_finalize(GObject *obj)
+{
+	PidginConvThemePrivate *priv;
+	GList *list;
+
+	priv = PIDGIN_CONV_THEME_GET_PRIVATE(obj);
+
+	g_free(priv->template_html);
+	g_free(priv->header_html);
+	g_free(priv->footer_html);
+	g_free(priv->topic_html);
+	g_free(priv->status_html);
+	g_free(priv->content_html);
+	g_free(priv->incoming_content_html);
+	g_free(priv->outgoing_content_html);
+	g_free(priv->incoming_next_content_html);
+	g_free(priv->outgoing_next_content_html);
+	g_free(priv->incoming_context_html);
+	g_free(priv->outgoing_context_html);
+	g_free(priv->incoming_next_context_html);
+	g_free(priv->outgoing_next_context_html);
+	g_free(priv->basestyle_css);
+
+	if (priv->info)
+		g_hash_table_destroy(priv->info);
+
+	list = priv->variants;
+	while (list) {
+		g_free(list->data);
+		list = g_list_delete_link(list, list);
+	}
+	g_free(priv->variant);
+
+	parent_class->finalize(obj);
+}
+
+static void
+pidgin_conv_theme_class_init(PidginConvThemeClass *klass)
+{
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+	GParamSpec *pspec;
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	g_type_class_add_private(klass, sizeof(PidginConvThemePrivate));
+
+	obj_class->get_property = pidgin_conv_theme_get_property;
+	obj_class->set_property = pidgin_conv_theme_set_property;
+	obj_class->finalize = pidgin_conv_theme_finalize;
+
+	/* INFO */
+	pspec = g_param_spec_boxed("info", "Info",
+			"The information about this theme",
+			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;
+
+}
+
+GType
+pidgin_conversation_theme_get_type(void)
+{
+	static GType type = 0;
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PidginConvThemeClass),
+			NULL, /* base_init */
+			NULL, /* base_finalize */
+			(GClassInitFunc)pidgin_conv_theme_class_init, /* class_init */
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof(PidginConvTheme),
+			0, /* n_preallocs */
+			pidgin_conv_theme_init, /* instance_init */
+			NULL, /* value table */
+		};
+		type = g_type_register_static(PURPLE_TYPE_THEME,
+				"PidginConvTheme", &info, 0);
+	}
+	return type;
+}
+
 /*****************************************************************************
  * Public API functions
  *****************************************************************************/
@@ -622,29 +673,14 @@
 
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
-	return g_strdup(priv->variant);
+	return priv->variant;
 }
 
 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 *