/soc/2013/ankitkv/gobjectification: cfbdf3297c99: Refactored msn...
Ankit Vani
a at nevitus.org
Sun Jun 23 14:14:17 EDT 2013
Changeset: cfbdf3297c99380ac3b75062293d3d9e485d9ffc
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-23 23:44 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/cfbdf3297c99
Description:
Refactored msn protocol to use GObject-based PurpleConversation
diffstat:
libpurple/protocols/msn/msg.c | 35 +++++++++++++++++----------------
libpurple/protocols/msn/msn.c | 17 ++++++++-------
libpurple/protocols/msn/notification.c | 3 +-
libpurple/protocols/msn/session.c | 21 +++++++++----------
libpurple/protocols/msn/slpcall.c | 22 +++++++++-----------
libpurple/protocols/msn/switchboard.c | 33 +++++++++++++++----------------
6 files changed, 64 insertions(+), 67 deletions(-)
diffs (truncated from 362 to 300 lines):
diff --git a/libpurple/protocols/msn/msg.c b/libpurple/protocols/msn/msg.c
--- a/libpurple/protocols/msn/msg.c
+++ b/libpurple/protocols/msn/msg.c
@@ -705,7 +705,7 @@ msn_plain_msg(MsnCmdProc *cmdproc, MsnMe
if (swboard->current_users > 1 ||
((swboard->conv != NULL) &&
- purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
+ PURPLE_IS_CHAT_CONVERSATION(swboard->conv)))
{
/* If current_users is always ok as it should then there is no need to
* check if this is a chat. */
@@ -717,7 +717,7 @@ msn_plain_msg(MsnCmdProc *cmdproc, MsnMe
time(NULL));
if (swboard->conv == NULL)
{
- swboard->conv = purple_conversations_find_chat(gc, swboard->chat_id);
+ swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(gc, swboard->chat_id));
swboard->flag |= MSN_SB_FLAG_IM;
}
}
@@ -727,8 +727,8 @@ msn_plain_msg(MsnCmdProc *cmdproc, MsnMe
serv_got_im(gc, passport, body_final, 0, time(NULL));
if (swboard->conv == NULL)
{
- swboard->conv = purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
- passport, purple_connection_get_account(gc));
+ swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(
+ passport, purple_connection_get_account(gc)));
swboard->flag |= MSN_SB_FLAG_IM;
}
}
@@ -795,18 +795,19 @@ datacast_inform_user(MsnSwitchBoard *swb
if (swboard->conv == NULL) {
if (chat)
- swboard->conv = purple_conversations_find_chat(purple_account_get_connection(account), swboard->chat_id);
+ swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(
+ purple_account_get_connection(account), swboard->chat_id));
else {
- swboard->conv = purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
- who, account);
+ swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(
+ who, account));
if (swboard->conv == NULL)
- swboard->conv = purple_im_conversation_new(account, who);
+ swboard->conv = PURPLE_CONVERSATION(purple_im_conversation_new(account, who));
}
}
if (chat)
serv_got_chat_in(pc,
- purple_chat_conversation_get_id(PURPLE_CONV_CHAT(swboard->conv)),
+ purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(swboard->conv)),
who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str,
time(NULL));
else
@@ -996,7 +997,8 @@ void msn_emoticon_msg(MsnCmdProc *cmdpro
* the conversation doesn't exist then we cannot associate the new
* smiley with its GtkIMHtml widget. */
if (!conv) {
- conv = purple_im_conversation_new(session->account, who);
+ /* TODO memory leak - dispose this conv */
+ conv = PURPLE_CONVERSATION(purple_im_conversation_new(session->account, who));
}
if (purple_conversation_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) {
@@ -1034,7 +1036,7 @@ msn_datacast_msg(MsnCmdProc *cmdproc, Ms
MsnSwitchBoard *swboard = cmdproc->data;
if (swboard->current_users > 1 ||
((swboard->conv != NULL) &&
- purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
+ PURPLE_IS_CHAT_CONVERSATION(swboard->conv)))
purple_prpl_got_attention_in_chat(gc, swboard->chat_id, user, MSN_NUDGE);
else
@@ -1140,21 +1142,20 @@ msn_invite_msg(MsnCmdProc *cmdproc, MsnM
purple_debug_info("msn", "Computer call\n");
if (cmdproc->session) {
- PurpleConversation *conv = NULL;
+ PurpleIMConversation *im = NULL;
gchar *from = msg->remote_user;
gchar *buf = NULL;
if (from)
- conv = purple_conversations_find_with_account(
- PURPLE_CONV_TYPE_IM, from,
- cmdproc->session->account);
- if (conv)
+ im = purple_conversations_find_im_with_account(
+ from, cmdproc->session->account);
+ if (im)
buf = g_strdup_printf(
_("%s sent you a voice chat "
"invite, which is not yet "
"supported."), from);
if (buf) {
- purple_conversation_write(conv, NULL, buf,
+ purple_conversation_write(PURPLE_CONVERSATION(im), NULL, buf,
PURPLE_MESSAGE_SYSTEM |
PURPLE_MESSAGE_NOTIFY,
time(NULL));
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -849,7 +849,8 @@ initiate_chat_cb(PurpleBlistNode *node,
/* TODO: This might move somewhere else, after USR might be */
swboard->chat_id = msn_switchboard_get_chat_id();
- swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat");
+ swboard->conv = PURPLE_CONVERSATION(serv_got_joined_chat(gc,
+ swboard->chat_id, "MSN Chat"));
swboard->flag = MSN_SB_FLAG_IM;
/* Local alias > Display name > Username */
@@ -857,7 +858,7 @@ initiate_chat_cb(PurpleBlistNode *node,
if ((alias = purple_connection_get_display_name(gc)) == NULL)
alias = purple_account_get_username(account);
- purple_chat_conversation_add_user(PURPLE_CONV_CHAT(swboard->conv),
+ purple_chat_conversation_add_user(PURPLE_CHAT_CONVERSATION(swboard->conv),
alias, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
}
@@ -1970,7 +1971,7 @@ msn_chat_invite(PurpleConnection *gc, in
swboard = msn_switchboard_new(session);
msn_switchboard_request(swboard);
swboard->chat_id = id;
- swboard->conv = purple_conversations_find_chat(gc, id);
+ swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(gc, id));
}
swboard->flag |= MSN_SB_FLAG_IM;
@@ -2885,11 +2886,11 @@ static gboolean msn_uri_handler(const ch
if (!g_ascii_strcasecmp(cmd, "Chat")) {
char *sname = g_hash_table_lookup(params, "contact");
if (sname) {
- PurpleConversation *conv = purple_conversations_find_with_account(
- PURPLE_CONV_TYPE_IM, sname, acct);
- if (conv == NULL)
- conv = purple_im_conversation_new(acct, sname);
- purple_conversation_present(conv);
+ PurpleIMConversation *im = purple_conversations_find_im_with_account(
+ sname, acct);
+ if (im == NULL)
+ im = purple_im_conversation_new(acct, sname);
+ purple_conversation_present(PURPLE_CONVERSATION(im));
}
/*else
**If pidgindialogs_im() was in the core, we could use it here.
diff --git a/libpurple/protocols/msn/notification.c b/libpurple/protocols/msn/notification.c
--- a/libpurple/protocols/msn/notification.c
+++ b/libpurple/protocols/msn/notification.c
@@ -1202,8 +1202,7 @@ ipg_cmd_post(MsnCmdProc *cmdproc, MsnCom
if (id && strcmp(id, "1")) {
PurpleConversation *conv
- = purple_conversations_find_with_account(PURPLE_CONV_TYPE_ANY,
- who, purple_connection_get_account(gc));
+ = purple_conversations_find_with_account(who, purple_connection_get_account(gc));
if (conv != NULL) {
const char *error;
if (!strcmp(id, "407"))
diff --git a/libpurple/protocols/msn/session.c b/libpurple/protocols/msn/session.c
--- a/libpurple/protocols/msn/session.c
+++ b/libpurple/protocols/msn/session.c
@@ -177,21 +177,20 @@ msn_session_find_swboard(MsnSession *ses
return NULL;
}
-static PurpleConversation *
-msn_session_get_conv(MsnSession *session,const char *passport)
+static PurpleIMConversation *
+msn_session_get_im(MsnSession *session,const char *passport)
{
PurpleAccount *account;
- PurpleConversation * conv;
+ PurpleIMConversation * im;
g_return_val_if_fail(session != NULL, NULL);
account = session->account;
- conv = purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
- passport, account);
- if(conv == NULL){
- conv = purple_im_conversation_new(account, passport);
+ im = purple_conversations_find_im_with_account(passport, account);
+ if(im == NULL){
+ im = purple_im_conversation_new(account, passport);
}
- return conv;
+ return im;
}
/* put Message to User Conversation
@@ -201,10 +200,10 @@ msn_session_get_conv(MsnSession *session
void
msn_session_report_user(MsnSession *session,const char *passport,const char *msg,PurpleMessageFlags flags)
{
- PurpleConversation * conv;
+ PurpleIMConversation * im;
- if ((conv = msn_session_get_conv(session,passport)) != NULL){
- purple_conversation_write(conv, NULL, msg, flags, time(NULL));
+ if ((im = msn_session_get_im(session,passport)) != NULL){
+ purple_conversation_write(PURPLE_CONVERSATION(im), NULL, msg, flags, time(NULL));
}
}
diff --git a/libpurple/protocols/msn/slpcall.c b/libpurple/protocols/msn/slpcall.c
--- a/libpurple/protocols/msn/slpcall.c
+++ b/libpurple/protocols/msn/slpcall.c
@@ -566,18 +566,17 @@ got_sessionreq(MsnSlpCall *slpcall, cons
} else if (!strcmp(euf_guid, MSN_CAM_REQUEST_GUID)) {
purple_debug_info("msn", "Cam request.\n");
if (slpcall->slplink && slpcall->slplink->session) {
- PurpleConversation *conv;
+ PurpleIMConversation *im;
gchar *from = slpcall->slplink->remote_user;
- conv = purple_conversations_find_with_account(
- PURPLE_CONV_TYPE_IM, from,
- slpcall->slplink->session->account);
- if (conv) {
+ im = purple_conversations_find_im_with_account(
+ from, slpcall->slplink->session->account);
+ if (im) {
char *buf;
buf = g_strdup_printf(
_("%s requests to view your "
"webcam, but this request is "
"not yet supported."), from);
- purple_conversation_write(conv, NULL, buf,
+ purple_conversation_write(PURPLE_CONVERSATION(im), NULL, buf,
PURPLE_MESSAGE_SYSTEM |
PURPLE_MESSAGE_NOTIFY,
time(NULL));
@@ -588,17 +587,16 @@ got_sessionreq(MsnSlpCall *slpcall, cons
} else if (!strcmp(euf_guid, MSN_CAM_GUID)) {
purple_debug_info("msn", "Cam invite.\n");
if (slpcall->slplink && slpcall->slplink->session) {
- PurpleConversation *conv;
+ PurpleIMConversation *im;
gchar *from = slpcall->slplink->remote_user;
- conv = purple_conversations_find_with_account(
- PURPLE_CONV_TYPE_IM, from,
- slpcall->slplink->session->account);
- if (conv) {
+ im = purple_conversations_find_im_with_account(
+ from, slpcall->slplink->session->account);
+ if (im) {
char *buf;
buf = g_strdup_printf(
_("%s invited you to view his/her webcam, but "
"this is not yet supported."), from);
- purple_conversation_write(conv, NULL, buf,
+ purple_conversation_write(PURPLE_CONVERSATION(im), NULL, buf,
PURPLE_MESSAGE_SYSTEM |
PURPLE_MESSAGE_NOTIFY,
time(NULL));
diff --git a/libpurple/protocols/msn/switchboard.c b/libpurple/protocols/msn/switchboard.c
--- a/libpurple/protocols/msn/switchboard.c
+++ b/libpurple/protocols/msn/switchboard.c
@@ -288,22 +288,21 @@ msn_switchboard_add_user(MsnSwitchBoard
return;
}
- if ((swboard->conv != NULL) &&
- (purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
+ if ((swboard->conv != NULL) && (PURPLE_IS_CHAT_CONVERSATION(swboard->conv)))
{
- purple_chat_conversation_add_user(PURPLE_CONV_CHAT(swboard->conv), msnuser->passport, NULL,
- PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
+ purple_chat_conversation_add_user(PURPLE_CHAT_CONVERSATION(swboard->conv),
+ msnuser->passport, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
msn_servconn_set_idle_timeout(swboard->servconn, 0);
}
else if (swboard->current_users > 1)
{
msn_servconn_set_idle_timeout(swboard->servconn, 0);
if (swboard->conv == NULL ||
- purple_conversation_get_type(swboard->conv) != PURPLE_CONV_TYPE_CHAT)
+ PURPLE_IS_IM_CONVERSATION(swboard->conv))
{
GList *l;
-#if 0
+#if 0 /* TODO if conv exists, it gets leaked? */
/* this is bad - it causes msn_switchboard_close to be called on the
* switchboard we're in the middle of using :( */
if (swboard->conv != NULL)
@@ -312,9 +311,9 @@ msn_switchboard_add_user(MsnSwitchBoard
swboard->chat_id = msn_switchboard_get_chat_id();
swboard->flag |= MSN_SB_FLAG_IM;
- swboard->conv = serv_got_joined_chat(purple_account_get_connection(account),
+ swboard->conv = PURPLE_CONVERSATION(serv_got_joined_chat(purple_account_get_connection(account),
swboard->chat_id,
- "MSN Chat");
+ "MSN Chat"));
More information about the Commits
mailing list