Code

main: update within timer_reconnect()
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 23:10:28 +0000 (01:10 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 23:10:28 +0000 (01:10 +0200)
Don't schedule the timer_mpd_update() call.  Always return "true" from
timer_mpd_update().

This sets the full event mask after a connection was established.  The
"database updated" message appears only if the connection existed
before.

src/main.c
src/screen.c

index 726f098f3d046414dfcd88b1930b6e8c07b67134..8669b6358bda9dcf87617790a99f8793f814add2 100644 (file)
@@ -165,8 +165,7 @@ enable_update_timer(void)
                return;
 
        update_source_id = g_timeout_add(update_interval,
-                                        timer_mpd_update,
-                                        GINT_TO_POINTER(TRUE));
+                                        timer_mpd_update, NULL);
 }
 
 static void
@@ -179,6 +178,26 @@ disable_update_timer(void)
        update_source_id = 0;
 }
 
+static void
+check_reconnect(void);
+
+static void
+do_mpd_update(void)
+{
+       if (mpdclient_is_connected(mpd))
+               mpdclient_update(mpd);
+
+#ifndef NCMPC_MINI
+       if (options.enable_xterm_title)
+               update_xterm_title();
+#endif
+
+       screen_update(mpd);
+       mpd->events = 0;
+
+       check_reconnect();
+}
+
 /**
  * This timer is installed when the connection to the MPD server is
  * broken.  It tries to recover by reconnecting periodically.
@@ -232,7 +251,11 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
        doupdate();
 
        /* update immediately */
-       g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE));
+       mpd->events = MPD_IDLE_DATABASE|MPD_IDLE_STORED_PLAYLIST|
+               MPD_IDLE_QUEUE|MPD_IDLE_PLAYER|MPD_IDLE_MIXER|MPD_IDLE_OUTPUT|
+               MPD_IDLE_OPTIONS|MPD_IDLE_UPDATE;
+
+       do_mpd_update();
 
        return FALSE;
 }
@@ -247,22 +270,11 @@ check_reconnect(void)
 }
 
 static gboolean
-timer_mpd_update(gpointer data)
+timer_mpd_update(G_GNUC_UNUSED gpointer data)
 {
-       if (mpdclient_is_connected(mpd))
-               mpdclient_update(mpd);
-
-#ifndef NCMPC_MINI
-       if (options.enable_xterm_title)
-               update_xterm_title();
-#endif
-
-       screen_update(mpd);
-       mpd->events = 0;
-
-       check_reconnect();
+       do_mpd_update();
 
-       return GPOINTER_TO_INT(data);
+       return true;
 }
 
 void begin_input_event(void)
index efbd37ff6fb8729cca81f1db00a92981faf7b099..19441707f0329c6d958ef21af55075db9ef50ad3 100644 (file)
@@ -366,6 +366,7 @@ void
 screen_update(struct mpdclient *c)
 {
 #ifndef NCMPC_MINI
+       static bool was_connected;
        static bool initialized = false;
        static bool repeat;
        static bool random_enabled;
@@ -424,8 +425,9 @@ screen_update(struct mpdclient *c)
                crossfade = mpd_status_get_crossfade(c->status);
        }
 
-       if (c->events & MPD_IDLE_DATABASE)
+       if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected)
                screen_status_printf(_("Database updated"));
+       was_connected = mpdclient_is_connected(c);
 
        /* update title/header window */
        if (screen.welcome_source_id != 0)