/soc/2013/ankitkv/gobjectification: e10df50ee8a9: Merged soc.201...

Ankit Vani a at nevitus.org
Fri Sep 6 17:10:39 EDT 2013


Changeset: e10df50ee8a940484f94dff0d9665af9d3e13dbb
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-07 02:40 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/e10df50ee8a9

Description:

Merged soc.2013.gobjectification branch

diffstat:

 libpurple/conversation.c                    |    4 -
 libpurple/plugins/perl/common/Whiteboard.xs |    6 +-
 libpurple/protocols/silc/wb.c               |    4 +-
 libpurple/protocols/yahoo/yahoo_doodle.c    |    6 +-
 libpurple/protocols/yahoo/ymsg.c            |    2 +-
 libpurple/whiteboard.c                      |  370 ++++++++++++++++++++++-----
 libpurple/whiteboard.h                      |   62 +++-
 pidgin/gtkwhiteboard.c                      |    4 +-
 8 files changed, 353 insertions(+), 105 deletions(-)

diffs (truncated from 740 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -921,10 +921,6 @@ purple_conversation_set_property(GObject
 	PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
 
 	switch (param_id) {
-		/* account, name and title are assigned directly here as
-		 * purple_im_conversation_new() and purple_chat_conversation_new()
-		 * pass these properties as parameters, and so the conversation hasn't
-		 * finished being set up */
 		case PROP_ACCOUNT:
 			priv->account = g_value_get_object(value);
 			break;
diff --git a/libpurple/plugins/perl/common/Whiteboard.xs b/libpurple/plugins/perl/common/Whiteboard.xs
--- a/libpurple/plugins/perl/common/Whiteboard.xs
+++ b/libpurple/plugins/perl/common/Whiteboard.xs
@@ -8,16 +8,12 @@ purple_whiteboard_clear(wb)
 	Purple::Whiteboard wb
 
 Purple::Whiteboard
-purple_whiteboard_create(account, who, state)
+purple_whiteboard_new(account, who, state)
 	Purple::Account account
 	const char* who
 	int state
 
 void
-purple_whiteboard_destroy(wb)
-	Purple::Whiteboard wb
-
-void
 purple_whiteboard_draw_line(wb, x1, y1, x2, y2, color, size)
 	Purple::Whiteboard wb
 	int x1
diff --git a/libpurple/protocols/silc/wb.c b/libpurple/protocols/silc/wb.c
--- a/libpurple/protocols/silc/wb.c
+++ b/libpurple/protocols/silc/wb.c
@@ -110,7 +110,7 @@ PurpleWhiteboard *silcpurple_wb_init(Sil
 
 	wb = purple_whiteboard_get_session(sg->account, client_entry->nickname);
 	if (!wb)
-		wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0);
+		wb = purple_whiteboard_new(sg->account, client_entry->nickname, 0);
 	if (!wb)
 		return NULL;
 
@@ -141,7 +141,7 @@ PurpleWhiteboard *silcpurple_wb_init_ch(
 
 	wb = purple_whiteboard_get_session(sg->account, channel->channel_name);
 	if (!wb)
-		wb = purple_whiteboard_create(sg->account, channel->channel_name, 0);
+		wb = purple_whiteboard_new(sg->account, channel->channel_name, 0);
 	if (!wb)
 		return NULL;
 
diff --git a/libpurple/protocols/yahoo/yahoo_doodle.c b/libpurple/protocols/yahoo/yahoo_doodle.c
--- a/libpurple/protocols/yahoo/yahoo_doodle.c
+++ b/libpurple/protocols/yahoo/yahoo_doodle.c
@@ -114,7 +114,7 @@ void yahoo_doodle_initiate(PurpleConnect
 		/* Insert this 'session' in the list.  At this point, it's only a
 		 * requested session.
 		 */
-		purple_whiteboard_create(account, to, DOODLE_STATE_REQUESTING);
+		purple_whiteboard_new(account, to, DOODLE_STATE_REQUESTING);
 	}
 
 	/* NOTE Perhaps some careful handling of remote assumed established
@@ -157,7 +157,7 @@ static void yahoo_doodle_command_got_req
 		dialog_message, NULL, NULL, NULL);
 		*/
 
-		wb = purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED);
+		wb = purple_whiteboard_new(account, from, DOODLE_STATE_REQUESTED);
 		ds = purple_whiteboard_get_protocol_data(wb);
 		ds->imv_key = g_strdup(imv_key);
 
@@ -370,7 +370,7 @@ void yahoo_doodle_command_got_shutdown(P
 	/* TODO Ask if user wants to save picture before the session is closed */
 
 	purple_whiteboard_set_state(wb, DOODLE_STATE_CANCELLED);
-	purple_whiteboard_destroy(wb);
+	g_object_unref(wb);
 }
 
 static void yahoo_doodle_command_send_generic(const char *type,
diff --git a/libpurple/protocols/yahoo/ymsg.c b/libpurple/protocols/yahoo/ymsg.c
--- a/libpurple/protocols/yahoo/ymsg.c
+++ b/libpurple/protocols/yahoo/ymsg.c
@@ -1062,7 +1062,7 @@ static void yahoo_process_message(Purple
 						if(wb == NULL)
 						{
 							doodle_session *ds;
-							wb = purple_whiteboard_create(account, im->from,
+							wb = purple_whiteboard_new(account, im->from,
 											DOODLE_STATE_REQUESTED);
 							ds = purple_whiteboard_get_protocol_data(wb);
 							ds->imv_key = g_strdup(pair->value);
diff --git a/libpurple/whiteboard.c b/libpurple/whiteboard.c
--- a/libpurple/whiteboard.c
+++ b/libpurple/whiteboard.c
@@ -25,26 +25,45 @@
 #include "whiteboard.h"
 #include "protocol.h"
 
-/**
- * A PurpleWhiteboard
- */
-struct _PurpleWhiteboard
+#define PURPLE_WHITEBOARD_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_WHITEBOARD, PurpleWhiteboardPrivate))
+
+/** @copydoc _PurpleWhiteboardPrivate */
+typedef struct _PurpleWhiteboardPrivate  PurpleWhiteboardPrivate;
+
+/** Private data for a whiteboard */
+struct _PurpleWhiteboardPrivate
 {
-	int state;                       /**< State of whiteboard session */
+	int state;                      /**< State of whiteboard session          */
 
-	PurpleAccount *account;            /**< Account associated with this session */
-	char *who;                       /**< Name of the remote user */
+	PurpleAccount *account;         /**< Account associated with this session */
+	char *who;                      /**< Name of the remote user              */
 
-	void *ui_data;                   /**< Graphical user-interface data */
-	void *proto_data;                /**< Protocol specific data */
+	void *proto_data;               /**< Protocol specific data
+	                                     TODO Remove this, and use
+	                                          protocol-specific subclasses    */
 	PurpleWhiteboardOps *protocol_ops; /**< Protocol operations */
 
-	GList *draw_list;                /**< List of drawing elements/deltas to send */
+	GList *draw_list;               /**< List of drawing elements/deltas to
+	                                     send                                 */
+};
+
+/* GObject Property enums */
+enum
+{
+	PROP_0,
+	PROP_STATE,
+	PROP_ACCOUNT,
+	PROP_WHO,
+	PROP_DRAW_LIST,
+	PROP_LAST
 };
 
 /******************************************************************************
  * Globals
  *****************************************************************************/
+static GObjectClass *parent_class;
+
 static PurpleWhiteboardUiOps *whiteboard_ui_ops = NULL;
 /* static PurpleWhiteboardOps *whiteboard_protocol_ops = NULL; */
 
@@ -62,76 +81,47 @@ void purple_whiteboard_set_ui_ops(Purple
 
 void purple_whiteboard_set_protocol_ops(PurpleWhiteboard *wb, PurpleWhiteboardOps *ops)
 {
-	wb->protocol_ops = ops;
-}
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-PurpleWhiteboard *purple_whiteboard_create(PurpleAccount *account, const char *who, int state)
-{
-	PurpleProtocol *protocol;
-	PurpleWhiteboard *wb = g_new0(PurpleWhiteboard, 1);
+	g_return_if_fail(priv != NULL);
 
-	wb->account = account;
-	wb->state   = state;
-	wb->who     = g_strdup(who);
-
-	protocol = purple_connection_get_protocol(purple_account_get_connection(account));
-	purple_whiteboard_set_protocol_ops(wb, purple_protocol_get_whiteboard_ops(protocol));
-
-	/* Start up protocol specifics */
-	if(wb->protocol_ops && wb->protocol_ops->start)
-		wb->protocol_ops->start(wb);
-
-	wbList = g_list_append(wbList, wb);
-
-	return wb;
-}
-
-void purple_whiteboard_destroy(PurpleWhiteboard *wb)
-{
-	g_return_if_fail(wb != NULL);
-
-	if(wb->ui_data)
-	{
-		/* Destroy frontend */
-		if(whiteboard_ui_ops && whiteboard_ui_ops->destroy)
-			whiteboard_ui_ops->destroy(wb);
-	}
-
-	/* Do protocol specific session ending procedures */
-	if(wb->protocol_ops && wb->protocol_ops->end)
-		wb->protocol_ops->end(wb);
-
-	g_free(wb->who);
-	wbList = g_list_remove(wbList, wb);
-	g_free(wb);
+	priv->protocol_ops = ops;
 }
 
 PurpleAccount *purple_whiteboard_get_account(const PurpleWhiteboard *wb)
 {
-	g_return_val_if_fail(wb != NULL, NULL);
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-	return wb->account;
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->account;
 }
 
 const char *purple_whiteboard_get_who(const PurpleWhiteboard *wb)
 {
-	g_return_val_if_fail(wb != NULL, NULL);
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-	return wb->who;	
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->who;	
 }
 
 void purple_whiteboard_set_state(PurpleWhiteboard *wb, int state)
 {
-	g_return_if_fail(wb != NULL);
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-	wb->state = state;
+	g_return_if_fail(priv != NULL);
+
+	priv->state = state;
 }
 
 int purple_whiteboard_get_state(const PurpleWhiteboard *wb)
 {
-	g_return_val_if_fail(wb != NULL, -1);
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-	return wb->state;
+	g_return_val_if_fail(priv != NULL, -1);
+
+	return priv->state;
 }
 
 void purple_whiteboard_start(PurpleWhiteboard *wb)
@@ -148,6 +138,7 @@ void purple_whiteboard_start(PurpleWhite
 PurpleWhiteboard *purple_whiteboard_get_session(const PurpleAccount *account, const char *who)
 {
 	PurpleWhiteboard *wb;
+	PurpleWhiteboardPrivate *priv;
 
 	GList *l = wbList;
 
@@ -156,8 +147,9 @@ PurpleWhiteboard *purple_whiteboard_get_
 	while(l != NULL)
 	{
 		wb = l->data;
+		priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
 
-		if(wb->account == account && purple_strequal(wb->who, who))
+		if(priv->account == account && purple_strequal(priv->who, who))
 			return wb;
 
 		l = l->next;
@@ -173,7 +165,12 @@ void purple_whiteboard_draw_list_destroy
 
 gboolean purple_whiteboard_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
 {
-	PurpleWhiteboardOps *protocol_ops = wb->protocol_ops;
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
+	PurpleWhiteboardOps *protocol_ops;
+
+	g_return_val_if_fail(priv != NULL, FALSE);
+
+	protocol_ops = priv->protocol_ops;
 
 	if (protocol_ops && protocol_ops->get_dimensions)
 	{
@@ -192,7 +189,12 @@ void purple_whiteboard_set_dimensions(Pu
 
 void purple_whiteboard_send_draw_list(PurpleWhiteboard *wb, GList *list)
 {
-	PurpleWhiteboardOps *protocol_ops = wb->protocol_ops;
+	PurpleWhiteboardPrivate *priv = PURPLE_WHITEBOARD_GET_PRIVATE(wb);
+	PurpleWhiteboardOps *protocol_ops;
+
+	g_return_if_fail(priv != NULL);
+
+	protocol_ops = priv->protocol_ops;
 
 	if (protocol_ops && protocol_ops->send_draw_list)
 		protocol_ops->send_draw_list(wb, list);



More information about the Commits mailing list