gobjectification: c504408b: Use GValue rather than PurpleValue to ho...

resiak at pidgin.im resiak at pidgin.im
Wed Jul 9 06:06:08 EDT 2008


-----------------------------------------------------------------
Revision: c504408b67e3c35dff5bf5671f86733e36de98b0
Ancestor: babab09c6944f786ca4078ef09aaf82bea3aa701
Author: resiak at pidgin.im
Date: 2008-07-04T22:19:38
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/c504408b67e3c35dff5bf5671f86733e36de98b0

Modified files:
        libpurple/blist.c libpurple/blist.h pidgin/gtkconv.c

ChangeLog: 

Use GValue rather than PurpleValue to hold blist node settings.

-------------- next part --------------
============================================================
--- libpurple/blist.c	46d5f25c44c505c9218c887221afbc530c05676f
+++ libpurple/blist.c	3de398a583bf8603d0b5d591f61202933e619d60
@@ -99,12 +99,12 @@ value_to_xmlnode(gpointer key, gpointer 
 value_to_xmlnode(gpointer key, gpointer hvalue, gpointer user_data)
 {
 	const char *name;
-	PurpleValue *value;
+	GValue *value;
 	xmlnode *node, *child;
 	char buf[20];
 
 	name    = (const char *)key;
-	value   = (PurpleValue *)hvalue;
+	value   = (GValue *)hvalue;
 	node    = (xmlnode *)user_data;
 
 	g_return_if_fail(value != NULL);
@@ -112,20 +112,30 @@ value_to_xmlnode(gpointer key, gpointer 
 	child = xmlnode_new_child(node, "setting");
 	xmlnode_set_attrib(child, "name", name);
 
-	if (purple_value_get_type(value) == PURPLE_TYPE_INT) {
-		xmlnode_set_attrib(child, "type", "int");
-		snprintf(buf, sizeof(buf), "%d", purple_value_get_int(value));
-		xmlnode_insert_data(child, buf, -1);
+	switch (G_VALUE_TYPE(value)) {
+		case G_TYPE_INT: {
+			gint i = g_value_get_int(value);
+			xmlnode_set_attrib(child, "type", "int");
+			snprintf(buf, sizeof(buf), "%d", i);
+			xmlnode_insert_data(child, buf, -1);
+			break;
+		}
+		case G_TYPE_STRING: {
+			const gchar *s = g_value_get_string(value);
+			xmlnode_set_attrib(child, "type", "string");
+			xmlnode_insert_data(child, s, -1);
+			break;
+		}
+		case G_TYPE_BOOLEAN: {
+			gboolean b = g_value_get_boolean(value);
+			xmlnode_set_attrib(child, "type", "bool");
+			snprintf(buf, sizeof(buf), "%d", b);
+			xmlnode_insert_data(child, buf, -1);
+			break;
+		}
+		default:
+			g_assert_not_reached();
 	}
-	else if (purple_value_get_type(value) == PURPLE_TYPE_STRING) {
-		xmlnode_set_attrib(child, "type", "string");
-		xmlnode_insert_data(child, purple_value_get_string(value), -1);
-	}
-	else if (purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN) {
-		xmlnode_set_attrib(child, "type", "bool");
-		snprintf(buf, sizeof(buf), "%d", purple_value_get_boolean(value));
-		xmlnode_insert_data(child, buf, -1);
-	}
 }
 
 static void
@@ -2515,23 +2525,13 @@ purple_blist_request_add_group(void)
 		ui_ops->request_add_group();
 }
 
-static void
-purple_blist_node_setting_free(gpointer data)
-{
-	PurpleValue *value;
-
-	value = (PurpleValue *)data;
-
-	purple_value_destroy(value);
-}
-
 static void purple_blist_node_initialize_settings(PurpleBlistNode *node)
 {
 	if (node->settings)
 		return;
 
 	node->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
-			(GDestroyNotify)purple_blist_node_setting_free);
+			(GDestroyNotify)purple_g_value_slice_free);
 }
 
 void purple_blist_node_remove_setting(PurpleBlistNode *node, const char *key)
@@ -2568,17 +2568,29 @@ purple_blist_node_get_type(PurpleBlistNo
 	return node->type;
 }
 
+
+gboolean
+purple_blist_node_has_setting(PurpleBlistNode *node,
+                              const char *key)
+{
+	g_return_val_if_fail(node != NULL, FALSE);
+	g_return_val_if_fail(node->settings != NULL, FALSE);
+	g_return_val_if_fail(key != NULL, FALSE);
+
+	return (g_hash_table_lookup(node->settings, key) != NULL);
+}
+
 void
 purple_blist_node_set_bool(PurpleBlistNode* node, const char *key, gboolean data)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_if_fail(node != NULL);
 	g_return_if_fail(node->settings != NULL);
 	g_return_if_fail(key != NULL);
 
-	value = purple_value_new(PURPLE_TYPE_BOOLEAN);
-	purple_value_set_boolean(value, data);
+	value = purple_g_value_slice_new(G_TYPE_BOOLEAN);
+	g_value_set_boolean(value, data);
 
 	g_hash_table_replace(node->settings, g_strdup(key), value);
 
@@ -2588,7 +2600,7 @@ purple_blist_node_get_bool(PurpleBlistNo
 gboolean
 purple_blist_node_get_bool(PurpleBlistNode* node, const char *key)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_val_if_fail(node != NULL, FALSE);
 	g_return_val_if_fail(node->settings != NULL, FALSE);
@@ -2599,22 +2611,22 @@ purple_blist_node_get_bool(PurpleBlistNo
 	if (value == NULL)
 		return FALSE;
 
-	g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN, FALSE);
+	g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(value), FALSE);
 
