LibraryPage: make tag list configurable
authorMax Kellermann <max@musicpd.org>
Wed, 17 Oct 2018 15:49:23 +0000 (17:49 +0200)
committerMax Kellermann <max@musicpd.org>
Wed, 17 Oct 2018 15:49:23 +0000 (17:49 +0200)
NEWS
doc/config.sample
doc/index.rst
src/LibraryPage.cxx
src/Options.hxx
src/conf.cxx

diff --git a/NEWS b/NEWS
index 6819c10..2e09aa6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
 ncmpc 0.33 - not yet released
 * artist page: rename to "library"
+* library page: make tag list configurable
 * fix color configuration parser bug
 * fix build failure when libpcre is not found
 * remove support for liblircclient (only liblirc)
index 2f78de2..e4f4351 100644 (file)
@@ -19,6 +19,9 @@
 ## Enable mouse support (if enabled at compile time).
 #enable-mouse = no
 
+# Which tags shall be grouped on the library page?
+#library-page-tags = artist album
+
 ## A list of screens to cycle through when using
 ## the previous/next screen commands (tab and shift+tab).
 ## names: playlist browse help library search song keydef lyrics outputs chat
index 23ef231..b13e426 100644 (file)
@@ -114,6 +114,9 @@ cycle through when using the previous/next screen commands.  Valid
 choices, if enabled at compile time, are playlist, browse, library,
 help, search, song, keydef, lyrics, outputs, and chat.
 
+:command:`library-page-tags = TAG1 TAG2 ...` - A list of tags to group
+the library page.  The default is ``artist album``.
+
 :command:`search-mode = MODE` - Default search mode for the search
 screen. MODE must be one of title, artist, album, filename, and
 artist+title, or an interger index (0 for title, 1 for artist etc.).
index d2c8ffe..8efa7b1 100644 (file)
@@ -117,14 +117,16 @@ public:
                :ProxyPage(_w),
                 song_list_page(_screen, this,
                                _w, size) {
-               tag_list_pages.emplace_back(_screen, nullptr,
-                                           MPD_TAG_ARTIST,
-                                           nullptr,
-                                           _w, size);
-               tag_list_pages.emplace_back(_screen, this,
-                                           MPD_TAG_ALBUM,
-                                           _("All tracks"),
-                                           _w, size);
+
+               bool first = true;
+               for (const auto &tag : options.library_page_tags) {
+                       tag_list_pages.emplace_back(_screen,
+                                                   first ? nullptr : this,
+                                                   tag,
+                                                   first ? nullptr : _("All"),
+                                                   _w, size);
+                       first = false;
+               }
        }
 
 private:
index f44e6f9..7310dcf 100644 (file)
@@ -23,6 +23,8 @@
 #include "config.h"
 #include "defaults.hxx"
 
+#include <mpd/tag.h>
+
 #include <vector>
 #include <string>
 #include <chrono>
@@ -47,6 +49,11 @@ struct Options {
        int search_mode;
        std::chrono::steady_clock::duration hide_cursor;
        int seek_time = 1;
+
+#ifdef ENABLE_LIBRARY_PAGE
+       std::vector<enum mpd_tag_type> library_page_tags{MPD_TAG_ARTIST, MPD_TAG_ALBUM};
+#endif
+
 #ifdef ENABLE_LYRICS_SCREEN
        std::chrono::steady_clock::duration lyrics_timeout = std::chrono::minutes(1);
        bool lyrics_autosave = false;
index 37f5775..1a899ab 100644 (file)
@@ -74,6 +74,7 @@
 #define CONF_SEARCH_MODE "search-mode"
 #define CONF_HIDE_CURSOR "hide-cursor"
 #define CONF_SEEK_TIME "seek-time"
+#define CONF_LIBRARY_PAGE_TAGS "library-page-tags"
 #define CONF_SCREEN_LIST "screen-list"
 #define CONF_TIMEDISPLAY_TYPE "timedisplay-type"
 #define CONF_HOST "host"
@@ -378,6 +379,32 @@ check_screen_list(char *value)
        return screen;
 }
 
+#ifdef ENABLE_LIBRARY_PAGE
+
+static auto
+ParseTagList(char *value)
+{
+       std::vector<enum mpd_tag_type> result;
+
+       while (char *name = NextItem(value)) {
+               auto type = mpd_tag_name_iparse(name);
+               if (type == MPD_TAG_UNKNOWN) {
+                       print_error(_("Unknown MPD tag"), name);
+                       result.clear();
+                       return result;
+               }
+
+               result.emplace_back(type);
+       }
+
+       if (result.empty())
+               fprintf(stderr, "Empty tag list\n");
+
+       return result;
+}
+
+#endif
+
 static int
 get_search_mode(char *value)
 {
@@ -523,7 +550,13 @@ parse_line(char *line)
                options.hide_cursor = std::chrono::seconds(atoi(value));
        else if (!strcasecmp(CONF_SEEK_TIME, name))
                options.seek_time = atoi(value);
-       else if (!strcasecmp(CONF_SCREEN_LIST, name)) {
+       else if (!strcasecmp(CONF_LIBRARY_PAGE_TAGS, name)) {
+#ifdef ENABLE_LIBRARY_PAGE
+               options.library_page_tags = ParseTagList(value);
+               if (options.library_page_tags.empty())
+                       return false;
+#endif
+       } else if (!strcasecmp(CONF_SCREEN_LIST, name)) {
                options.screen_list = check_screen_list(value);
        } else if (!strcasecmp(CONF_HOST, name))
                options.host = GetStringValue(value);