Mercurial > pidgin
changeset 19470:fb69c4dd757e
merge of '1e84e66f6954510525d3db02bb2899bca1caacdb'
and 'd47f20dcdb0fc5877e4e74981796382067cbd2a6'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 27 Aug 2007 17:17:04 +0000 |
parents | 11c727b19201 (diff) 42ee8f13c917 (current diff) |
children | 217c4b1d3a09 |
files | |
diffstat | 11 files changed, 200 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/msn/msn.c Mon Aug 27 17:17:04 2007 +0000 @@ -100,25 +100,62 @@ return buf; } -static PurpleCmdRet -msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) +static gboolean +msn_send_attention(PurpleConnection *gc, const char *username, guint type) { - PurpleAccount *account = purple_conversation_get_account(conv); - PurpleConnection *gc = purple_account_get_connection(account); MsnMessage *msg; MsnSession *session; MsnSwitchBoard *swboard; msg = msn_message_new_nudge(); session = gc->proto_data; - swboard = msn_session_get_swboard(session, purple_conversation_get_name(conv), MSN_SB_FLAG_IM); + swboard = msn_session_get_swboard(session, username, MSN_SB_FLAG_IM); if (swboard == NULL) - return PURPLE_CMD_RET_FAILED; + return FALSE; msn_switchboard_send_msg(swboard, msg, TRUE); + return TRUE; +} + +#ifdef MSN_USE_ATTENTION_API +static GList * +msn_attention_types(PurpleAccount *account) +{ + PurpleAttentionType *attn; + static GList *list = NULL; + + if (!list) { + attn = g_new0(PurpleAttentionType, 1); + attn->name = _("nudge"); + attn->incoming_description = _("nudged"); + attn->outgoing_description = _("Nudging"); + list = g_list_append(list, attn); + } + + return list; +} +#endif + + +static PurpleCmdRet +msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) +{ + PurpleAccount *account = purple_conversation_get_account(conv); + PurpleConnection *gc = purple_account_get_connection(account); + const gchar *username; + + username = purple_conversation_get_name(conv); + +#ifdef MSN_USE_ATTENTION_API + serv_send_attention(gc, username, MSN_NUDGE); +#else + if (!msn_send_attention(gc, username, MSN_NUDGE)) + return PURPLE_CMD_RET_FAILED; + purple_conversation_write(conv, NULL, _("You have just sent a Nudge!"), PURPLE_MESSAGE_SYSTEM, time(NULL)); +#endif return PURPLE_CMD_RET_OK; } @@ -2102,9 +2139,14 @@ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ +#ifdef MSN_USE_ATTENTION_API + msn_send_attention, /* send_attention */ + msn_attention_types, /* attention_types */ +#else /* padding */ NULL, NULL, +#endif NULL, NULL };
--- a/libpurple/protocols/msn/msn.h Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/msn/msn.h Mon Aug 27 17:17:04 2007 +0000 @@ -79,6 +79,10 @@ "Client-Name: Purple/" VERSION "\r\n" \ "Chat-Logging: Y\r\n" +/* Index into attention_types */ +#define MSN_NUDGE 0 + +#define MSN_USE_ATTENTION_API typedef enum {
--- a/libpurple/protocols/msn/switchboard.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/msn/switchboard.c Mon Aug 27 17:17:04 2007 +0000 @@ -951,6 +951,8 @@ PurpleBuddy *buddy; const char *user; + str = NULL; + swboard = cmdproc->data; account = cmdproc->session->account; user = msg->remote_user; @@ -960,9 +962,13 @@ else username = g_markup_escape_text(user, -1); +#ifdef MSN_USE_ATTENTION_API + serv_got_attention(account->gc, buddy->name, MSN_NUDGE); +#else str = g_strdup_printf(_("%s just sent you a Nudge!"), username); + msn_switchboard_report_user(swboard, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, str); +#endif g_free(username); - msn_switchboard_report_user(swboard, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, str); g_free(str); }
--- a/libpurple/protocols/myspace/markup.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/myspace/markup.c Mon Aug 27 17:17:04 2007 +0000 @@ -645,7 +645,7 @@ purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n", symbol ? symbol : "(NULL)", replacement ? replacement : "(NULL)"); - new = str_replace(old, symbol, replacement); + new = purple_strreplace(old, symbol, replacement); g_free(replacement); g_free(old);
--- a/libpurple/protocols/myspace/myspace.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Mon Aug 27 17:17:04 2007 +0000 @@ -92,6 +92,8 @@ static void msim_connect_cb(gpointer data, gint source, const gchar *error_message); static void msim_import_friends(PurplePluginAction *action); +static void msim_import_friends_cb(MsimSession *session, MsimMessage *reply, gpointer user_data); +static gboolean msim_get_contact_list(MsimSession *session, int what_to_do_after); static gboolean msim_uri_handler(const gchar *proto, const gchar *cmd, GHashTable *params); static void msim_uri_handler_addContact_cb(MsimSession *session, MsimMessage *userinfo, gpointer data); @@ -176,32 +178,6 @@ return "myspace"; } -/** - * Replace 'old' with 'new' in 'str'. - * - * @param str The original string. - * @param old The substring of 'str' to replace. - * @param new The replacement for 'old' within 'str'. - * - * @return A _new_ string, based on 'str', with 'old' replaced - * by 'new'. Must be g_free()'d by caller. - * - * This string replace method is based on - * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html - * - */ -gchar * -str_replace(const gchar *str, const gchar *old, const gchar *new) -{ - gchar **items; - gchar *ret; - - items = g_strsplit(str, old, -1); - ret = g_strjoinv(new, items); - g_free(items); - return ret; -} - #ifdef MSIM_DEBUG_MSG static void print_hash_item(gpointer key, gpointer value, gpointer user_data) @@ -1528,12 +1504,14 @@ (GSourceFunc)msim_check_alive, session); #endif + /* Check mail if they want to. */ if (purple_account_get_check_mail(session->account)) { purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK, (GSourceFunc)msim_check_inbox, session); msim_check_inbox(session); } + msim_get_contact_list(session, MSIM_CONTACT_LIST_INITIAL_FRIENDS); return TRUE; } @@ -1951,7 +1929,7 @@ fmt_string = msim_msg_pack_element_data(elem); uid_str = g_strdup_printf("%d", uid); - new_str = str_replace(fmt_string, "<uid>", uid_str); + new_str = purple_strreplace(fmt_string, "<uid>", uid_str); g_free(uid_str); g_free(fmt_string); @@ -2633,15 +2611,43 @@ } } - msg = g_strdup_printf(_("%d buddies were added or updated"), buddy_count); - - purple_notify_info(session->account, _("Add contacts from server"), msg, NULL); - - g_free(msg); + switch (GPOINTER_TO_UINT(user_data)) { + case MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS: + msg = g_strdup_printf(_("%d buddies were added or updated"), buddy_count); + purple_notify_info(session->account, _("Add contacts from server"), msg, NULL); + g_free(msg); + break; + + case MSIM_CONTACT_LIST_IMPORT_TOP_FRIENDS: + /* TODO */ + break; + + case MSIM_CONTACT_LIST_INITIAL_FRIENDS: + /* Nothing */ + break; + } msim_msg_free(body); } +/* Get contact list, calling msim_got_contact_list() with what_to_do_after as user_data gpointer. */ +static gboolean +msim_get_contact_list(MsimSession *session, int what_to_do_after) +{ + return msim_send(session, + "persist", MSIM_TYPE_INTEGER, 1, + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET, + "dsn", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_DSN, + "lid", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_LID, + "uid", MSIM_TYPE_INTEGER, session->userid, + "rid", MSIM_TYPE_INTEGER, + msim_new_reply_callback(session, msim_got_contact_list, GUINT_TO_POINTER(what_to_do_after)), + "body", MSIM_TYPE_STRING, g_strdup(""), + NULL); +} + + /** Called when friends have been imported to buddy list on server. */ static void msim_import_friends_cb(MsimSession *session, MsimMessage *reply, gpointer user_data) @@ -2670,17 +2676,7 @@ purple_debug_info("msim_import_friends_cb", "added friends to server-side buddy list, requesting new contacts from server"); - g_return_if_fail(msim_send(session, - "persist", MSIM_TYPE_INTEGER, 1, - "sesskey", MSIM_TYPE_INTEGER, session->sesskey, - "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET, - "dsn", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_DSN, - "lid", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_LID, - "uid", MSIM_TYPE_INTEGER, session->userid, - "rid", MSIM_TYPE_INTEGER, - msim_new_reply_callback(session, msim_got_contact_list, NULL), - "body", MSIM_TYPE_STRING, g_strdup(""), - NULL)); + msim_get_contact_list(session, MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS); /* TODO: show, X friends have been added */ }
--- a/libpurple/protocols/myspace/myspace.h Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.h Mon Aug 27 17:17:04 2007 +0000 @@ -164,13 +164,18 @@ #define MSIM_STATUS_CODE_AWAY 5 -/* Inbox status bitfield values for MsimSession.inbox_status */ +/* Inbox status bitfield values for MsimSession.inbox_status. */ #define MSIM_INBOX_MAIL (1 << 0) #define MSIM_INBOX_BLOG_COMMENT (1 << 1) #define MSIM_INBOX_PROFILE_COMMENT (1 << 2) #define MSIM_INBOX_FRIEND_REQUEST (1 << 3) #define MSIM_INBOX_PICTURE_COMMENT (1 << 4) +/* Codes for msim_got_contact_list(), to tell what to do afterwards. */ +#define MSIM_CONTACT_LIST_INITIAL_FRIENDS 0 +#define MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS 1 +#define MSIM_CONTACT_LIST_IMPORT_TOP_FRIENDS 2 + #ifdef MSIM_USE_ATTENTION_API #define MsimAttentionType PurpleAttentionType #else @@ -188,8 +193,6 @@ }; #endif -gchar *str_replace(const gchar *str, const gchar *old, const gchar *new); - /* Functions */ gboolean msim_load(PurplePlugin *plugin); GList *msim_status_types(PurpleAccount *acct);
--- a/libpurple/protocols/myspace/zap.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/myspace/zap.c Mon Aug 27 17:17:04 2007 +0000 @@ -81,9 +81,7 @@ return FALSE; } - /* TODO: make use of the MsimAttentionType we found, instead of - * doing it all over in msim_send_zap_from_menu. */ - msim_send_zap_from_menu(&buddy->node, GUINT_TO_POINTER(code)); + msim_send_zap(session, username, code); return TRUE; } @@ -105,7 +103,7 @@ #ifdef MSIM_USE_ATTENTION_API - serv_send_attention(session->gc, username, code); + /* serv_send_attention(session->gc, username, code); */ #else types = msim_attention_types(session->account); @@ -167,7 +165,11 @@ zap = GPOINTER_TO_INT(zap_num_ptr); +#ifdef MSIM_USE_ATTENTION_API + serv_send_attention(session->gc, buddy->name, zap); +#else g_return_if_fail(msim_send_zap(session, buddy->name, zap)); +#endif } /** Return menu, if any, for a buddy list node. */
--- a/libpurple/protocols/yahoo/yahoo.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/yahoo/yahoo.c Mon Aug 27 17:17:04 2007 +0000 @@ -899,6 +899,8 @@ PurpleConversation *c; char *username, *str; + str = NULL; + account = purple_connection_get_account(gc); c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from); @@ -907,10 +909,13 @@ else username = g_markup_escape_text(im->from, -1); +#ifdef YAHOO_USE_ATTENTION_API + serv_got_attention(gc, username, YAHOO_BUZZ); +#else str = g_strdup_printf(_("%s just sent you a Buzz!"), username); purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, im->time); - +#endif g_free(username); g_free(str); g_free(m); @@ -4012,17 +4017,24 @@ static PurpleCmdRet yahoopurple_cmd_buzz(PurpleConversation *c, const gchar *cmd, gchar **args, gchar **error, void *data) { - PurpleAccount *account = purple_conversation_get_account(c); +#ifndef YAHOO_USE_ATTENTION_API const char *username = purple_account_get_username(account); +#endif if (*args && args[0]) return PURPLE_CMD_RET_FAILED; +#ifdef YAHOO_USE_ATTENTION_API + serv_send_attention(account->gc, c->name, YAHOO_BUZZ); +#else + purple_debug(PURPLE_DEBUG_INFO, "yahoo", "Sending <ding> on account %s to buddy %s.\n", username, c->name); purple_conv_im_send(PURPLE_CONV_IM(c), "<ding>"); purple_conversation_write(c, NULL, _("You have just sent a Buzz!"), PURPLE_MESSAGE_SYSTEM, time(NULL)); +#endif + return PURPLE_CMD_RET_OK; } @@ -4072,6 +4084,42 @@ { return TRUE; } + +gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type) +{ + PurpleConversation *c; + + c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, + username, gc->account); + + g_return_val_if_fail(c != NULL, FALSE); + + purple_debug(PURPLE_DEBUG_INFO, "yahoo", + "Sending <ding> on account %s to buddy %s.\n", username, c->name); + /* TODO: find out how to send a <ding> without showing up as a blank line on + * the conversation window. */ + purple_conv_im_send(PURPLE_CONV_IM(c), "<ding>"); + + return TRUE; +} + +GList *yahoo_attention_types(PurpleAccount *account) +{ + PurpleAttentionType *attn; + static GList *list = NULL; + + if (!list) { + /* Yahoo only supports one attention command: the 'buzz'. */ + /* This is index number YAHOO_BUZZ. */ + attn = g_new0(PurpleAttentionType, 1); + attn->name = _("buzz"); + attn->incoming_description = _("buzzed"); + attn->outgoing_description = _("Buzzing"); + list = g_list_append(list, attn); + } + + return list; +} /************************** Plugin Initialization ****************************/ static void @@ -4281,9 +4329,15 @@ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ - /* padding */ +#ifdef YAHOO_USE_ATTENTION_API + yahoo_send_attention, + yahoo_attention_types, +#else NULL, NULL, +#endif + + /* padding */ NULL, NULL };
--- a/libpurple/protocols/yahoo/yahoo.h Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/protocols/yahoo/yahoo.h Mon Aug 27 17:17:04 2007 +0000 @@ -67,6 +67,13 @@ #define YAHOO_STATUS_TYPE_INVISIBLE "invisible" #define YAHOO_STATUS_TYPE_MOBILE "mobile" +#define YAHOO_USE_ATTENTION_API + +#ifdef YAHOO_USE_ATTENTION_API +/* Index into attention types list. */ +#define YAHOO_BUZZ 0 +#endif + enum yahoo_status { YAHOO_STATUS_AVAILABLE = 0, YAHOO_STATUS_BRB, @@ -213,4 +220,7 @@ gboolean yahoo_privacy_check (PurpleConnection *gc, const char *who); +gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type); +GList *yahoo_attention_types(PurpleAccount *account); + #endif /* _YAHOO_H_ */
--- a/libpurple/prpl.h Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/prpl.h Mon Aug 27 17:17:04 2007 +0000 @@ -348,9 +348,9 @@ char *(*roomlist_room_serialize)(PurpleRoomlistRoom *room); /* Attention API for sending & receiving zaps/nudges/buzzes etc. */ - gboolean (*send_attention)(PurpleConnection *gc, - const char *username, guint type); + gboolean (*send_attention)(PurpleConnection *gc, const char *username, guint type); GList *(*attention_types)(PurpleAccount *acct); + void (*_purple_reserved3)(void); void (*_purple_reserved4)(void); };
--- a/libpurple/server.c Mon Aug 27 17:16:11 2007 +0000 +++ b/libpurple/server.c Mon Aug 27 17:17:04 2007 +0000 @@ -246,18 +246,18 @@ { PurplePlugin *prpl; PurpleAttentionType* attn; - GList *(*function)(PurpleAccount *); + GList *(*get_attention_types)(PurpleAccount *); g_return_val_if_fail(account != NULL, NULL); prpl = purple_find_prpl(purple_account_get_protocol_id(account)); /* Lookup the attention type in the protocol's attention_types list, if any. */ - function = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->attention_types; - if (function) { + get_attention_types = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->attention_types; + if (get_attention_types) { GList *attention_types; - attention_types = function(account); + attention_types = get_attention_types(account); attn = (PurpleAttentionType *)g_list_nth_data(attention_types, type_code); } else { attn = NULL; @@ -271,12 +271,19 @@ { PurpleAttentionType *attn; PurpleMessageFlags flags; + PurplePlugin *prpl; + gboolean (*send_attention)(PurpleConnection *, const char *, guint); + gchar *description; time_t mtime; g_return_if_fail(gc != NULL); g_return_if_fail(who != NULL); + prpl = purple_find_prpl(purple_account_get_protocol_id(gc->account)); + send_attention = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention; + g_return_if_fail(send_attention != NULL); + mtime = time(NULL); attn = purple_get_attention_type_from_code(gc->account, type_code); @@ -289,8 +296,13 @@ flags = PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_SYSTEM; + purple_debug_info("server", "serv_send_attention: sending '%s' to %s\n", + description, who); + + if (!send_attention(gc, who, type_code)) + return; + /* TODO: icons, sound, shaking... same as serv_got_attention(). */ - serv_got_im(gc, who, description, flags, mtime); g_free(description); @@ -320,6 +332,9 @@ description = g_strdup(_("Attention!")); } + purple_debug_info("server", "serv_got_attention: got '%s' from %s\n", + description, who); + serv_got_im(gc, who, description, flags, mtime); /* TODO: sounds (depending on PurpleAttentionType), shaking, etc. */