diff libpurple/protocols/jabber/usertune.c @ 21978:cacc01b50a23

Fixes for incorrectly displaying user tune emblem and empty current media. We now send an empty tune when not listening to any music, don't interpret empty tune information as valid tune info and deactivate the "tune" status when receiving empty tune information.
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 03 Jan 2008 18:31:58 +0000
parents 5913725cbcd6
children 5f9a24d1c25e 26eabe8e739b
line wrap: on
line diff
--- a/libpurple/protocols/jabber/usertune.c	Thu Jan 03 11:12:36 2008 +0000
+++ b/libpurple/protocols/jabber/usertune.c	Thu Jan 03 18:31:58 2008 +0000
@@ -35,11 +35,12 @@
 	xmlnode *tuneinfo, *tune;
 	PurpleJabberTuneInfo tuneinfodata;
 	JabberBuddyResource *resource;
-	
+	gboolean valid = FALSE;
+
 	/* ignore the tune of people not on our buddy list */
 	if (!buddy || !item)
 		return;
-	
+
 	tuneinfodata.artist = NULL;
 	tuneinfodata.title = NULL;
 	tuneinfodata.album = NULL;
@@ -58,36 +59,47 @@
 			if (!strcmp(tuneinfo->name, "artist")) {
 				if (tuneinfodata.artist == NULL) /* only pick the first one */
 					tuneinfodata.artist = xmlnode_get_data(tuneinfo);
+				valid = TRUE;
 			} else if (!strcmp(tuneinfo->name, "length")) {
 				if (tuneinfodata.time == -1) {
 					char *length = xmlnode_get_data(tuneinfo);
 					if (length)
 						tuneinfodata.time = strtol(length, NULL, 10);
 					g_free(length);
+					if (tuneinfodata.time > 0)
+						valid = TRUE;
 				}
 			} else if (!strcmp(tuneinfo->name, "source")) {
 				if (tuneinfodata.album == NULL) /* only pick the first one */
 					tuneinfodata.album = xmlnode_get_data(tuneinfo);
+				valid = TRUE;
 			} else if (!strcmp(tuneinfo->name, "title")) {
 				if (tuneinfodata.title == NULL) /* only pick the first one */
 					tuneinfodata.title = xmlnode_get_data(tuneinfo);
+				valid = TRUE;
 			} else if (!strcmp(tuneinfo->name, "track")) {
 				if (tuneinfodata.track == NULL) /* only pick the first one */
 					tuneinfodata.track = xmlnode_get_data(tuneinfo);
+				valid = TRUE;
 			} else if (!strcmp(tuneinfo->name, "uri")) {
 				if (tuneinfodata.url == NULL) /* only pick the first one */
 					tuneinfodata.url = xmlnode_get_data(tuneinfo);
+				valid = TRUE;
 			}
 		}
 	}
 
-	purple_prpl_got_user_status(js->gc->account, from, "tune",
-			PURPLE_TUNE_ARTIST, tuneinfodata.artist,
-			PURPLE_TUNE_TITLE, tuneinfodata.title,
-			PURPLE_TUNE_ALBUM, tuneinfodata.album,
-			PURPLE_TUNE_TRACK, tuneinfodata.track,
-			PURPLE_TUNE_TIME, tuneinfodata.time,
-			PURPLE_TUNE_URL, tuneinfodata.url, NULL);
+	if (valid) {
+		purple_prpl_got_user_status(js->gc->account, from, "tune",
+				PURPLE_TUNE_ARTIST, tuneinfodata.artist,
+				PURPLE_TUNE_TITLE, tuneinfodata.title,
+				PURPLE_TUNE_ALBUM, tuneinfodata.album,
+				PURPLE_TUNE_TRACK, tuneinfodata.track,
+				PURPLE_TUNE_TIME, tuneinfodata.time,
+				PURPLE_TUNE_URL, tuneinfodata.url, NULL);
+	} else {
+		purple_prpl_got_user_status_deactive(js->gc->account, from, "tune");
+	}
 
 	g_free(tuneinfodata.artist);
 	g_free(tuneinfodata.title);
@@ -119,7 +131,7 @@
 			xmlnode_insert_data(xmlnode_new_child(tunenode, "source"),tuneinfo->album,-1);
 		if(tuneinfo->url && tuneinfo->url[0] != '\0')
 			xmlnode_insert_data(xmlnode_new_child(tunenode, "uri"),tuneinfo->url,-1);
-		if(tuneinfo->time >= 0) {
+		if(tuneinfo->time > 0) {
 			char *length = g_strdup_printf("%d", tuneinfo->time);
 			xmlnode_insert_data(xmlnode_new_child(tunenode, "length"),length,-1);
 			g_free(length);