{Queue,FileList}Page: show total duration of range selection in status bar
authorMax Kellermann <max@musicpd.org>
Wed, 10 Apr 2019 08:41:09 +0000 (10:41 +0200)
committerMax Kellermann <max@musicpd.org>
Wed, 10 Apr 2019 08:41:09 +0000 (10:41 +0200)
Closes https://github.com/MusicPlayerDaemon/ncmpc/issues/46

NEWS
src/FileListPage.cxx
src/FileListPage.hxx
src/QueuePage.cxx

diff --git a/NEWS b/NEWS
index 8973057..9edda54 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 ncmpc 0.34 - not yet released
+* show total duration of range selection in status bar
 * fix high CPU usage in key bindings check
 * fix high CPU usage during text input
 * fix background color "none"
index b5cbd37..cb92f75 100644 (file)
@@ -35,6 +35,7 @@
 #include "Styles.hxx"
 #include "paint.hxx"
 #include "song_paint.hxx"
+#include "time_format.hxx"
 #include "util/UriUtil.hxx"
 
 #include <mpd/client.h>
@@ -533,3 +534,38 @@ FileListPage::Paint() const noexcept
 {
        lw.Paint(*this);
 }
+
+bool
+FileListPage::PaintStatusBarOverride(const Window &window) const noexcept
+{
+       if (!lw.HasRangeSelection())
+               return false;
+
+       WINDOW *const w = window.w;
+
+       wmove(w, 0, 0);
+       wclrtoeol(w);
+
+       unsigned duration = 0;
+
+       assert(filelist != nullptr);
+       for (const unsigned i : lw.GetRange()) {
+               assert(i < filelist->size());
+               const auto &entry = (*filelist)[i];
+
+               if (mpd_entity_get_type(entry.entity) == MPD_ENTITY_TYPE_SONG)
+                       duration += mpd_song_get_duration(mpd_entity_get_song(entry.entity));
+       }
+
+       char duration_string[32];
+       format_duration_short(duration_string, sizeof(duration_string),
+                             duration);
+       const unsigned duration_width = strlen(duration_string);
+
+       SelectStyle(w, Style::STATUS_TIME);
+       mvwaddstr(w, 0, window.size.width - duration_width, duration_string);
+
+       wnoutrefresh(w);
+
+       return true;
+}
index ae941ff..2b67daa 100644 (file)
@@ -85,6 +85,7 @@ private:
 public:
        /* virtual methods from class Page */
        void Paint() const noexcept override;
+       bool PaintStatusBarOverride(const Window &window) const noexcept override;
        bool OnCommand(struct mpdclient &c, Command cmd) override;
 
 #ifdef HAVE_GETMOUSE
index 6c698f1..bdbb8f3 100644 (file)
@@ -35,6 +35,7 @@
 #include "Completion.hxx"
 #include "Styles.hxx"
 #include "song_paint.hxx"
+#include "time_format.hxx"
 #include "screen.hxx"
 #include "screen_utils.hxx"
 #include "SongPage.hxx"
@@ -131,6 +132,7 @@ public:
        void OnOpen(struct mpdclient &c) noexcept override;
        void OnClose() noexcept override;
        void Paint() const noexcept override;
+       bool PaintStatusBarOverride(const Window &window) const noexcept override;
        void Update(struct mpdclient &c, unsigned events) noexcept override;
        bool OnCommand(struct mpdclient &c, Command cmd) override;
 
@@ -409,6 +411,40 @@ QueuePage::Paint() const noexcept
        lw.Paint(*this);
 }
 
+bool
+QueuePage::PaintStatusBarOverride(const Window &window) const noexcept
+{
+       if (!lw.HasRangeSelection())
+               return false;
+
+       WINDOW *const w = window.w;
+
+       wmove(w, 0, 0);
+       wclrtoeol(w);
+
+       unsigned duration = 0;
+
+       assert(playlist != nullptr);
+       for (const unsigned i : lw.GetRange()) {
+               assert(i < playlist->size());
+               const auto &song = (*playlist)[i];
+
+               duration += mpd_song_get_duration(&song);
+       }
+
+       char duration_string[32];
+       format_duration_short(duration_string, sizeof(duration_string),
+                             duration);
+       const unsigned duration_width = strlen(duration_string);
+
+       SelectStyle(w, Style::STATUS_TIME);
+       mvwaddstr(w, 0, window.size.width - duration_width, duration_string);
+
+       wnoutrefresh(w);
+
+       return true;
+}
+
 void
 QueuePage::Update(struct mpdclient &c, unsigned events) noexcept
 {