/soc/2013/ankitkv/gobjectification: 60a278f1365b: Refactored lib...

Ankit Vani a at nevitus.org
Tue Jul 2 19:28:39 EDT 2013


Changeset: 60a278f1365b2c55ea7fab3674c5e57716009aa2
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-03 04:58 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/60a278f1365b

Description:

Refactored libpurple plugins with initial GObject blist API
* Removed PurpleBuddyListNodeFlags
* Added purple_blist_node_[gs]et_dont_save()

diffstat:

 libpurple/blist.c                          |   2 +-
 libpurple/blist.h                          |  36 ++++++++++++-------------
 libpurple/plugins/autoaccept.c             |  14 +++++-----
 libpurple/plugins/buddynote.c              |   2 +-
 libpurple/plugins/perl/common/BuddyList.xs |  42 ++++++-----------------------
 libpurple/plugins/perl/common/module.h     |   2 -
 libpurple/plugins/perl/common/typemap      |   2 -
 libpurple/plugins/signals-test.c           |  36 ++++++++++---------------
 libpurple/plugins/tcl/tcl_cmds.c           |  20 +++++---------
 libpurple/plugins/tcl/tcl_signals.c        |  18 +++---------
 10 files changed, 61 insertions(+), 113 deletions(-)

diffs (truncated from 432 to 300 lines):

diff --git a/libpurple/blist.c b/libpurple/blist.c
--- a/libpurple/blist.c
+++ b/libpurple/blist.c
@@ -44,7 +44,7 @@ struct _PurpleBlistNodePrivate {
 	PurpleBlistNode *parent;  /**< The parent of this node                 */
 	PurpleBlistNode *child;   /**< The child of this node                  */
 	GHashTable *settings;     /**< per-node settings                       */
-	gboolean no_save;         /**< node should not be saved with the buddy
+	gboolean dont_save;       /**< node should not be saved with the buddy
 	                               list                                    */
 };
 
diff --git a/libpurple/blist.h b/libpurple/blist.h
--- a/libpurple/blist.h
+++ b/libpurple/blist.h
@@ -324,6 +324,14 @@ struct _PurpleBlistUiOps
 
 G_BEGIN_DECLS
 
+/* TODO move */
+GType purple_blist_node_get_type(void);
+GType purple_buddy_get_type(void);
+GType purple_contact_get_type(void);
+GType purple_group_get_type(void);
+GType purple_chat_get_type(void);
+GType purple_buddy_list_get_type(void);
+
 /**************************************************************************/
 /** @name Buddy List API                                                  */
 /**************************************************************************/
@@ -1188,32 +1196,22 @@ const char *purple_blist_node_get_string
 void purple_blist_node_remove_setting(PurpleBlistNode *node, const char *key);
 
 /**
- * Set the flags for the given node.  Setting a node's flags will overwrite
- * the old flags, so if you want to save them, you must first call
- * purple_blist_node_get_flags and modify that appropriately.
+ * Sets whether the node should be saved with the buddy list or not
  *
- * @param node  The node on which to set the flags.
- * @param flags The flags to set.  This is a bitmask.
+ * @param node  The node
+ * @param dont_save TRUE if the node should NOT be saved, FALSE if node should
+ *                  be saved
  */
-void purple_blist_node_set_flags(PurpleBlistNode *node, PurpleBlistNodeFlags flags);
+void purple_blist_node_set_dont_save(PurpleBlistNode *node, gboolean dont_save);
 
 /**
- * Get the current flags on a given node.
+ * Gets whether the node should be saved with the buddy list or not
  *
- * @param node The node from which to get the flags.
+ * @param node  The node
  *
- * @return The flags on the node.  This is a bitmask.
+ * @return TRUE if the node should NOT be saved, FALSE if node should be saved
  */
-PurpleBlistNodeFlags purple_blist_node_get_flags(PurpleBlistNode *node);
-
-/**
- * Get the type of a given node.
- *
- * @param node The node.
- *
- * @return The type of the node.
- */
-PurpleBlistNodeType purple_blist_node_get_type(PurpleBlistNode *node);
+gboolean purple_blist_node_get_dont_save(PurpleBlistNode *node);
 
 /*@}*/
 
