diff --git a/doc/config b/doc/config index 01b2c014..719539a3 100644 --- a/doc/config +++ b/doc/config @@ -179,6 +179,17 @@ #tag_editor_album_format = "{(%y) }%b" # ## +## Note: Below variables are used for sorting the library browser. +## The sort mode determines how the song library is sorted, and can +## be used in combination with a sort format to specify a custom sorting format. +## Possible values for sort_mode are "name", "mtime" and "format". +## +# +#sort_mode = "name" +# +#sort_format = "{%b~%n}|{~%n}|{~~%t}|{~~%f}" +# +## ## Note: Below variables are for alternative version of user's interface. ## Their syntax supports all tags and colors listed above plus some extra ## markers used for text attributes. They are followed by character '$'. diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 36630d63..bbd9eb21 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -131,6 +131,12 @@ Format for albums' list in Tag editor. .TP .B song_window_title_format Song format for window title. +.TP +.B sort_mode +Determines the sort mode for the song library. Possible values are "name", "mtime" and "format". +.TP +.B sort_format +Format to use for sorting the song library. For this option to be effective, sort_mode must be set to "format". .TP .B external_editor = PATH Path to external editor used to edit lyrics. @@ -295,7 +301,7 @@ If enabled, bitrate of currently playing song will be displayed in statusbar. If enabled, remaining time of currently playing song will be be displayed in statusbar instead of elapsed time. .TP .B ignore_leading_the = yes/no -If enabled, word "the" at the beginning of tags/filenames will be ignored while sorting items. +If enabled, word "the" at the beginning of tags/filenames will be ignored while sorting items. Note that this doesn't currently work with custom sorting formats. .TP .B use_console_editor = yes/no If your external editor is console application, you need to enable it. diff --git a/src/browser.cpp b/src/browser.cpp index 93a80ed1..6e866e1a 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -100,9 +100,6 @@ void Browser::SwitchTo() if (hasToBeResized || myLockedScreen) Resize(); - if (isLocal()) // local browser doesn't support sorting by mtime - Config.browser_sort_by_mtime = 0; - w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList(); if (myScreen != this && myScreen->isTabbable()) diff --git a/src/helpers.cpp b/src/helpers.cpp index 38922f03..c81b4b54 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -306,10 +306,16 @@ bool CaseInsensitiveSorting::operator()(const MPD::Item &a, const MPD::Item &b) return cmp(ExtractTopName(a.name), ExtractTopName(b.name)) < 0; case MPD::itPlaylist: return cmp(a.name, b.name) < 0; - case MPD::itSong: - return Config.browser_sort_by_mtime - ? a.song->GetMTime() > b.song->GetMTime() - : operator()(a.song, b.song); + case MPD::itSong: { + unsigned mode = Config.sort_mode; + if (myBrowser->isLocal() && mode == 1) mode = 0; // local browser doesn't support sorting by mtime. + switch (mode) { + case 0: return operator()(a.song, b.song); + case 1: return a.song->GetMTime() > b.song->GetMTime(); + case 2: return cmp(a.song->toString(Config.sort_format), b.song->toString(Config.sort_format)) < 0; + default: return 0; // no other mode. + } + } default: // there's no other type, just silence compiler. return 0; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 89930750..e175a55c 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2177,9 +2177,13 @@ int main(int argc, char **argv) } else if (myScreen == myBrowser && !myBrowser->isLocal()) { - Config.browser_sort_by_mtime = !Config.browser_sort_by_mtime; + Config.sort_mode = (Config.sort_mode + 1) % 3; myBrowser->Main()->Sort(myBrowser->CurrentDir() != "/"); - ShowMessage("Sort songs by: %s", Config.browser_sort_by_mtime ? "Modification time" : "Name"); + switch (Config.sort_mode) { + case 0: ShowMessage("Sort songs by: Name"); break; + case 1: ShowMessage("Sort songs by: Modification time"); break; + case 2: ShowMessage("Sort songs by: Custom format"); break; + } } else if (myScreen->ActiveWindow() == myLibrary->Artists || (myLibrary->Columns() == 2 && myScreen->ActiveWindow() == myLibrary->Albums)) diff --git a/src/settings.cpp b/src/settings.cpp index e8af2c29..c88505ac 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -372,6 +372,7 @@ void NcmpcppConfig::SetDefaults() song_status_format_no_colors = song_status_format; song_window_title_format = "{{%a - }{%t}|{%f}}"; song_library_format = "{{%n - }{%t}|{%f}}"; + sort_format = "{%b~%n}|{~%n}|{~~%t}|{~~%f}"; tag_editor_album_format = "{{(%y) }%b}"; new_header_first_line = "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/b}"; new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}"; @@ -444,7 +445,6 @@ void NcmpcppConfig::SetDefaults() new_design = false; visualizer_use_wave = true; visualizer_in_stereo = false; - browser_sort_by_mtime = false; tag_editor_extended_numeration = false; media_library_display_date = true; media_library_display_empty_tag = true; @@ -464,6 +464,7 @@ void NcmpcppConfig::SetDefaults() lines_scrolled = 2; search_engine_default_search_mode = 0; visualizer_sync_interval = 30; + sort_mode = 0; locked_screen_width_part = 0.5; selected_item_suffix_length = 0; now_playing_suffix_length = 0; @@ -853,6 +854,11 @@ void NcmpcppConfig::Read() tag_editor_album_format += '}'; } } + else if (name == "sort_format") + { + if (!v.empty()) + sort_format = v; + } else if (name == "external_editor") { if (!v.empty()) @@ -1232,6 +1238,12 @@ void NcmpcppConfig::Read() if (interval) visualizer_sync_interval = interval; } + else if (name == "sort_mode") + { + if (v == "mtime") sort_mode = 1; + else if (v == "format") sort_mode = 2; + else sort_mode = 0; // "name" or invalid + } else if (name == "locked_screen_width_part") { int part = StrToInt(v); diff --git a/src/settings.h b/src/settings.h index 79564f87..69562f97 100644 --- a/src/settings.h +++ b/src/settings.h @@ -168,6 +168,7 @@ struct NcmpcppConfig std::string song_library_format; std::string tag_editor_album_format; std::string song_in_columns_to_string_format; + std::string sort_format; std::string external_editor; std::string system_encoding; std::string execute_on_song_change; @@ -252,7 +253,6 @@ struct NcmpcppConfig bool new_design; bool visualizer_use_wave; bool visualizer_in_stereo; - bool browser_sort_by_mtime; bool tag_editor_extended_numeration; bool media_library_display_date; bool media_library_display_empty_tag; @@ -273,6 +273,7 @@ struct NcmpcppConfig unsigned lines_scrolled; unsigned search_engine_default_search_mode; unsigned visualizer_sync_interval; + unsigned sort_mode; double locked_screen_width_part;