/soc/2013/ankitkv/gobjectification: e7f4631e93f7: Begun adding G...

Ankit Vani a at nevitus.org
Tue Jun 25 17:39:11 EDT 2013


Changeset: e7f4631e93f7457b6596cbbe82a661048707fbee
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-26 03:08 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/e7f4631e93f7

Description:

Begun adding GObject code to conversation sources

diffstat:

 libpurple/Makefile.am                         |    1 +
 libpurple/connection.h                        |    2 +-
 libpurple/conversation.c                      |  655 +++++++---------
 libpurple/conversation.h                      |   13 +-
 libpurple/conversations.h                     |   21 +
 libpurple/conversationtypes.c                 |  957 +++++++++++++++++++++++--
 libpurple/conversationtypes.h                 |    9 +
 libpurple/plugins/perl/common/Conversation.xs |    8 +
 8 files changed, 1186 insertions(+), 480 deletions(-)

diffs (truncated from 2360 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -186,6 +186,7 @@ purple_enumheaders = \
 	accounts.h \
 	cipher.h \
 	circularbuffer.h \
+	connection.h \
 	conversation.h \
 	conversationtypes.h \
 	conversations.h \
diff --git a/libpurple/connection.h b/libpurple/connection.h
--- a/libpurple/connection.h
+++ b/libpurple/connection.h
@@ -33,7 +33,7 @@ typedef struct _PurpleConnection PurpleC
 /**
  * Flags to change behavior of the client for a given connection.
  */
-typedef enum
+typedef enum /*< flags >*/
 {
 	PURPLE_CONNECTION_HTML       = 0x0001, /**< Connection sends/receives in 'HTML'. */
 	PURPLE_CONNECTION_NO_BGCOLOR = 0x0002, /**< Connection does not send/receive
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -33,6 +33,9 @@
 #include "signals.h"
 #include "util.h"
 
+#define PURPLE_CONVERSATION_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_CONVERSATION, PurpleConversationPrivate))
+
 /** @copydoc _PurpleConversationPrivate */
 typedef struct _PurpleConversationPrivate  PurpleConversationPrivate;
 
@@ -43,11 +46,8 @@ typedef struct _PurpleConversationPrivat
  */
 struct _PurpleConversationPrivate
 {
-	PurpleConversationType type;  /**< The type of conversation.          */
-
 	PurpleAccount *account;       /**< The user using this conversation.  */
 
-
 	char *name;                 /**< The name of the conversation.      */
 	char *title;                /**< The window title.                  */
 
@@ -77,6 +77,18 @@ struct _PurpleConversationMessage
 	char *alias;
 };
 
+/* GObject Property enums */
+enum
+{
+	PROP_0,
+	PROP_ACCOUNT,
+	PROP_NAME,
+	PROP_TITLE,
+	PROP_LOGGING,
+	PROP_FEATURES,
+	PROP_LAST
+};
+
 /**
  * A hash table used for efficient lookups of conversations by name.
  * struct _purple_hconv => PurpleConversation*
@@ -193,7 +205,7 @@ common_send(PurpleConversation *conv, co
 			displayed = purple_markup_linkify(message);
 	}
 
-	if (displayed && (conv->features & PURPLE_CONNECTION_HTML) &&
+	if (displayed && (priv->features & PURPLE_CONNECTION_HTML) &&
 		!(msgflags & PURPLE_MESSAGE_RAW)) {
 		sent = g_strdup(displayed);
 	} else
@@ -272,8 +284,8 @@ common_send(PurpleConversation *conv, co
 static void
 open_log(PurpleConversation *conv)
 {
-	conv->logs = g_list_append(NULL, purple_log_new(conv->type == PURPLE_CONVERSATION_TYPE_CHAT ? PURPLE_LOG_CHAT :
-							   PURPLE_LOG_IM, conv->name, conv->account,
+	priv->logs = g_list_append(NULL, purple_log_new(priv->type == PURPLE_CONVERSATION_TYPE_CHAT ? PURPLE_LOG_CHAT :
+							   PURPLE_LOG_IM, priv->name, priv->account,
 							   conv, time(NULL), NULL));
 }
 
@@ -286,14 +298,14 @@ add_message_to_history(PurpleConversatio
 	PurpleConversationMessage *msg;
 	PurpleConnection *gc;
 
-	gc = purple_account_get_connection(conv->account);
+	gc = purple_account_get_connection(priv->account);
 
 	if (flags & PURPLE_MESSAGE_SEND) {
 		const char *me = NULL;
 		if (gc)
 			me = purple_connection_get_display_name(gc);
 		if (!me)
-			me = purple_account_get_username(conv->account);
+			me = purple_account_get_username(priv->account);
 		who = me;
 	}
 
@@ -306,7 +318,7 @@ add_message_to_history(PurpleConversatio
 	msg->when = when;
 	msg->conv = conv;
 
-	conv->message_history = g_list_prepend(conv->message_history, msg);
+	priv->message_history = g_list_prepend(priv->message_history, msg);
 }
 
 static void
@@ -329,316 +341,6 @@ message_history_free(GList *list)
 /**************************************************************************
  * Conversation API
  **************************************************************************/
-static void
-purple_conversation_chat_cleanup_for_rejoin(PurpleConversation *conv)
-{
-	const char *disp;
-	PurpleAccount *account;
-	PurpleConnection *gc;
-
-	account = purple_conversation_get_account(conv);
-
-	purple_conversation_close_logs(conv);
-	open_log(conv);
-
-	gc = purple_account_get_connection(account);
-
-	if ((disp = purple_connection_get_display_name(gc)) != NULL)
-		purple_chat_conversation_set_nick(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv), disp);
-	else
-	{
-		purple_chat_conversation_set_nick(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv),
-								purple_account_get_username(account));
-	}
-
-	purple_chat_conversation_clear_users(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv));
-	purple_chat_conversation_set_topic(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv), NULL, NULL);
-	PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)->left = FALSE;
-
-	purple_conversation_update(conv, PURPLE_CONVERSATION_UPDATE_CHATLEFT);
-}
-
-PurpleConversation *
-purple_conversation_new(PurpleConversationType type, PurpleAccount *account,
-					  const char *name)
-{
-	PurpleConversation *conv;
-	PurpleConnection *gc;
-	PurpleConversationUiOps *ops;
-	struct _purple_hconv *hc;
-
-	g_return_val_if_fail(type    != PURPLE_CONVERSATION_TYPE_UNKNOWN, NULL);
-	g_return_val_if_fail(account != NULL, NULL);
-	g_return_val_if_fail(name    != NULL, NULL);
-
-	/* Check if this conversation already exists. */
-	if ((conv = purple_conversations_find_with_account(type, name, account)) != NULL)
-	{
-		if (purple_conversation_get_type(conv) == PURPLE_CONVERSATION_TYPE_CHAT &&
-				!purple_chat_conversation_has_left(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv))) {
-			purple_debug_warning("conversation", "Trying to create multiple "
-					"chats (%s) with the same name is deprecated and will be "
-					"removed in libpurple 3.0.0", name);
-		}
-
-		/*
-		 * This hack is necessary because some prpls (MSN) have unnamed chats
-		 * that all use the same name.  A PurpleConversation for one of those
-		 * is only ever re-used if the user has left, so calls to
-		 * purple_conversation_new need to fall-through to creating a new
-		 * chat.
-		 * TODO 3.0.0: Remove this workaround and mandate unique names.
-		 */
-		if (purple_conversation_get_type(conv) != PURPLE_CONVERSATION_TYPE_CHAT ||
-				purple_chat_conversation_has_left(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)))
-		{
-			if (purple_conversation_get_type(conv) == PURPLE_CONVERSATION_TYPE_CHAT)
-				purple_conversation_chat_cleanup_for_rejoin(conv);
-
-			return conv;
-		}
-	}
-
-	gc = purple_account_get_connection(account);
-	g_return_val_if_fail(gc != NULL, NULL);
-
-	conv = g_new0(PurpleConversation, 1);
-	PURPLE_DBUS_REGISTER_POINTER(conv, PurpleConversation);
-
-	conv->type         = type;
-	conv->account      = account;
-	conv->name         = g_strdup(name);
-	conv->title        = g_strdup(name);
-	conv->data         = g_hash_table_new_full(g_str_hash, g_str_equal,
-											   g_free, NULL);
-	/* copy features from the connection. */
-	conv->features = purple_connection_get_flags(gc);
-
-	if (type == PURPLE_CONVERSATION_TYPE_IM)
-	{
-		PurpleBuddyIcon *icon;
-		conv->u.im = g_new0(PurpleIMConversationPrivate, 1);
-		conv->u.im->conv = conv;
-		PURPLE_DBUS_REGISTER_POINTER(conv->u.im, PurpleIMConversationPrivate);
-
-		ims = g_list_prepend(ims, conv);
-		if ((icon = purple_buddy_icons_find(account, name)))
-		{
-			purple_im_conversation_set_icon(conv->u.im, icon);
-			/* purple_im_conversation_set_icon refs the icon. */
-			purple_buddy_icon_unref(icon);
-		}
-
-		if (purple_prefs_get_bool("/purple/logging/log_ims"))
-		{
-			purple_conversation_set_logging(conv, TRUE);
-			open_log(conv);
-		}
-	}
-	else if (type == PURPLE_CONVERSATION_TYPE_CHAT)
-	{
-		const char *disp;
-
-		conv->u.chat = g_new0(PurpleChatConversationPrivate, 1);
-		conv->u.chat->conv = conv;
-		conv->u.chat->users = g_hash_table_new_full(_purple_conversation_user_hash,
-				_purple_conversation_user_equal, g_free, NULL);
-		PURPLE_DBUS_REGISTER_POINTER(conv->u.chat, PurpleChatConversationPrivate);
-
-		chats = g_list_prepend(chats, conv);
-
-		if ((disp = purple_connection_get_display_name(purple_account_get_connection(account))))
-			purple_chat_conversation_set_nick(conv->u.chat, disp);
-		else
-			purple_chat_conversation_set_nick(conv->u.chat,
-									purple_account_get_username(account));
-
-		if (purple_prefs_get_bool("/purple/logging/log_chats"))
-		{
-			purple_conversation_set_logging(conv, TRUE);
-			open_log(conv);
-		}
-	}
-
-	conversations = g_list_prepend(conversations, conv);
-
-	hc = g_new(struct _purple_hconv, 1);
-	hc->name = g_strdup(purple_normalize(account, conv->name));
-	hc->account = account;
-	hc->type = type;
-
-	g_hash_table_insert(conversation_cache, hc, conv);
-
-	/* Auto-set the title. */
-	purple_conversation_autoset_title(conv);
-
-	/* Don't move this.. it needs to be one of the last things done otherwise
-	 * it causes mysterious crashes on my system.
-	 *  -- Gary
-	 */
-	ops  = conv->ui_ops = default_ops;
-	if (ops != NULL && ops->create_conversation != NULL)
-		ops->create_conversation(conv);
-
-	purple_signal_emit(purple_conversations_get_handle(),
-					 "conversation-created", conv);
-
-	return conv;
-}
-
-void
-purple_conversation_destroy(PurpleConversation *conv)
-{
-	PurplePluginProtocolInfo *prpl_info = NULL;
-	PurpleConversationUiOps *ops;
-	PurpleConnection *gc;
-	const char *name;
-	struct _purple_hconv hc;
-
-	g_return_if_fail(conv != NULL);
-
-	purple_request_close_with_handle(conv);
-
-	ops  = purple_conversation_get_ui_ops(conv);
-	gc   = purple_conversation_get_connection(conv);
-	name = purple_conversation_get_name(conv);
-
-	if (gc != NULL)
-	{
-		/* Still connected */
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
-
-		if (purple_conversation_get_type(conv) == PURPLE_CONVERSATION_TYPE_IM)
-		{
-			if (purple_prefs_get_bool("/purple/conversations/im/send_typing"))
-				serv_send_typing(gc, name, PURPLE_IM_CONVERSATION_NOT_TYPING);



More information about the Commits mailing list