-	return purple_value_get_boolean(value);
+	return g_value_get_boolean(value);
 }
 
 void
 purple_blist_node_set_int(PurpleBlistNode* node, const char *key, int data)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_if_fail(node != NULL);
 	g_return_if_fail(node->settings != NULL);
 	g_return_if_fail(key != NULL);
 
-	value = purple_value_new(PURPLE_TYPE_INT);
-	purple_value_set_int(value, data);
+	value = purple_g_value_slice_new(G_TYPE_INT);
+	g_value_set_int(value, data);
 
 	g_hash_table_replace(node->settings, g_strdup(key), value);
 
@@ -2624,7 +2636,7 @@ purple_blist_node_get_int(PurpleBlistNod
 int
 purple_blist_node_get_int(PurpleBlistNode* node, const char *key)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_val_if_fail(node != NULL, 0);
 	g_return_val_if_fail(node->settings != NULL, 0);
@@ -2635,22 +2647,22 @@ purple_blist_node_get_int(PurpleBlistNod
 	if (value == NULL)
 		return 0;
 
-	g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_INT, 0);
+	g_return_val_if_fail(G_VALUE_HOLDS_INT(value), 0);
 
-	return purple_value_get_int(value);
+	return g_value_get_int(value);
 }
 
 void
 purple_blist_node_set_string(PurpleBlistNode* node, const char *key, const char *data)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_if_fail(node != NULL);
 	g_return_if_fail(node->settings != NULL);
 	g_return_if_fail(key != NULL);
 
-	value = purple_value_new(PURPLE_TYPE_STRING);
-	purple_value_set_string(value, data);
+	value = purple_g_value_slice_new(G_TYPE_STRING);
+	g_value_set_string(value, data);
 
 	g_hash_table_replace(node->settings, g_strdup(key), value);
 
@@ -2660,7 +2672,7 @@ purple_blist_node_get_string(PurpleBlist
 const char *
 purple_blist_node_get_string(PurpleBlistNode* node, const char *key)
 {
-	PurpleValue *value;
+	GValue *value;
 
 	g_return_val_if_fail(node != NULL, NULL);
 	g_return_val_if_fail(node->settings != NULL, NULL);
@@ -2671,9 +2683,9 @@ purple_blist_node_get_string(PurpleBlist
 	if (value == NULL)
 		return NULL;
 
-	g_return_val_if_fail(purple_value_get_type(value) == PURPLE_TYPE_STRING, NULL);
+	g_return_val_if_fail(G_VALUE_HOLDS_STRING(value), NULL);
 
-	return purple_value_get_string(value);
+	return g_value_get_string(value);
 }
 
 GList *
============================================================
--- libpurple/blist.h	b1dac94a9ac59d6dc854ceed75d0a1e5438bd57c
+++ libpurple/blist.h	76d45efe5b13522b4a0bc3e8e676a26b84ca940e
@@ -99,8 +99,14 @@ struct _PurpleBlistNode {
 	PurpleBlistNode *next;                /**< The sibling after this buddy.  */
 	PurpleBlistNode *parent;              /**< The parent of this node        */
 	PurpleBlistNode *child;               /**< The child of this node         */
-	GHashTable *settings;               /**< per-node settings              */
-	void          *ui_data;             /**< The UI can put data here.      */
+
+	/* FIXME: this should be made private */
+	GHashTable *settings;                 /**< per-node settings; keys are
+	                                           <tt>gchar *</tt>, values are
+	                                           slice-allocated
+	                                           <tt>GValue</tt>.  */
+
+	void          *ui_data;               /**< The UI can put data here.      */
 	PurpleBlistNodeFlags flags;           /**< The buddy flags                */
 };
 
@@ -885,6 +891,16 @@ void purple_blist_request_add_group(void
 void purple_blist_request_add_group(void);
 
 /**
+ * Checks whether a node has a particular setting.
+ *
+ * @param node  The node in question
+ * @param key   The name of a setting
+ * @return @c TRUE if @a node has any value set for @a key, and @c FALSE
+ *         otherwise.
+ */
+gboolean purple_blist_node_has_setting(PurpleBlistNode *node, const char *key);
+
+/**
  * Associates a boolean with a node in the buddy list
  *
  * @param node  The node to associate the data with
============================================================
--- pidgin/gtkconv.c	837235a34b9dd7005d2da85f38ff3317f8f4eeef
+++ pidgin/gtkconv.c	096b3e002aebfe10ee4d7d9390fda2f9bbc45193
@@ -5097,7 +5097,6 @@ private_gtkconv_new(PurpleConversation *
 	GtkWidget *pane = NULL;
 	GtkWidget *tab_cont;
 	PurpleBlistNode *convnode;
-	PurpleValue *value;
 
 	if (conv_type == PURPLE_CONV_TYPE_IM && (gtkconv = pidgin_conv_find_gtkconv(conv))) {
 		conv->ui_data = gtkconv;
@@ -5181,10 +5180,11 @@ private_gtkconv_new(PurpleConversation *
 		gtkconv->make_sound = TRUE;
 
 	if (convnode != NULL &&
-	    (value = g_hash_table_lookup(convnode->settings, "enable-logging")) &&
-	    purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN)
+	    purple_blist_node_has_setting(convnode, "enable-logging"))
 	{
-		purple_conversation_set_logging(conv, purple_value_get_boolean(value));
+		gboolean enable_logging = purple_blist_node_get_bool(convnode,
+			"enable-logging");
+		purple_conversation_set_logging(conv, enable_logging);
 	}
 
 	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_formatting_toolbar"))


More information about the Commits mailing list