/soc/2013/ankitkv/gobjectification: 6ea8ce77ec34: Started GObjec...

Ankit Vani a at nevitus.org
Fri Sep 6 11:32:33 EDT 2013


Changeset: 6ea8ce77ec3487801fd5ff88845fbb0b6c5b461e
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-06 20:02 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/6ea8ce77ec34

Description:

Started GObjectification of PurpleRoomlist

diffstat:

 libpurple/Makefile.am                     |    1 +
 libpurple/plugins/perl/common/Roomlist.xs |    8 -
 libpurple/roomlist.c                      |  180 +++++++++++++++++++----------
 libpurple/roomlist.h                      |   76 +++++++++---
 4 files changed, 172 insertions(+), 93 deletions(-)

diffs (truncated from 547 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -192,6 +192,7 @@ purple_enumheaders = \
 	connection.h \
 	conversation.h \
 	conversationtypes.h \
+	roomlist.h \
 	status.h \
 	xfer.h
 
diff --git a/libpurple/plugins/perl/common/Roomlist.xs b/libpurple/plugins/perl/common/Roomlist.xs
--- a/libpurple/plugins/perl/common/Roomlist.xs
+++ b/libpurple/plugins/perl/common/Roomlist.xs
@@ -50,10 +50,6 @@ purple_roomlist_new(account)
 	Purple::Account account
 
 void 
-purple_roomlist_ref(list)
-	Purple::Roomlist list
-
-void 
 purple_roomlist_room_add(list, room)
 	Purple::Roomlist list
 	Purple::Roomlist::Room room
@@ -94,7 +90,3 @@ void
 purple_roomlist_show_with_account(account)
 	Purple::Account account
 
-void 
-purple_roomlist_unref(list)
-	Purple::Roomlist list
-
diff --git a/libpurple/roomlist.c b/libpurple/roomlist.c
--- a/libpurple/roomlist.c
+++ b/libpurple/roomlist.c
@@ -2,7 +2,6 @@
  * @file roomlist.c Room List API
  * @ingroup core
  */
-
 /* purple
  *
  * Purple is the legal property of its developers, whose names are too numerous
@@ -32,17 +31,23 @@
 #include "roomlist.h"
 #include "server.h"
 
+#define PURPLE_ROOMLIST_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ROOMLIST, PurpleRoomlistPrivate))
+
+/** @copydoc _PurpleRoomlistPrivate */
+typedef struct _PurpleRoomlistPrivate  PurpleRoomlistPrivate;
+
 /**
- * Represents a list of rooms for a given connection on a given protocol.
+ * Private data for a room list.
  */
-struct _PurpleRoomlist {
-	PurpleAccount *account; /**< The account this list belongs to. */
-	GList *fields; /**< The fields. */
-	GList *rooms; /**< The list of rooms. */
-	gboolean in_progress; /**< The listing is in progress. */
-	gpointer ui_data; /**< UI private data. */
-	gpointer proto_data; /** Prpl private data. */
-	guint ref; /**< The reference count. */
+struct _PurpleRoomlistPrivate {
+	PurpleAccount *account;  /**< The account this list belongs to. */
+	GList *fields;           /**< The fields.                       */
+	GList *rooms;            /**< The list of rooms.                */
+	gboolean in_progress;    /**< The listing is in progress.       */
+	gpointer proto_data;     /** Protocol private data.
+	                             TODO Remove this, and use
+	                                  protocol-specific subclasses  */
 };
 
 /**
@@ -66,6 +71,18 @@ struct _PurpleRoomlistField {
 	gboolean hidden; /**< Hidden? */
 };
 
+/* Room list property enums */
+enum
+{
+	PROP_0,
+	PROP_ACCOUNT,
+	PROP_FIELDS,
+	PROP_ROOMS,
+	PROP_IN_PROGRESS,
+	PROP_LAST
+};
+
+static GObjectClass *parent_class;
 static PurpleRoomlistUiOps *ops = NULL;
 
 /**************************************************************************/
@@ -86,10 +103,10 @@ PurpleRoomlist *purple_roomlist_new(Purp
 	g_return_val_if_fail(account != NULL, NULL);
 
 	list = g_new0(PurpleRoomlist, 1);
-	list->account = account;
-	list->rooms = NULL;
-	list->fields = NULL;
-	list->ref = 1;
+	priv->account = account;
+	priv->rooms = NULL;
+	priv->fields = NULL;
+	priv->ref = 1;
 
 	if (ops && ops->create)
 		ops->create(list);
@@ -97,19 +114,11 @@ PurpleRoomlist *purple_roomlist_new(Purp
 	return list;
 }
 
-void purple_roomlist_ref(PurpleRoomlist *list)
-{
-	g_return_if_fail(list != NULL);
-
-	list->ref++;
-	purple_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref);
-}
-
 static void purple_roomlist_room_destroy(PurpleRoomlist *list, PurpleRoomlistRoom *r)
 {
 	GList *l, *j;
 
-	for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) {
+	for (l = priv->fields, j = r->fields; l && j; l = l->next, j = j->next) {
 		PurpleRoomlistField *f = l->data;
 		if (f->type == PURPLE_ROOMLIST_FIELD_STRING)
 			g_free(j->data);
@@ -129,6 +138,7 @@ static void purple_roomlist_field_destro
 
 static void purple_roomlist_destroy(PurpleRoomlist *list)
 {
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 	GList *l;
 
 	purple_debug_misc("roomlist", "destroying list %p\n", list);
@@ -136,42 +146,34 @@ static void purple_roomlist_destroy(Purp
 	if (ops && ops->destroy)
 		ops->destroy(list);
 
-	for (l = list->rooms; l; l = l->next) {
+	for (l = priv->rooms; l; l = l->next) {
 		PurpleRoomlistRoom *r = l->data;
 		purple_roomlist_room_destroy(list, r);
 	}
-	g_list_free(list->rooms);
+	g_list_free(priv->rooms);
 
-	g_list_foreach(list->fields, (GFunc)purple_roomlist_field_destroy, NULL);
-	g_list_free(list->fields);
+	g_list_foreach(priv->fields, (GFunc)purple_roomlist_field_destroy, NULL);
+	g_list_free(priv->fields);
 
 	g_free(list);
 }
 
-void purple_roomlist_unref(PurpleRoomlist *list)
-{
-	g_return_if_fail(list != NULL);
-	g_return_if_fail(list->ref > 0);
-
-	list->ref--;
-
-	purple_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref);
-	if (list->ref == 0)
-		purple_roomlist_destroy(list);
-}
-
 PurpleAccount *purple_roomlist_get_account(PurpleRoomlist *list)
 {
-	g_return_val_if_fail(list != NULL, NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	return list->account;
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->account;
 }
 
 void purple_roomlist_set_fields(PurpleRoomlist *list, GList *fields)
 {
-	g_return_if_fail(list != NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	list->fields = fields;
+	g_return_if_fail(priv != NULL);
+
+	priv->fields = fields;
 
 	if (ops && ops->set_fields)
 		ops->set_fields(list, fields);
@@ -179,9 +181,11 @@ void purple_roomlist_set_fields(PurpleRo
 
 void purple_roomlist_set_in_progress(PurpleRoomlist *list, gboolean in_progress)
 {
-	g_return_if_fail(list != NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	list->in_progress = in_progress;
+	g_return_if_fail(priv != NULL);
+
+	priv->in_progress = in_progress;
 
 	if (ops && ops->in_progress)
 		ops->in_progress(list, in_progress);
@@ -189,17 +193,21 @@ void purple_roomlist_set_in_progress(Pur
 
 gboolean purple_roomlist_get_in_progress(PurpleRoomlist *list)
 {
-	g_return_val_if_fail(list != NULL, FALSE);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	return list->in_progress;
+	g_return_val_if_fail(priv != NULL, FALSE);
+
+	return priv->in_progress;
 }
 
 void purple_roomlist_room_add(PurpleRoomlist *list, PurpleRoomlistRoom *room)
 {
-	g_return_if_fail(list != NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
+
+	g_return_if_fail(priv != NULL);
 	g_return_if_fail(room != NULL);
 
-	list->rooms = g_list_append(list->rooms, room);
+	priv->rooms = g_list_append(priv->rooms, room);
 
 	if (ops && ops->add_room)
 		ops->add_room(list, room);
@@ -226,13 +234,14 @@ PurpleRoomlist *purple_roomlist_get_list
 
 void purple_roomlist_cancel_get_list(PurpleRoomlist *list)
 {
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleConnection *gc;
 
-	g_return_if_fail(list != NULL);
+	g_return_if_fail(priv != NULL);
 
-	gc = purple_account_get_connection(list->account);
+	gc = purple_account_get_connection(priv->account);
 
 	g_return_if_fail(gc != NULL);
 
@@ -248,15 +257,16 @@ void purple_roomlist_cancel_get_list(Pur
 
 void purple_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category)
 {
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleConnection *gc;
 
-	g_return_if_fail(list != NULL);
+	g_return_if_fail(priv != NULL);
 	g_return_if_fail(category != NULL);
 	g_return_if_fail(category->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY);
 
-	gc = purple_account_get_connection(list->account);
+	gc = purple_account_get_connection(priv->account);
 	g_return_if_fail(gc != NULL);
 
 	if(gc)
@@ -271,21 +281,29 @@ void purple_roomlist_expand_category(Pur
 
 GList * purple_roomlist_get_fields(PurpleRoomlist *list)
 {
-	return list->fields;
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->fields;
 }
 
 gpointer purple_roomlist_get_proto_data(PurpleRoomlist *list)
 {
-	g_return_val_if_fail(list != NULL, NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	return list->proto_data;
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->proto_data;
 }
 
 void purple_roomlist_set_proto_data(PurpleRoomlist *list, gpointer proto_data)
 {
-	g_return_if_fail(list != NULL);
+	PurpleRoomlistPrivate *priv = PURPLE_ROOMLIST_GET_PRIVATE(list);
 
-	list->proto_data = proto_data;



More information about the Commits mailing list