changeset 22265:7bd8ec61e687

merge of '127e166396532169c471488d7be34927a0f32b39' and 'b75a11995dcb2d3d2dc04522842a884fa0b5d06f'
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Mon, 04 Feb 2008 04:04:02 +0000
parents 99c6ed4c9cbe (current diff) e808d83d797e (diff)
children fc31c35d8024 1f3481447197
files
diffstat 2 files changed, 86 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Sun Feb 03 21:23:48 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Mon Feb 04 04:04:02 2008 +0000
@@ -158,6 +158,19 @@
 	_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 @@
 		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);
 	}
--- a/libpurple/protocols/myspace/user.c	Sun Feb 03 21:23:48 2008 +0000
+++ b/libpurple/protocols/myspace/user.c	Mon Feb 04 04:04:02 2008 +0000
@@ -20,7 +20,7 @@
 #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 @@
  * @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 @@
 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 @@
 		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 @@
 	}
 }
 
+/** 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 @@
 		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);