gobjectification: e1e95870: Parameterized PurpleBuddy

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


-----------------------------------------------------------------
Revision: e1e95870dec44bcc30219a0adf31b9284aa35ec7
Ancestor: 9e10aac209143fe6adc17d38c9e6b2a317a9e459
Author: aluink at soc.pidgin.im
Date: 2009-07-02T02:59:58
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/e1e95870dec44bcc30219a0adf31b9284aa35ec7

Modified files:
        finch/gntblist.c libpurple/buddy.c libpurple/buddy.h
        libpurple/chat.c libpurple/protocols/jabber/roster.c
        libpurple/protocols/novell/novell.c
        libpurple/protocols/oscar/oscar.c
        libpurple/protocols/qq/buddy_memo.c
        libpurple/protocols/simple/simple.c libpurple/server.c
        pidgin/gtkblist.c pidgin/gtkconv.c pidgin/gtkdialogs.c

ChangeLog: 

Parameterized PurpleBuddy

-------------- next part --------------
============================================================
--- finch/gntblist.c	32e12f417b6239606badc46b28284f70606c0934
+++ finch/gntblist.c	2bcfd9719a474215dae679902df765d105d41bc6
@@ -1383,10 +1383,10 @@ rename_blist_node(PurpleBlistNode *node,
 		PurpleContact *contact = (PurpleContact*)node;
 		PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact);
 		purple_blist_alias_contact(contact, name);
-		purple_blist_alias_buddy(buddy, name);
+		purple_buddy_set_alias(buddy, name);
 		serv_alias_buddy(buddy);
 	} else if (PURPLE_IS_BUDDY(node)) {
-		purple_blist_alias_buddy((PurpleBuddy*)node, name);
+		purple_buddy_set_alias((PurpleBuddy*)node, name);
 		serv_alias_buddy((PurpleBuddy*)node);
 	} else if (PURPLE_IS_CHAT(node))
 		purple_chat_set_alias((PurpleChat*)node, name);
============================================================
--- libpurple/buddy.c	5e6c3534255d110c7c4b33e5a4fdc88af5185d35
+++ libpurple/buddy.c	5697063f68626e980c58a4801a32f8415044387b
@@ -138,7 +138,7 @@ purple_blist_update_buddy_icon(PurpleBud
 	purple_blist_update_node_icon((PurpleBlistNode *)buddy);
 }
 
-void purple_blist_alias_buddy(PurpleBuddy *buddy, const char *alias)
+void purple_buddy_set_alias(PurpleBuddy *buddy, const char *alias)
 {
 	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
 	PurpleConversation *conv;
@@ -220,32 +220,6 @@ void purple_blist_server_alias_buddy(Pur
 	g_free(old_alias);
 }
 
-PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias)
-{
-	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
-	PurpleBuddy *buddy;
-
-	g_return_val_if_fail(account != NULL, NULL);
-	g_return_val_if_fail(name != NULL, NULL);
-
-	buddy = g_object_new(PURPLE_BUDDY_TYPE, NULL);
-	g_object_ref(buddy);
-	buddy->account  = account;
-	buddy->name     = purple_utf8_strip_unprintables(name);
-	buddy->alias    = purple_utf8_strip_unprintables(alias);
-	buddy->presence = purple_presence_new_for_buddy(buddy);
-
-	purple_presence_set_status_active(buddy->presence, "offline", TRUE);
-
-	purple_blist_node_initialize_settings((PurpleBlistNode *)buddy);
-
-	if (ops && ops->new_node)
-		ops->new_node((PurpleBlistNode *)buddy);
-
-	PURPLE_DBUS_REGISTER_POINTER(buddy, PurpleBuddy);
-	return buddy;
-}
-
 void
 purple_buddy_destroy(PurpleBuddy *buddy)
 {
@@ -434,10 +408,48 @@ buddy_to_xmlnode(PurpleBlistNode *bnode)
 	return node;
 }
 
+static void
+purple_buddy_set_account(PurpleBuddy *buddy, PurpleAccount *account)
+{
+	g_return_if_fail(buddy != NULL);
+	buddy->account = account;
+}
+
+static void
+purple_buddy_set_name(PurpleBuddy *buddy, const char *name)
+{
+	g_return_if_fail(buddy != NULL);
+	buddy->name = g_strdup(name);
+}
+
 /******************/
 /*  GObject Code  */
 /******************/
 