diff --git a/libpurple/plugins/autoaccept.c b/libpurple/plugins/autoaccept.c
--- a/libpurple/plugins/autoaccept.c
+++ b/libpurple/plugins/autoaccept.c
@@ -100,7 +100,7 @@ file_recv_request_cb(PurpleXfer *xfer, g
 	   stranger setting. */
 	if (node) {
 		node = purple_blist_node_get_parent(node);
-		g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
+		g_return_if_fail(PURPLE_IS_CONTACT(node));
 		accept_setting = purple_blist_node_get_int(node, "autoaccept");
 	} else {
 		accept_setting = purple_prefs_get_int(PREF_STRANGER);
@@ -182,9 +182,9 @@ file_recv_request_cb(PurpleXfer *xfer, g
 static void
 save_cb(PurpleBlistNode *node, int choice)
 {
-	if (PURPLE_BLIST_NODE_IS_BUDDY(node))
+	if (PURPLE_IS_BUDDY(node))
 		node = purple_blist_node_get_parent(node);
-	g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
+	g_return_if_fail(PURPLE_IS_CONTACT(node));
 	purple_blist_node_set_int(node, "autoaccept", choice);
 }
 
@@ -193,9 +193,9 @@ set_auto_accept_settings(PurpleBlistNode
 {
 	char *message;
 
-	if (PURPLE_BLIST_NODE_IS_BUDDY(node))
+	if (PURPLE_IS_BUDDY(node))
 		node = purple_blist_node_get_parent(node);
-	g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
+	g_return_if_fail(PURPLE_IS_CONTACT(node));
 
 	message = g_strdup_printf(_("When a file-transfer request arrives from %s"),
 					purple_contact_get_alias((PurpleContact *)node));
@@ -218,8 +218,8 @@ context_menu(PurpleBlistNode *node, GLis
 {
 	PurpleMenuAction *action;
 
-	if (!PURPLE_BLIST_NODE_IS_BUDDY(node) && !PURPLE_BLIST_NODE_IS_CONTACT(node) &&
-		!(purple_blist_node_get_flags(node) & PURPLE_BLIST_NODE_FLAG_NO_SAVE))
+	if (!PURPLE_IS_BUDDY(node) && !PURPLE_IS_CONTACT(node) &&
+		!purple_blist_node_get_dont_save(node))
 		return;
 
 	action = purple_menu_action_new(_("Autoaccept File Transfers..."),
diff --git a/libpurple/plugins/buddynote.c b/libpurple/plugins/buddynote.c
--- a/libpurple/plugins/buddynote.c
+++ b/libpurple/plugins/buddynote.c
@@ -58,7 +58,7 @@ buddynote_extended_menu_cb(PurpleBlistNo
 {
 	PurpleMenuAction *bna = NULL;
 
-	if (purple_blist_node_get_flags(node) & PURPLE_BLIST_NODE_FLAG_NO_SAVE)
+	if (purple_blist_node_get_dont_save(node))
 		return;
 
 	*m = g_list_append(*m, bna);
diff --git a/libpurple/plugins/perl/common/BuddyList.xs b/libpurple/plugins/perl/common/BuddyList.xs
--- a/libpurple/plugins/perl/common/BuddyList.xs
+++ b/libpurple/plugins/perl/common/BuddyList.xs
@@ -13,26 +13,6 @@ chat_components_foreach(gpointer key, gp
 MODULE = Purple::BuddyList  PACKAGE = Purple  PREFIX = purple_
 PROTOTYPES: ENABLE
 
-BOOT:
-{
-	HV *stash = gv_stashpv("Purple::BuddyList::Node", 1);
-
-	static const constiv *civ, const_iv[] = {
-#define const_iv(name) {#name, (IV)PURPLE_BLIST_##name##_NODE}
-		const_iv(GROUP),
-		const_iv(CONTACT),
-		const_iv(BUDDY),
-		const_iv(CHAT),
-		const_iv(OTHER),
-#undef const_iv
-#define const_iv(name) {#name, (IV)PURPLE_BLIST_NODE_FLAG_##name}
-		const_iv(NO_SAVE),
-	};
-
-	for (civ = const_iv + sizeof(const_iv) / sizeof(const_iv[0]); civ-- > const_iv; )
-		newCONSTSUB(stash, (char *)civ->name, newSViv(civ->iv));
-}
-
 Purple::BuddyList
 purple_get_blist()
 
@@ -287,23 +267,19 @@ purple_blist_node_get_string(node, key)
 	const char * key
 
 void
+purple_blist_node_set_dont_save(node, dont_save)
+	Purple::BuddyList::Node node
+	gboolean dont_save
+
+gboolean
+purple_blist_node_get_dont_save(node);
+	Purple::BuddyList::Node node
+
+void
 purple_blist_node_remove_setting(node, key)
 	Purple::BuddyList::Node node
 	const char * key
 
-void
-purple_blist_node_set_flags(node, flags)
-	Purple::BuddyList::Node node
-	Purple::BuddyList::NodeFlags flags
-
-Purple::BuddyList::NodeFlags
-purple_blist_node_get_flags(node)
-	Purple::BuddyList::Node node
-
-Purple::BuddyList::NodeType
-purple_blist_node_get_type(node)
-	Purple::BuddyList::Node node
-
 Purple::BuddyList::Node
 purple_blist_node_next(node, offline)
 	Purple::BuddyList::Node node
diff --git a/libpurple/plugins/perl/common/module.h b/libpurple/plugins/perl/common/module.h
--- a/libpurple/plugins/perl/common/module.h
+++ b/libpurple/plugins/perl/common/module.h
@@ -85,8 +85,6 @@ typedef PurpleAccountPrivacyType		Purple
 
 /* blist.h */
 typedef PurpleBlistNode *			Purple__BuddyList__Node;
-typedef PurpleBlistNodeFlags		Purple__BuddyList__NodeFlags;
-typedef PurpleBlistNodeType		Purple__BuddyList__NodeType;
 typedef PurpleBuddyList *			Purple__BuddyList;
 typedef PurpleBuddy *			Purple__BuddyList__Buddy;
 typedef PurpleChat *			Purple__BuddyList__Chat;
diff --git a/libpurple/plugins/perl/common/typemap b/libpurple/plugins/perl/common/typemap
--- a/libpurple/plugins/perl/common/typemap
+++ b/libpurple/plugins/perl/common/typemap
@@ -52,8 +52,6 @@ Purple::BuddyList::Chat			T_PurpleObj
 Purple::BuddyList::Contact		T_PurpleObj
 Purple::BuddyList::Group			T_PurpleObj
 Purple::BuddyList::Node			T_PurpleObj
-Purple::BuddyList::NodeFlags		T_IV
-Purple::BuddyList::NodeType		T_IV
 
 Purple::Cipher				T_PurpleObj
 Purple::Hash				T_PurpleObj
diff --git a/libpurple/plugins/signals-test.c b/libpurple/plugins/signals-test.c
--- a/libpurple/plugins/signals-test.c
+++ b/libpurple/plugins/signals-test.c
@@ -148,12 +148,12 @@ static void
 blist_node_added_cb(PurpleBlistNode *bnode, void *data)
 {
 	const char *name;
-	if (PURPLE_BLIST_NODE_IS_GROUP(bnode))
+	if (PURPLE_IS_GROUP(bnode))
 		name = purple_group_get_name(PURPLE_GROUP(bnode));
-	else if (PURPLE_BLIST_NODE_IS_CONTACT(bnode))
+	else if (PURPLE_IS_CONTACT(bnode))
 		/* Close enough */
 		name = purple_contact_get_alias(PURPLE_CONTACT(bnode));
-	else if (PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+	else if (PURPLE_IS_BUDDY(bnode))
 		name = purple_buddy_get_name(PURPLE_BUDDY(bnode));
 	else
 		name = "(unknown)";
@@ -166,12 +166,12 @@ static void
 blist_node_removed_cb(PurpleBlistNode *bnode, void *data)
 {
 	const char *name;
-	if (PURPLE_BLIST_NODE_IS_GROUP(bnode))
+	if (PURPLE_IS_GROUP(bnode))
 		name = purple_group_get_name(PURPLE_GROUP(bnode));
-	else if (PURPLE_BLIST_NODE_IS_CONTACT(bnode))
+	else if (PURPLE_IS_CONTACT(bnode))
 		/* Close enough */
 		name = purple_contact_get_alias(PURPLE_CONTACT(bnode));
-	else if (PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+	else if (PURPLE_IS_BUDDY(bnode))
 		name = purple_buddy_get_name(PURPLE_BUDDY(bnode));
 	else
 		name = "(unknown)";
@@ -188,26 +188,22 @@ blist_node_aliased(PurpleBlistNode *node
 	PurpleChat *c = (PurpleChat *)node;
 	PurpleGroup *g = (PurpleGroup *)node;
 
-	if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
+	if (PURPLE_IS_CONTACT(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-aliased (Contact: %s, %s)\n",
 		                  purple_contact_get_alias(p), old_alias);
-	} else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
+	} else if (PURPLE_IS_BUDDY(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-aliased (Buddy: %s, %s)\n",
 		                  purple_buddy_get_name(b), old_alias);
-	} else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
+	} else if (PURPLE_IS_CHAT(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-aliased (Chat: %s, %s)\n",
 		                  purple_chat_get_name(c), old_alias);
-	} else if (PURPLE_BLIST_NODE_IS_GROUP(node)) {
+	} else if (PURPLE_IS_GROUP(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-aliased (Group: %s, %s)\n",
 		                  purple_group_get_name(g), old_alias);
-	} else {
-		purple_debug_misc("signals test",
-		                  "blist-node-aliased (UNKNOWN: %d, %s)\n",
-		                  purple_blist_node_get_type(node), old_alias);
 	}
 }
 
@@ -219,26 +215,22 @@ blist_node_extended_menu_cb(PurpleBlistN
 	PurpleChat *c = (PurpleChat *)node;
 	PurpleGroup *g = (PurpleGroup *)node;
 
-	if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
+	if (PURPLE_IS_CONTACT(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-extended-menu (Contact: %s)\n",
 		                  purple_contact_get_alias(p));
-	} else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
+	} else if (PURPLE_IS_BUDDY(node)) {
 		purple_debug_misc("signals test",
 		                  "blist-node-extended-menu (Buddy: %s)\n",
 		                  purple_buddy_get_name(b));
-	} else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
+	} else if (PURPLE_IS_CHAT(node)) {



More information about the Commits mailing list