Mercurial > pidgin
changeset 17944:c109b7f1c739
Allow setting status string messages. Known bug: custom status messages always
make you go away, instead of to what status primitive you set it to be.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Thu, 12 Jul 2007 03:21:07 +0000 |
parents | 12606e503d70 |
children | cf55077a3752 |
files | libpurple/protocols/myspace/CHANGES libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h |
diffstat | 4 files changed, 64 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/CHANGES Wed Jul 11 05:23:19 2007 +0000 +++ b/libpurple/protocols/myspace/CHANGES Thu Jul 12 03:21:07 2007 +0000 @@ -1,6 +1,7 @@ 2007-07-xx Jeff Connelly <jeff2@soc.pidgin.im> - 0.12 * Allow logging in with passwords containing uppercase letters (bug #2066) * Add /3 -> | translation to escaping. +* Allow setting status string. 2007-07-09 Jeff Connelly <jeff2@soc.pidgin.im> - 0.11 * Allow going idle (tested with I'dle Ma'ker) and viewing idle status of
--- a/libpurple/protocols/myspace/message.c Wed Jul 11 05:23:19 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Thu Jul 12 03:21:07 2007 +0000 @@ -249,6 +249,7 @@ gboolean success; raw = msim_msg_pack(msg); + g_return_val_if_fail(raw != NULL, FALSE); success = msim_send_raw(session, raw); g_free(raw); @@ -478,6 +479,8 @@ "\n", "<MsimMessage: \n", "\n/MsimMessage>"); } + g_return_if_fail(debug_str != NULL); + purple_debug_info("msim", fmt_string, debug_str); g_free(debug_str);
--- a/libpurple/protocols/myspace/myspace.c Wed Jul 11 05:23:19 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Thu Jul 12 03:21:07 2007 +0000 @@ -72,17 +72,31 @@ types = NULL; - status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, NULL, NULL, FALSE, TRUE, FALSE); - types = g_list_append(types, status); - - status = purple_status_type_new_full(PURPLE_STATUS_AWAY, NULL, NULL, FALSE, TRUE, FALSE); - types = g_list_append(types, status); - - status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE); - types = g_list_append(types, status); - - status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, NULL, NULL, FALSE, TRUE, FALSE); - types = g_list_append(types, status); + /* Statuses are almost all the same. Define a macro to reduce code repetition. */ +#define _MSIM_ADD_NEW_STATUS(prim) status = \ + purple_status_type_new_with_attrs( \ + prim, /* PurpleStatusPrimitive */ \ + NULL, /* id - use default */ \ + NULL, /* name - use default */ \ + TRUE, /* savable */ \ + TRUE, /* user_settable */ \ + FALSE, /* not independent */ \ + \ + /* Attributes - each status can have a message. */ \ + "message", \ + _("Message"), \ + purple_value_new(PURPLE_TYPE_STRING), \ + NULL); \ + \ + \ + types = g_list_append(types, status) + + + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE); + return types; } @@ -205,10 +219,10 @@ gboolean msim_send_raw(MsimSession *session, const gchar *msg) { - purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); g_return_val_if_fail(msg != NULL, FALSE); + + purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); return msim_send_really_raw(session->gc, msg, strlen(msg)) == strlen(msg); @@ -1322,13 +1336,15 @@ g_free(user_to_lookup); } -/** Set your status - callback for when user manually sets it. */ +/** Set your status - callback for when user manually sets it. + * TODO: find out why when setting status with a message, it ALWAYS goes to away! */ void msim_set_status(PurpleAccount *account, PurpleStatus *status) { PurpleStatusType *type; MsimSession *session; guint status_code; + const gchar *statstring; session = (MsimSession *)account->gc->proto_data; @@ -1339,14 +1355,20 @@ switch (purple_status_type_get_primitive(type)) { case PURPLE_STATUS_AVAILABLE: + purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE, + MSIM_STATUS_CODE_ONLINE); status_code = MSIM_STATUS_CODE_ONLINE; break; case PURPLE_STATUS_INVISIBLE: + purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE, + MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN); status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN; break; case PURPLE_STATUS_AWAY: + purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY, + MSIM_STATUS_CODE_AWAY); status_code = MSIM_STATUS_CODE_AWAY; break; @@ -1357,8 +1379,12 @@ break; } - - msim_set_status_code(session, status_code); + statstring = purple_status_get_attr_string(status, "message"); + + if (!statstring) + statstring = g_strdup(""); + + msim_set_status_code(session, status_code, g_strdup(statstring)); } /** Go idle. */ @@ -1379,23 +1405,30 @@ * from the other states (you can only be away or idle, but not * both, for example), so by going non-idle I go online. */ - msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE); + /* TODO: find out how to keep old status string? */ + msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup("")); } else { /* msim doesn't support idle time, so just go idle */ - msim_set_status_code(session, MSIM_STATUS_CODE_IDLE); + msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup("")); } } -/** Set status using an MSIM_STATUS_CODE_* value. (TODO: also set message) */ +/** Set status using an MSIM_STATUS_CODE_* value. + * @param status_code An MSIM_STATUS_CODE_* value. + * @param statstring Status string, must be a dynamic string (will be freed by msim_send). + */ void -msim_set_status_code(MsimSession *session, guint status_code) +msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring) { g_return_if_fail(MSIM_SESSION_VALID(session)); + purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n", + status_code, statstring); + if (!msim_send(session, "status", MSIM_TYPE_INTEGER, status_code, "sesskey", MSIM_TYPE_INTEGER, session->sesskey, - "statstring", MSIM_TYPE_STRING, g_strdup(""), + "statstring", MSIM_TYPE_STRING, statstring, "locstring", MSIM_TYPE_STRING, g_strdup(""), NULL)) { @@ -1660,10 +1693,13 @@ session->username = msim_msg_get_string(msg, "uniquenick"); #ifdef MSIM_FAKE_SELF_ONLINE - /* Fake our self coming online. */ - purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); + purple_debug_info("msim", "msim_we_are_logged_on: faking self as coming online\n"); + /* Fake our self coming online. TODO: do we need this anymore?! */ + purple_prpl_got_user_status(session->account, session->username, + purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); #endif + purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n"); /* Notify servers of our current status. */ msim_set_status(session->account, purple_account_get_active_status(session->account));
--- a/libpurple/protocols/myspace/myspace.h Wed Jul 11 05:23:19 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.h Thu Jul 12 03:21:07 2007 +0000 @@ -227,7 +227,7 @@ void msim_set_status(PurpleAccount *account, PurpleStatus *status); void msim_set_idle(PurpleConnection *gc, int time); -void msim_set_status_code(MsimSession *session, guint code); +void msim_set_status_code(MsimSession *session, guint code, gchar *statstring); void msim_store_buddy_info_each(gpointer key, gpointer value, gpointer user_data); gboolean msim_store_buddy_info(MsimSession *session, MsimMessage *msg);