/soc/2013/ankitkv/gobjectification: 88c104a20f4b: Refactored the...

Ankit Vani a at nevitus.org
Wed Jun 26 16:01:48 EDT 2013


Changeset: 88c104a20f4bf49e78821b80e4d2d9bb64253139
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-27 01:24 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/88c104a20f4b

Description:

Refactored the PurpleConversation subclasses and subsystem to use the GObject conversation API.
* Removed the virtual function send_message of PurpleConversation as it did the same thing in both IMs and chats
* Renamed purple_conversation_send_message back to purple_conversation_send_with_flags
* Changed the argument of chat_update_user of PurpleConversationUiOps to PurpleChatConversationBuddy *
* purple_conversations_update_cache() updates the conversations cache with a new account and/or name
* Renamed purple_chat_conversation_find_user to a more appropriate purple_chat_conversation_has_user as it returns boolean
* Removed purple_chat_conversation_[set,get]_user_flags and added buddy methods purple_chat_conversation_buddy_[set,get]_flags
* Added purple_chat_conversation_buddy_[set,get]_chat methods to set and get the chat that the chat buddy is a part of
* Added PurpleChatConversation * argument to purple_chat_conversation_buddy_new.

diffstat:

 libpurple/conversation.c      |   24 +-
 libpurple/conversation.h      |   21 +-
 libpurple/conversations.c     |   77 +--
 libpurple/conversations.h     |   26 +-
 libpurple/conversationtypes.c |  929 ++++++++++++++++++++++++-----------------
 libpurple/conversationtypes.h |   75 ++-
 6 files changed, 624 insertions(+), 528 deletions(-)

