new feature: sort songs in browser by mtime (optional)

This commit is contained in:
Andrzej Rybczak
2009-10-10 23:32:05 +02:00
parent b48133a743
commit 3551057dbb
7 changed files with 17 additions and 2 deletions

View File

@@ -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;

View File

@@ -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";

View File

@@ -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;
}

View File

@@ -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))
{

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);