im.pidgin.pidgin: b75a11995dcb2d3d2dc04522842a884fa0b5d06f

jeff2 at soc.pidgin.im jeff2 at soc.pidgin.im
Sun Feb 3 23:06:08 EST 2008


-----------------------------------------------------------------
Revision: b75a11995dcb2d3d2dc04522842a884fa0b5d06f
Ancestor: ae7f8e3acb446776f833c3b44514295ae56184b3
Author: jeff2 at soc.pidgin.im
Date: 2008-02-04T04:00:12
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b75a11995dcb2d3d2dc04522842a884fa0b5d06f

Modified files:
        libpurple/protocols/myspace/myspace.c
        libpurple/protocols/myspace/user.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	7b76a0f8faf42457a8b30390e473e8a21f2f116b
+++ libpurple/protocols/myspace/myspace.c	b335f1ad3cc7df10679b98f0e76726378cb27f4e
@@ -158,7 +158,20 @@ msim_status_types(PurpleAccount *acct)
 	_MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE);
 	_MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE);
 
+	/* Except tune status is different... */
+	status = purple_status_type_new_with_attrs(
+			PURPLE_STATUS_TUNE,	/* primitive */
+			"tune",                 /* ID */
+			NULL,                   /* name - use default */
+			TRUE,                   /* savable */
+			TRUE,                   /* should be user_settable some day */
+			TRUE,                   /* independent */
 
+			PURPLE_TUNE_ARTIST, _("Artist"), purple_value_new(PURPLE_TYPE_STRING),
+			PURPLE_TUNE_TITLE, _("Title"), purple_value_new(PURPLE_TYPE_STRING));
+
+	types = g_list_append(types, status);
+
 	return types;
 }
 
@@ -995,8 +1008,6 @@ msim_get_info_cb(MsimSession *session, M
 		g_free(user->headline);
 		g_free(user->display_name);
 		g_free(user->username);
-		g_free(user->band_name);
-		g_free(user->song_name);
 		g_free(user->image_url);
 		g_free(user);
 	}
============================================================
--- libpurple/protocols/myspace/user.c	84748406d4ca2bae5c19366f42f8a806116bf8cf
+++ libpurple/protocols/myspace/user.c	7d5b00aea51f2bcb48b16ab014186beccbc219cf
@@ -20,7 +20,7 @@ static void msim_store_user_info_each(co
 #include "myspace.h"
 
 static void msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user);
-static gchar *msim_format_now_playing(gchar *band, gchar *song);
+static gchar *msim_format_now_playing(const gchar *band, const gchar *song);
 static void msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text,
 		gsize len, const gchar *error_message);
 
@@ -28,7 +28,7 @@ static gchar *
  * @return Return a new string (must be g_free()'d), or NULL.
  */
 static gchar *
-msim_format_now_playing(gchar *band, gchar *song)
+msim_format_now_playing(const gchar *band, const gchar *song)
 {
 	if ((band && *band) || (song && *song)) {
 		return g_strdup_printf("%s - %s",
@@ -85,6 +85,7 @@ msim_append_user_info(MsimSession *sessi
 void
 msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full)
 {
+	PurplePresence *presence;
 	gchar *str;
 	guint uid;
 	guint cv;
@@ -128,11 +129,22 @@ msim_append_user_info(MsimSession *sessi
 		purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
 	}
 
-	str = msim_format_now_playing(user->band_name, user->song_name);
-	if (str && *str) {
-		purple_notify_user_info_add_pair(user_info, _("Song"), str);
+	presence = purple_buddy_get_presence(user->buddy);
+
+	if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
+		PurpleStatus *status;
+		const char *artist, *title;
+		
+		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);
+
+		str = msim_format_now_playing(artist, title);
+		if (str && *str) {
+			purple_notify_user_info_add_pair(user_info, _("Song"), str);
+		}
+		g_free(str);
 	}
-	g_free(str);
 
 	/* Note: total friends only available if looked up by uid, not username. */
 	if (user->total_friends) {
@@ -161,6 +173,59 @@ msim_append_user_info(MsimSession *sessi
 	}
 }
 
+/** Set the currently playing song artist and or title.
+ *
+ * @param user User associated with the now playing information.
+ *
+ * @param new_artist New artist to set, or NULL/empty to not change artist.
+ *
+ * @param new_title New title to set, or NULL/empty to not change title.
+ *
+ * If new_artist and new_title are NULL/empty, deactivate PURPLE_STATUS_TUNE.
+ *
+ * This function is useful because it lets you set the artist or title
+ * individually, which purple_prpl_got_user_status() doesn't do.
+ */
+static void msim_set_artist_or_title(MsimUser *user, const char *new_artist, const char *new_title)
+{
+	PurplePresence *presence;
+	const char *prev_artist, *prev_title;
+
+	prev_artist = NULL;
+	prev_title = NULL;
+
+	if (new_artist && !strlen(new_artist))
+		new_artist = NULL;
+	if (new_title && !strlen(new_title))
+		new_title = NULL;
+
+	if (!new_artist && !new_title) {
+		purple_prpl_got_user_status_deactive(user->buddy->account, user->buddy->name, "tune");
+		return;
+	}
+
+	presence = purple_buddy_get_presence(user->buddy);
+
+	if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
+		PurpleStatus *status;
+		
+		status = purple_presence_get_status(presence, "tune");
+		prev_title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
+		prev_artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
+	} 
+
+	if (!new_artist)
+		new_artist = prev_artist;
+	
+	if (!new_title)
+		new_title = prev_title;
+
+	purple_prpl_got_user_status(user->buddy->account, user->buddy->name, "tune",
+			PURPLE_TUNE_TITLE, new_title,
+			PURPLE_TUNE_ARTIST, new_artist,
+			NULL);
+}
+
 /** Store a field of information about a buddy. 
  *
  * @param key_str Key to store.
@@ -194,11 +259,9 @@ msim_store_user_info_each(const gchar *k
 		g_free(user->display_name);
 		user->display_name = value_str;
 	} else if (g_str_equal(key_str, "BandName")) {
-		g_free(user->band_name);
-		user->band_name = value_str;
+		msim_set_artist_or_title(user, value_str, NULL);
 	} else if (g_str_equal(key_str, "SongName")) {
-		g_free(user->song_name);
-		user->song_name = value_str;
+		msim_set_artist_or_title(user, NULL, value_str);
 	} else if (g_str_equal(key_str, "UserName") || g_str_equal(key_str, "IMName") || g_str_equal(key_str, "NickName")) {
 		/* Ignore because PurpleBuddy knows this already */
 		g_free(value_str);


More information about the Commits mailing list