Code

Update copyright notices
[ncmpc.git] / src / status_bar.c
index 00724e3aae062952b1a9ab96ca74368f0c6de862..c6357f43e6b5f1caab63032d27a96bb30176ab3c 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
@@ -79,18 +79,27 @@ status_bar_clear_message(gpointer data)
        return false;
 }
 
+#ifndef NCMPC_MINI
+
+static void
+format_bitrate(char *p, size_t max_length, const struct mpd_status *status)
+{
+       if (options.visible_bitrate && mpd_status_get_kbit_rate(status) > 0)
+               g_snprintf(p, max_length,
+                          " [%d kbps]",
+                          mpd_status_get_kbit_rate(status));
+       else
+               p[0] = '\0';
+}
+
+#endif /* !NCMPC_MINI */
+
 void
 status_bar_paint(struct status_bar *p, const struct mpd_status *status,
                 const struct mpd_song *song)
 {
        WINDOW *w = p->window.w;
        enum mpd_state state;
-       int elapsedTime = 0;
-#ifdef NCMPC_MINI
-       static char bitrate[1];
-#else
-       char bitrate[16];
-#endif
        const char *str = NULL;
        int x = 0;
        char buffer[p->window.cols * 4 + 1];
@@ -129,29 +138,28 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status,
 
        /* create time string */
        if (state == MPD_STATE_PLAY || state == MPD_STATE_PAUSE) {
+               int elapsedTime = seek_id >= 0 &&
+                       seek_id == mpd_status_get_song_id(status)
+                       ? (unsigned)seek_target_time
+                       : mpd_status_get_elapsed_time(status);
                int total_time = mpd_status_get_total_time(status);
-               if (total_time > 0) {
+               if (elapsedTime > 0 || total_time > 0) {
+#ifdef NCMPC_MINI
+                       static const char bitrate[1];
+#else
+                       char bitrate[16];
+#endif
                        char elapsed_string[32], duration_string[32];
 
                        /*checks the conf to see whether to display elapsed or remaining time */
-                       if (song != NULL &&
-                           seek_id == (int)mpd_song_get_id(song))
-                               elapsedTime = seek_target_time;
-                       else if (options.display_remaining_time)
-                               elapsedTime = total_time -
-                                       mpd_status_get_elapsed_time(status);
-                       else
-                               elapsedTime = mpd_status_get_elapsed_time(status);
+                       if (options.display_remaining_time)
+                               elapsedTime = elapsedTime < total_time
+                                       ? total_time - elapsedTime
+                                       : 0;
 
                        /* display bitrate if visible-bitrate is true */
 #ifndef NCMPC_MINI
-                       if (options.visible_bitrate) {
-                               g_snprintf(bitrate, 16,
-                                          " [%d kbps]",
-                                          mpd_status_get_kbit_rate(status));
-                       } else {
-                               bitrate[0] = '\0';
-                       }
+                       format_bitrate(bitrate, sizeof(bitrate), status);
 #endif
 
                        /* write out the time */
@@ -165,13 +173,11 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status,
                        g_snprintf(buffer, sizeof(buffer), "%s [%s/%s]",
                                   bitrate, elapsed_string, duration_string);
 #ifndef NCMPC_MINI
-               } else if (options.visible_bitrate) {
-                       g_snprintf(buffer, sizeof(buffer),
-                                  " [%d kbps]",
-                                  mpd_status_get_kbit_rate(status));
-#endif
                } else {
+                       format_bitrate(buffer, sizeof(buffer), status);
+#else
                        buffer[0] = 0;
+#endif
                }
        } else {
 #ifndef NCMPC_MINI