/soc/2013/ankitkv/gobjectification: 4a0ec0fff2e1: Refactored Pur...
Ankit Vani
a at nevitus.org
Wed Jun 26 16:01:48 EDT 2013
Changeset: 4a0ec0fff2e14df867016b0b7a89207c1a6d1763
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-26 16:33 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/4a0ec0fff2e1
Description:
Refactored PurpleConversation base object to use the GObject conversation API
diffstat:
libpurple/conversation.c | 328 +++++++++++++----------------------------
libpurple/conversations.c | 47 ++++++
libpurple/conversations.h | 22 ++
libpurple/conversationtypes.c | 140 +++++++++++++++++
4 files changed, 318 insertions(+), 219 deletions(-)
diffs (truncated from 938 to 300 lines):
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -25,6 +25,7 @@
#include "conversation.h"
#include "dbus-maybe.h"
#include "debug.h"
+#include "enums.h"
#include "imgstore.h"
#include "notify.h"
#include "prefs.h"
@@ -92,55 +93,17 @@ enum
static GObjectClass *parent_class;
-static gboolean
-reset_typing_cb(gpointer data)
-{
- PurpleConversation *c = (PurpleConversation *)data;
- PurpleIMConversationPrivate *priv;
-
- im = PURPLE_IM_CONVERSATION_GET_PRIVATE(c);
-
- purple_im_conversation_set_typing_state(im, PURPLE_IM_CONVERSATION_NOT_TYPING);
- purple_im_conversation_stop_typing_timeout(im);
-
- return FALSE;
-}
-
-static gboolean
-send_typed_cb(gpointer data)
-{
- PurpleConversation *conv = (PurpleConversation *)data;
- PurpleConnection *gc;
- const char *name;
-
- g_return_val_if_fail(conv != NULL, FALSE);
-
- gc = purple_conversation_get_connection(conv);
- name = purple_conversation_get_name(conv);
-
- if (gc != NULL && name != NULL) {
- /* We set this to 1 so that PURPLE_IM_CONVERSATION_TYPING will be sent
- * if the Purple user types anything else.
- */
- purple_im_conversation_set_type_again(PURPLE_IM_CONVERSATION_GET_PRIVATE(conv), 1);
-
- serv_send_typing(gc, name, PURPLE_IM_CONVERSATION_TYPED);
-
- purple_debug(PURPLE_DEBUG_MISC, "conversation", "typed...\n");
- }
-
- return FALSE;
-}
-
static void
common_send(PurpleConversation *conv, const char *message, PurpleMessageFlags msgflags)
{
- PurpleConversationType type;
PurpleAccount *account;
PurpleConnection *gc;
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
char *displayed = NULL, *sent = NULL;
int err = 0;
+ g_return_if_fail(priv != NULL);
+
if (*message == '\0')
return;
@@ -150,8 +113,6 @@ common_send(PurpleConversation *conv, co
g_return_if_fail(account != NULL);
g_return_if_fail(gc != NULL);
- type = purple_conversation_get_type(conv);
-
/* Always linkfy the text for display, unless we're
* explicitly asked to do otheriwse*/
if (!(msgflags & PURPLE_MESSAGE_INVISIBLE)) {
@@ -169,9 +130,7 @@ common_send(PurpleConversation *conv, co
msgflags |= PURPLE_MESSAGE_SEND;
- if (type == PURPLE_CONVERSATION_TYPE_IM) {
- PurpleIMConversationPrivate *priv = PURPLE_IM_CONVERSATION_GET_PRIVATE(conv);
-
+ if (PURPLE_IS_IM_CONVERSATION(conv)) {
purple_signal_emit(purple_conversations_get_handle(), "sending-im-msg",
account,
purple_conversation_get_name(conv), &sent);
@@ -182,7 +141,7 @@ common_send(PurpleConversation *conv, co
sent, msgflags);
if ((err > 0) && (displayed != NULL))
- purple_im_conversation_write(im, NULL, displayed, msgflags, time(NULL));
+ purple_conversation_write_message(conv, NULL, displayed, msgflags, time(NULL));
purple_signal_emit(purple_conversations_get_handle(), "sent-im-msg",
account,
@@ -190,16 +149,17 @@ common_send(PurpleConversation *conv, co
}
}
else {
+ PurpleChatConversation *chat = PURPLE_CHAT_CONVERSATION(conv);
purple_signal_emit(purple_conversations_get_handle(), "sending-chat-msg",
account, &sent,
- purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)));
+ purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(conv)));
if (sent != NULL && sent[0] != '\0') {
- err = serv_chat_send(gc, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)), sent, msgflags);
+ err = serv_chat_send(gc, purple_chat_conversation_get_id(chat), sent, msgflags);
purple_signal_emit(purple_conversations_get_handle(), "sent-chat-msg",
account, sent,
- purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv)));
+ purple_chat_conversation_get_id(chat));
}
}
@@ -240,7 +200,11 @@ common_send(PurpleConversation *conv, co
static void
open_log(PurpleConversation *conv)
{
- priv->logs = g_list_append(NULL, purple_log_new(priv->type == PURPLE_CONVERSATION_TYPE_CHAT ? PURPLE_LOG_CHAT :
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_if_fail(priv != NULL);
+
+ priv->logs = g_list_append(NULL, purple_log_new(PURPLE_IS_CHAT_CONVERSATION(conv) ? PURPLE_LOG_CHAT :
PURPLE_LOG_IM, priv->name, priv->account,
conv, time(NULL), NULL));
}
@@ -251,9 +215,12 @@ static void
add_message_to_history(PurpleConversation *conv, const char *who, const char *alias,
const char *message, PurpleMessageFlags flags, time_t when)
{
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
PurpleConversationMessage *msg;
PurpleConnection *gc;
+ g_return_if_fail(priv != NULL);
+
gc = purple_account_get_connection(priv->account);
if (flags & PURPLE_MESSAGE_SEND) {
@@ -311,33 +278,31 @@ purple_conversation_present(PurpleConver
void
purple_conversation_set_features(PurpleConversation *conv, PurpleConnectionFlags features)
{
- g_return_if_fail(conv != NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_if_fail(priv != NULL);
priv->features = features;
-
purple_conversation_update(conv, PURPLE_CONVERSATION_UPDATE_FEATURES);
}
PurpleConnectionFlags
purple_conversation_get_features(PurpleConversation *conv)
{
- g_return_val_if_fail(conv != NULL, 0);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_val_if_fail(priv != NULL, 0);
+
return priv->features;
}
-PurpleConversationType
-purple_conversation_get_type(const PurpleConversation *conv)
-{
- g_return_val_if_fail(conv != NULL, PURPLE_CONVERSATION_TYPE_UNKNOWN);
-
- return priv->type;
-}
-
void
purple_conversation_set_ui_ops(PurpleConversation *conv,
PurpleConversationUiOps *ops)
{
- g_return_if_fail(conv != NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_if_fail(priv != NULL);
if (priv->ui_ops == ops)
return;
@@ -346,14 +311,15 @@ purple_conversation_set_ui_ops(PurpleCon
priv->ui_ops->destroy_conversation(conv);
priv->ui_data = NULL;
-
priv->ui_ops = ops;
}
PurpleConversationUiOps *
purple_conversation_get_ui_ops(const PurpleConversation *conv)
{
- g_return_val_if_fail(conv != NULL, NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_val_if_fail(priv != NULL, NULL);
return priv->ui_ops;
}
@@ -361,11 +327,14 @@ purple_conversation_get_ui_ops(const Pur
void
purple_conversation_set_account(PurpleConversation *conv, PurpleAccount *account)
{
- g_return_if_fail(conv != NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_if_fail(priv != NULL);
if (account == purple_conversation_get_account(conv))
return;
+ purple_conversations_update_cache_account(conv, account);
priv->account = account;
purple_conversation_update(conv, PURPLE_CONVERSATION_UPDATE_ACCOUNT);
@@ -374,7 +343,9 @@ purple_conversation_set_account(PurpleCo
PurpleAccount *
purple_conversation_get_account(const PurpleConversation *conv)
{
- g_return_val_if_fail(conv != NULL, NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_val_if_fail(priv != NULL, NULL);
return priv->account;
}
@@ -397,7 +368,9 @@ purple_conversation_get_connection(const
void
purple_conversation_set_title(PurpleConversation *conv, const char *title)
{
- g_return_if_fail(conv != NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_if_fail(priv != NULL);
g_return_if_fail(title != NULL);
g_free(priv->title);
@@ -409,7 +382,9 @@ purple_conversation_set_title(PurpleConv
const char *
purple_conversation_get_title(const PurpleConversation *conv)
{
- g_return_val_if_fail(conv != NULL, NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+ g_return_val_if_fail(priv != NULL, NULL);
return priv->title;
}
@@ -427,15 +402,14 @@ purple_conversation_autoset_title(Purple
account = purple_conversation_get_account(conv);
name = purple_conversation_get_name(conv);
- if(purple_conversation_get_type(conv) == PURPLE_CONVERSATION_TYPE_IM) {
- if(account && ((b = purple_find_buddy(account, name)) != NULL))
+ if (PURPLE_IS_IM_CONVERSATION(conv)) {
+ if (account && ((b = purple_find_buddy(account, name)) != NULL))
text = purple_buddy_get_contact_alias(b);
- } else if(purple_conversation_get_type(conv) == PURPLE_CONVERSATION_TYPE_CHAT) {
- if(account && ((chat = purple_blist_find_chat(account, name)) != NULL))
+ } else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
+ if (account && ((chat = purple_blist_find_chat(account, name)) != NULL))
text = purple_chat_get_name(chat);
}
-
if(text == NULL)
text = name;
@@ -445,20 +419,14 @@ purple_conversation_autoset_title(Purple
void
purple_conversation_set_name(PurpleConversation *conv, const char *name)
{
- struct _purple_hconv *hc;
- g_return_if_fail(conv != NULL);
+ PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
- hc = g_new(struct _purple_hconv, 1);
- hc->type = priv->type;
- hc->account = priv->account;
- hc->name = (gchar *)purple_normalize(priv->account, priv->name);
+ g_return_if_fail(priv != NULL);
- g_hash_table_remove(conversation_cache, hc);
+ purple_conversations_update_cache_name(conv, name);
+
g_free(priv->name);
-
priv->name = g_strdup(name);
- hc->name = g_strdup(purple_normalize(priv->account, priv->name));
- g_hash_table_insert(conversation_cache, hc, conv);
More information about the Commits
mailing list