im.pidgin.pidgin: cfbfcf4098c65b271fa8a29be41a318ccb5e5035

sadrul at pidgin.im sadrul at pidgin.im
Sat Jan 5 06:10:38 EST 2008


-----------------------------------------------------------------
Revision: cfbfcf4098c65b271fa8a29be41a318ccb5e5035
Ancestor: 38f9a3189979905bf69cbbc5640138ad2c7618ca
Author: sadrul at pidgin.im
Date: 2008-01-05T11:08:48
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/msn/msn.c libpurple/util.c
        libpurple/util.h

ChangeLog: 

Utility functions to set and format song information. Closes #4398.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	0bc8b88a9da8f8f1dea61243bcf0c8b2d320bbe8
+++ libpurple/protocols/jabber/jabber.c	f97cf719dfbefa80f47998f7f303e19f39421904
@@ -1523,10 +1523,16 @@ void jabber_tooltip_text(PurpleBuddy *b,
 				} else
 					purple_notify_user_info_add_pair(user_info, _("Mood"), mood);
 			}
-			if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {	
+			if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
 				PurpleStatus *tune = purple_presence_get_status(presence, "tune");
 				const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
-				purple_notify_user_info_add_pair(user_info, _("Current media"), title);
+				const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
+				const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
+				char *playing = purple_util_format_song_info(title, artist, album, NULL);
+				if (playing) {
+					purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing);
+					g_free(playing);
+				}
 			}
 		}
 
============================================================
--- libpurple/protocols/msn/msn.c	bb0de7cd52ec8ed9aa827db242e84131973de907
+++ libpurple/protocols/msn/msn.c	51607f0cffcd9939617526f95ae2abb9741064ce
@@ -593,8 +593,8 @@ msn_tooltip_text(PurpleBuddy *buddy, Pur
 			PurpleStatus *tune = purple_presence_get_status(presence, "tune");
 			const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
 			const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
-			currentmedia = g_strdup_printf("%s%s%s", title, artist ? " - " : "",
-					artist ? artist : "");
+			const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
+			currentmedia = purple_util_format_song_info(title, artist, album, NULL);
 			/* We could probably just use user->media.title etc. here */
 		}
 
@@ -643,9 +643,7 @@ msn_tooltip_text(PurpleBuddy *buddy, Pur
 		}
 
 		if (currentmedia) {
-			tmp = g_markup_escape_text(currentmedia, -1);
-			purple_notify_user_info_add_pair(user_info, _("Current media"), tmp);
-			g_free(tmp);
+			purple_notify_user_info_add_pair(user_info, _("Now Listening"), currentmedia);
 			g_free(currentmedia);
 		}
 	}
============================================================
--- libpurple/util.c	37ecfde93f37532c0f23b16c1e626c42774276ed
+++ libpurple/util.c	fefb802459ac8814b5a17e82f9a47761558cf8af
@@ -4628,3 +4628,57 @@ void purple_restore_default_signal_handl
 #endif /* HAVE_SIGNAL_H */
 #endif /* !_WIN32 */
 }
+
+void purple_util_set_current_song(const char *title, const char *artist, const char *album)
+{
+	GList *list = purple_accounts_get_all();
+	for (; list; list = list->next) {
+		PurplePresence *presence;
+		PurpleStatus *tune;
+		PurpleAccount *account = list->data;
+		if (!purple_account_get_enabled(account, purple_core_get_ui()))
+			continue;
+
+		presence = purple_account_get_presence(account);
+		tune = purple_presence_get_status(presence, "tune");
+		if (!tune)
+			continue;
+		if (title) {
+			purple_status_set_active(tune, TRUE);
+			purple_status_set_attr_string(tune, PURPLE_TUNE_TITLE, title);
+			purple_status_set_attr_string(tune, PURPLE_TUNE_ARTIST, artist);
+			purple_status_set_attr_string(tune, PURPLE_TUNE_ALBUM, album);
+		} else {
+			purple_status_set_active(tune, FALSE);
+		}
+	}
+}
+
+char * purple_util_format_song_info(const char *title, const char *artist, const char *album, gpointer unused)
+{
+	GString *string;
+	char *esc;
+
+	if (!title)
+		return NULL;
+
+	esc = g_markup_escape_text(title, -1);
+	string = g_string_new("");
+	g_string_append_printf(string, "%s", esc);
+	g_free(esc);
+
+	if (artist) {
+		esc = g_markup_escape_text(artist, -1);
+		g_string_append_printf(string, _(" - %s"), esc);
+		g_free(esc);
+	}
+
+	if (album) {
+		esc = g_markup_escape_text(album, -1);
+		g_string_append_printf(string, _(" (%s)"), esc);
+		g_free(esc);
+	}
+
+	return g_string_free(string, FALSE);
+}
+
============================================================
--- libpurple/util.h	f8c70e19d811f651f26c47ceac09bf93635b19c3
+++ libpurple/util.h	55564322be9c4ef39a3dce010516ee0bc1b3668c
@@ -85,6 +85,31 @@ void purple_menu_action_free(PurpleMenuA
  */
 void purple_menu_action_free(PurpleMenuAction *act);
 
+/**
+ * Set the appropriate presence values for the currently playing song.
+ *
+ * @param title     The title of the song, @c NULL to unset the value.
+ * @param artist    The artist of the song, can be @c NULL.
+ * @param album     The album of the song, can be @c NULL.
+ * @since 2.4.0
+ */
+void purple_util_set_current_song(const char *title, const char *artist,
+		const char *album);
+
+/**
+ * Format song information.
+ *
+ * @param title     The title of the song, @c NULL to unset the value.
+ * @param artist    The artist of the song, can be @c NULL.
+ * @param album     The album of the song, can be @c NULL.
+ * @param unused    Currently unused, must be @c NULL.
+ *
+ * @return   The formatted string. The caller must #g_free the returned string.
+ * @since 2.4.0
+ */
+char * purple_util_format_song_info(const char *title, const char *artist,
+		const char *album, gpointer unused);
+
 /**************************************************************************/
 /** @name Utility Subsystem                                               */
 /**************************************************************************/


More information about the Commits mailing list