Mercurial > pidgin-audacious
changeset 19:12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
- new debug macros.
- removed watchdog_func().
- added connect_purple_signals().
- renamed is_app_running() as is_app_playing().
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 04 Oct 2008 12:06:45 +0900 |
parents | dc3aa0bf24c0 |
children | 4aa711530489 |
files | pidgin-audacious.c |
diffstat | 1 files changed, 47 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin-audacious.c Sat Oct 04 04:19:46 2008 +0900 +++ b/pidgin-audacious.c Sat Oct 04 12:06:45 2008 +0900 @@ -33,12 +33,13 @@ #include "savedstatuses.h" #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" - +#define PLUGIN_NAME "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_SONG_TEMPLATE OPT_PIDGINAUD "/song_template" #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" +#define OPT_LOG_OUTPUT OPT_PIDGINAUD "/log_output" #define DEFAULT_SONG_TEMPLATE "%artist - %title" #define SONG_TOKEN "%song" @@ -46,12 +47,10 @@ #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) -#define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, \ - "Pidgin-Audacious", \ - fmt, ## __VA_ARGS__); -#define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, \ - "Pidgin-Audacious", \ - fmt, ## __VA_ARGS__); +#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); + /* xxx move up */ #define TITLE "%title" #define ARTIST "%artist" @@ -80,9 +79,11 @@ static void aud_process(gchar *aud_info); static void track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data); static void status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data); -static gboolean is_app_running(void); +static gboolean is_app_playing(void); static GHashTable *get_song_table(void); static song_tuple *get_song_tuple(GHashTable *table); +static void signed_on_cb(PurpleConnection *gc, void *data); +static void prefs_cb(const char *name, PurplePrefType type, gconstpointer value, gpointer data); /* implementation */ @@ -128,14 +129,33 @@ NULL, NULL); } +static void +connect_purple_signals(PurplePlugin *plugin) +{ + purple_signal_connect(purple_connections_get_handle(), + "signed-on", + plugin, + PURPLE_CALLBACK(signed_on_cb), + NULL); + + purple_signal_connect(purple_savedstatuses_get_handle(), + "savedstatus-changed", + plugin, + PURPLE_CALLBACK(signed_on_cb), + NULL); + + purple_prefs_connect_callback(purple_prefs_get_handle(), + OPT_PIDGINAUD, + prefs_cb, + NULL); +} + static GHashTable * get_song_table(void) { GHashTable *table = NULL; - status_signal_cb(NULL, -1, NULL); - - if(is_app_running()) { + if(is_app_playing()) { dbus_g_proxy_call(session, "GetMetadata", NULL, @@ -263,67 +283,6 @@ } -#if 0 -static gboolean -watchdog_func(void) -{ - gint playpos = 0; - gchar *song = NULL, *tmp = NULL; - - gboolean rv = TRUE; - size_t dummy; - - if(!session) { - session = get_dbus_session(); - } - - aud_debug("session = %p\n", session); - aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); - - if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ - aud_process(NULL); - purple_util_set_current_song(NULL, NULL, NULL); - return rv; - } - - playpos = audacious_remote_get_playlist_pos(session); - tmp = audacious_remote_get_playlist_title(session, playpos); - if(tmp) { - if(botch_utf) /* if function exists */ - song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); - else - song = g_strdup(tmp); - } - g_free(tmp); - tmp = NULL; - - aud_process(song); - g_free(song); - song = NULL; - - /* preliminary support for purple_util_set_current_song() */ - gchar *artist = NULL, *title = NULL, *album = NULL; - - artist = audacious_get_tuple_field_data(session, "artist", playpos); - title = audacious_get_tuple_field_data(session, "title", playpos); - album = audacious_get_tuple_field_data(session, "album", playpos); - - purple_util_set_current_song(title ? title : "", - artist ? artist : "", - album ? album : ""); - - g_free(artist); - g_free(title); - g_free(album); - - return rv; -} -#endif - - - - - static void aud_process_status(PurpleConnection *gc, gchar *aud_info) { @@ -527,10 +486,6 @@ g_free(data); } - - - - static PurpleCmdRet paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) @@ -541,7 +496,7 @@ const gchar *template = NULL; /* audacious isn't playing */ - if(!is_app_running()) { + if(!is_app_playing()) { return PURPLE_CMD_RET_OK; } @@ -588,12 +543,8 @@ return PURPLE_CMD_RET_OK; } - - - - static gboolean -is_app_running(void) +is_app_playing(void) { gchar *player_name = g_strconcat("org.mpris.", "audacious", NULL); @@ -627,21 +578,27 @@ GHashTable *table = NULL; song_tuple *tuple = NULL; + aud_debug("called\n"); + table = get_song_table(); tuple = get_song_tuple(table); + g_hash_table_destroy(table); + + /* set current song */ + purple_util_set_current_song(tuple->title ? tuple->title : "", + tuple->artist ? tuple->artist : "", + tuple->album ? tuple->album : ""); song_info = format_song_info(tuple); free_song_tuple(tuple); - g_hash_table_destroy(table); - if(song_info) - aud_process(song_info); - + aud_process(song_info); g_free(song_info); } -static void prefs_cb(const char *name, PurplePrefType type, +static void +prefs_cb(const char *name, PurplePrefType type, gconstpointer value, gpointer data) { aud_debug("settings change detected at %s\n", name); @@ -668,22 +625,7 @@ connect_dbus_signals(); /* connect to purple signals */ - purple_signal_connect(purple_connections_get_handle(), - "signed-on", - plugin, - PURPLE_CALLBACK(signed_on_cb), - NULL); - - purple_signal_connect(purple_savedstatuses_get_handle(), - "savedstatus-changed", - plugin, - PURPLE_CALLBACK(signed_on_cb), - NULL); - - purple_prefs_connect_callback(purple_prefs_get_handle(), - OPT_PIDGINAUD, - prefs_cb, - NULL); + connect_purple_signals(plugin); status_signal_cb(NULL, -1, NULL); @@ -777,7 +719,7 @@ PURPLE_PRIORITY_DEFAULT, /**< priority */ PIDGINAUD_PLUGIN_ID, /**< id */ "Pidgin-Audacious", /**< name */ - "3.0.0d2", /**< version */ + "3.0.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 " @@ -804,6 +746,7 @@ purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); purple_prefs_add_string(OPT_SONG_TEMPLATE, DEFAULT_SONG_TEMPLATE); purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); + purple_prefs_add_bool(OPT_LOG_OUTPUT, TRUE); }