diff options
-rw-r--r-- | src/browser.cpp | 4 | ||||
-rw-r--r-- | src/help.cpp | 1 | ||||
-rw-r--r-- | src/helpers.cpp | 4 | ||||
-rw-r--r-- | src/ncmpcpp.cpp | 6 | ||||
-rw-r--r-- | src/settings.cpp | 1 | ||||
-rw-r--r-- | src/settings.h | 1 | ||||
-rw-r--r-- | src/song.h | 2 |
7 files changed, 17 insertions, 2 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index d621a3fe..f1e7cff3 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -76,7 +76,6 @@ void Browser::SwitchTo() # ifndef WIN32 myBrowser->ChangeBrowseMode(); # endif // !WIN32 - return; } if (!isInitialized) @@ -85,6 +84,9 @@ void Browser::SwitchTo() if (hasToBeResized) Resize(); + if (isLocal()) // local browser doesn't support sorting by mtime + Config.browser_sort_by_mtime = 0; + w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList(); myScreen = this; RedrawHeader = 1; diff --git a/src/help.cpp b/src/help.cpp index ed0449c8..5cef44cc 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -230,6 +230,7 @@ void Help::GetKeybindings() # endif // HAVE_TAGLIB_H if (Mpd.GetHostname()[0] == '/') // are we connected to unix socket? *w << DisplayKeys(Key.Browser) << "Browse MPD database/local filesystem\n"; + *w << DisplayKeys(Key.SwitchTagTypeList) << "Toggle sort order\n"; *w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n"; *w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n"; *w << DisplayKeys(Key.Delete) << "Delete playlist/file/directory\n"; diff --git a/src/helpers.cpp b/src/helpers.cpp index e4089773..b0242085 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -233,7 +233,9 @@ bool CaseInsensitiveSorting::operator()(const Item &a, const Item &b) case itPlaylist: return cmp(a.name, b.name) < 0; case itSong: - return operator()(a.song, b.song); + return Config.browser_sort_by_mtime + ? a.song->GetMTime() > b.song->GetMTime() + : operator()(a.song, b.song); default: // there's no other type, just silence compiler. return 0; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index b31408f1..172c6786 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1808,6 +1808,12 @@ int main(int argc, char *argv[]) if (number && Mpd.AddRandomSongs(number)) ShowMessage("%zu random song%s added to playlist!", number, number == 1 ? "" : "s"); } + else if (myScreen == myBrowser && !myBrowser->isLocal()) + { + Config.browser_sort_by_mtime = !Config.browser_sort_by_mtime; + myBrowser->Main()->Sort<CaseInsensitiveSorting>(myBrowser->CurrentDir() != "/"); + ShowMessage("Sort songs by: %s", Config.browser_sort_by_mtime ? "Modification time" : "Name"); + } else if (myScreen->ActiveWindow() == myLibrary->Artists || (myLibrary->Columns() == 2 && myScreen->ActiveWindow() == myLibrary->Albums)) { diff --git a/src/settings.cpp b/src/settings.cpp index 9bf16d82..6bd9c7a8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -313,6 +313,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.mouse_support = true; conf.new_design = false; conf.visualizer_use_wave = true; + conf.browser_sort_by_mtime = false; conf.set_window_title = true; conf.mpd_port = 6600; conf.mpd_connection_timeout = 15; diff --git a/src/settings.h b/src/settings.h index 1580c19a..63f5800b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -207,6 +207,7 @@ struct ncmpcpp_config bool mouse_support; bool new_design; bool visualizer_use_wave; + bool browser_sort_by_mtime; int mpd_port; int mpd_connection_timeout; @@ -64,6 +64,8 @@ namespace MPD unsigned GetPosition() const { return mpd_song_get_pos(itsSong); } unsigned GetID() const { return mpd_song_get_id(itsSong); } + time_t GetMTime() const { return mpd_song_get_last_modified(itsSong); } + void SetArtist(const std::string &, unsigned = 0); void SetTitle(const std::string &, unsigned = 0); void SetAlbum(const std::string &, unsigned = 0); |