# HG changeset patch # User Elliott Sales de Andrade # Date 1227505878 0 # Node ID e344426d7c28eb65c4abde448b8615f85c900422 # Parent 1ee0ded8926b176ed90f5119f02f602fc9185f88 Add the Games and Office media to MSN as attributes tacked on to the tune status, as suggested by rlaager. Should probably generalize "tune" into "media" for 3.0. Also, updates the status text to include the album, if it's available. Fixes #4872. diff -r 1ee0ded8926b -r e344426d7c28 ChangeLog --- a/ChangeLog Mon Nov 24 00:52:41 2008 +0000 +++ b/ChangeLog Mon Nov 24 05:51:18 2008 +0000 @@ -15,6 +15,9 @@ * The Buddy State Notification plugin no longer turns JID's, MSN Passport ID's, etc. into links (Florian Quèze) * Fix a crash in SIMPLE when a malformed message is received. + * On MSN, the Games and Office media can now be set and displayed (in + addition to the previous Music media). The Media status text now shows + the album, if possible. Pidgin: * On GTK+ 2.14 and higher, we're using the gtk-tooltip-delay setting diff -r 1ee0ded8926b -r e344426d7c28 libpurple/protocols/msn/msn.c --- a/libpurple/protocols/msn/msn.c Mon Nov 24 00:52:41 2008 +0000 +++ b/libpurple/protocols/msn/msn.c Mon Nov 24 05:51:18 2008 +0000 @@ -647,25 +647,41 @@ presence = purple_buddy_get_presence(buddy); status = purple_presence_get_active_status(presence); - /* I think status message should take precedence over media */ - msg = purple_status_get_attr_string(status, "message"); - if (msg && *msg) - return g_markup_escape_text(msg, -1); - if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { - const char *title, *artist; + const char *title, *game, *office; char *media, *esc; status = purple_presence_get_status(presence, "tune"); title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE); - artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST); - - media = g_strdup_printf("%s%s%s", title, artist ? " - " : "", - artist ? artist : ""); + + game = purple_status_get_attr_string(status, "game"); + office = purple_status_get_attr_string(status, "office"); + + if (title && *title) { + const char *artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST); + const char *album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM); + media = g_strdup_printf("%s%s%s%s%s%s", title, + (artist && *artist) ? " - " : "", + (artist && *artist) ? artist : "", + (album && *album) ? " (" : "", + (album && *album) ? album : "", + (album && *album) ? ")" : ""); + } + else if (game && *game) + media = g_strdup_printf("Playing %s", game); + else if (office && *office) + media = g_strdup_printf("Editing %s", office); + else + return NULL; esc = g_markup_escape_text(media, -1); g_free(media); return esc; } + /* Official client says media takes precedence over message */ + msg = purple_status_get_attr_string(status, "message"); + if (msg && *msg) + return g_markup_escape_text(msg, -1); + return NULL; } @@ -681,6 +697,7 @@ if (purple_presence_is_online(presence)) { const char *psm, *name; + const char *mediatype = NULL; char *currentmedia = NULL; char *tmp; @@ -690,8 +707,18 @@ const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE); const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST); const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM); - currentmedia = purple_util_format_song_info(title, artist, album, NULL); - /* We could probably just use user->media.title etc. here */ + const char *game = purple_status_get_attr_string(tune, "game"); + const char *office = purple_status_get_attr_string(tune, "office"); + if (title && *title) { + mediatype = _("Now Listening"); + currentmedia = purple_util_format_song_info(title, artist, album, NULL); + } else if (game && *game) { + mediatype = _("Playing a game"); + currentmedia = g_strdup(game); + } else if (office && *office) { + mediatype = _("Working"); + currentmedia = g_strdup(office); + } } if (!purple_status_is_available(status)) { @@ -745,7 +772,7 @@ } if (currentmedia) { - purple_notify_user_info_add_pair(user_info, _("Now Listening"), currentmedia); + purple_notify_user_info_add_pair(user_info, mediatype, currentmedia); g_free(currentmedia); } } @@ -840,6 +867,8 @@ PURPLE_TUNE_ARTIST, _("Artist"), purple_value_new(PURPLE_TYPE_STRING), PURPLE_TUNE_ALBUM, _("Album"), purple_value_new(PURPLE_TYPE_STRING), PURPLE_TUNE_TITLE, _("Title"), purple_value_new(PURPLE_TYPE_STRING), + "game", _("Game Title"), purple_value_new(PURPLE_TYPE_STRING), + "office", _("Office Title"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, status); diff -r 1ee0ded8926b -r e344426d7c28 libpurple/protocols/msn/notification.c --- a/libpurple/protocols/msn/notification.c Mon Nov 24 00:52:41 2008 +0000 +++ b/libpurple/protocols/msn/notification.c Mon Nov 24 05:51:18 2008 +0000 @@ -1578,7 +1578,7 @@ MsnUser *user; const char *passport; char *psm_str, *str; - CurrentMedia media = {NULL, NULL, NULL}; + CurrentMedia media = {CURRENT_MEDIA_UNKNOWN, NULL, NULL, NULL}; session = cmdproc->session; account = session->account; diff -r 1ee0ded8926b -r e344426d7c28 libpurple/protocols/msn/state.c --- a/libpurple/protocols/msn/state.c Mon Nov 24 00:52:41 2008 +0000 +++ b/libpurple/protocols/msn/state.c Mon Nov 24 05:51:18 2008 +0000 @@ -100,14 +100,15 @@ cmedia_array = g_strsplit(cmedia, "\\0", 0); /* - * 0: Media Player - * 1: 'Music' + * 0: Application + * 1: 'Music'/'Games'/'Office' * 2: '1' if enabled, '0' if not * 3: Format (eg. {0} by {1}) * 4: Title - * 5: Artist - * 6: Album - * 7: ? + * If 'Music': + * 5: Artist + * 6: Album + * 7: ? */ #if GLIB_CHECK_VERSION(2,6,0) strings = g_strv_length(cmedia_array); @@ -118,6 +119,15 @@ if (strings >= 4 && !strcmp(cmedia_array[2], "1")) { parsed = TRUE; + if (!strcmp(cmedia_array[1], "Music")) + media->type = CURRENT_MEDIA_MUSIC; + else if (!strcmp(cmedia_array[1], "Games")) + media->type = CURRENT_MEDIA_GAMES; + else if (!strcmp(cmedia_array[1], "Office")) + media->type = CURRENT_MEDIA_OFFICE; + else + media->type = CURRENT_MEDIA_UNKNOWN; + g_free(media->title); if (strings == 4) { media->title = g_strdup(cmedia_array[3]); @@ -199,21 +209,32 @@ static char * create_media_string(PurplePresence *presence) { - const char *artist, *title, *album; + const char *artist, *title, *album, *game, *office; 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"); + return g_strdup_printf("\\0Music\\00\\0\\0"); + title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE); 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); + game = purple_status_get_attr_string(status, "game"); + office = purple_status_get_attr_string(status, "office"); - 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 : ""); + if (title && *title) + ret = g_strdup_printf("WMP\\0Music\\01\\0{0}%s%s\\0%s\\0%s\\0%s\\0", + artist ? " - {1}" : "", + album ? " ({2})" : "", + title, + artist ? artist : "", + album ? album : ""); + else if (game && *game) + ret = g_strdup_printf("\\0Games\\01\\0Playing {0}\\0%s\\0", game); + else if (office && *office) + ret = g_strdup_printf("\\0Office\\01\\0Editing {0}\\0%s\\0", office); + else + ret = g_strdup_printf("\\0Music\\00\\0\\0"); + return ret; } diff -r 1ee0ded8926b -r e344426d7c28 libpurple/protocols/msn/user.c --- a/libpurple/protocols/msn/user.c Mon Nov 24 00:52:41 2008 +0000 +++ b/libpurple/protocols/msn/user.c Mon Nov 24 05:51:18 2008 +0000 @@ -106,12 +106,25 @@ purple_prpl_got_user_status_deactive(account, user->passport, "mobile"); } - if (!offline && user->media.title) { - purple_prpl_got_user_status(account, user->passport, "tune", - PURPLE_TUNE_ARTIST, user->media.artist, - PURPLE_TUNE_ALBUM, user->media.album, - PURPLE_TUNE_TITLE, user->media.title, - NULL); + if (!offline && user->media.type != CURRENT_MEDIA_UNKNOWN) { + if (user->media.type == CURRENT_MEDIA_MUSIC) { + purple_prpl_got_user_status(account, user->passport, "tune", + PURPLE_TUNE_ARTIST, user->media.artist, + PURPLE_TUNE_ALBUM, user->media.album, + PURPLE_TUNE_TITLE, user->media.title, + NULL); + } else if (user->media.type == CURRENT_MEDIA_GAMES) { + purple_prpl_got_user_status(account, user->passport, "tune", + "game", user->media.title, + NULL); + } else if (user->media.type == CURRENT_MEDIA_OFFICE) { + purple_prpl_got_user_status(account, user->passport, "tune", + "office", user->media.title, + NULL); + } else { + purple_debug_warning("msn", "Got CurrentMedia with unknown type %d.\n", + user->media.type); + } } else { purple_prpl_got_user_status_deactive(account, user->passport, "tune"); } @@ -191,6 +204,7 @@ g_free(user->media.album); g_free(user->media.artist); + user->media.type = media ? media->type : CURRENT_MEDIA_UNKNOWN; user->media.title = media ? g_strdup(media->title) : NULL; user->media.artist = media ? g_strdup(media->artist) : NULL; user->media.album = media ? g_strdup(media->album) : NULL; diff -r 1ee0ded8926b -r e344426d7c28 libpurple/protocols/msn/user.h --- a/libpurple/protocols/msn/user.h Mon Nov 24 00:52:41 2008 +0000 +++ b/libpurple/protocols/msn/user.h Mon Nov 24 05:51:18 2008 +0000 @@ -45,11 +45,20 @@ /** * Current media. */ +typedef enum +{ + CURRENT_MEDIA_UNKNOWN, + CURRENT_MEDIA_MUSIC, + CURRENT_MEDIA_GAMES, + CURRENT_MEDIA_OFFICE +} CurrentMediaType; + typedef struct _CurrentMedia { + CurrentMediaType type; /**< Type. */ + char *title; /**< Title. */ char *artist; /**< Artist. */ char *album; /**< Album. */ - char *title; /**< Title. */ } CurrentMedia; /** diff -r 1ee0ded8926b -r e344426d7c28 pidgin/gtkblist.c --- a/pidgin/gtkblist.c Mon Nov 24 00:52:41 2008 +0000 +++ b/pidgin/gtkblist.c Mon Nov 24 05:51:18 2008 +0000 @@ -3626,6 +3626,7 @@ const char *name = NULL; char *filename, *path; PurplePresence *p; + PurpleStatus *tune; if(PURPLE_BLIST_NODE_IS_CONTACT(node)) { if(!gtknode->contact_expanded) { @@ -3664,7 +3665,21 @@ return _pidgin_blist_get_cached_emblem(path); } - if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_TUNE)) { + tune = purple_presence_get_status(p, "tune"); + if (tune && purple_status_is_active(tune)) { + /* Only in MSN. + * TODO: Replace "Tune" with generalized "Media" in 3.0. */ + if (purple_status_get_attr_string(tune, "game") != NULL) { + path = g_build_filename(DATADIR, "pixmaps", "pidgin", "emblems", "16", "game.png", NULL); + return _pidgin_blist_get_cached_emblem(path); + } + /* Only in MSN. + * TODO: Replace "Tune" with generalized "Media" in 3.0. */ + if (purple_status_get_attr_string(tune, "office") != NULL) { + path = g_build_filename(DATADIR, "pixmaps", "pidgin", "emblems", "16", "office.png", NULL); + return _pidgin_blist_get_cached_emblem(path); + } + /* Regular old "tune" is the only one in all protocols. */ path = g_build_filename(DATADIR, "pixmaps", "pidgin", "emblems", "16", "music.png", NULL); return _pidgin_blist_get_cached_emblem(path); }