changeset 11:43cb653de212

paste template has been implemented.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 18 Sep 2008 01:55:32 +0900
parents 7c9624c8a109
children 79f081cdfb19
files pidgin-audacious.c
diffstat 1 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Wed Sep 17 11:06:15 2008 +0900
+++ b/pidgin-audacious.c	Thu Sep 18 01:55:32 2008 +0900
@@ -36,10 +36,11 @@
 
 #define PIDGINAUD_PLUGIN_ID	"pidgin_audacious"
 
-#define OPT_PIDGINAUD 		"/plugins/pidgin_audacious"
-#define OPT_PROCESS_STATUS	OPT_PIDGINAUD "/process_status"
-#define OPT_PROCESS_USERINFO	OPT_PIDGINAUD "/process_userinfo"
-#define OPT_PROCESS_ALIAS	OPT_PIDGINAUD "/process_alias"
+#define OPT_PIDGINAUD           "/plugins/pidgin_audacious"
+#define OPT_PROCESS_STATUS      OPT_PIDGINAUD "/process_status"
+#define OPT_PROCESS_USERINFO    OPT_PIDGINAUD "/process_userinfo"
+#define OPT_PROCESS_ALIAS       OPT_PIDGINAUD "/process_alias"
+#define OPT_PASTE_TEMPLATE      OPT_PIDGINAUD "/paste_template"
 
 #define SONG_TOKEN		"%song"
 #define NO_SONG_MESSAGE "No song being played."
@@ -407,25 +408,39 @@
 paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
 {
 	gint playpos = 0;
-	gchar *song = NULL, *tmp = NULL;
+	gchar *song = NULL, *tmp = NULL, *tmp2 = NULL;
     PurpleConversationType type = purple_conversation_get_type(conv);
 	size_t dummy;
+    const gchar *template = NULL;
 
-    if(!audacious_remote_is_playing(session)) {	/* audacious isn't playing */
+	/* audacious isn't playing */
+    if(!audacious_remote_is_playing(session)) {
         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);
+    template = purple_prefs_get_string(OPT_PASTE_TEMPLATE);
+
+    if(template && strstr(template, SONG_TOKEN)) {
+        tmp2 = purple_strreplace(template, SONG_TOKEN, tmp);
+        g_free(tmp);
+        tmp = NULL;
+    }
+    else {
+        tmp2 = tmp;
+    }
+
+    if(tmp2) {
+        if(botch_utf) {
+            song = (gchar *) botch_utf(tmp2, strlen(tmp2), &dummy);
+            g_free(tmp2);
+            tmp2 = NULL;
+        }
         else
-            song = g_strdup(tmp);
+            song = tmp2;
     }
-    g_free(tmp);
-    tmp = NULL;
 
     if(type == PURPLE_CONV_TYPE_CHAT) {
         PurpleConvChat *chat = purple_conversation_get_chat_data(conv);
@@ -510,6 +525,11 @@
 			"Expand " SONG_TOKEN " to song info in the alias");
 	purple_plugin_pref_frame_add(frame, pref);
 
+    /* paste template */
+    pref = purple_plugin_pref_new_with_name_and_label(OPT_PASTE_TEMPLATE,
+                                                      "Paste template");
+	purple_plugin_pref_frame_add(frame, pref);
+
 	return frame;
 }
 
@@ -556,6 +576,7 @@
 	purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE);
 	purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE);
 	purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE);
+    purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN);
 
     session = get_dbus_proxy();
 }