gobjectification: 9e10aac2: Parameterized PurpleChat

aluink at soc.pidgin.im aluink at soc.pidgin.im
Wed Jul 1 23:05:34 EDT 2009


-----------------------------------------------------------------
Revision: 9e10aac209143fe6adc17d38c9e6b2a317a9e459
Ancestor: 379595b90783157740701b9923c5eb761e51efc7
Author: aluink at soc.pidgin.im
Date: 2009-07-01T16:55:10
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/9e10aac209143fe6adc17d38c9e6b2a317a9e459

Modified files:
        finch/gntblist.c libpurple/blist.h libpurple/chat.c
        libpurple/chat.h libpurple/protocols/qq/group_internal.c
        pidgin/gtkblist.c pidgin/gtkdialogs.c

ChangeLog: 

Parameterized PurpleChat

-------------- next part --------------
============================================================
--- finch/gntblist.c	abdb101468d14f92b8de6779f086f0ba00f2a418
+++ finch/gntblist.c	32e12f417b6239606badc46b28284f70606c0934
@@ -744,7 +744,7 @@ add_chat_cb(void *data, PurpleRequestFie
 			purple_blist_add_group(grp, NULL);
 		}
 		purple_blist_add_chat(chat, grp, NULL);
-		purple_blist_alias_chat(chat, alias);
+		purple_chat_set_alias(chat, alias);
 		purple_blist_node_set_bool((PurpleBlistNode*)chat, "gnt-autojoin", autojoin);
 		if (autojoin) {
 			join_chat(chat);
@@ -1389,7 +1389,7 @@ rename_blist_node(PurpleBlistNode *node,
 		purple_blist_alias_buddy((PurpleBuddy*)node, name);
 		serv_alias_buddy((PurpleBuddy*)node);
 	} else if (PURPLE_IS_CHAT(node))
-		purple_blist_alias_chat((PurpleChat*)node, name);
+		purple_chat_set_alias((PurpleChat*)node, name);
 	else if (PURPLE_IS_GROUP(node) && (name != NULL))
 		purple_blist_rename_group((PurpleGroup*)node, name);
 	else
============================================================
--- libpurple/blist.h	e38f9262ee7254d33d097361d7e3d563eaa3107b
+++ libpurple/blist.h	0dbe462ed24bf7230be59224963bf52e04029987
@@ -397,17 +397,6 @@ PurpleChat *purple_blist_find_chat(Purpl
 PurpleChat *purple_blist_find_chat(PurpleAccount *account, const char *name);
 
 /**
- * Returns the account the chat belongs to.
- *
- * @param chat  The chat.
- *
- * @return  The account the chat belongs to.
- *
- * @since 2.4.0
- */
-PurpleAccount *purple_chat_get_account(PurpleChat *chat);
-
-/**
  * Called when an account connects.  Tells the UI to update all the
  * buddies.
  *
============================================================
--- libpurple/chat.c	9c950e3e65a6c1fdbbf4412f28eab0ca47e9d459
+++ libpurple/chat.c	be00e519915a5f34b5c0ad4b799e3546ea4a6db7
@@ -123,7 +123,7 @@ parse_chat(PurpleGroup *group, xmlnode *
 	g_free(alias);
 }
 
-void purple_blist_alias_chat(PurpleChat *chat, const char *alias)
+void purple_chat_set_alias(PurpleChat *chat, const char *alias)
 {
 	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
 	char *old_alias;
@@ -158,28 +158,6 @@ void purple_blist_alias_chat(PurpleChat 
 	g_free(old_alias);
 }
 
-PurpleChat *purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components)
-{
-	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
-	PurpleChat *chat;
-
-	g_return_val_if_fail(account != NULL, FALSE);
-	g_return_val_if_fail(components != NULL, FALSE);
-
-	chat = g_object_new(PURPLE_CHAT_TYPE, NULL);
-	chat->account = account;
-	if ((alias != NULL) && (*alias != '\0'))
-		chat->alias = purple_utf8_strip_unprintables(alias);
-	chat->components = components;
-	purple_blist_node_initialize_settings((PurpleBlistNode *)chat);
-
-	if (ops != NULL && ops->new_node != NULL)
-		ops->new_node((PurpleBlistNode *)chat);
-
-	PURPLE_DBUS_REGISTER_POINTER(chat, PurpleChat);
-	return chat;
-}
-
 void
 purple_chat_destroy(PurpleChat *chat)
 {
@@ -222,6 +200,14 @@ purple_chat_get_account(PurpleChat *chat
 	return chat->account;
 }
 
+static void
+purple_chat_set_account(PurpleChat *chat, PurpleAccount *account)
+{
+	g_return_if_fail(chat != NULL);
+
+	chat->account = account;
+}
+
 GHashTable *
 purple_chat_get_components(PurpleChat *chat)
 {
@@ -230,12 +216,46 @@ purple_chat_get_components(PurpleChat *c
 	return chat->components;
 }
 
+static void
+purple_chat_set_components(PurpleChat *chat, GHashTable *components)
+{
+	g_return_if_fail(chat != NULL);
+
+	chat->components = components;
+}
+
 /******************/
 /*  GObject Code  */
 /******************/
 
+enum {
+	PROP_0,
+	PROP_ALIAS,
+	PROP_ACCOUNT,
+	PROP_COMPONENTS,
+	PROP_LAST
+};
+
+#define PROP_ALIAS_S "alias"
+#define PROP_ACCOUNT_S "account"
+#define PROP_COMPONENTS_S "components"
+
 static GObjectClass *parent_class = NULL;
 
+PurpleChat *purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components)
+{
+	PurpleChat *chat;
+
+	g_return_val_if_fail(account != NULL, FALSE);
+	g_return_val_if_fail(components != NULL, FALSE);
+
+	chat = g_object_new(PURPLE_CHAT_TYPE, 
+									PROP_ACCOUNT_S, account, 
+									PROP_ALIAS_S, alias, 
+									PROP_COMPONENTS_S, components);
+	return chat;
+}
+
 static void
 purple_chat_finalize(GObject *object)
 {
@@ -248,18 +268,89 @@ static void
 }
 
 static void
+purple_chat_set_property(GObject *obj, guint param_id, GValue *value,
+		GParamSpec *pspec)
+{
+	PurpleChat *chat = PURPLE_CHAT(obj);
+	switch(param_id){
+		case PROP_ALIAS:
+			purple_chat_set_alias(chat, g_value_get_string(value));
+			break;
+		case PROP_ACCOUNT:
+			purple_chat_set_account(chat, g_value_get_object(value));
+			break;
+		case PROP_COMPONENTS:
+			purple_chat_set_components(chat, g_value_get_object(value));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+	}
+}
+
+static void
+purple_chat_get_property(GObject *obj, guint param_id, GValue *value,
+		GParamSpec *pspec)
+{
+	PurpleChat *chat = PURPLE_CHAT(obj);
+	switch(param_id){
+		case PROP_ALIAS:
+			g_value_set_string(value, purple_chat_get_name(chat));
+			break;
+		case PROP_COMPONENTS:
+			g_value_set_object(value, purple_chat_get_components(chat));
+			break;
+		case PROP_ACCOUNT:
+			g_value_set_object(value, purple_chat_get_account(chat));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+			break;
+	}
+}
+
+static void
 purple_chat_class_init(PurpleChatClass *klass)
 {
 	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 
 	parent_class = g_type_class_peek_parent(klass);
 	obj_class->finalize = purple_chat_finalize;
+
+	/* Setup properties */
+	obj_class->get_property = purple_chat_get_property;
+	obj_class->set_property = purple_chat_set_property;
+
+	g_object_class_install_property(obj_class, PROP_ALIAS,
+			g_param_spec_string(PROP_ALIAS_S, _("Alias"),
+				_("The alias for the chat."), NULL,
+				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
+			);
+
+	g_object_class_install_property(obj_class, PROP_ACCOUNT,
+			g_param_spec_string(PROP_ACCOUNT_S, _("Account"),
+				_("The account for the chat."), NULL,
+				G_PARAM_CONSTRUCT_ONLY)
+			);
+
+	g_object_class_install_property(obj_class, PROP_COMPONENTS,
+			g_param_spec_string(PROP_COMPONENTS_S, _("Components"),
+				_("The components for the chat."), NULL,
+				G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY)
+			);
 }
 
 static void
 purple_chat_init(GTypeInstance *instance, gpointer class)
 {
+	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
+	PurpleChat *chat = PURPLE_CHAT(instance);
 
+	purple_blist_node_initialize_settings((PurpleBlistNode *)chat);
+
+	if (ops != NULL && ops->new_node != NULL)
+		ops->new_node((PurpleBlistNode *)chat);
+
+	PURPLE_DBUS_REGISTER_POINTER(chat, PurpleChat);
 }
 
 GType
============================================================
--- libpurple/chat.h	6bf9a79a648f9b556d194807f7e19ead8dc278ea
+++ libpurple/chat.h	1eae39ee9c5c181ec9566cf71db75df3498ed853
@@ -88,12 +88,15 @@ const char *purple_chat_get_name(PurpleC
 const char *purple_chat_get_name(PurpleChat *chat);
 
 /**
- * Aliases a chat in the buddy list.
+ * Returns the account the chat belongs to.
  *
- * @param chat  The chat whose alias will be changed.
- * @param alias The chat's new alias.
+ * @param chat  The chat.
+ *
+ * @return  The account the chat belongs to.
+ *
+ * @since 2.4.0
  */
-void purple_blist_alias_chat(PurpleChat *chat, const char *alias);
+PurpleAccount *purple_chat_get_account(PurpleChat *chat);
 
 /**
  * Get a hashtable containing information about a chat.
@@ -107,6 +110,14 @@ GHashTable *purple_chat_get_components(P
 GHashTable *purple_chat_get_components(PurpleChat *chat);
 
 /**
+ * Aliases a chat in the buddy list.
+ *
+ * @param chat  The chat whose alias will be changed.
+ * @param alias The chat's new alias.
+ */
+void purple_chat_set_alias(PurpleChat *chat, const char *alias);
+
+/**
  * Get the GType for PurpleChat
  */
 GType purple_chat_get_type(void);
============================================================
--- libpurple/protocols/qq/group_internal.c	f909fad4110cfe31acdba3a6b0aaf1b5bdd84243
+++ libpurple/protocols/qq/group_internal.c	ea4921fefc58ba756a0685aa9cc9fa7d27d3aeac
@@ -106,7 +106,7 @@ void qq_room_update_chat_info(PurpleChat
 	GHashTable *components;
 
 	if (rmd->title_utf8 != NULL && strlen(rmd->title_utf8) > 0) {
-		purple_blist_alias_chat(chat, rmd->title_utf8);
+		purple_chat_set_alias(chat, rmd->title_utf8);
 	}
 
 	components = purple_chat_get_components(chat);
============================================================
--- pidgin/gtkblist.c	8c36e7b835f1342654e7292c3daef900378c425e
+++ pidgin/gtkblist.c	f37ce3cbe1abc91c62901c10c948a8e5fb6dc525
@@ -635,7 +635,7 @@ static void gtk_blist_renderer_edited_cb
 			purple_blist_rename_group(PURPLE_GROUP(node), arg2);
 		}
 	} else if(PURPLE_IS_CHAT(node)) {
-		purple_blist_alias_chat(PURPLE_CHAT(node), arg2);
+		purple_chat_set_alias(PURPLE_CHAT(node), arg2);
 	}
 	pidgin_blist_refresh(list);
 }
============================================================
--- pidgin/gtkdialogs.c	4422e8747889f9d44a2f83ffd318c3e949c82850
+++ pidgin/gtkdialogs.c	74f6ff30a67dbc0d74275be4e5c8e9d5ed3fe2e9
@@ -1036,7 +1036,7 @@ pidgin_dialogs_alias_chat_cb(PurpleChat 
 static void
 pidgin_dialogs_alias_chat_cb(PurpleChat *chat, const char *new_alias)
 {
-	purple_blist_alias_chat(chat, new_alias);
+	purple_chat_set_alias(chat, new_alias);
 }
 
 void


More information about the Commits mailing list