# HG changeset patch # User Yoshiki Yazawa # Date 1232776640 -32400 # Node ID c0280cf3ca84f6f76297341505a635062e687d15 # Parent 8ac1ebc63fabee1d364c4e591e5e1e1c8423a513 first try to avoid too frequent updates. diff -r 8ac1ebc63fab -r c0280cf3ca84 pidgin-audacious.c --- a/pidgin-audacious.c Sat Jan 10 14:41:46 2009 +0900 +++ b/pidgin-audacious.c Sat Jan 24 14:57:20 2009 +0900 @@ -27,6 +27,7 @@ static DBusGConnection *connection = NULL; static DBusGProxy *session = NULL; static PurpleCmdId cmdid_paste_current_song; +static GTimeVal latest; /* time of the latest notification */ /* implementation */ @@ -201,12 +202,11 @@ } - -static void -track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data) +static gboolean +track_signal_hook(gpointer data) { + song_tuple *tuple = (song_tuple *)data; gchar *song_info = NULL; - song_tuple *tuple = get_song_tuple(table); /* set current song */ purple_util_set_current_song(tuple->title ? tuple->title : "", @@ -215,28 +215,91 @@ song_info = format_song_info(tuple); - aud_process(song_info); + aud_process(song_info); free_song_tuple(tuple); - g_free(song_info); + g_free(song_info); + + return FALSE; /* one time */ +} + + +static void +track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data) +{ + GTimeVal current; + gulong interval; + song_tuple *tuple = get_song_tuple(table); + + g_get_current_time(¤t); + + if(current.tv_sec > latest.tv_sec) { + interval = current.tv_sec - latest.tv_sec; + + if(interval < MINIMAL_INTERVAL) { + g_timeout_add_seconds(MINIMAL_INTERVAL - interval, + track_signal_hook, (gpointer)tuple); + + latest.tv_sec = current.tv_sec + MINIMAL_INTERVAL - interval; + } + else { + track_signal_hook((gpointer)tuple); + latest.tv_sec = current.tv_sec; + } + } + else { + latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL; + g_timeout_add_seconds(latest.tv_sec - current.tv_sec, + track_signal_hook, (gpointer)tuple); + } +} + + +static gboolean +status_signal_hook(gpointer data) +{ + gboolean stopped = !is_app_playing(); + + if(stopped) { + /* clear status/user info */ + aud_process(NULL); + /* clear current song */ + purple_util_set_current_song(NULL, NULL, NULL); + } + + return FALSE; } static void status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data) { + GTimeVal current; + gulong interval; + aud_debug("StatusChange %d\n", status); - 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; + g_get_current_time(¤t); + + if(current.tv_sec > latest.tv_sec) { + interval = current.tv_sec - latest.tv_sec; + + if(interval < MINIMAL_INTERVAL) { + g_timeout_add_seconds(MINIMAL_INTERVAL - interval, + status_signal_hook, NULL); + latest.tv_sec = current.tv_sec + MINIMAL_INTERVAL - interval; + } + else { + status_signal_hook(NULL); + latest.tv_sec = current.tv_sec; + } + } + else { /* current < latest */ + /* latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL; */ + /* g_timeout_add_seconds(latest.tv_sec - current.tv_sec, */ + /* status_signal_hook, NULL); */ + latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL; + g_timeout_add_seconds(latest.tv_sec - current.tv_sec, + status_signal_hook, NULL); } } diff -r 8ac1ebc63fab -r c0280cf3ca84 pidgin-audacious.h --- a/pidgin-audacious.h Sat Jan 10 14:41:46 2009 +0900 +++ b/pidgin-audacious.h Sat Jan 24 14:57:20 2009 +0900 @@ -40,6 +40,7 @@ /* constants */ #define DBUS_TIMEOUT 1000 +#define MINIMAL_INTERVAL 8 #define PLAYING 0 #define PAUSED 1 #define STOPPED 2