/soc/2013/ankitkv/gobjectification: a6587d8cf907: Added missing ...

Ankit Vani a at nevitus.org
Wed Jun 26 05:15:52 EDT 2013


Changeset: a6587d8cf907c86212076f3999fe72832d9667ba
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-26 14:45 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/a6587d8cf907

Description:

Added missing API implementations to PurpleConversation and subclasses

diffstat:

 libpurple/conversation.c      |   89 ++++++++------------
 libpurple/conversation.h      |   13 +-
 libpurple/conversations.c     |  173 +++++++++++++++++++++++++++++++++++++----
 libpurple/conversations.h     |   14 +-
 libpurple/conversationtypes.c |   76 ++++++-----------
 libpurple/conversationtypes.h |   84 +------------------
 6 files changed, 240 insertions(+), 209 deletions(-)

diffs (truncated from 803 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -89,52 +89,8 @@ enum
 	PROP_LAST
 };
 
-/**
- * A hash table used for efficient lookups of conversations by name.
- * struct _purple_hconv => PurpleConversation*
- */
-static GHashTable *conversation_cache = NULL;
+static GObjectClass *parent_class;
 
-struct _purple_hconv {
-	PurpleConversationType type;
-	char *name;
-	const PurpleAccount *account;
-};
-
-static guint _purple_conversations_hconv_hash(struct _purple_hconv *hc)
-{
-	return g_str_hash(hc->name) ^ hc->type ^ g_direct_hash(hc->account);
-}
-
-static guint _purple_conversations_hconv_equal(struct _purple_hconv *hc1, struct _purple_hconv *hc2)
-{
-	return (hc1->type == hc2->type &&
-	        hc1->account == hc2->account &&
-	        g_str_equal(hc1->name, hc2->name));
-}
-
-static void _purple_conversations_hconv_free_key(struct _purple_hconv *hc)
-{
-	g_free(hc->name);
-	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);
-}
 
 static gboolean
 reset_typing_cb(gpointer data)
@@ -673,6 +629,40 @@ purple_conversation_write(PurpleConversa
 	g_free(displayed);
 }
 
