changeset 21:83002f858ee9

- do not retract current song if playing has been paused. - little bit cleanup.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 05 Oct 2008 14:19:55 +0900
parents 4aa711530489
children fbad40babe88
files pidgin-audacious.c
diffstat 1 files changed, 53 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Sat Oct 04 17:59:07 2008 +0900
+++ b/pidgin-audacious.c	Sun Oct 05 14:19:55 2008 +0900
@@ -34,6 +34,8 @@
 
 #define PIDGINAUD_PLUGIN_ID     "pidgin_audacious"
 #define PLUGIN_NAME             "Pidgin-Audacious"
+
+/* preferences */
 #define OPT_PIDGINAUD           "/plugins/pidgin_audacious"
 #define OPT_PROCESS_STATUS      OPT_PIDGINAUD "/process_status"
 #define OPT_PROCESS_USERINFO    OPT_PIDGINAUD "/process_userinfo"
@@ -42,23 +44,23 @@
 #define OPT_LOG_OUTPUT          OPT_PIDGINAUD "/log_output"
 #define OPT_PLAYER              OPT_PIDGINAUD "/player"
 
+/* templates */
+#define TITLE   "%title"
+#define ARTIST  "%artist"
+#define ALBUM   "%album"
+#define GENRE   "%genre"
 #define DEFAULT_SONG_TEMPLATE   "%title - %artist"
 #define DEFAULT_PLAYER          "audacious"
 #define SONG_TOKEN              "%song"
 #define NO_SONG_MESSAGE         "No song being played."
 
-#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
-
-#define aud_debug(fmt, ...)	do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d:  " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0);
-
-#define aud_error(fmt, ...)	do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d:  " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0);
+/* constants */
+#define DBUS_TIMEOUT 1000
+#define PLAYING 0
+#define PAUSED  1
+#define STOPPED 2
 
-/* xxx move up */
-#define TITLE   "%title"
-#define ARTIST  "%artist"
-#define ALBUM   "%album"
-#define GENRE   "%genre"
-
+/* custom data type */
 typedef struct song_tuple {
     gchar *title;
     gchar *artist;
@@ -66,6 +68,15 @@
     gchar *genre;
 } song_tuple;
 
+/* mpris data containers */
+#define DBUS_TYPE_MPRIS_STATUS (dbus_g_type_get_struct ("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID))
+
+#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
+
+/* debug macros */
+#define aud_debug(fmt, ...)	do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d:  " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0);
+
+#define aud_error(fmt, ...)	do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d:  " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0);
 
 /* globals */
 static GHashTable *seed_status;
@@ -89,7 +100,6 @@
 
 
 /* implementation */
-
 static DBusGProxy *
 get_dbus_session(void)
 {
@@ -286,13 +296,18 @@
 {
 	aud_debug("StatusChange %d\n", status);
 
-	if (status != 0) {
+    switch(status) {
+    case STOPPED:
+        /* clear status/user info */
 		aud_process(NULL);
-
         /* clear current song */
         purple_util_set_current_song(NULL, NULL, NULL);
-
-	}
+        break;
+    case PLAYING:
+    case PAUSED:
+    default:
+        break;
+    }
 }
 
 
@@ -556,21 +571,16 @@
     return PURPLE_CMD_RET_OK;
 }
 
-#define DBUS_TIMEOUT 1000
-#define DBUS_TYPE_MPRIS_STATUS (dbus_g_type_get_struct ("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID))
-
-#define PLAYING 0
-#define PAUSED  1
-#define STOPPED 2
-
 static gboolean
 is_app_playing(void)
 {
+    GError *error = NULL;
+    int status = STOPPED;
+
 	gchar *player_name = g_strconcat("org.mpris.",
                                      purple_prefs_get_string(OPT_PLAYER),
                                      NULL);
 
-
     aud_debug("player_name = %s\n", player_name);
 
     if(!session) {
@@ -580,9 +590,6 @@
     }
 
     /* audacious only supports this form */
-    GError *error = NULL;
-    int status = STOPPED;
-
     gboolean result =
         dbus_g_proxy_call_with_timeout(
             session,
@@ -595,18 +602,22 @@
             G_TYPE_INVALID);
 
     aud_debug("GetStatus result = %d\n", result);
-
-    if(status == PLAYING || status == PAUSED)
-        return TRUE;
-    else
-        return FALSE;
-
     aud_debug("GetStatus status = %d\n", status);
 
+    switch(status) {
+    case PLAYING:
+    case PAUSED:
+        return TRUE;
+        break;
+    case STOPPED:
+    default:
+        return FALSE;
+        break;
+    }
 
+#if 0
     /* mpris specification 1.0 insists this is the way. no player
      * supports this at this time. --yaz */
-#if 0
     GError *error = NULL;
     GValueArray *s;
     gboolean result =
@@ -630,15 +641,18 @@
 
         aud_debug("status = %d\n", status);
 
-        if(status == STOPPED)
+        switch(status) {
+        case PLAYING:
+        case PAUSED:
+            return TRUE;
+            break;
+        case STOPPED:
+        default:
             return FALSE;
-        else
-            return TRUE;
     }
 
 	return FALSE;
 #endif
-
 }
 
 static void
@@ -711,9 +725,9 @@
     /* connect to purple signals */
     connect_purple_signals(plugin);
 
+    /* clear status */
 	status_signal_cb(NULL, -1, NULL);
 
-
     /* register /song command */
     cmdid_paste_current_song =
         purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT,