summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 78123e6)
raw | patch | inline | side by side (parent: 78123e6)
author | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 19:11:22 +0000 (21:11 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 3 Oct 2009 19:11:22 +0000 (21:11 +0200) |
src/main.c | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 8abdcbda94c60f4a043b9bd4bd403645abae8436..8d9152b27cb8e64e3e90d252bc2465755dbde10d 100644 (file)
--- a/src/main.c
+++ b/src/main.c
static gboolean
timer_mpd_update(gpointer data);
+static void
+enable_update_timer(void)
+{
+ if (update_source_id != 0)
+ return;
+
+ update_source_id = g_timeout_add(update_interval,
+ timer_mpd_update,
+ GINT_TO_POINTER(TRUE));
+}
+
+static void
+disable_update_timer(void)
+{
+ if (update_source_id == 0)
+ return;
+
+ g_source_remove(update_source_id);
+ update_source_id = 0;
+}
+
/**
* This timer is installed when the connection to the MPD server is
* broken. It tries to recover by reconnecting periodically.
if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) {
/* make sure we don't update the volume yet */
- g_source_remove(update_source_id);
- update_source_id = g_timeout_add(update_interval,
- timer_mpd_update,
- GINT_TO_POINTER(TRUE));
+ disable_update_timer();
+ enable_update_timer();
}
return 0;
/* attempt to connect */
reconnect_source_id = g_timeout_add(1, timer_reconnect, NULL);
- update_source_id = g_timeout_add(update_interval,
- timer_mpd_update,
- GINT_TO_POINTER(TRUE));
+ enable_update_timer();
+
#ifndef NCMPC_MINI
check_key_bindings_source_id = g_timeout_add(10000, timer_check_key_bindings, NULL);
#endif
cancel_seek_timer();
- g_source_remove(update_source_id);
+ disable_update_timer();
#ifndef NCMPC_MINI
if (check_key_bindings_source_id != 0)