Code

configure.ac: disable -Wdeclaration-after-statement
[ncmpc.git] / src / screen.c
index 19441707f0329c6d958ef21af55075db9ef50ad3..9bbfda742ff2a32afd7c82d78ac26cd03e02af86 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
 #include "colors.h"
 #include "player_command.h"
 #include "screen_help.h"
-#include "screen_play.h"
+#include "screen_queue.h"
 #include "screen_file.h"
 #include "screen_artist.h"
 #include "screen_search.h"
@@ -60,8 +60,8 @@ static const int SCREEN_MIN_ROWS = 5;
 /* screens */
 
 struct screen screen;
-static const struct screen_functions *mode_fn = &screen_playlist;
-static const struct screen_functions *mode_fn_prev = &screen_playlist;
+static const struct screen_functions *mode_fn = &screen_queue;
+static const struct screen_functions *mode_fn_prev = &screen_queue;
 
 gboolean
 screen_is_visible(const struct screen_functions *sf)
@@ -154,24 +154,23 @@ paint_top_window(const char *header, const struct mpdclient *c)
 }
 
 static void
-paint_progress_window(struct mpdclient *c)
+update_progress_window(struct mpdclient *c, bool repaint)
 {
        unsigned elapsed, duration;
 
-       if (c->song != NULL && seek_id == (int)mpd_song_get_id(c->song))
+       if (c->status == NULL)
+               elapsed = 0;
+       else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
                elapsed = seek_target_time;
-       else if (c->status != NULL)
-               elapsed = mpd_status_get_elapsed_time(c->status);
        else
-               elapsed = 0;
+               elapsed = mpd_status_get_elapsed_time(c->status);
 
-       duration = c->status != NULL &&
-               (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
-                mpd_status_get_state(c->status) == MPD_STATE_PAUSE)
+       duration = mpdclient_is_playing(c)
                ? mpd_status_get_total_time(c->status)
                : 0;
 
-       if (progress_bar_set(&screen.progress_bar, elapsed, duration))
+       if (progress_bar_set(&screen.progress_bar, elapsed, duration) ||
+           repaint)
                progress_bar_paint(&screen.progress_bar);
 }
 
@@ -342,7 +341,7 @@ screen_paint(struct mpdclient *c)
 
        /* paint the bottom window */
 
-       paint_progress_window(c);
+       update_progress_window(c, true);
        status_bar_paint(&screen.status_bar, c->status, c->song);
 
        /* paint the main window */
@@ -425,7 +424,8 @@ screen_update(struct mpdclient *c)
                crossfade = mpd_status_get_crossfade(c->status);
        }
 
-       if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected)
+       if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected &&
+           mpdclient_is_connected(c))
                screen_status_printf(_("Database updated"));
        was_connected = mpdclient_is_connected(c);
 
@@ -440,7 +440,7 @@ screen_update(struct mpdclient *c)
                paint_top_window("", c);
 
        /* update progress window */
-       paint_progress_window(c);
+       update_progress_window(c, false);
 
        /* update status window */
        status_bar_paint(&screen.status_bar, c->status, c->song);
@@ -521,7 +521,7 @@ screen_cmd(struct mpdclient *c, command_t cmd)
                screen_next_mode(c, 1);
                break;
        case CMD_SCREEN_PLAY:
-               screen_switch(&screen_playlist, c);
+               screen_switch(&screen_queue, c);
                break;
        case CMD_SCREEN_FILE:
                screen_switch(&screen_browse, c);