make sorting window use main ncmpcpp loop
This commit is contained in:
@@ -417,9 +417,9 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
||||
case itSong:
|
||||
{
|
||||
bool bold = 0;
|
||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); ++i)
|
||||
for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
|
||||
{
|
||||
if (myPlaylist->Main()->at(i).GetHash() == it->song->GetHash())
|
||||
if (myPlaylist->Items->at(i).GetHash() == it->song->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -492,9 +492,9 @@ void Browser::UpdateItemList()
|
||||
{
|
||||
if (w->at(i).type == itSong)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Main()->Size(); ++j)
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if (myPlaylist->Main()->at(j).GetHash() == w->at(i).song->GetHash())
|
||||
if (myPlaylist->Items->at(j).GetHash() == w->at(i).song->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
|
||||
@@ -65,7 +65,7 @@ void Clock::Resize()
|
||||
{
|
||||
if (myPlaylist->hasToBeResized)
|
||||
myPlaylist->Resize();
|
||||
myPlaylist->Main()->Hide();
|
||||
myPlaylist->Items->Hide();
|
||||
w->Display();
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ void Clock::SwitchTo()
|
||||
Resize();
|
||||
|
||||
myScreen = this;
|
||||
myPlaylist->Main()->Hide();
|
||||
myPlaylist->Items->Hide();
|
||||
RedrawHeader = 1;
|
||||
Prepare();
|
||||
// clearing screen apparently fixes the problem with last digits being misrendered
|
||||
|
||||
@@ -245,9 +245,9 @@ void UpdateSongList(Menu<Song> *menu)
|
||||
bool bold = 0;
|
||||
for (size_t i = 0; i < menu->Size(); ++i)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Main()->Size(); ++j)
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if (myPlaylist->Main()->at(j).GetHash() == menu->at(i).GetHash())
|
||||
if (myPlaylist->Items->at(j).GetHash() == menu->at(i).GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
|
||||
@@ -303,9 +303,9 @@ void MediaLibrary::Update()
|
||||
|
||||
for (SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Main()->Size(); ++j)
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if ((*it)->GetHash() == myPlaylist->Main()->at(j).GetHash())
|
||||
if ((*it)->GetHash() == myPlaylist->Items->at(j).GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
|
||||
178
src/ncmpcpp.cpp
178
src/ncmpcpp.cpp
@@ -52,7 +52,7 @@
|
||||
#include "visualizer.h"
|
||||
|
||||
#define CHECK_PLAYLIST_FOR_FILTERING \
|
||||
if (myPlaylist->Main()->isFiltered()) \
|
||||
if (myPlaylist->Items->isFiltered()) \
|
||||
{ \
|
||||
ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled); \
|
||||
continue; \
|
||||
@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
TraceMpdStatus();
|
||||
if (myPlaylist->isPlaying())
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
myPlaylist->Items->Highlight(myPlaylist->NowPlaying);
|
||||
}
|
||||
|
||||
while (!main_exit)
|
||||
@@ -545,18 +545,18 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.Delete))
|
||||
{
|
||||
if (!myPlaylist->Main()->Empty() && myScreen == myPlaylist)
|
||||
if (!myPlaylist->Items->Empty() && myScreen == myPlaylist)
|
||||
{
|
||||
Playlist::BlockUpdate = 1;
|
||||
if (myPlaylist->Main()->hasSelected())
|
||||
if (myPlaylist->Items->hasSelected())
|
||||
{
|
||||
std::vector<size_t> list;
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
myPlaylist->Items->GetSelected(list);
|
||||
Mpd.StartCommandsList();
|
||||
for (std::vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); ++it)
|
||||
{
|
||||
Mpd.DeleteID((*myPlaylist->Main())[*it].GetID());
|
||||
myPlaylist->Main()->DeleteOption(*it);
|
||||
Mpd.DeleteID((*myPlaylist->Items)[*it].GetID());
|
||||
myPlaylist->Items->DeleteOption(*it);
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
myPlaylist->FixPositions(list.front());
|
||||
@@ -565,11 +565,11 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
Playlist::BlockNowPlayingUpdate = 1;
|
||||
myPlaylist->Main()->SetTimeout(50);
|
||||
myPlaylist->Items->SetTimeout(50);
|
||||
int del_counter = 0;
|
||||
while (!myPlaylist->Main()->Empty() && Keypressed(input, Key.Delete))
|
||||
while (!myPlaylist->Items->Empty() && Keypressed(input, Key.Delete))
|
||||
{
|
||||
size_t id = myPlaylist->Main()->Choice();
|
||||
size_t id = myPlaylist->Items->Choice();
|
||||
TraceMpdStatus();
|
||||
Playlist::BlockUpdate = 1;
|
||||
myPlaylist->UpdateTimer();
|
||||
@@ -577,13 +577,13 @@ int main(int argc, char *argv[])
|
||||
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()-del_counter)
|
||||
myPlaylist->NowPlaying--;
|
||||
Mpd.DeleteID(myPlaylist->CurrentSong()->GetID());
|
||||
myPlaylist->Main()->DeleteOption(id);
|
||||
myPlaylist->Main()->Refresh();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->DeleteOption(id);
|
||||
myPlaylist->Items->Refresh();
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
del_counter++;
|
||||
}
|
||||
myPlaylist->FixPositions(myPlaylist->Main()->Choice());
|
||||
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
|
||||
myPlaylist->FixPositions(myPlaylist->Items->Choice());
|
||||
myPlaylist->Items->SetTimeout(ncmpcpp_window_timeout);
|
||||
Playlist::BlockNowPlayingUpdate = 0;
|
||||
}
|
||||
}
|
||||
@@ -738,11 +738,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
if (!playlist_name.empty())
|
||||
{
|
||||
if (myPlaylist->Main()->isFiltered())
|
||||
if (myPlaylist->Items->isFiltered())
|
||||
{
|
||||
Mpd.StartCommandsList();
|
||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); ++i)
|
||||
Mpd.AddToPlaylist(real_playlist_name, (*myPlaylist->Main())[i]);
|
||||
for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
|
||||
Mpd.AddToPlaylist(real_playlist_name, (*myPlaylist->Items)[i]);
|
||||
Mpd.CommitCommandsList();
|
||||
if (Mpd.GetErrorMessage().empty())
|
||||
ShowMessage("Filtered items added to playlist \"%s\"", playlist_name.c_str());
|
||||
@@ -796,18 +796,20 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.MvSongUp))
|
||||
{
|
||||
if (myScreen == myPlaylist && !myPlaylist->Main()->Empty())
|
||||
if (myScreen == myPlaylist && myPlaylist->SortingInProgress())
|
||||
myPlaylist->AdjustSortOrder(input);
|
||||
else if (myScreen == myPlaylist && !myPlaylist->Items->Empty())
|
||||
{
|
||||
CHECK_PLAYLIST_FOR_FILTERING;
|
||||
myPlaylist->Main()->SetTimeout(50);
|
||||
if (myPlaylist->Main()->hasSelected())
|
||||
myPlaylist->Items->SetTimeout(50);
|
||||
if (myPlaylist->Items->hasSelected())
|
||||
{
|
||||
std::vector<size_t> list;
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
myPlaylist->Items->GetSelected(list);
|
||||
|
||||
for (std::vector<size_t>::iterator it = list.begin(); it != list.end(); ++it)
|
||||
if (*it == size_t(myPlaylist->NowPlaying) && list.front() > 0)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
myPlaylist->Items->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
|
||||
std::vector<size_t> origs(list);
|
||||
|
||||
@@ -819,13 +821,13 @@ int main(int argc, char *argv[])
|
||||
for (std::vector<size_t>::iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
--*it;
|
||||
myPlaylist->Main()->at((*it)+1).SetPosition(*it);
|
||||
myPlaylist->Main()->at(*it).SetPosition((*it)+1);
|
||||
myPlaylist->Main()->Swap(*it, (*it)+1);
|
||||
myPlaylist->Items->at((*it)+1).SetPosition(*it);
|
||||
myPlaylist->Items->at(*it).SetPosition((*it)+1);
|
||||
myPlaylist->Items->Swap(*it, (*it)+1);
|
||||
}
|
||||
myPlaylist->Main()->Highlight(list[(list.size()-1)/2]);
|
||||
myPlaylist->Main()->Refresh();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->Highlight(list[(list.size()-1)/2]);
|
||||
myPlaylist->Items->Refresh();
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
}
|
||||
Mpd.StartCommandsList();
|
||||
for (size_t i = 0; i < list.size(); ++i)
|
||||
@@ -835,27 +837,27 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
size_t from, to;
|
||||
from = to = myPlaylist->Main()->Choice();
|
||||
from = to = myPlaylist->Items->Choice();
|
||||
// unbold now playing as if song changes during move, this won't be unbolded.
|
||||
if (to == size_t(myPlaylist->NowPlaying) && to > 0)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
myPlaylist->Items->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
while (Keypressed(input, Key.MvSongUp) && to > 0)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
Playlist::BlockUpdate = 1;
|
||||
myPlaylist->UpdateTimer();
|
||||
--to;
|
||||
myPlaylist->Main()->at(from).SetPosition(to);
|
||||
myPlaylist->Main()->at(to).SetPosition(from);
|
||||
myPlaylist->Main()->Swap(to, to+1);
|
||||
myPlaylist->Main()->Scroll(wUp);
|
||||
myPlaylist->Main()->Refresh();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->at(from).SetPosition(to);
|
||||
myPlaylist->Items->at(to).SetPosition(from);
|
||||
myPlaylist->Items->Swap(to, to+1);
|
||||
myPlaylist->Items->Scroll(wUp);
|
||||
myPlaylist->Items->Refresh();
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
}
|
||||
Mpd.Move(from, to);
|
||||
UpdateStatusImmediately = 1;
|
||||
}
|
||||
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
|
||||
myPlaylist->Items->SetTimeout(ncmpcpp_window_timeout);
|
||||
}
|
||||
else if (myScreen->ActiveWindow() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
|
||||
{
|
||||
@@ -908,22 +910,24 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.MvSongDown))
|
||||
{
|
||||
if (myScreen == myPlaylist && !myPlaylist->Main()->Empty())
|
||||
if (myScreen == myPlaylist && myPlaylist->SortingInProgress())
|
||||
myPlaylist->AdjustSortOrder(input);
|
||||
else if (myScreen == myPlaylist && !myPlaylist->Items->Empty())
|
||||
{
|
||||
CHECK_PLAYLIST_FOR_FILTERING;
|
||||
myPlaylist->Main()->SetTimeout(50);
|
||||
if (myPlaylist->Main()->hasSelected())
|
||||
myPlaylist->Items->SetTimeout(50);
|
||||
if (myPlaylist->Items->hasSelected())
|
||||
{
|
||||
std::vector<size_t> list;
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
myPlaylist->Items->GetSelected(list);
|
||||
|
||||
for (std::vector<size_t>::iterator it = list.begin(); it != list.end(); ++it)
|
||||
if (*it == size_t(myPlaylist->NowPlaying) && list.back() < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
if (*it == size_t(myPlaylist->NowPlaying) && list.back() < myPlaylist->Items->Size()-1)
|
||||
myPlaylist->Items->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
|
||||
std::vector<size_t> origs(list);
|
||||
|
||||
while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylist->Main()->Size()-1)
|
||||
while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylist->Items->Size()-1)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
Playlist::BlockUpdate = 1;
|
||||
@@ -931,13 +935,13 @@ int main(int argc, char *argv[])
|
||||
for (std::vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); ++it)
|
||||
{
|
||||
++*it;
|
||||
myPlaylist->Main()->at((*it)-1).SetPosition(*it);
|
||||
myPlaylist->Main()->at(*it).SetPosition((*it)-1);
|
||||
myPlaylist->Main()->Swap(*it, (*it)-1);
|
||||
myPlaylist->Items->at((*it)-1).SetPosition(*it);
|
||||
myPlaylist->Items->at(*it).SetPosition((*it)-1);
|
||||
myPlaylist->Items->Swap(*it, (*it)-1);
|
||||
}
|
||||
myPlaylist->Main()->Highlight(list[(list.size()-1)/2]);
|
||||
myPlaylist->Main()->Refresh();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->Highlight(list[(list.size()-1)/2]);
|
||||
myPlaylist->Items->Refresh();
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
}
|
||||
Mpd.StartCommandsList();
|
||||
for (int i = list.size()-1; i >= 0; --i)
|
||||
@@ -947,27 +951,27 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
size_t from, to;
|
||||
from = to = myPlaylist->Main()->Choice();
|
||||
from = to = myPlaylist->Items->Choice();
|
||||
// unbold now playing as if song changes during move, this won't be unbolded.
|
||||
if (to == size_t(myPlaylist->NowPlaying) && to < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
while (Keypressed(input, Key.MvSongDown) && to < myPlaylist->Main()->Size()-1)
|
||||
if (to == size_t(myPlaylist->NowPlaying) && to < myPlaylist->Items->Size()-1)
|
||||
myPlaylist->Items->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
while (Keypressed(input, Key.MvSongDown) && to < myPlaylist->Items->Size()-1)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
Playlist::BlockUpdate = 1;
|
||||
myPlaylist->UpdateTimer();
|
||||
++to;
|
||||
myPlaylist->Main()->at(from).SetPosition(to);
|
||||
myPlaylist->Main()->at(to).SetPosition(from);
|
||||
myPlaylist->Main()->Swap(to, to-1);
|
||||
myPlaylist->Main()->Scroll(wDown);
|
||||
myPlaylist->Main()->Refresh();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->at(from).SetPosition(to);
|
||||
myPlaylist->Items->at(to).SetPosition(from);
|
||||
myPlaylist->Items->Swap(to, to-1);
|
||||
myPlaylist->Items->Scroll(wDown);
|
||||
myPlaylist->Items->Refresh();
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
}
|
||||
Mpd.Move(from, to);
|
||||
UpdateStatusImmediately = 1;
|
||||
}
|
||||
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
|
||||
myPlaylist->Items->SetTimeout(ncmpcpp_window_timeout);
|
||||
|
||||
}
|
||||
else if (myScreen->ActiveWindow() == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
|
||||
@@ -1022,18 +1026,18 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.MoveTo) && myScreen == myPlaylist)
|
||||
{
|
||||
CHECK_PLAYLIST_FOR_FILTERING;
|
||||
if (!myPlaylist->Main()->hasSelected())
|
||||
if (!myPlaylist->Items->hasSelected())
|
||||
{
|
||||
ShowMessage("No selected items to move!");
|
||||
continue;
|
||||
}
|
||||
Playlist::BlockUpdate = 1;
|
||||
size_t pos = myPlaylist->Main()->Choice();
|
||||
size_t pos = myPlaylist->Items->Choice();
|
||||
// if cursor is at the last item, break convention and move at the end of playlist
|
||||
if (pos == myPlaylist->Main()->Size()-1)
|
||||
if (pos == myPlaylist->Items->Size()-1)
|
||||
pos++;
|
||||
std::vector<size_t> list;
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
myPlaylist->Items->GetSelected(list);
|
||||
if (pos >= list.front() && pos <= list.back())
|
||||
continue;
|
||||
int diff = pos-list.front();
|
||||
@@ -1045,7 +1049,7 @@ int main(int argc, char *argv[])
|
||||
for (std::vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); ++it, --i)
|
||||
{
|
||||
Mpd.Move(*it, pos+i);
|
||||
myPlaylist->Main()->Move(*it, pos+i);
|
||||
myPlaylist->Items->Move(*it, pos+i);
|
||||
}
|
||||
}
|
||||
else if (diff < 0)
|
||||
@@ -1054,11 +1058,11 @@ int main(int argc, char *argv[])
|
||||
for (std::vector<size_t>::const_iterator it = list.begin(); it != list.end(); ++it, ++i)
|
||||
{
|
||||
Mpd.Move(*it, pos+i);
|
||||
myPlaylist->Main()->Move(*it, pos+i);
|
||||
myPlaylist->Items->Move(*it, pos+i);
|
||||
}
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
myPlaylist->Main()->Highlight(pos);
|
||||
myPlaylist->Items->Highlight(pos);
|
||||
myPlaylist->FixPositions();
|
||||
}
|
||||
else if (Keypressed(input, Key.Add))
|
||||
@@ -1105,7 +1109,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
TraceMpdStatus();
|
||||
myPlaylist->UpdateTimer();
|
||||
myPlaylist->Main()->ReadKey(input);
|
||||
myPlaylist->Items->ReadKey(input);
|
||||
|
||||
int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
|
||||
|
||||
@@ -1179,15 +1183,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (Config.columns_in_playlist)
|
||||
{
|
||||
myPlaylist->Main()->SetItemDisplayer(Display::SongsInColumns);
|
||||
myPlaylist->Main()->SetTitle(Display::Columns());
|
||||
myPlaylist->Main()->SetGetStringFunction(Playlist::SongInColumnsToString);
|
||||
myPlaylist->Items->SetItemDisplayer(Display::SongsInColumns);
|
||||
myPlaylist->Items->SetTitle(Display::Columns());
|
||||
myPlaylist->Items->SetGetStringFunction(Playlist::SongInColumnsToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
myPlaylist->Main()->SetItemDisplayer(Display::Songs);
|
||||
myPlaylist->Main()->SetTitle("");
|
||||
myPlaylist->Main()->SetGetStringFunction(Playlist::SongToString);
|
||||
myPlaylist->Items->SetItemDisplayer(Display::Songs);
|
||||
myPlaylist->Items->SetTitle("");
|
||||
myPlaylist->Items->SetGetStringFunction(Playlist::SongToString);
|
||||
}
|
||||
}
|
||||
else if (myScreen == myBrowser)
|
||||
@@ -1220,8 +1224,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Config.autocenter_mode = !Config.autocenter_mode;
|
||||
ShowMessage("Auto center mode: %s", Config.autocenter_mode ? "On" : "Off");
|
||||
if (Config.autocenter_mode && myPlaylist->isPlaying() && !myPlaylist->Main()->isFiltered())
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
if (Config.autocenter_mode && myPlaylist->isPlaying() && !myPlaylist->Items->isFiltered())
|
||||
myPlaylist->Items->Highlight(myPlaylist->NowPlaying);
|
||||
}
|
||||
else if (Keypressed(input, Key.UpdateDB))
|
||||
{
|
||||
@@ -1239,7 +1243,7 @@ int main(int argc, char *argv[])
|
||||
if (myScreen == myPlaylist && myPlaylist->isPlaying())
|
||||
{
|
||||
CHECK_PLAYLIST_FOR_FILTERING;
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
myPlaylist->Items->Highlight(myPlaylist->NowPlaying);
|
||||
}
|
||||
else if (myScreen == myBrowser)
|
||||
{
|
||||
@@ -1552,17 +1556,17 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.Crop))
|
||||
{
|
||||
CHECK_PLAYLIST_FOR_FILTERING;
|
||||
if (myPlaylist->Main()->hasSelected())
|
||||
if (myPlaylist->Items->hasSelected())
|
||||
{
|
||||
Mpd.StartCommandsList();
|
||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; --i)
|
||||
for (int i = myPlaylist->Items->Size()-1; i >= 0; --i)
|
||||
{
|
||||
if (!myPlaylist->Main()->isSelected(i) && i != myPlaylist->NowPlaying)
|
||||
if (!myPlaylist->Items->isSelected(i) && i != myPlaylist->NowPlaying)
|
||||
Mpd.Delete(i);
|
||||
}
|
||||
// if mpd deletes now playing song deletion will be sluggishly slow
|
||||
// then so we have to assure it will be deleted at the very end.
|
||||
if (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
|
||||
if (myPlaylist->isPlaying() && !myPlaylist->Items->isSelected(myPlaylist->NowPlaying))
|
||||
Mpd.DeleteID(myPlaylist->NowPlayingSong()->GetID());
|
||||
|
||||
ShowMessage("Deleting all items but selected...");
|
||||
@@ -1577,7 +1581,7 @@ int main(int argc, char *argv[])
|
||||
continue;
|
||||
}
|
||||
Mpd.StartCommandsList();
|
||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; --i)
|
||||
for (int i = myPlaylist->Items->Size()-1; i >= 0; --i)
|
||||
if (i != myPlaylist->NowPlaying)
|
||||
Mpd.Delete(i);
|
||||
ShowMessage("Deleting all items except now playing one...");
|
||||
@@ -1616,12 +1620,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (myPlaylist->Main()->isFiltered())
|
||||
if (myPlaylist->Items->isFiltered())
|
||||
{
|
||||
ShowMessage("Deleting filtered items...");
|
||||
Mpd.StartCommandsList();
|
||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; --i)
|
||||
Mpd.Delete((*myPlaylist->Main())[i].GetPosition());
|
||||
for (int i = myPlaylist->Items->Size()-1; i >= 0; --i)
|
||||
Mpd.Delete((*myPlaylist->Items)[i].GetPosition());
|
||||
Mpd.CommitCommandsList();
|
||||
ShowMessage("Filtered items deleted!");
|
||||
}
|
||||
|
||||
353
src/playlist.cpp
353
src/playlist.cpp
@@ -37,28 +37,29 @@ bool Playlist::ReloadRemaining = 0;
|
||||
|
||||
bool Playlist::BlockNowPlayingUpdate = 0;
|
||||
bool Playlist::BlockUpdate = 0;
|
||||
bool Playlist::BlockRefreshing = 0;
|
||||
|
||||
Menu< std::pair<std::string, MPD::Song::GetFunction> > *Playlist::SortDialog;
|
||||
|
||||
const size_t Playlist::SortOptions = 10;
|
||||
const size_t Playlist::SortDialogWidth = 30;
|
||||
size_t Playlist::SortDialogHeight;
|
||||
|
||||
Menu< std::pair<std::string, MPD::Song::GetFunction> > *Playlist::SortDialog = 0;
|
||||
|
||||
void Playlist::Init()
|
||||
{
|
||||
w = new Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist ? Display::Columns() : "", Config.main_color, brNone);
|
||||
w->SetTimeout(ncmpcpp_window_timeout);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
w->SetItemDisplayer(Config.columns_in_playlist ? Display::SongsInColumns : Display::Songs);
|
||||
w->SetItemDisplayerUserData(&Config.song_list_format);
|
||||
w->SetGetStringFunction(Config.columns_in_playlist ? SongInColumnsToString : SongToString);
|
||||
w->SetGetStringFunctionUserData(&Config.song_list_format);
|
||||
Items = new Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist ? Display::Columns() : "", Config.main_color, brNone);
|
||||
Items->SetTimeout(ncmpcpp_window_timeout);
|
||||
Items->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Items->HighlightColor(Config.main_highlight_color);
|
||||
Items->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Items->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Items->SetItemDisplayer(Config.columns_in_playlist ? Display::SongsInColumns : Display::Songs);
|
||||
Items->SetItemDisplayerUserData(&Config.song_list_format);
|
||||
Items->SetGetStringFunction(Config.columns_in_playlist ? SongInColumnsToString : SongToString);
|
||||
Items->SetGetStringFunctionUserData(&Config.song_list_format);
|
||||
|
||||
SortDialogHeight = std::min(int(MainHeight-2), 18);
|
||||
if (!SortDialog)
|
||||
{
|
||||
SortDialogHeight = std::min(int(MainHeight), 18);
|
||||
|
||||
SortDialog = new Menu< std::pair<std::string, MPD::Song::GetFunction> >((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY, SortDialogWidth, SortDialogHeight, "Sort songs by...", Config.main_color, Config.window_border);
|
||||
SortDialog->SetTimeout(ncmpcpp_window_timeout);
|
||||
@@ -79,7 +80,9 @@ void Playlist::Init()
|
||||
SortDialog->AddOption(std::make_pair("Sort", static_cast<MPD::Song::GetFunction>(0)));
|
||||
SortDialog->AddOption(std::make_pair("Reverse", static_cast<MPD::Song::GetFunction>(0)));
|
||||
SortDialog->AddOption(std::make_pair("Cancel", static_cast<MPD::Song::GetFunction>(0)));
|
||||
}
|
||||
|
||||
w = Items;
|
||||
isInitialized = 1;
|
||||
}
|
||||
|
||||
@@ -97,20 +100,30 @@ void Playlist::SwitchTo()
|
||||
Resize();
|
||||
|
||||
myScreen = this;
|
||||
w->Window::Clear();
|
||||
Items->Window::Clear();
|
||||
EnableHighlighting();
|
||||
if (w != Items) // even if sorting window is active, background has to be refreshed anyway
|
||||
Items->Display();
|
||||
RedrawHeader = 1;
|
||||
}
|
||||
|
||||
void Playlist::Resize()
|
||||
{
|
||||
w->Resize(COLS, MainHeight);
|
||||
w->MoveTo(0, MainStartY);
|
||||
w->SetTitle(Config.columns_in_playlist ? Display::Columns() : "");
|
||||
Items->Resize(COLS, MainHeight);
|
||||
Items->MoveTo(0, MainStartY);
|
||||
Items->SetTitle(Config.columns_in_playlist ? Display::Columns() : "");
|
||||
if (w == SortDialog) // if sorting window is active, playlist needs refreshing
|
||||
Items->Display();
|
||||
|
||||
SortDialogHeight = std::min(int(MainHeight), 18);
|
||||
if (MainHeight > 5)
|
||||
if (Items->GetWidth() >= SortDialogWidth && MainHeight >= 5)
|
||||
{
|
||||
SortDialog->Resize(SortDialogWidth, SortDialogHeight);
|
||||
SortDialog->MoveTo((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY);
|
||||
}
|
||||
else // if screen is too low to display sorting window, fall back to items list
|
||||
w = Items;
|
||||
|
||||
hasToBeResized = 0;
|
||||
}
|
||||
|
||||
@@ -119,166 +132,59 @@ std::basic_string<my_char_t> Playlist::Title()
|
||||
std::basic_string<my_char_t> result = U("Playlist ");
|
||||
if (ReloadTotalLength || ReloadRemaining)
|
||||
itsBufferedStats = TotalLength();
|
||||
result += Scroller(itsBufferedStats, itsScrollBegin, w->GetWidth()-result.length()-(Config.new_design ? 2 : VolumeState.length()));
|
||||
result += Scroller(itsBufferedStats, itsScrollBegin, Items->GetWidth()-result.length()-(Config.new_design ? 2 : VolumeState.length()));
|
||||
return result;
|
||||
}
|
||||
|
||||
void Playlist::EnterPressed()
|
||||
{
|
||||
if (!w->Empty())
|
||||
if (w == Items)
|
||||
{
|
||||
Mpd.PlayID(w->Current().GetID());
|
||||
UpdateStatusImmediately = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::SpacePressed()
|
||||
{
|
||||
w->SelectCurrent();
|
||||
w->Scroll(wDown);
|
||||
}
|
||||
|
||||
void Playlist::MouseButtonPressed(MEVENT me)
|
||||
{
|
||||
if (w->Empty() || !w->hasCoords(me.x, me.y) || size_t(me.y) >= w->Size())
|
||||
return;
|
||||
if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))
|
||||
if (!Items->Empty())
|
||||
{
|
||||
w->Goto(me.y);
|
||||
if (me.bstate & BUTTON3_PRESSED)
|
||||
{
|
||||
Mpd.Play(w->Current().GetPosition());
|
||||
Mpd.PlayID(Items->Current().GetID());
|
||||
UpdateStatusImmediately = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
Screen< Menu<MPD::Song> >::MouseButtonPressed(me);
|
||||
}
|
||||
|
||||
MPD::Song *Playlist::CurrentSong()
|
||||
{
|
||||
return !w->Empty() ? &w->Current() : 0;
|
||||
}
|
||||
|
||||
void Playlist::GetSelectedSongs(MPD::SongList &v)
|
||||
{
|
||||
std::vector<size_t> selected;
|
||||
w->GetSelected(selected);
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
v.push_back(new MPD::Song(w->at(*it)));
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::ApplyFilter(const std::string &s)
|
||||
{
|
||||
w->ApplyFilter(s, 0, REG_ICASE | Config.regex_type);
|
||||
}
|
||||
|
||||
void Playlist::Sort()
|
||||
{
|
||||
if (w->GetWidth() < SortDialogWidth || MainHeight <= 6)
|
||||
{
|
||||
ShowMessage("Screen is too small to display dialog window!");
|
||||
return;
|
||||
}
|
||||
|
||||
int input;
|
||||
|
||||
SortDialog->Reset();
|
||||
SortDialog->Display();
|
||||
|
||||
BlockRefreshing = 1;
|
||||
while (1)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
SortDialog->Refresh();
|
||||
SortDialog->ReadKey(input);
|
||||
|
||||
if (Keypressed(input, Key.Up))
|
||||
{
|
||||
SortDialog->Scroll(wUp);
|
||||
}
|
||||
else if (Keypressed(input, Key.Down))
|
||||
{
|
||||
SortDialog->Scroll(wDown);
|
||||
}
|
||||
else if (Keypressed(input, Key.PageUp))
|
||||
{
|
||||
SortDialog->Scroll(wPageUp);
|
||||
}
|
||||
else if (Keypressed(input, Key.PageDown))
|
||||
{
|
||||
SortDialog->Scroll(wPageDown);
|
||||
}
|
||||
else if (Keypressed(input, Key.Home))
|
||||
{
|
||||
SortDialog->Scroll(wHome);
|
||||
}
|
||||
else if (Keypressed(input, Key.End))
|
||||
{
|
||||
SortDialog->Scroll(wEnd);
|
||||
}
|
||||
else if (Keypressed(input, Key.MvSongUp))
|
||||
{
|
||||
size_t pos = SortDialog->Choice();
|
||||
if (pos > 0 && pos < SortOptions)
|
||||
{
|
||||
SortDialog->Swap(pos, pos-1);
|
||||
SortDialog->Scroll(wUp);
|
||||
}
|
||||
}
|
||||
else if (Keypressed(input, Key.MvSongDown))
|
||||
{
|
||||
size_t pos = SortDialog->Choice();
|
||||
if (pos < SortOptions-1)
|
||||
{
|
||||
SortDialog->Swap(pos, pos+1);
|
||||
SortDialog->Scroll(wDown);
|
||||
}
|
||||
}
|
||||
else if (Keypressed(input, Key.Enter))
|
||||
else if (w == SortDialog)
|
||||
{
|
||||
size_t pos = SortDialog->Choice();
|
||||
if (pos > SortOptions)
|
||||
{
|
||||
BlockRefreshing = 0;
|
||||
if (pos == SortOptions+1) // sort
|
||||
break;
|
||||
else if (pos == SortOptions+2) // reverse
|
||||
if (pos == SortOptions+2) // reverse
|
||||
{
|
||||
BlockUpdate = 1;
|
||||
ShowMessage("Reversing playlist order...");
|
||||
Mpd.StartCommandsList();
|
||||
for (size_t i = 0, j = w->Size()-1; i < w->Size()/2; ++i, --j)
|
||||
for (size_t i = 0, j = Items->Size()-1; i < Items->Size()/2; ++i, --j)
|
||||
{
|
||||
Mpd.Swap(i, j);
|
||||
w->Swap(i, j);
|
||||
Items->Swap(i, j);
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
ShowMessage("Playlist reversed!");
|
||||
ShowMessage(Mpd.CommitCommandsList() ? "Playlist reversed!" : "Error while reversing playlist!");
|
||||
w = Items;
|
||||
return;
|
||||
}
|
||||
else if (pos == SortOptions+3) // cancel
|
||||
{
|
||||
w = Items;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMessage("Move tag types up and down to adjust sort order");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MPD::SongList playlist, cmp;
|
||||
|
||||
playlist.reserve(w->Size());
|
||||
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
playlist.reserve(Items->Size());
|
||||
for (size_t i = 0; i < Items->Size(); ++i)
|
||||
{
|
||||
(*w)[i].SetPosition(i);
|
||||
playlist.push_back(&(*w)[i]);
|
||||
(*Items)[i].SetPosition(i);
|
||||
playlist.push_back(&(*Items)[i]);
|
||||
}
|
||||
|
||||
cmp = playlist;
|
||||
sort(playlist.begin(), playlist.end(), Playlist::Sorting);
|
||||
|
||||
@@ -299,32 +205,119 @@ void Playlist::Sort()
|
||||
{
|
||||
Mpd.Swap(playlist[i]->GetPosition(), i);
|
||||
std::swap(cmp[playlist[i]->GetPosition()], cmp[i]);
|
||||
w->Swap(playlist[i]->GetPosition(), i);
|
||||
Items->Swap(playlist[i]->GetPosition(), i);
|
||||
}
|
||||
cmp[i]->SetPosition(i);
|
||||
}
|
||||
}
|
||||
while (playlist != cmp);
|
||||
Mpd.CommitCommandsList();
|
||||
ShowMessage("Playlist sorted!");
|
||||
ShowMessage(Mpd.CommitCommandsList() ? "Playlist sorted!" : "Error while sorting playlist!");
|
||||
w = Items;
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::SpacePressed()
|
||||
{
|
||||
if (w == Items)
|
||||
{
|
||||
Items->SelectCurrent();
|
||||
Items->Scroll(wDown);
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::MouseButtonPressed(MEVENT me)
|
||||
{
|
||||
if (w == Items && !Items->Empty() && Items->hasCoords(me.x, me.y))
|
||||
{
|
||||
if (size_t(me.y) < Items->Size() && (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)))
|
||||
{
|
||||
Items->Goto(me.y);
|
||||
if (me.bstate & BUTTON3_PRESSED)
|
||||
EnterPressed();
|
||||
}
|
||||
else
|
||||
Screen<Window>::MouseButtonPressed(me);
|
||||
}
|
||||
else if (w == SortDialog && SortDialog->hasCoords(me.x, me.y))
|
||||
{
|
||||
if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))
|
||||
{
|
||||
SortDialog->Goto(me.y);
|
||||
if (me.bstate & BUTTON3_PRESSED)
|
||||
EnterPressed();
|
||||
}
|
||||
else
|
||||
Screen<Window>::MouseButtonPressed(me);
|
||||
}
|
||||
}
|
||||
|
||||
MPD::Song *Playlist::CurrentSong()
|
||||
{
|
||||
return !Items->Empty() ? &Items->Current() : 0;
|
||||
}
|
||||
|
||||
void Playlist::GetSelectedSongs(MPD::SongList &v)
|
||||
{
|
||||
std::vector<size_t> selected;
|
||||
Items->GetSelected(selected);
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(new MPD::Song(Items->at(*it)));
|
||||
}
|
||||
|
||||
void Playlist::ApplyFilter(const std::string &s)
|
||||
{
|
||||
if (w == Items)
|
||||
Items->ApplyFilter(s, 0, REG_ICASE | Config.regex_type);
|
||||
}
|
||||
|
||||
void Playlist::Sort()
|
||||
{
|
||||
if (Items->GetWidth() < SortDialogWidth || MainHeight < 5)
|
||||
ShowMessage("Screen is too small to display dialog window!");
|
||||
else
|
||||
{
|
||||
SortDialog->Reset();
|
||||
w = SortDialog;
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::AdjustSortOrder(int key)
|
||||
{
|
||||
if (Keypressed(key, Key.MvSongUp))
|
||||
{
|
||||
size_t pos = SortDialog->Choice();
|
||||
if (pos > 0 && pos < SortOptions)
|
||||
{
|
||||
SortDialog->Swap(pos, pos-1);
|
||||
SortDialog->Scroll(wUp);
|
||||
}
|
||||
}
|
||||
else if (Keypressed(key, Key.MvSongDown))
|
||||
{
|
||||
size_t pos = SortDialog->Choice();
|
||||
if (pos < SortOptions-1)
|
||||
{
|
||||
SortDialog->Swap(pos, pos+1);
|
||||
SortDialog->Scroll(wDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::FixPositions(size_t beginning)
|
||||
{
|
||||
bool was_filtered = w->isFiltered();
|
||||
w->ShowAll();
|
||||
for (size_t i = beginning; i < w->Size(); ++i)
|
||||
{
|
||||
(*w)[i].SetPosition(i);
|
||||
}
|
||||
bool was_filtered = Items->isFiltered();
|
||||
Items->ShowAll();
|
||||
for (size_t i = beginning; i < Items->Size(); ++i)
|
||||
(*Items)[i].SetPosition(i);
|
||||
if (was_filtered)
|
||||
w->ShowFiltered();
|
||||
Items->ShowFiltered();
|
||||
}
|
||||
|
||||
void Playlist::EnableHighlighting()
|
||||
{
|
||||
w->Highlighting(1);
|
||||
w->Refresh();
|
||||
Items->Highlighting(1);
|
||||
if (w == Items)
|
||||
Items->Refresh();
|
||||
UpdateTimer();
|
||||
}
|
||||
|
||||
@@ -354,26 +347,26 @@ std::string Playlist::TotalLength()
|
||||
if (ReloadTotalLength)
|
||||
{
|
||||
itsTotalLength = 0;
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
itsTotalLength += (*w)[i].GetTotalLength();
|
||||
for (size_t i = 0; i < Items->Size(); ++i)
|
||||
itsTotalLength += (*Items)[i].GetTotalLength();
|
||||
ReloadTotalLength = 0;
|
||||
}
|
||||
if (Config.playlist_show_remaining_time && ReloadRemaining && !w->isFiltered())
|
||||
if (Config.playlist_show_remaining_time && ReloadRemaining && !Items->isFiltered())
|
||||
{
|
||||
itsRemainingTime = 0;
|
||||
for (size_t i = NowPlaying; i < w->Size(); ++i)
|
||||
itsRemainingTime += (*w)[i].GetTotalLength();
|
||||
for (size_t i = NowPlaying; i < Items->Size(); ++i)
|
||||
itsRemainingTime += (*Items)[i].GetTotalLength();
|
||||
ReloadRemaining = 0;
|
||||
}
|
||||
|
||||
result << '(' << w->Size() << (w->Size() == 1 ? " item" : " items");
|
||||
result << '(' << Items->Size() << (Items->Size() == 1 ? " item" : " items");
|
||||
|
||||
if (w->isFiltered())
|
||||
if (Items->isFiltered())
|
||||
{
|
||||
w->ShowAll();
|
||||
size_t real_size = w->Size();
|
||||
w->ShowFiltered();
|
||||
if (w->Size() != real_size)
|
||||
Items->ShowAll();
|
||||
size_t real_size = Items->Size();
|
||||
Items->ShowFiltered();
|
||||
if (Items->Size() != real_size)
|
||||
result << " (out of " << Mpd.GetPlaylistLength() << ")";
|
||||
}
|
||||
|
||||
@@ -382,7 +375,7 @@ std::string Playlist::TotalLength()
|
||||
result << ", length: ";
|
||||
ShowTime(result, itsTotalLength);
|
||||
}
|
||||
if (Config.playlist_show_remaining_time && itsRemainingTime && !w->isFiltered() && w->Size() > 1)
|
||||
if (Config.playlist_show_remaining_time && itsRemainingTime && !Items->isFiltered() && Items->Size() > 1)
|
||||
{
|
||||
result << " :: remaining: ";
|
||||
ShowTime(result, itsRemainingTime);
|
||||
@@ -436,11 +429,11 @@ void Playlist::ShowTime(std::ostringstream &result, size_t length)
|
||||
|
||||
const MPD::Song *Playlist::NowPlayingSong()
|
||||
{
|
||||
bool was_filtered = w->isFiltered();
|
||||
w->ShowAll();
|
||||
const MPD::Song *s = isPlaying() ? &w->at(NowPlaying) : 0;
|
||||
bool was_filtered = Items->isFiltered();
|
||||
Items->ShowAll();
|
||||
const MPD::Song *s = isPlaying() ? &Items->at(NowPlaying) : 0;
|
||||
if (was_filtered)
|
||||
w->ShowFiltered();
|
||||
Items->ShowFiltered();
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -480,9 +473,9 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play)
|
||||
unsigned hash = s.GetHash();
|
||||
if (play)
|
||||
{
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
for (size_t i = 0; i < Items->Size(); ++i)
|
||||
{
|
||||
if (w->at(i).GetHash() == hash)
|
||||
if (Items->at(i).GetHash() == hash)
|
||||
{
|
||||
Mpd.Play(i);
|
||||
break;
|
||||
@@ -494,12 +487,12 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play)
|
||||
{
|
||||
Playlist::BlockUpdate = 1;
|
||||
Mpd.StartCommandsList();
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
for (size_t i = 0; i < Items->Size(); ++i)
|
||||
{
|
||||
if ((*w)[i].GetHash() == hash)
|
||||
if ((*Items)[i].GetHash() == hash)
|
||||
{
|
||||
Mpd.Delete(i);
|
||||
w->DeleteOption(i);
|
||||
Items->DeleteOption(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -528,7 +521,7 @@ bool Playlist::Add(const MPD::SongList &l, bool play)
|
||||
if (l.empty())
|
||||
return false;
|
||||
|
||||
size_t old_playlist_size = w->Size();
|
||||
size_t old_playlist_size = Items->Size();
|
||||
|
||||
Mpd.StartCommandsList();
|
||||
MPD::SongList::const_iterator it = l.begin();
|
||||
@@ -537,10 +530,10 @@ bool Playlist::Add(const MPD::SongList &l, bool play)
|
||||
break;
|
||||
Mpd.CommitCommandsList();
|
||||
|
||||
if (play && old_playlist_size < w->Size())
|
||||
if (play && old_playlist_size < Items->Size())
|
||||
Mpd.Play(old_playlist_size);
|
||||
|
||||
if (w->Back().GetHash() != l.back()->GetHash())
|
||||
if (Items->Back().GetHash() != l.back()->GetHash())
|
||||
{
|
||||
if (it != l.begin())
|
||||
ShowMessage("%s", MPD::Message::PartOfSongsAdded);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "screen.h"
|
||||
#include "song.h"
|
||||
|
||||
class Playlist : public Screen< Menu<MPD::Song> >
|
||||
class Playlist : public Screen<Window>
|
||||
{
|
||||
public:
|
||||
Playlist() : NowPlaying(-1), OldPlaying(-1), itsTotalLength(0), itsRemainingTime(0), itsScrollBegin(0) { }
|
||||
@@ -44,18 +44,20 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
|
||||
virtual MPD::Song *CurrentSong();
|
||||
|
||||
virtual bool allowsSelection() { return true; }
|
||||
virtual void ReverseSelection() { w->ReverseSelection(); }
|
||||
virtual bool allowsSelection() { return w == Items; }
|
||||
virtual void ReverseSelection() { Items->ReverseSelection(); }
|
||||
virtual void GetSelectedSongs(MPD::SongList &);
|
||||
|
||||
virtual void ApplyFilter(const std::string &);
|
||||
|
||||
virtual List *GetList() { return w; }
|
||||
virtual List *GetList() { return w == Items ? Items : 0; }
|
||||
|
||||
bool isPlaying() { return NowPlaying >= 0 && !w->Empty(); }
|
||||
bool isPlaying() { return NowPlaying >= 0 && !Items->Empty(); }
|
||||
const MPD::Song *NowPlayingSong();
|
||||
|
||||
void Sort();
|
||||
void AdjustSortOrder(int key);
|
||||
bool SortingInProgress() { return w == SortDialog; }
|
||||
void FixPositions(size_t = 0);
|
||||
|
||||
void EnableHighlighting();
|
||||
@@ -68,6 +70,8 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
static std::string SongToString(const MPD::Song &, void *);
|
||||
static std::string SongInColumnsToString(const MPD::Song &, void *);
|
||||
|
||||
Menu< MPD::Song > *Items;
|
||||
|
||||
int NowPlaying;
|
||||
int OldPlaying;
|
||||
|
||||
@@ -76,7 +80,6 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
|
||||
static bool BlockNowPlayingUpdate;
|
||||
static bool BlockUpdate;
|
||||
static bool BlockRefreshing;
|
||||
|
||||
protected:
|
||||
virtual void Init();
|
||||
@@ -96,7 +99,6 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
static bool Sorting(MPD::Song *a, MPD::Song *b);
|
||||
|
||||
static Menu< std::pair<std::string, MPD::Song::GetFunction> > *SortDialog;
|
||||
|
||||
static const size_t SortOptions;
|
||||
static const size_t SortDialogWidth;
|
||||
static size_t SortDialogHeight;
|
||||
|
||||
@@ -139,9 +139,9 @@ void PlaylistEditor::Update()
|
||||
bool bold = 0;
|
||||
for (SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Main()->Size(); ++j)
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if ((*it)->GetHash() == myPlaylist->Main()->at(j).GetHash())
|
||||
if ((*it)->GetHash() == myPlaylist->Items->at(j).GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
|
||||
@@ -303,9 +303,9 @@ void SearchEngine::UpdateFoundList()
|
||||
bool bold = 0;
|
||||
for (size_t i = StaticOptions; i < w->Size(); ++i)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Main()->Size(); ++j)
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if (myPlaylist->Main()->at(j).GetHash() == w->at(i).second->GetHash())
|
||||
if (myPlaylist->Items->at(j).GetHash() == w->at(i).second->GetHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -375,9 +375,9 @@ void SearchEngine::Search()
|
||||
Mpd.GetDirectoryRecursive("/", list);
|
||||
else
|
||||
{
|
||||
list.reserve(myPlaylist->Main()->Size());
|
||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); ++i)
|
||||
list.push_back(&(*myPlaylist->Main())[i]);
|
||||
list.reserve(myPlaylist->Items->Size());
|
||||
for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
|
||||
list.push_back(&(*myPlaylist->Items)[i]);
|
||||
}
|
||||
|
||||
bool any_found = 1;
|
||||
|
||||
@@ -130,7 +130,7 @@ void TraceMpdStatus()
|
||||
wFooter->Refresh();
|
||||
|
||||
if (myScreen == myPlaylist && now.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay)
|
||||
myPlaylist->Main()->Highlighting(!Config.playlist_disable_highlight_delay);
|
||||
myPlaylist->Items->Highlighting(!Config.playlist_disable_highlight_delay);
|
||||
|
||||
if (lock_statusbar_delay > 0)
|
||||
{
|
||||
@@ -187,20 +187,20 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
{
|
||||
myPlaylist->OldPlaying = myPlaylist->NowPlaying;
|
||||
myPlaylist->NowPlaying = Mpd.GetCurrentSongPos();
|
||||
bool was_filtered = myPlaylist->Main()->isFiltered();
|
||||
myPlaylist->Main()->ShowAll();
|
||||
bool was_filtered = myPlaylist->Items->isFiltered();
|
||||
myPlaylist->Items->ShowAll();
|
||||
try
|
||||
{
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->OldPlaying, 0);
|
||||
myPlaylist->Items->BoldOption(myPlaylist->OldPlaying, 0);
|
||||
}
|
||||
catch (std::out_of_range) { }
|
||||
try
|
||||
{
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 1);
|
||||
myPlaylist->Items->BoldOption(myPlaylist->NowPlaying, 1);
|
||||
}
|
||||
catch (std::out_of_range) { }
|
||||
if (was_filtered)
|
||||
myPlaylist->Main()->ShowFiltered();
|
||||
myPlaylist->Items->ShowFiltered();
|
||||
}
|
||||
|
||||
if (changed.Playlist)
|
||||
@@ -211,44 +211,44 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
if (Mpd.GetState() > psStop)
|
||||
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
||||
|
||||
bool was_filtered = myPlaylist->Main()->isFiltered();
|
||||
myPlaylist->Main()->ShowAll();
|
||||
bool was_filtered = myPlaylist->Items->isFiltered();
|
||||
myPlaylist->Items->ShowAll();
|
||||
SongList list;
|
||||
|
||||
size_t playlist_length = Mpd.GetPlaylistLength();
|
||||
if (playlist_length < myPlaylist->Main()->Size())
|
||||
myPlaylist->Main()->ResizeList(playlist_length);
|
||||
if (playlist_length < myPlaylist->Items->Size())
|
||||
myPlaylist->Items->ResizeList(playlist_length);
|
||||
|
||||
Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), list);
|
||||
myPlaylist->Main()->Reserve(playlist_length);
|
||||
myPlaylist->Items->Reserve(playlist_length);
|
||||
for (SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
int pos = (*it)->GetPosition();
|
||||
if (pos < int(myPlaylist->Main()->Size()))
|
||||
if (pos < int(myPlaylist->Items->Size()))
|
||||
{
|
||||
// if song's already in playlist, replace it with a new one
|
||||
myPlaylist->Main()->at(pos) = **it;
|
||||
myPlaylist->Items->at(pos) = **it;
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise just add it to playlist
|
||||
myPlaylist->Main()->AddOption(**it, myPlaylist->NowPlaying == pos);
|
||||
myPlaylist->Items->AddOption(**it, myPlaylist->NowPlaying == pos);
|
||||
}
|
||||
myPlaylist->Main()->at(pos).CopyPtr(0);
|
||||
myPlaylist->Items->at(pos).CopyPtr(0);
|
||||
(*it)->NullMe();
|
||||
}
|
||||
|
||||
if (myScreen == myPlaylist)
|
||||
{
|
||||
if (!playlist_length || myPlaylist->Main()->Size() < myPlaylist->Main()->GetHeight())
|
||||
myPlaylist->Main()->Window::Clear();
|
||||
myPlaylist->Main()->Refresh();
|
||||
if (!playlist_length || myPlaylist->Items->Size() < myPlaylist->Items->GetHeight())
|
||||
myPlaylist->Items->Window::Clear();
|
||||
myPlaylist->Items->Refresh();
|
||||
}
|
||||
if (was_filtered)
|
||||
{
|
||||
myPlaylist->ApplyFilter(myPlaylist->Main()->GetFilter());
|
||||
if (myPlaylist->Main()->Empty())
|
||||
myPlaylist->Main()->ShowAll();
|
||||
myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter());
|
||||
if (myPlaylist->Items->Empty())
|
||||
myPlaylist->Items->ShowAll();
|
||||
}
|
||||
FreeSongList(list);
|
||||
}
|
||||
@@ -259,9 +259,9 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
if (myScreen == myPlaylist)
|
||||
RedrawHeader = 1;
|
||||
|
||||
if (myPlaylist->Main()->Empty())
|
||||
if (myPlaylist->Items->Empty())
|
||||
{
|
||||
myPlaylist->Main()->Reset();
|
||||
myPlaylist->Items->Reset();
|
||||
ShowMessage("Cleared playlist!");
|
||||
}
|
||||
|
||||
@@ -376,8 +376,8 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
system(Config.execute_on_song_change.c_str());
|
||||
if (Mpd.GetState() > psStop)
|
||||
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
||||
if (Config.autocenter_mode && !myPlaylist->Main()->isFiltered())
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
if (Config.autocenter_mode && !myPlaylist->Items->isFiltered())
|
||||
myPlaylist->Items->Highlight(myPlaylist->NowPlaying);
|
||||
|
||||
if (!Mpd.GetElapsedTime())
|
||||
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
|
||||
@@ -627,8 +627,8 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
wHeader->SetColor(Config.header_color);
|
||||
wHeader->Refresh();
|
||||
}
|
||||
if (myScreen == myPlaylist && !Playlist::BlockRefreshing)
|
||||
myPlaylist->Main()->Refresh();
|
||||
if (myScreen->ActiveWindow() == myPlaylist->Items)
|
||||
myPlaylist->Items->Refresh();
|
||||
*wFooter << fmtBoldEnd;
|
||||
wFooter->GotoXY(sx, sy);
|
||||
wFooter->Refresh();
|
||||
|
||||
@@ -201,7 +201,7 @@ void TinyTagEditor::EnterPressed()
|
||||
else
|
||||
{
|
||||
if (myOldScreen == myPlaylist)
|
||||
myPlaylist->Main()->Current() = s;
|
||||
myPlaylist->Items->Current() = s;
|
||||
else if (myOldScreen == myBrowser)
|
||||
*myBrowser->Main()->Current().song = s;
|
||||
}
|
||||
@@ -1000,13 +1000,13 @@ bool TagEditor::WriteTags(Song &s)
|
||||
{
|
||||
// if we rename local file, it won't get updated
|
||||
// so just remove it from playlist and add again
|
||||
size_t pos = myPlaylist->Main()->Choice();
|
||||
size_t pos = myPlaylist->Items->Choice();
|
||||
Mpd.StartCommandsList();
|
||||
Mpd.Delete(pos);
|
||||
int id = Mpd.AddSong("file://" + new_name);
|
||||
if (id >= 0)
|
||||
{
|
||||
s = myPlaylist->Main()->Back();
|
||||
s = myPlaylist->Items->Back();
|
||||
Mpd.Move(s.GetPosition(), pos);
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
|
||||
Reference in New Issue
Block a user