changeset 10:7c9624c8a109

added /song command which sends name of currently playing song.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 17 Sep 2008 11:06:15 +0900
parents d5702f04b19c
children 43cb653de212
files pidgin-audacious.c
diffstat 1 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Wed Sep 17 11:04:42 2008 +0900
+++ b/pidgin-audacious.c	Wed Sep 17 11:06:15 2008 +0900
@@ -28,6 +28,7 @@
 #include "debug.h"
 #include "connection.h"
 #include "version.h"
+#include "cmds.h"
 #include <audacious/audctrl.h>
 #include <audacious/dbus.h>
 
@@ -62,6 +63,8 @@
 
 DBusGProxy *session = NULL;
 
+static PurpleCmdId cmdid_paste_current_song;
+
 static void aud_process(gchar *aud_info);
 
 static DBusGProxy *get_dbus_proxy(void)
@@ -400,6 +403,44 @@
 	return TRUE;
 }
 
+static PurpleCmdRet
+paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
+{
+	gint playpos = 0;
+	gchar *song = NULL, *tmp = NULL;
+    PurpleConversationType type = purple_conversation_get_type(conv);
+	size_t dummy;
+
+    if(!audacious_remote_is_playing(session)) {	/* audacious isn't playing */
+        return PURPLE_CMD_RET_OK;
+    }
+
+    playpos = audacious_remote_get_playlist_pos(session);
+    tmp = audacious_remote_get_playlist_title(session, playpos);
+
+    if(tmp) {
+        if(botch_utf) // function exists
+            song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy);
+        else
+            song = g_strdup(tmp);
+    }
+    g_free(tmp);
+    tmp = NULL;
+
+    if(type == PURPLE_CONV_TYPE_CHAT) {
+        PurpleConvChat *chat = purple_conversation_get_chat_data(conv);
+        if (chat && song)
+            purple_conv_chat_send(chat, song);
+    }
+    else if(type == PURPLE_CONV_TYPE_IM) {
+        PurpleConvIm *im = purple_conversation_get_im_data(conv);
+        if(im && song)
+            purple_conv_im_send(im, song);
+    }
+
+    g_free(song);
+    return PURPLE_CMD_RET_OK;
+}
 
 static gboolean
 load_plugin(PurplePlugin *plugin)
@@ -418,6 +459,11 @@
 	purple_signal_connect(purple_connections_get_handle(), "signing-off", plugin,
 						PURPLE_CALLBACK(restore_alias), NULL);
 
+    cmdid_paste_current_song =
+        purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT,
+                            PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT,
+                            NULL, paste_current_song,
+                            "song: Paste currently plaing song", NULL);
 
 	return TRUE;
 }
@@ -437,6 +483,8 @@
 	g_hash_table_destroy(pushed_alias);
 	g_hash_table_destroy(pushed_userinfo);
 
+    purple_cmd_unregister(cmdid_paste_current_song);
+
 	return TRUE;
 }
 
@@ -482,7 +530,7 @@
 	PURPLE_PRIORITY_DEFAULT,	/**< priority	*/
 	PIDGINAUD_PLUGIN_ID,		/**< id		*/
 	"Pidgin-Audacious",			/**< name	*/
-	"2.0.0",					/**< version	*/
+	"2.1.0d1",					/**< version	*/
 	"Automatically updates your Pidgin status info	with the currently "
 			"playing music in Audacious.", /**  summary	*/
 	"Automatically updates your Pidgin status info with the currently "