actions: implement filtering playlist on priorities

This commit is contained in:
Andrzej Rybczak
2012-09-08 00:28:02 +02:00
parent 45a097a45b
commit a26b1f62f9
6 changed files with 42 additions and 7 deletions

View File

@@ -2204,9 +2204,9 @@ void SetSelectedItemsPriority::Run()
Statusbar() << "Set priority [0-255]: ";
std::string strprio = wFooter->getString();
UnlockStatusbar();
if (!isInteger(strprio.c_str()))
if (!isInteger(strprio.c_str(), true))
return;
int prio = atoi(strprio.c_str());
int prio = stringToInt(strprio);
if (prio < 0 || prio > 255)
{
ShowMessage("Number is out of range");
@@ -2215,6 +2215,29 @@ void SetSelectedItemsPriority::Run()
myPlaylist->SetSelectedItemsPriority(prio);
}
bool FilterPlaylistOnPriorities::canBeRun() const
{
return myScreen->ActiveWindow() == myPlaylist->Items;
}
void FilterPlaylistOnPriorities::Run()
{
using Global::wFooter;
LockStatusbar();
Statusbar() << "Show songs with priority higher than: ";
std::string strprio = wFooter->getString();
UnlockStatusbar();
if (!isInteger(strprio.c_str(), false))
return;
unsigned prio = stringToInt(strprio);
myPlaylist->Items->filter(myPlaylist->Items->begin(), myPlaylist->Items->end(),
[prio](const NC::Menu<MPD::Song>::Item &s) {
return s.value().getPrio() > prio;
});
ShowMessage("Playlist filtered (songs with priority higher than %u)", prio);
}
void ShowSongInfo::Run()
{
mySongInfo->SwitchTo();
@@ -2578,6 +2601,7 @@ void populateActions()
insertAction(new RefetchLyrics());
insertAction(new RefetchArtistInfo());
insertAction(new SetSelectedItemsPriority());
insertAction(new FilterPlaylistOnPriorities());
insertAction(new ShowSongInfo());
insertAction(new ShowArtistInfo());
insertAction(new ShowLyrics());