+void
+purple_conversation_write_message(PurpleConversation *conv, const char *who,
+		const char *message, PurpleMessageFlags flags, time_t mtime)
+{
+	PurpleConversationClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
+
+	klass = PURPLE_CONVERSATION_GET_CLASS(conv);
+
+	if (klass && klass->write_message)
+		klass->write_message(conv, who, message, flags, mtime);
+}
+
+void
+purple_conversation_send(PurpleConversation *conv, const char *message)
+{
+	purple_conversation_send_message(conv, message, 0);
+}
+
+void
+purple_conversation_send_message(PurpleConversation *conv, const char *message,
+		PurpleMessageFlags flags)
+{
+	PurpleConversationClass *klass = 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);
+}
+
 gboolean
 purple_conversation_has_focus(PurpleConversation *conv)
 {
@@ -1072,6 +1062,8 @@ purple_conversation_init(GTypeInstance *
 	PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
 
 	priv->data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+	PURPLE_DBUS_REGISTER_POINTER(conv, PurpleConversation);
 }
 
 /* GObject dispose function */
@@ -1085,7 +1077,6 @@ purple_conversation_dispose(GObject *obj
 	PurpleConversationUiOps *ops;
 	PurpleConnection *gc;
 	const char *name;
-	struct _purple_hconv hc;
 
 	g_return_if_fail(conv != NULL);
 
@@ -1098,12 +1089,6 @@ purple_conversation_dispose(GObject *obj
 	/* remove from conversations and im/chats lists prior to emit */
 	purple_conversations_remove(conv);
 
-	hc.name = (gchar *)purple_normalize(priv->account, priv->name);
-	hc.account = priv->account;
-	hc.type = priv->type;
-
-	g_hash_table_remove(conversation_cache, &hc);
-
 	purple_signal_emit(purple_conversations_get_handle(),
 					 "deleting-conversation", conv);
 
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -130,14 +130,13 @@ struct _PurpleConversationClass {
 	/*< private >*/
 	GObjectClass parent_class;
 
-	/** Writes a message to a chat or IM conversation. TODO
+	/** Writes a message to a chat or IM conversation.
 	 *  @see purple_conversation_write_message()
 	 */
 	void (*write_message)(PurpleConversation *conv, const char *who,
-			const char *message, PurpleMessageFlags flags,
-			time_t mtime);
+			const char *message, PurpleMessageFlags flags, time_t mtime);
 
-	/** Sends a message to a chat or IM conversation. TODO
+	/** Sends a message to a chat or IM conversation.
 	 *  @see purple_conversation_send_message()
 	 */
 	void (*send_message)(PurpleConversation *conv,
@@ -447,7 +446,7 @@ void purple_conversation_write(PurpleCon
 		const char *message, PurpleMessageFlags flags,
 		time_t mtime);
 
-/** TODO pure virtual
+/**
  * Writes to a chat or an IM.
  *
  * @param conv    The conversation.
@@ -460,7 +459,7 @@ void purple_conversation_write_message(P
 		const char *who, const char *message,
 		PurpleMessageFlags flags, time_t mtime);
 
-/** TODO forward to send_message
+/**
  * Sends a message to this conversation. This function calls
  * purple_conversation_send_message() with no additional flags.
  *
@@ -469,7 +468,7 @@ void purple_conversation_write_message(P
  */
 void purple_conversation_send(PurpleConversation *conv, const char *message);
 
-/** TODO pure virtual
+/**
  * Sends a message to this conversation with specified flags.
  *
  * @param conv    The conversation.
diff --git a/libpurple/conversations.c b/libpurple/conversations.c
--- a/libpurple/conversations.c
+++ b/libpurple/conversations.c
@@ -26,6 +26,112 @@ static GList *ims = NULL;
 static GList *chats = NULL;
 static PurpleConversationUiOps *default_ops = NULL;
 
+/**
+ * A hash table used for efficient lookups of conversations by name.
+ * struct _purple_hconv => PurpleConversation*
+ */
+static GHashTable *conversation_cache = NULL;
+
+struct _purple_hconv {
+	gboolean im;
+	char *name;
+	const PurpleAccount *account;
+};
+
+static guint
+_purple_conversations_hconv_hash(struct _purple_hconv *hc)
+{
+	return g_str_hash(hc->name) ^ hc->im ^ g_direct_hash(hc->account);
+}
+
+static guint
+_purple_conversations_hconv_equal(struct _purple_hconv *hc1, struct _purple_hconv *hc2)
+{
+	return (hc1->im == hc2->im &&
+	        hc1->account == hc2->account &&
+	        g_str_equal(hc1->name, hc2->name));
+}
+
+static void
+_purple_conversations_hconv_free_key(struct _purple_hconv *hc)
+{
+	g_free(hc->name);
+	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)
+{
+	PurpleAccount *account;
+	struct _purple_hconv *hc;
+
+	g_return_if_fail(conv != NULL);
+
+	if (g_list_find(conversations, conv) != NULL)
+		return;
+
+	conversations = g_list_prepend(conversations, conv);
+
+	if (PURPLE_IS_IM_CONVERSATION(conv))
+		g_list_prepend(ims, conv);
+	else
+		g_list_prepend(chats, conv);
+
+	account = purple_conversation_get_account(conv);
+
+	hc = g_new(struct _purple_hconv, 1);
+	hc->name = g_strdup(purple_normalize(account,
+				purple_conversation_get_name(conv)));
+	hc->account = account;
+	hc->im = PURPLE_IS_IM_CONVERSATION(conv);
+
+	g_hash_table_insert(conversation_cache, hc, conv);
+}
+
+void
+purple_conversations_remove(PurpleConversation *conv)
+{
+	PurpleAccount *account;
+	struct _purple_hconv hc;
+
+	g_return_if_fail(conv != NULL);
+
+	conversations = g_list_remove(conversations, conv);
+
+	if (PURPLE_IS_IM_CONVERSATION(conv))
+		g_list_remove(ims, conv);
+	else
+		g_list_remove(chats, conv);
+
+	account = purple_conversation_get_account(conv);
+
+	hc.name = (gchar *)purple_normalize(account,
+				purple_conversation_get_name(conv));
+	hc.account = account;
+	hc.im = PURPLE_IS_IM_CONVERSATION(conv);
+
+	g_hash_table_remove(conversation_cache, &hc);
+}
+
 GList *
 purple_conversations_get(void)
 {
@@ -45,9 +151,8 @@ purple_conversations_get_chats(void)
 }
 
 PurpleConversation *
-purple_conversations_find_with_account(PurpleConversationType type,
-									const char *name,
-									const PurpleAccount *account)
+purple_conversations_find_with_account(const char *name,



More information about the Commits mailing list