diffs (truncated from 2394 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -334,7 +334,7 @@ purple_conversation_set_account(PurpleCo
 	if (account == purple_conversation_get_account(conv))
 		return;
 
-	purple_conversations_update_cache_account(conv, account);
+	purple_conversations_update_cache(conv, NULL, account);
 	priv->account = account;
 
 	purple_conversation_update(conv, PURPLE_CONVERSATION_UPDATE_ACCOUNT);
@@ -423,7 +423,7 @@ purple_conversation_set_name(PurpleConve
 
 	g_return_if_fail(priv != NULL);
 
-	purple_conversations_update_cache_name(conv, name);
+	purple_conversations_update_cache(conv, name, NULL);
 
 	g_free(priv->name);
 	priv->name = g_strdup(name);
@@ -451,6 +451,9 @@ purple_conversation_set_logging(PurpleCo
 	if (priv->logging != log)
 	{
 		priv->logging = log;
+		if (log && priv->logs == NULL)
+			open_log(conv);
+
 		purple_conversation_update(conv, PURPLE_CONVERSATION_UPDATE_LOGGING);
 	}
 }
@@ -586,9 +589,6 @@ purple_conversation_write(PurpleConversa
 	if (!(flags & PURPLE_MESSAGE_NO_LOG) && purple_conversation_is_logging(conv)) {
 		GList *log;
 
-		if (priv->logs == NULL)
-			open_log(conv);
-
 		log = priv->logs;
 		while (log != NULL) {
 			purple_log_write((PurpleLog *)log->data, flags, alias, mtime, displayed);
@@ -625,21 +625,17 @@ purple_conversation_write_message(Purple
 void
 purple_conversation_send(PurpleConversation *conv, const char *message)
 {
-	purple_conversation_send_message(conv, message, 0);
+	purple_conversation_send_with_flags(conv, message, 0);
 }
 
 void
-purple_conversation_send_message(PurpleConversation *conv, const char *message,
+purple_conversation_send_with_flags(PurpleConversation *conv, const char *message,
 		PurpleMessageFlags flags)
 {
-	PurpleConversationClass *klass = NULL;
+	g_return_if_fail(conv != NULL);
+	g_return_if_fail(message != NULL);
 
-	g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
-
-	klass = PURPLE_CONVERSATION_GET_CLASS(conv);
-
-	if (klass && klass->send_message)
-		klass->send_message(conv, message, flags);
+	common_send(conv, message, flags);
 }
 
 gboolean
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -1,5 +1,5 @@
 /**
- * @file conversation.h Conversation API
+ * @file conversation.h Conversation base class API
  * @ingroup core
  */
 
@@ -136,12 +136,6 @@ struct _PurpleConversationClass {
 	void (*write_message)(PurpleConversation *conv, const char *who,
 			const char *message, PurpleMessageFlags flags, time_t mtime);
 
-	/** Sends a message to a chat or IM conversation.
-	 *  @see purple_conversation_send_message()
-	 */
-	void (*send_message)(PurpleConversation *conv,
-			const char *message, PurpleMessageFlags flags);
-
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
 	void (*_purple_reserved3)(void);
@@ -155,8 +149,9 @@ struct _PurpleConversationClass {
 /**************************************************************************/
 /** PurpleConversationUiOps                                               */
 /**************************************************************************/
-typedef struct _PurpleIMConversation    PurpleIMConversation;
-typedef struct _PurpleChatConversation  PurpleChatConversation;
+typedef struct _PurpleIMConversation         PurpleIMConversation;
+typedef struct _PurpleChatConversation       PurpleChatConversation;
+typedef struct _PurpleChatConversationBuddy  PurpleChatConversationBuddy;
 /**
  * Conversation operations and events.
  *
@@ -224,9 +219,9 @@ struct _PurpleConversationUiOps
 	 */
 	void (*chat_remove_users)(PurpleChatConversation *chat, GList *users);
 	/** Called when a user's flags are changed.
-	 *  @see purple_chat_conversation_user_set_flags()
+	 *  @see purple_chat_conversation_buddy_set_flags()
 	 */
-	void (*chat_update_user)(PurpleChatConversation *chat, const char *user);
+	void (*chat_update_user)(PurpleChatConversationBuddy *cb);
 
 	/** Present this conversation to the user; for example, by displaying
 	 *  the IM dialog.
@@ -461,7 +456,7 @@ void purple_conversation_write_message(P
 
 /**
  * Sends a message to this conversation. This function calls
- * purple_conversation_send_message() with no additional flags.
+ * purple_conversation_send_with_flags() with no additional flags.
  *
  * @param conv    The conversation.
  * @param message The message to send.
@@ -476,7 +471,7 @@ void purple_conversation_send(PurpleConv
  * @param flags   The PurpleMessageFlags flags to use in addition to
  *                PURPLE_MESSAGE_SEND.
  */
-void purple_conversation_send_message(PurpleConversation *conv, const char *message,
+void purple_conversation_send_with_flags(PurpleConversation *conv, const char *message,
 		PurpleMessageFlags flags);
 
 /**
diff --git a/libpurple/conversations.c b/libpurple/conversations.c
--- a/libpurple/conversations.c
+++ b/libpurple/conversations.c
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
+#include "internal.h"
 #include "conversations.h"
 
 static GList *conversations = NULL;
@@ -59,25 +60,6 @@ static void
 	g_free(hc);
 }
 
-static guint
-_purple_conversation_user_hash(gconstpointer data)
-{
-	const gchar *name = data;
-	gchar *collated;
-	guint hash;
-
-	collated = g_utf8_collate_key(name, -1);
-	hash     = g_str_hash(collated);
-	g_free(collated);
-	return hash;
-}
-
-static gboolean
-_purple_conversation_user_equal(gconstpointer a, gconstpointer b)
-{
-	return !g_utf8_collate(a, b);
-}
-
 void
 purple_conversations_add(PurpleConversation *conv)
 {
@@ -92,9 +74,9 @@ purple_conversations_add(PurpleConversat
 	conversations = g_list_prepend(conversations, conv);
 
 	if (PURPLE_IS_IM_CONVERSATION(conv))
-		g_list_prepend(ims, conv);
+		ims = g_list_prepend(ims, conv);
 	else
-		g_list_prepend(chats, conv);
+		chats = g_list_prepend(chats, conv);
 
 	account = purple_conversation_get_account(conv);
 
@@ -118,9 +100,9 @@ purple_conversations_remove(PurpleConver
 	conversations = g_list_remove(conversations, conv);
 
 	if (PURPLE_IS_IM_CONVERSATION(conv))
-		g_list_remove(ims, conv);
+		ims = g_list_remove(ims, conv);
 	else
-		g_list_remove(chats, conv);
+		chats = g_list_remove(chats, conv);
 
 	account = purple_conversation_get_account(conv);
 
@@ -133,49 +115,30 @@ purple_conversations_remove(PurpleConver
 }
 
 void
-purple_conversations_update_cache_name(PurpleConversation *conv,
-		const char *name)
-{
-	PurpleAccount *account;
-	struct _purple_hconv *hc;
-
-	g_return_if_fail(conv != NULL);
-
-	account = purple_conversation_get_account(conv);
-
-	hc = g_new(struct _purple_hconv, 1);
-	hc->im = PURPLE_IS_IM_CONVERSATION(im);
-	hc->account = account;
-	hc->name = (gchar *)purple_normalize(account,
-				purple_conversation_get_name(conv));
-
-	g_hash_table_remove(conversation_cache, hc);
-
-	hc->name = g_strdup(purple_normalize(account, name));
-	g_hash_table_insert(conversation_cache, hc, conv);
-}
-
-void
-purple_conversations_update_cache_account(PurpleConversation *conv,
+purple_conversations_update_cache(PurpleConversation *conv, const char *name,
 		PurpleAccount *account)
 {
 	PurpleAccount *old_account;
 	struct _purple_hconv *hc;
 
 	g_return_if_fail(conv != NULL);
-	g_return_if_fail(account != NULL);
+	g_return_if_fail(account != NULL || name != NULL);
 
 	old_account = purple_conversation_get_account(conv);
 
 	hc = g_new(struct _purple_hconv, 1);
-	hc->im = PURPLE_IS_IM_CONVERSATION(im);
+	hc->im = PURPLE_IS_IM_CONVERSATION(conv);
 	hc->account = old_account;
 	hc->name = (gchar *)purple_normalize(old_account,
 				purple_conversation_get_name(conv));
 
 	g_hash_table_remove(conversation_cache, hc);
 
-	hc->account = account;
+	if (account)
+		hc->account = account;
+	if (name)
+		hc->name = g_strdup(purple_normalize(account, name));
+
 	g_hash_table_insert(conversation_cache, hc, conv);
 }
 
@@ -208,7 +171,6 @@ purple_conversations_find_with_account(c
 
 	hc.name = (gchar *)purple_normalize(account, name);
 	hc.account = account;
-	hc.type = type;
 
 	hc.im = TRUE;
 	c = g_hash_table_lookup(conversation_cache, &hc);
@@ -260,14 +222,14 @@ PurpleChatConversation *
 purple_conversations_find_chat(const PurpleConnection *gc, int id)
 {
 	GList *l;
-	PurpleConversation *conv;
+	PurpleChatConversation *chat;
 
 	for (l = purple_conversations_get_chats(); l != NULL; l = l->next) {
-		conv = (PurpleConversation *)l->data;
+		chat = (PurpleChatConversation *)l->data;
 
-		if (purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)) == id &&
-			purple_conversation_get_connection(conv) == gc)
-			return conv;
+		if (purple_chat_conversation_get_id(chat) == id &&
+				purple_conversation_get_connection(PURPLE_CONVERSATION(chat)) == gc)
+			return chat;
 	}
 
 	return NULL;
@@ -620,7 +582,8 @@ void
 purple_conversations_uninit(void)
 {
 	while (conversations)
-		purple_conversation_destroy((PurpleConversation*)conversations->data);
+		g_object_unref(G_OBJECT(conversations->data));
+
 	g_hash_table_destroy(conversation_cache);
 	purple_signals_unregister_by_instance(purple_conversations_get_handle());
 }
diff --git a/libpurple/conversations.h b/libpurple/conversations.h
--- a/libpurple/conversations.h
+++ b/libpurple/conversations.h
@@ -1,5 +1,5 @@
 /**
- * @file conversations.h Conversations API
+ * @file conversations.h IM and Chat Conversations API
  * @ingroup core
  * @see @ref conversation-signals
  */



More information about the Commits mailing list