+enum {
+	PROP_0,
+	PROP_ACCOUNT,
+	PROP_NAME,
+	PROP_ALIAS,
+	PROP_LAST
+};
+
+#define PROP_ACCOUNT_S "account"
+#define PROP_NAME_S "name"
+#define PROP_ALIAS_S "alias"
+
+PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias)
+{
+	g_return_val_if_fail(account != NULL, NULL);
+	g_return_val_if_fail(name != NULL, NULL);
+
+	return g_object_new(PURPLE_BUDDY_TYPE, 
+									PROP_ACCOUNT_S, account,
+									PROP_NAME_S, name,
+									PROP_ALIAS_S, alias,
+									NULL);
+}
+
 /* GObject destructor function */
 static void
 purple_buddy_finalize(GObject *object)
@@ -478,18 +490,90 @@ static void
 }
 
 static void
+purple_buddy_set_property(GObject *obj, guint param_id, const GValue *value,
+		GParamSpec *pspec)
+{
+	PurpleBuddy *buddy = PURPLE_BUDDY(obj);
+	switch(param_id){
+		case PROP_ACCOUNT:
+			purple_buddy_set_account(buddy, g_value_get_object(value));
+			break;
+		case PROP_NAME:
+			purple_buddy_set_name(buddy, g_value_get_string(value));
+			break;
+		case PROP_ALIAS:
+			purple_buddy_set_alias(buddy, g_value_get_string(value));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+	}
+}
+
+static void
+purple_buddy_get_property(GObject *obj, guint param_id, GValue *value,
+		GParamSpec *pspec)
+{
+	PurpleBuddy *buddy = PURPLE_BUDDY(obj);
+	switch(param_id){
+		case PROP_ACCOUNT:
+			g_value_set_object(value, purple_buddy_get_account(buddy));
+			break;
+		case PROP_NAME:
+			g_value_set_string(value, purple_buddy_get_name(buddy));
+			break;
+		case PROP_ALIAS:
+			g_value_set_string(value, purple_buddy_get_name(buddy));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+			break;
+	}
+}
+
+static void
 purple_buddy_class_init(PurpleBuddyClass *klass)
 {
 	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 
 	parent_class = g_type_class_peek_parent(klass);
 	obj_class->finalize = purple_buddy_finalize;
+
+	obj_class->set_property = purple_buddy_set_property;
+	obj_class->get_property = purple_buddy_get_property;
+
+	g_object_class_install_property(obj_class, PROP_ACCOUNT,
+			g_param_spec_string(PROP_ACCOUNT_S, _("Account"),
+				_("The account for the buddy."), NULL,
+				G_PARAM_CONSTRUCT_ONLY)
+			);
+	g_object_class_install_property(obj_class, PROP_NAME,
+			g_param_spec_string(PROP_NAME_S, _("Name"),
+				_("The name for the buddy."), NULL,
+				G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY)
+			);
+	g_object_class_install_property(obj_class, PROP_ALIAS,
+			g_param_spec_string(PROP_ALIAS_S, _("Alias"),
+				_("The alias for the buddy."), NULL,
+				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
+			);
 }
 
 static void
 purple_buddy_init(GTypeInstance *instance, gpointer class)
 {
+	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
+	PurpleBuddy *buddy = PURPLE_BUDDY(instance);
 
+	buddy->presence = purple_presence_new_for_buddy(buddy);
+
+	purple_presence_set_status_active(buddy->presence, "offline", TRUE);
+
+	purple_blist_node_initialize_settings((PurpleBlistNode *)buddy);
+
+	if (ops && ops->new_node)
+		ops->new_node((PurpleBlistNode *)buddy);
+
+	PURPLE_DBUS_REGISTER_POINTER(buddy, PurpleBuddy);
 }
 
 GType
============================================================
--- libpurple/buddy.h	55eb99b376c4e9012ebf94abcb580f504465feb5
+++ libpurple/buddy.h	9cd2a852c1fc6ca78f003a0d7457a205461a8a77
@@ -165,7 +165,7 @@ gpointer purple_buddy_get_protocol_data(
  * @param buddy  The buddy whose alias will be changed.
  * @param alias  The buddy's alias.
  */
-void purple_blist_alias_buddy(PurpleBuddy *buddy, const char *alias);
+void purple_buddy_set_alias(PurpleBuddy *buddy, const char *alias);
 
 /**
 * Returns the alias of a buddy.
============================================================
--- libpurple/chat.c	be00e519915a5f34b5c0ad4b799e3546ea4a6db7
+++ libpurple/chat.c	53c710db60e9c8fc05d2f5904f70162075bbb6b6
@@ -252,7 +252,8 @@ PurpleChat *purple_chat_new(PurpleAccoun
 	chat = g_object_new(PURPLE_CHAT_TYPE, 
 									PROP_ACCOUNT_S, account, 
 									PROP_ALIAS_S, alias, 
-									PROP_COMPONENTS_S, components);
+									PROP_COMPONENTS_S, components,
+									NULL);
 	return chat;
 }
 
@@ -268,7 +269,7 @@ static void
 }
 
 static void
-purple_chat_set_property(GObject *obj, guint param_id, GValue *value,
+purple_chat_set_property(GObject *obj, guint param_id, const GValue *value,
 		GParamSpec *pspec)
 {
 	PurpleChat *chat = PURPLE_CHAT(obj);
============================================================
--- libpurple/protocols/jabber/roster.c	8dcf172668b221eb515d2116ebb52113583c5891
+++ libpurple/protocols/jabber/roster.c	4c1b220b093a3df46f2455f7a266ef92c5dd1740
@@ -115,7 +115,7 @@ static void add_purple_buddies_to_groups
 		}
 
 		purple_blist_add_buddy(b, NULL, g, NULL);
-		purple_blist_alias_buddy(b, alias);
+		purple_buddy_set_alias(b, alias);
 
 		/* If we just learned about ourself, then fake our status,
 		 * because we won't be receiving a normal presence message
@@ -393,7 +393,7 @@ void jabber_roster_alias_change(PurpleCo
 	PurpleBuddy *b = purple_find_buddy(purple_connection_get_account(gc), name);
 
 	if(b != NULL) {
-		purple_blist_alias_buddy(b, alias);
+		purple_buddy_set_alias(b, alias);
 
 		purple_debug_info("jabber", "jabber_roster_alias_change(): Aliased %s to %s\n",
 				name, alias ? alias : "(null)");
============================================================
--- libpurple/protocols/novell/novell.c	856a4284a0ca45167ec57a597098bd586199ac7d
+++ libpurple/protocols/novell/novell.c	ba757729419cc58c39dff41837efc44d60f921d3
@@ -294,7 +294,7 @@ _get_details_resp_setup_buddy(NMUser * u
 
 		alias = purple_buddy_get_alias(buddy);
 		if (alias == NULL || *alias == '\0' || (strcmp(alias, purple_buddy_get_name(buddy)) == 0)) {
-			purple_blist_alias_buddy(buddy,
+			purple_buddy_set_alias(buddy,
 								   nm_user_record_get_full_name(user_record));
 
 			/* Tell the server about the new display name */
@@ -2696,7 +2696,7 @@ novell_alias_buddy(PurpleConnection * gc
 													 name, group);
 					balias = buddy ? purple_buddy_get_local_buddy_alias(buddy) : NULL;
 					if (balias && strcmp(balias, alias))
-						purple_blist_alias_buddy(buddy, alias);
+						purple_buddy_set_alias(buddy, alias);
 				}
 
 				/* Tell the server to alias the contact */
============================================================
--- libpurple/protocols/oscar/oscar.c	5a32e8f625c3275d2ee154f7f7d481cb92bb8492
+++ libpurple/protocols/oscar/oscar.c	3a0780985927357b2b2fbe515da0add7b298ac47
@@ -5256,7 +5256,7 @@ static int purple_ssi_parselist(OscarDat
 					b = purple_find_buddy_in_group(account, curitem->name, g);
 					if (b) {
 						/* Get server stored alias */
-						purple_blist_alias_buddy(b, alias_utf8);
+						purple_buddy_set_alias(b, alias_utf8);
 					} else {
 						b = purple_buddy_new(account, curitem->name, alias_utf8);
 
@@ -5473,7 +5473,7 @@ purple_ssi_parseaddmod(OscarData *od, Fl
 		 * of your buddies, so update our local buddy list with
 		 * the person's new alias.
 		 */
-		purple_blist_alias_buddy(b, alias_utf8);
+		purple_buddy_set_alias(b, alias_utf8);
 	} else if (snac_subtype == 0x0008) {
 		/*
 		 * You're logged in somewhere else and you added a buddy to
============================================================
--- libpurple/protocols/qq/buddy_memo.c	ee5fbc637ea956eb8ad0d358df6babe7963d048e
+++ libpurple/protocols/qq/buddy_memo.c	cb18e314eef4917029d6eefa72103cb0a05ff174
@@ -124,7 +124,7 @@ static void update_buddy_memo(PurpleConn
 		purple_debug_info("QQ", "Error...Can NOT find %d!\n", bd_uid);
 		return;
 	}
-	purple_blist_alias_buddy(buddy, (const char*)alias);
+	purple_buddy_set_alias(buddy, (const char*)alias);
 }
 
 static void request_change_memo(PurpleConnection *gc, guint32 bd_uid, gchar **segments)
============================================================
--- libpurple/protocols/simple/simple.c	739ae097ae4baf44e4c3caef05862b88f1e5ffaf
+++ libpurple/protocols/simple/simple.c	e8d9f5840fd7c1a0c7edb9d640aea43fecdff609
@@ -920,7 +920,7 @@ static gboolean simple_add_lcs_contacts(
 			g_free(buddy_name);
 
 			purple_blist_add_buddy(b, NULL, g, NULL);
-			purple_blist_alias_buddy(b, uri);
+			purple_buddy_set_alias(b, uri);
 			bs = g_new0(struct simple_buddy, 1);
 			bs->name = g_strdup(purple_buddy_get_name(b));
 			g_hash_table_insert(sip->buddies, bs->name, bs);
============================================================
--- libpurple/server.c	c0befb04dfd7e25dca3c48672712945623d99d14
+++ libpurple/server.c	75f532f95476048ec158df1dfac679de5aeaf14c
@@ -300,7 +300,7 @@ purple_serv_got_private_alias(PurpleConn
 		if (purple_strequal(balias, alias))
 			continue;
 
-		purple_blist_alias_buddy(b, alias);
+		purple_buddy_set_alias(b, alias);
 	}
 }
 
============================================================
--- pidgin/gtkblist.c	f37ce3cbe1abc91c62901c10c948a8e5fb6dc525
+++ pidgin/gtkblist.c	af8885e45078cac80dd31d936fde07183c02a28e
@@ -617,14 +617,14 @@ static void gtk_blist_renderer_edited_cb
 			gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
 		} else {
 			PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact);
-			purple_blist_alias_buddy(buddy, arg2);
+			purple_buddy_set_alias(buddy, arg2);
 			serv_alias_buddy(buddy);
 			gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
 		}
 	} else if(PURPLE_IS_BUDDY(node)){
 		PurpleGroup *group = purple_buddy_get_group(PURPLE_BUDDY(node));
 
-		purple_blist_alias_buddy(PURPLE_BUDDY(node), arg2);
+		purple_buddy_set_alias(PURPLE_BUDDY(node), arg2);
 		serv_alias_buddy(PURPLE_BUDDY(node));
 		gtk_blist_auto_personize(PURPLE_BLIST_NODE(group), arg2);
 	} else if (PURPLE_IS_GROUP(node)){
============================================================
--- pidgin/gtkconv.c	0d5db701ccb3a4a43b97735402ef2501384621fe
+++ pidgin/gtkconv.c	61e4eef676f98cf54157cfa8e7d8d0dceee732c4
@@ -8952,7 +8952,7 @@ alias_cb(GtkEntry *entry, gpointer user_
 		PurpleBuddy *buddy;
 		buddy = purple_find_buddy(account, name);
 		if (buddy != NULL) {
-			purple_blist_alias_buddy(buddy,
+			purple_buddy_set_alias(buddy,
                                                  gtk_entry_get_text(entry));
 		}
 		serv_alias_buddy(buddy);
============================================================
--- pidgin/gtkdialogs.c	74f6ff30a67dbc0d74275be4e5c8e9d5ed3fe2e9
+++ pidgin/gtkdialogs.c	c552da3089476542d95b609fbc23be8b7ec65ca7
@@ -1010,7 +1010,7 @@ pidgin_dialogs_alias_buddy_cb(PurpleBudd
 static void
 pidgin_dialogs_alias_buddy_cb(PurpleBuddy *buddy, const char *new_alias)
 {
-	purple_blist_alias_buddy(buddy, new_alias);
+	purple_buddy_set_alias(buddy, new_alias);
 	serv_alias_buddy(buddy);
 }
 


More information about the Commits mailing list