Mercurial > pidgin.yaz
diff libpurple/protocols/msn/state.c @ 20570:5913725cbcd6
Use an independant status type for 'current media' stuff, instead of using
status attributes. This includes changes in both xmpp and msn.
Also, in MSN, CurrentMedia is sent with PSM if you turn on the status and
set the attributes on the account.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 20 Sep 2007 16:30:17 +0000 |
parents | 5bef3197383a |
children | 1933f2084eb3 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/state.c Thu Sep 20 06:29:21 2007 +0000 +++ b/libpurple/protocols/msn/state.c Thu Sep 20 16:30:17 2007 +0000 @@ -83,16 +83,15 @@ } /* parse CurrentMedia string */ -char * -msn_parse_currentmedia(const char *cmedia) +gboolean +msn_parse_currentmedia(const char *cmedia, CurrentMedia *media) { char **cmedia_array; - GString *buffer = NULL; int strings; if ((cmedia == NULL) || (*cmedia == '\0')) { purple_debug_info("msn", "No currentmedia string\n"); - return NULL; + return FALSE; } purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia); @@ -104,6 +103,30 @@ * the cmedia string starting with \0 -- see the examples below. */ while (cmedia_array[++strings] != NULL); + if (strings < 4) + return FALSE; + if (strcmp(cmedia_array[2], "1")) + return FALSE; + + if (strings == 4) { + media->title = g_strdup(cmedia_array[3]); + } else { + media->title = g_strdup(cmedia_array[4]); + } + + if (strings > 5) + media->artist = g_strdup(cmedia_array[5]); + else + media->artist = NULL; + + if (strings > 6) + media->album = g_strdup(cmedia_array[6]); + else + media->album = NULL; + + return TRUE; + +#if 0 /* The cmedia_array[2] field contains a 1 if enabled. */ if ((strings > 3) && (!strcmp(cmedia_array[2], "1"))) { char *inptr = cmedia_array[3]; @@ -137,6 +160,7 @@ g_strfreev(cmedia_array); return buffer ? g_string_free(buffer, FALSE) : NULL; +#endif } /* get the CurrentMedia info from the XML string */ @@ -191,6 +215,27 @@ return psm; } +static char * +create_media_string(PurplePresence *presence) +{ + const char *artist, *title, *album; + char *ret; + PurpleStatus *status = purple_presence_get_status(presence, "tune"); + if (!status || !purple_status_is_active(status)) + return g_strdup_printf("WMP\\0Music\\00\\0{0} - {1}\\0\\0\\0\\0\\0"); + + artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST); + title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE); + album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM); + + ret = g_strdup_printf("WMP\\0Music\\0%c\\0{0} - {1}\\0%s\\0%s\\0%s\\0\\0", + (title && *title) ? '1' : '0', + title ? title : "", + artist ? artist : "", + album ? album : ""); + return ret; +} + /* set the MSN's PSM info,Currently Read from the status Line * Thanks for Cris Code */ @@ -204,7 +249,7 @@ MsnTransaction *trans; char *payload; const char *statusline; - gchar *unescapedstatusline; + gchar *unescapedstatusline, *media = NULL; g_return_if_fail(session != NULL); g_return_if_fail(session->notification != NULL); @@ -219,8 +264,10 @@ status = purple_presence_get_active_status(presence); statusline = purple_status_get_attr_string(status, "message"); unescapedstatusline = purple_unescape_html(statusline); - session->psm = msn_build_psm(unescapedstatusline, NULL, NULL); + media = create_media_string(presence); + session->psm = msn_build_psm(unescapedstatusline, media, NULL); g_free(unescapedstatusline); + g_free(media); payload = session->psm; purple_debug_misc("MSNP14","Sending UUX command with payload: %s\n",payload);