comparison libpurple/protocols/myspace/user.c @ 22264:e808d83d797e

In msimprpl, use a PURPLE_STATUS_TUNE presence type to hold the "now playing" artist and song title, instead of storing it in the MsimUser struct. So now Pidgin shows music notes by MySpaceIM users that have music playing. Though you can't yet click the notes to play the music, as in the official client (that's #4766). Closes #4140.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Mon, 04 Feb 2008 04:00:12 +0000
parents 3f8b32a4786c
children 0e2207b46080
comparison
equal deleted inserted replaced
22229:ae5917260eac 22264:e808d83d797e
18 */ 18 */
19 19
20 #include "myspace.h" 20 #include "myspace.h"
21 21
22 static void msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user); 22 static void msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user);
23 static gchar *msim_format_now_playing(gchar *band, gchar *song); 23 static gchar *msim_format_now_playing(const gchar *band, const gchar *song);
24 static void msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, 24 static void msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text,
25 gsize len, const gchar *error_message); 25 gsize len, const gchar *error_message);
26 26
27 /** Format the "now playing" indicator, showing the artist and song. 27 /** Format the "now playing" indicator, showing the artist and song.
28 * @return Return a new string (must be g_free()'d), or NULL. 28 * @return Return a new string (must be g_free()'d), or NULL.
29 */ 29 */
30 static gchar * 30 static gchar *
31 msim_format_now_playing(gchar *band, gchar *song) 31 msim_format_now_playing(const gchar *band, const gchar *song)
32 { 32 {
33 if ((band && *band) || (song && *song)) { 33 if ((band && *band) || (song && *song)) {
34 return g_strdup_printf("%s - %s", 34 return g_strdup_printf("%s - %s",
35 (band && *band) ? band : "Unknown Artist", 35 (band && *band) ? band : "Unknown Artist",
36 (song && *song) ? song : "Unknown Song"); 36 (song && *song) ? song : "Unknown Song");
83 * Used by msim_tooltip_text() and msim_get_info_cb() to show a user's profile. 83 * Used by msim_tooltip_text() and msim_get_info_cb() to show a user's profile.
84 */ 84 */
85 void 85 void
86 msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full) 86 msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full)
87 { 87 {
88 PurplePresence *presence;
88 gchar *str; 89 gchar *str;
89 guint uid; 90 guint uid;
90 guint cv; 91 guint cv;
91 92
92 /* Useful to identify the account the tooltip refers to. 93 /* Useful to identify the account the tooltip refers to.
126 /* Other information */ 127 /* Other information */
127 if (user->headline && *user->headline) { 128 if (user->headline && *user->headline) {
128 purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline); 129 purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
129 } 130 }
130 131
131 str = msim_format_now_playing(user->band_name, user->song_name); 132 presence = purple_buddy_get_presence(user->buddy);
132 if (str && *str) { 133
133 purple_notify_user_info_add_pair(user_info, _("Song"), str); 134 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
134 } 135 PurpleStatus *status;
135 g_free(str); 136 const char *artist, *title;
137
138 status = purple_presence_get_status(presence, "tune");
139 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
140 artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
141
142 str = msim_format_now_playing(artist, title);
143 if (str && *str) {
144 purple_notify_user_info_add_pair(user_info, _("Song"), str);
145 }
146 g_free(str);
147 }
136 148
137 /* Note: total friends only available if looked up by uid, not username. */ 149 /* Note: total friends only available if looked up by uid, not username. */
138 if (user->total_friends) { 150 if (user->total_friends) {
139 char friends[16]; 151 char friends[16];
140 g_snprintf(friends, sizeof(friends), "%d", user->total_friends); 152 g_snprintf(friends, sizeof(friends), "%d", user->total_friends);
157 } 169 }
158 if (client && *client) 170 if (client && *client)
159 purple_notify_user_info_add_pair(user_info, _("Client Version"), client); 171 purple_notify_user_info_add_pair(user_info, _("Client Version"), client);
160 g_free(client); 172 g_free(client);
161 } 173 }
174 }
175
176 /** Set the currently playing song artist and or title.
177 *
178 * @param user User associated with the now playing information.
179 *
180 * @param new_artist New artist to set, or NULL/empty to not change artist.
181 *
182 * @param new_title New title to set, or NULL/empty to not change title.
183 *
184 * If new_artist and new_title are NULL/empty, deactivate PURPLE_STATUS_TUNE.
185 *
186 * This function is useful because it lets you set the artist or title
187 * individually, which purple_prpl_got_user_status() doesn't do.
188 */
189 static void msim_set_artist_or_title(MsimUser *user, const char *new_artist, const char *new_title)
190 {
191 PurplePresence *presence;
192 const char *prev_artist, *prev_title;
193
194 prev_artist = NULL;
195 prev_title = NULL;
196
197 if (new_artist && !strlen(new_artist))
198 new_artist = NULL;
199 if (new_title && !strlen(new_title))
200 new_title = NULL;
201
202 if (!new_artist && !new_title) {
203 purple_prpl_got_user_status_deactive(user->buddy->account, user->buddy->name, "tune");
204 return;
205 }
206
207 presence = purple_buddy_get_presence(user->buddy);
208
209 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
210 PurpleStatus *status;
211
212 status = purple_presence_get_status(presence, "tune");
213 prev_title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
214 prev_artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
215 }
216
217 if (!new_artist)
218 new_artist = prev_artist;
219
220 if (!new_title)
221 new_title = prev_title;
222
223 purple_prpl_got_user_status(user->buddy->account, user->buddy->name, "tune",
224 PURPLE_TUNE_TITLE, new_title,
225 PURPLE_TUNE_ARTIST, new_artist,
226 NULL);
162 } 227 }
163 228
164 /** Store a field of information about a buddy. 229 /** Store a field of information about a buddy.
165 * 230 *
166 * @param key_str Key to store. 231 * @param key_str Key to store.
192 user->total_friends = atol(value_str); 257 user->total_friends = atol(value_str);
193 } else if (g_str_equal(key_str, "DisplayName")) { 258 } else if (g_str_equal(key_str, "DisplayName")) {
194 g_free(user->display_name); 259 g_free(user->display_name);
195 user->display_name = value_str; 260 user->display_name = value_str;
196 } else if (g_str_equal(key_str, "BandName")) { 261 } else if (g_str_equal(key_str, "BandName")) {
197 g_free(user->band_name); 262 msim_set_artist_or_title(user, value_str, NULL);
198 user->band_name = value_str;
199 } else if (g_str_equal(key_str, "SongName")) { 263 } else if (g_str_equal(key_str, "SongName")) {
200 g_free(user->song_name); 264 msim_set_artist_or_title(user, NULL, value_str);
201 user->song_name = value_str;
202 } else if (g_str_equal(key_str, "UserName") || g_str_equal(key_str, "IMName") || g_str_equal(key_str, "NickName")) { 265 } else if (g_str_equal(key_str, "UserName") || g_str_equal(key_str, "IMName") || g_str_equal(key_str, "NickName")) {
203 /* Ignore because PurpleBuddy knows this already */ 266 /* Ignore because PurpleBuddy knows this already */
204 g_free(value_str); 267 g_free(value_str);
205 } else if (g_str_equal(key_str, "ImageURL") || g_str_equal(key_str, "AvatarURL")) { 268 } else if (g_str_equal(key_str, "ImageURL") || g_str_equal(key_str, "AvatarURL")) {
206 const gchar *previous_url; 269 const gchar *previous_url;