comparison libpurple/protocols/msn/state.c @ 24510:e344426d7c28

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.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 24 Nov 2008 05:51:18 +0000
parents 187b0e2ff49d
children 7a5f6ddd11b1
comparison
equal deleted inserted replaced
24509:1ee0ded8926b 24510:e344426d7c28
98 purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia); 98 purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia);
99 99
100 cmedia_array = g_strsplit(cmedia, "\\0", 0); 100 cmedia_array = g_strsplit(cmedia, "\\0", 0);
101 101
102 /* 102 /*
103 * 0: Media Player 103 * 0: Application
104 * 1: 'Music' 104 * 1: 'Music'/'Games'/'Office'
105 * 2: '1' if enabled, '0' if not 105 * 2: '1' if enabled, '0' if not
106 * 3: Format (eg. {0} by {1}) 106 * 3: Format (eg. {0} by {1})
107 * 4: Title 107 * 4: Title
108 * 5: Artist 108 * If 'Music':
109 * 6: Album 109 * 5: Artist
110 * 7: ? 110 * 6: Album
111 * 7: ?
111 */ 112 */
112 #if GLIB_CHECK_VERSION(2,6,0) 113 #if GLIB_CHECK_VERSION(2,6,0)
113 strings = g_strv_length(cmedia_array); 114 strings = g_strv_length(cmedia_array);
114 #else 115 #else
115 while (cmedia_array[++strings] != NULL); 116 while (cmedia_array[++strings] != NULL);
116 #endif 117 #endif
117 118
118 if (strings >= 4 && !strcmp(cmedia_array[2], "1")) { 119 if (strings >= 4 && !strcmp(cmedia_array[2], "1")) {
119 parsed = TRUE; 120 parsed = TRUE;
120 121
122 if (!strcmp(cmedia_array[1], "Music"))
123 media->type = CURRENT_MEDIA_MUSIC;
124 else if (!strcmp(cmedia_array[1], "Games"))
125 media->type = CURRENT_MEDIA_GAMES;
126 else if (!strcmp(cmedia_array[1], "Office"))
127 media->type = CURRENT_MEDIA_OFFICE;
128 else
129 media->type = CURRENT_MEDIA_UNKNOWN;
130
121 g_free(media->title); 131 g_free(media->title);
122 if (strings == 4) { 132 if (strings == 4) {
123 media->title = g_strdup(cmedia_array[3]); 133 media->title = g_strdup(cmedia_array[3]);
124 } else { 134 } else {
125 media->title = g_strdup(cmedia_array[4]); 135 media->title = g_strdup(cmedia_array[4]);
197 } 207 }
198 208
199 static char * 209 static char *
200 create_media_string(PurplePresence *presence) 210 create_media_string(PurplePresence *presence)
201 { 211 {
202 const char *artist, *title, *album; 212 const char *artist, *title, *album, *game, *office;
203 char *ret; 213 char *ret;
204 PurpleStatus *status = purple_presence_get_status(presence, "tune"); 214 PurpleStatus *status = purple_presence_get_status(presence, "tune");
205 if (!status || !purple_status_is_active(status)) 215 if (!status || !purple_status_is_active(status))
206 return g_strdup_printf("WMP\\0Music\\00\\0{0} - {1}\\0\\0\\0\\0\\0"); 216 return g_strdup_printf("\\0Music\\00\\0\\0");
207 217
218 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
208 artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST); 219 artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
209 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
210 album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM); 220 album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM);
211 221 game = purple_status_get_attr_string(status, "game");
212 ret = g_strdup_printf("WMP\\0Music\\0%c\\0{0} - {1}\\0%s\\0%s\\0%s\\0\\0", 222 office = purple_status_get_attr_string(status, "office");
213 (title && *title) ? '1' : '0', 223
214 title ? title : "", 224 if (title && *title)
215 artist ? artist : "", 225 ret = g_strdup_printf("WMP\\0Music\\01\\0{0}%s%s\\0%s\\0%s\\0%s\\0",
216 album ? album : ""); 226 artist ? " - {1}" : "",
227 album ? " ({2})" : "",
228 title,
229 artist ? artist : "",
230 album ? album : "");
231 else if (game && *game)
232 ret = g_strdup_printf("\\0Games\\01\\0Playing {0}\\0%s\\0", game);
233 else if (office && *office)
234 ret = g_strdup_printf("\\0Office\\01\\0Editing {0}\\0%s\\0", office);
235 else
236 ret = g_strdup_printf("\\0Music\\00\\0\\0");
237
217 return ret; 238 return ret;
218 } 239 }
219 240
220 /* set the MSN's PSM info,Currently Read from the status Line 241 /* set the MSN's PSM info,Currently Read from the status Line
221 * Thanks for Cris Code 242 * Thanks for Cris Code