/soc/2013/ankitkv/gobjectification: d433bf40792a: Added blistnod...

Ankit Vani a at nevitus.org
Sat Jul 6 06:04:24 EDT 2013


Changeset: d433bf40792a91e409a31eeae1eda5339fe3837c
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-06 15:34 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d433bf40792a

Description:

Added blistnode.[ch] and blistnodetypes.[ch]
* Moved PurpleBListNode to blistnode.[ch]. PurpleCountingNode will be added here too.
* Moved PurpleBuddy, PurpleGroup, PurpleChat and PurpleContact to blistnodetypes.[ch].
* Made PurpleBuddyList a normal struct again, it will be a GBoxed.

diffstat:

 libpurple/Makefile.am      |   30 +-
 libpurple/blistnode.c      |  331 +++++++++++++++
 libpurple/blistnode.h      |  281 ++++++++++++
 libpurple/blistnodetypes.c |  694 +++++++++++++++++++++++++++++++
 libpurple/blistnodetypes.h |  537 ++++++++++++++++++++++++
 libpurple/buddylist.c      |  981 +--------------------------------------------
 libpurple/buddylist.h      |  734 +---------------------------------
 7 files changed, 1878 insertions(+), 1710 deletions(-)

diffs (truncated from 3918 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -40,7 +40,9 @@ purple_coresources = \
 	account.c \
 	accounts.c \
 	accountopt.c \
-	blist.c \
+	blistnode.c \
+	blistnodetypes.c \
+	buddylist.c \
 	buddyicon.c \
 	certificate.c \
 	cipher.c \
@@ -112,7 +114,9 @@ purple_coreheaders = \
 	account.h \
 	accounts.h \
 	accountopt.h \
-	blist.h \
+	blistnode.h \
+	blistnodetypes.h \
+	buddylist.h \
 	buddyicon.h \
 	certificate.h \
 	cipher.h \
@@ -182,20 +186,10 @@ purple_builtheaders = purple.h version.h
 
 purple_enumheaders = \
 	account.h \
-	accounts.h \
 	cipher.h \
-	circularbuffer.h \
 	connection.h \
 	conversation.h \
-	conversationtypes.h \
-	conversations.h \
-	hash.h \
-	smiley.h \
-	sound-theme.h \
-	sound-theme-loader.h \
-	theme.h \
-	theme-loader.h \
-	theme-manager.h
+	conversationtypes.h
 
 marshallers.h: marshallers.list
 	$(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=purple_smarshal $(srcdir)/marshallers.list --header > marshallers.h
@@ -232,11 +226,11 @@ CLEANFILES = \
 dbus_sources  = dbus-server.c dbus-useful.c
 dbus_headers  = dbus-bindings.h dbus-purple.h dbus-server.h dbus-useful.h dbus-define-api.h dbus-types.h
 
-dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blist.h \
-                buddyicon.h connection.h conversation.h conversationtypes.h \
-                conversations.h core.h ft.h log.h notify.h prefs.h roomlist.h \
-                savedstatuses.h smiley.h status.h server.h util.h xmlnode.h \
-                prpl.h
+dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blistnode.h \
+                blistnodetypes.h buddylist.h buddyicon.h connection.h conversation.h \
+                conversationtypes.h conversations.h core.h ft.h log.h notify.h \
+                prefs.h roomlist.h savedstatuses.h smiley.h status.h server.h util.h \
+                xmlnode.h prpl.h
 
 purple_build_coreheaders = $(addprefix $(srcdir)/, $(purple_coreheaders)) \
 		$(addprefix $(srcdir)/media/, $(purple_mediaheaders)) \
diff --git a/libpurple/blistnode.c b/libpurple/blistnode.c
new file mode 100644
--- /dev/null
+++ b/libpurple/blistnode.c
@@ -0,0 +1,331 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+#include "blistnode.h"
+
+#define PURPLE_BLIST_NODE_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BLIST_NODE, PurpleBListNodePrivate))
+
+/** @copydoc _PurpleBListNodePrivate */
+typedef struct _PurpleBListNodePrivate  PurpleBListNodePrivate;
+
+/** Private data of a buddy list node */
+struct _PurpleBListNodePrivate {
+	GHashTable *settings;     /**< per-node settings                       */
+	gboolean dont_save;       /**< node should not be saved with the buddy
+	                               list                                    */
+};
+
+/**************************************************************************/
+/* Buddy list node API                                                    */
+/**************************************************************************/
+
+PurpleBListNode *purple_blist_node_next(PurpleBListNode *node, gboolean offline)
+{
+	PurpleBListNode *ret = node;
+
+	if (offline)
+		return get_next_node(ret, TRUE);
+	do
+	{
+		ret = get_next_node(ret, TRUE);
+	} while (ret && PURPLE_IS_BUDDY(ret) &&
+			!purple_account_is_connected(purple_buddy_get_account((PurpleBuddy *)ret)));
+
+	return ret;
+}
+
+PurpleBListNode *purple_blist_node_get_parent(PurpleBListNode *node)
+{
+	return node ? node->parent : NULL;
+}
+
+PurpleBListNode *purple_blist_node_get_first_child(PurpleBListNode *node)
+{
+	return node ? node->child : NULL;
+}
+
+PurpleBListNode *purple_blist_node_get_sibling_next(PurpleBListNode *node)
+{
+	return node? node->next : NULL;
+}
+
+PurpleBListNode *purple_blist_node_get_sibling_prev(PurpleBListNode *node)
+{
+	return node? node->prev : NULL;
+}
+
+void *
+purple_blist_node_get_ui_data(const PurpleBListNode *node)
+{
+	g_return_val_if_fail(node, NULL);
+
+	return node->ui_data;
+}
+
+void
+purple_blist_node_set_ui_data(PurpleBListNode *node, void *ui_data) {
+	g_return_if_fail(node);
+
+	node->ui_data = ui_data;
+}
+
+/* TODO GObjectify */
+static void
+purple_blist_node_destroy(PurpleBListNode *node)
+{
+	PurpleBlistUiOps *ui_ops;
+	PurpleBListNode *child, *next_child;
+
+	ui_ops = purple_blist_get_ui_ops();
+	child = node->child;
+	while (child) {
+		next_child = child->next;
+		purple_blist_node_destroy(child);
+		child = next_child;
+	}
+
+	/* Allow the UI to free data */
+	node->parent = NULL;
+	node->child  = NULL;
+	node->next   = NULL;
+	node->prev   = NULL;
+	if (ui_ops && ui_ops->remove)
+		ui_ops->remove(purplebuddylist, node);
+
+	if (PURPLE_IS_BUDDY(node))
+		purple_buddy_destroy((PurpleBuddy*)node);
+	else if (PURPLE_IS_CHAT(node))
+		purple_chat_destroy((PurpleChat*)node);
+	else if (PURPLE_IS_CONTACT(node))
+		purple_contact_destroy((PurpleContact*)node);
+	else if (PURPLE_IS_GROUP(node))
+		purple_group_destroy((PurpleGroup*)node);
+}
+
+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)
+{
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_if_fail(priv != NULL);
+
+	if (priv->settings)
+		return;
+
+	priv->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+			(GDestroyNotify)purple_blist_node_setting_free);
+}
+
+void purple_blist_node_remove_setting(PurpleBListNode *node, const char *key)
+{
+	PurpleBlistUiOps *ops;
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_if_fail(priv != NULL);
+	g_return_if_fail(priv->settings != NULL);
+	g_return_if_fail(key != NULL);
+
+	g_hash_table_remove(priv->settings, key);
+
+	ops = purple_blist_get_ui_ops();
+	if (ops && ops->save_node)
+		ops->save_node(node);
+}
+
+void
+purple_blist_node_set_dont_save(PurpleBListNode *node, gboolean dont_save)
+{
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_if_fail(priv != NULL);
+
+	priv->dont_save = dont_save;
+}
+
+gboolean
+purple_blist_node_get_dont_save(PurpleBListNode *node)
+{
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_val_if_fail(priv != NULL, 0);
+
+	return priv->dont_save;
+}
+
+gboolean
+purple_blist_node_has_setting(PurpleBListNode* node, const char *key)
+{
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_val_if_fail(priv != NULL, FALSE);
+	g_return_val_if_fail(priv->settings != NULL, FALSE);
+	g_return_val_if_fail(key != NULL, FALSE);
+
+	/* Boxed type, so it won't ever be NULL, so no need for _extended */
+	return (g_hash_table_lookup(priv->settings, key) != NULL);
+}
+
+void
+purple_blist_node_set_bool(PurpleBListNode* node, const char *key, gboolean data)
+{
+	PurpleValue *value;
+	PurpleBlistUiOps *ops;
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_if_fail(priv != NULL);
+	g_return_if_fail(priv->settings != NULL);
+	g_return_if_fail(key != NULL);
+
+	value = purple_value_new(PURPLE_TYPE_BOOLEAN);
+	purple_value_set_boolean(value, data);
+
+	g_hash_table_replace(priv->settings, g_strdup(key), value);
+
+	ops = purple_blist_get_ui_ops();
+	if (ops && ops->save_node)
+		ops->save_node(node);
+}
+
+gboolean
+purple_blist_node_get_bool(PurpleBListNode* node, const char *key)
+{
+	PurpleValue *value;
+	PurpleBListNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);
+
+	g_return_val_if_fail(priv != NULL, FALSE);
+	g_return_val_if_fail(priv->settings != NULL, FALSE);
+	g_return_val_if_fail(key != NULL, FALSE);
+
+	value = g_hash_table_lookup(priv->settings, key);
+
+	if (value == NULL)
+		return FALSE;



More information about the Commits mailing list