get rid of this awful casting to List *

This commit is contained in:
Andrzej Rybczak
2009-02-17 07:30:26 +01:00
parent ab2c925654
commit 2c66178663
15 changed files with 129 additions and 86 deletions

View File

@@ -42,9 +42,10 @@ class Browser : public Screen< Menu<MPD::Item> >
virtual bool allowsSelection() { return true; }
virtual void ReverseSelection();
virtual bool Deselect() { return w->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList() { return w; }
const std::string &CurrentDir() { return itsBrowsedDir; }
void GetDirectory(std::string, std::string = "/");

View File

@@ -44,6 +44,8 @@ class Clock : public Screen<Window>
virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; }
protected:
static void Prepare();
static void Set(int, int);

View File

@@ -35,6 +35,8 @@ class Help : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; }
protected:
std::string DisplayKeys(int *, int = 2);
void GetKeybindings();

View File

@@ -38,6 +38,8 @@ class Info : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; }
void GetSong();
# ifdef HAVE_CURL_CURL_H
void GetArtist();

View File

@@ -56,6 +56,8 @@ class Lyrics : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; }
static bool Reload;
# ifdef HAVE_CURL_CURL_H

View File

@@ -256,6 +256,18 @@ MPD::Song *MediaLibrary::CurrentSong()
return w == Songs && !Songs->Empty() ? &Songs->Current() : 0;
}
List *MediaLibrary::GetList()
{
if (w == Artists)
return Artists;
else if (w == Albums)
return Albums;
else if (w == Songs)
return Songs;
else // silence compiler
return 0;
}
void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
{
std::vector<size_t> selected;

View File

@@ -43,9 +43,10 @@ class MediaLibrary : public Screen<Window>
virtual bool allowsSelection() { return w == Songs; }
virtual void ReverseSelection() { Songs->ReverseSelection(); }
virtual bool Deselect() { return Songs->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList();
void NextColumn();
void PrevColumn();

View File

@@ -281,7 +281,7 @@ int main(int argc, char *argv[])
{
myLibrary->Songs->Clear(0);
}
else if (myScreen->Cmp() == myPlaylistEditor->List)
else if (myScreen->Cmp() == myPlaylistEditor->Playlists)
{
myPlaylistEditor->Content->Clear(0);
}
@@ -468,10 +468,10 @@ int main(int argc, char *argv[])
}
Mpd->CommitQueue();
}
else if (myScreen == myBrowser || myScreen->Cmp() == myPlaylistEditor->List)
else if (myScreen == myBrowser || myScreen->Cmp() == myPlaylistEditor->Playlists)
{
LockStatusbar();
string name = myScreen == myBrowser ? myBrowser->Main()->Current().name : myPlaylistEditor->List->Current();
string name = myScreen == myBrowser ? myBrowser->Main()->Current().name : myPlaylistEditor->Playlists->Current();
if (myScreen != myBrowser || myBrowser->Main()->Current().type == itPlaylist)
{
Statusbar() << "Delete playlist " << name << " ? [y/n] ";
@@ -493,7 +493,7 @@ int main(int argc, char *argv[])
else
ShowMessage("Aborted!");
curs_set(0);
myPlaylistEditor->List->Clear(0); // make playlists list update itself
myPlaylistEditor->Playlists->Clear(0); // make playlists list update itself
}
UnlockStatusbar();
}
@@ -503,29 +503,29 @@ int main(int argc, char *argv[])
{
vector<size_t> list;
myPlaylistEditor->Content->GetSelected(list);
locale_to_utf(myPlaylistEditor->List->Current());
locale_to_utf(myPlaylistEditor->Playlists->Current());
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
{
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->List->Current(), *it);
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), *it);
myPlaylistEditor->Content->DeleteOption(*it);
}
utf_to_locale(myPlaylistEditor->List->Current());
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->List->Current().c_str());
utf_to_locale(myPlaylistEditor->Playlists->Current());
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->Playlists->Current().c_str());
}
else
{
myPlaylistEditor->Content->SetTimeout(50);
locale_to_utf(myPlaylistEditor->List->Current());
locale_to_utf(myPlaylistEditor->Playlists->Current());
while (!myPlaylistEditor->Content->Empty() && Keypressed(input, Key.Delete))
{
TraceMpdStatus();
timer = time(NULL);
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->List->Current(), myPlaylistEditor->Content->Choice());
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
utf_to_locale(myPlaylistEditor->List->Current());
utf_to_locale(myPlaylistEditor->Playlists->Current());
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
Mpd->CommitQueue();
@@ -561,7 +561,7 @@ int main(int argc, char *argv[])
if (Mpd->SavePlaylist(real_playlist_name))
{
ShowMessage("Playlist saved as: %s", playlist_name.c_str());
myPlaylistEditor->List->Clear(0); // make playlist's list update itself
myPlaylistEditor->Playlists->Clear(0); // make playlist's list update itself
}
else
{
@@ -586,7 +586,7 @@ int main(int argc, char *argv[])
else
ShowMessage("Aborted!");
curs_set(0);
myPlaylistEditor->List->Clear(0); // make playlist's list update itself
myPlaylistEditor->Playlists->Clear(0); // make playlist's list update itself
UnlockStatusbar();
}
}
@@ -677,7 +677,7 @@ int main(int argc, char *argv[])
}
for (size_t i = 0; i < list.size(); i++)
if (origs[i] != list[i])
Mpd->QueueMove(myPlaylistEditor->List->Current(), origs[i], list[i]);
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitQueue();
}
else
@@ -695,7 +695,7 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->ReadKey(input);
}
if (from != to)
Mpd->Move(myPlaylistEditor->List->Current(), from, to);
Mpd->Move(myPlaylistEditor->Playlists->Current(), from, to);
}
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
@@ -781,7 +781,7 @@ int main(int argc, char *argv[])
}
for (int i = list.size()-1; i >= 0; i--)
if (origs[i] != list[i])
Mpd->QueueMove(myPlaylistEditor->List->Current(), origs[i], list[i]);
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitQueue();
}
else
@@ -799,7 +799,7 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->ReadKey(input);
}
if (from != to)
Mpd->Move(myPlaylistEditor->List->Current(), from, to);
Mpd->Move(myPlaylistEditor->Playlists->Current(), from, to);
}
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
@@ -1113,9 +1113,9 @@ int main(int argc, char *argv[])
ShowMessage("Cannot rename '%s' to '%s'!", old_dir.c_str(), new_dir.c_str());
}
}
else if (myScreen->Cmp() == myPlaylistEditor->List || (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist))
else if (myScreen->Cmp() == myPlaylistEditor->Playlists || (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist))
{
string old_name = myScreen->Cmp() == myPlaylistEditor->List ? myPlaylistEditor->List->Current() : myBrowser->Main()->Current().name;
string old_name = myScreen->Cmp() == myPlaylistEditor->Playlists ? myPlaylistEditor->Playlists->Current() : myBrowser->Main()->Current().name;
LockStatusbar();
Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd;
string new_name = wFooter->GetString(old_name);
@@ -1126,7 +1126,7 @@ int main(int argc, char *argv[])
ShowMessage("Playlist '%s' renamed to '%s'", old_name.c_str(), new_name.c_str());
if (!Config.local_browser)
myBrowser->GetDirectory("/");
myPlaylistEditor->List->Clear(0);
myPlaylistEditor->Playlists->Clear(0);
}
}
}
@@ -1192,7 +1192,7 @@ int main(int argc, char *argv[])
{
if (myScreen->allowsSelection())
{
if (myScreen->Deselect())
if (myScreen->GetList()->Deselect())
{
ShowMessage("Items deselected!");
}
@@ -1313,7 +1313,7 @@ int main(int argc, char *argv[])
// refresh playlist's lists
if (!Config.local_browser && myBrowser->CurrentDir() == "/")
myBrowser->GetDirectory("/");
myPlaylistEditor->List->Clear(0); // make playlist editor update itself
myPlaylistEditor->Playlists->Clear(0); // make playlist editor update itself
}
timer = time(NULL);
delete mDialog;
@@ -1360,16 +1360,9 @@ int main(int argc, char *argv[])
}
else if (Keypressed(input, Key.FindForward) || Keypressed(input, Key.FindBackward))
{
if ((myScreen == myHelp
|| myScreen == mySearcher
# ifdef HAVE_TAGLIB_H
|| myScreen == myTinyTagEditor
|| myScreen->Cmp() == myTagEditor->TagTypes
# endif // HAVE_TAGLIB_H
)
&& (myScreen != mySearcher
|| mySearcher->Main()->Current().first)
)
List *mList = myScreen->GetList();
if (!mList)
continue;
string how = Keypressed(input, Key.FindForward) ? "forward" : "backward";
@@ -1385,7 +1378,6 @@ int main(int argc, char *argv[])
CLEAR_FIND_HISTORY;
ShowMessage("Searching...");
List *mList = reinterpret_cast<Menu<Song> *>(myWindow->Main());
for (size_t i = (myScreen == mySearcher ? SearchEngine::StaticOptions : 0); i < mList->Size(); i++)
{
string name;
@@ -1424,8 +1416,8 @@ int main(int argc, char *argv[])
}
else if (myScreen == myPlaylistEditor)
{
if (myScreen->Cmp() == myPlaylistEditor->List)
name = myPlaylistEditor->List->at(i);
if (myScreen->Cmp() == myPlaylistEditor->Playlists)
name = myPlaylistEditor->Playlists->at(i);
else
name = myPlaylistEditor->Content->at(i).toString(Config.song_list_format);
}
@@ -1517,32 +1509,34 @@ int main(int argc, char *argv[])
}
else if (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition))
{
if (!vFoundPositions.empty())
List *mList = myScreen->GetList();
if (!mList || vFoundPositions.empty())
continue;
bool next = Keypressed(input, Key.NextFoundPosition);
try
{
List *mList = reinterpret_cast<Menu<Song> *>(myWindow->Main());
try
mList->Highlight(vFoundPositions.at(next ? ++found_pos : --found_pos));
}
catch (std::out_of_range)
{
if (Config.wrapped_search)
{
mList->Highlight(vFoundPositions.at(Keypressed(input, Key.NextFoundPosition) ? ++found_pos : --found_pos));
}
catch (std::out_of_range)
{
if (Config.wrapped_search)
if (next)
{
if (Keypressed(input, Key.NextFoundPosition))
{
mList->Highlight(vFoundPositions.front());
found_pos = 0;
}
else
{
mList->Highlight(vFoundPositions.back());
found_pos = vFoundPositions.size()-1;
}
mList->Highlight(vFoundPositions.front());
found_pos = 0;
}
else // prev
{
mList->Highlight(vFoundPositions.back());
found_pos = vFoundPositions.size()-1;
}
else
found_pos = Keypressed(input, Key.NextFoundPosition) ? vFoundPositions.size()-1 : 0;
}
else
found_pos = next ? vFoundPositions.size()-1 : 0;
}
}
else if (Keypressed(input, Key.ToggleFindMode))

View File

@@ -44,9 +44,10 @@ class Playlist : public Screen< Menu<MPD::Song> >
virtual bool allowsSelection() { return true; }
virtual void ReverseSelection() { w->ReverseSelection(); }
virtual bool Deselect() { return w->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList() { return w; }
bool isPlaying() { return NowPlaying >= 0 && !w->Empty(); }
const MPD::Song &NowPlayingSong();

View File

@@ -46,10 +46,10 @@ void PlaylistEditor::Init()
RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1;
List = new Menu<string>(0, main_start_y, LeftColumnWidth, main_height, "Playlists", Config.main_color, brNone);
List->HighlightColor(Config.active_column_color);
List->SetTimeout(ncmpcpp_window_timeout);
List->SetItemDisplayer(Display::Generic);
Playlists = new Menu<string>(0, main_start_y, LeftColumnWidth, main_height, "Playlists", Config.main_color, brNone);
Playlists->HighlightColor(Config.active_column_color);
Playlists->SetTimeout(ncmpcpp_window_timeout);
Playlists->SetItemDisplayer(Display::Generic);
Content = new Menu<Song>(RightColumnStartX, main_start_y, RightColumnWidth, main_height, "Playlist's content", Config.main_color, brNone);
Content->HighlightColor(Config.main_highlight_color);
@@ -59,7 +59,7 @@ void PlaylistEditor::Init()
Content->SetItemDisplayer(Display::Songs);
Content->SetItemDisplayerUserData(&Config.song_list_format);
w = List;
w = Playlists;
}
void PlaylistEditor::Resize()
@@ -68,7 +68,7 @@ void PlaylistEditor::Resize()
RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1;
List->Resize(LeftColumnWidth, main_height);
Playlists->Resize(LeftColumnWidth, main_height);
Content->Resize(RightColumnWidth, main_height);
Content->MoveTo(RightColumnStartX, main_start_y);
@@ -83,7 +83,7 @@ std::string PlaylistEditor::Title()
void PlaylistEditor::Refresh()
{
List->Display();
Playlists->Display();
mvvline(main_start_y, RightColumnStartX-1, 0, main_height);
Content->Display();
}
@@ -105,7 +105,7 @@ void PlaylistEditor::SwitchTo()
void PlaylistEditor::Update()
{
if (List->Empty())
if (Playlists->Empty())
{
Content->Clear(0);
TagList list;
@@ -114,17 +114,17 @@ void PlaylistEditor::Update()
for (TagList::iterator it = list.begin(); it != list.end(); it++)
{
utf_to_locale(*it);
List->AddOption(*it);
Playlists->AddOption(*it);
}
List->Window::Clear();
List->Refresh();
Playlists->Window::Clear();
Playlists->Refresh();
}
if (!List->Empty() && Content->Empty())
if (!Playlists->Empty() && Content->Empty())
{
Content->Reset();
SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(List->Current()), list);
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
if (!list.empty())
Content->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)"));
else
@@ -151,8 +151,8 @@ void PlaylistEditor::Update()
if (w == Content && Content->Empty())
{
Content->HighlightColor(Config.main_highlight_color);
List->HighlightColor(Config.active_column_color);
w = List;
Playlists->HighlightColor(Config.active_column_color);
w = Playlists;
}
if (Content->Empty())
@@ -163,10 +163,10 @@ void PlaylistEditor::Update()
void PlaylistEditor::NextColumn()
{
if (w == List)
if (w == Playlists)
{
CLEAR_FIND_HISTORY;
List->HighlightColor(Config.main_highlight_color);
Playlists->HighlightColor(Config.main_highlight_color);
w->Refresh();
w = Content;
Content->HighlightColor(Config.active_column_color);
@@ -180,8 +180,8 @@ void PlaylistEditor::PrevColumn()
CLEAR_FIND_HISTORY;
Content->HighlightColor(Config.main_highlight_color);
w->Refresh();
w = List;
List->HighlightColor(Config.active_column_color);
w = Playlists;
Playlists->HighlightColor(Config.active_column_color);
}
}
@@ -189,14 +189,14 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
{
SongList list;
if (w == List && !List->Empty())
if (w == Playlists && !Playlists->Empty())
{
Mpd->GetPlaylistContent(locale_to_utf_cpy(List->Current()), list);
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
{
ShowMessage("Loading playlist %s...", List->Current().c_str());
ShowMessage("Loading playlist %s...", Playlists->Current().c_str());
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
if (s.GetHash() == list[0]->GetHash())
{
@@ -287,3 +287,13 @@ void PlaylistEditor::GetSelectedSongs(MPD::SongList &v)
}
}
List *PlaylistEditor::GetList()
{
if (w == Playlists)
return Playlists;
else if (w == Content)
return Content;
else // silence compiler
return 0;
}

View File

@@ -42,13 +42,14 @@ class PlaylistEditor : public Screen<Window>
virtual bool allowsSelection() { return w == Content; }
virtual void ReverseSelection() { Content->ReverseSelection(); }
virtual bool Deselect() { return Content->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList();
void NextColumn();
void PrevColumn();
Menu<std::string> *List;
Menu<std::string> *Playlists;
Menu<MPD::Song> *Content;
protected:

View File

@@ -52,9 +52,10 @@ class BasicScreen
virtual bool allowsSelection() = 0;
virtual void ReverseSelection() { }
virtual bool Deselect() { return false; }
virtual void GetSelectedSongs(MPD::SongList &) { }
virtual List *GetList() = 0;
bool hasToBeResized;
};

View File

@@ -53,9 +53,10 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
virtual bool allowsSelection() { return w->Choice() >= StaticOptions; }
virtual void ReverseSelection() { w->ReverseSelection(StaticOptions); }
virtual bool Deselect() { return w->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList() { return w; }
void UpdateFoundList();
static size_t StaticOptions;

View File

@@ -734,6 +734,16 @@ void TagEditor::GetSelectedSongs(MPD::SongList &v)
}
}
List *TagEditor::GetList()
{
if (w == LeftColumn)
return LeftColumn;
else if (w == Tags)
return Tags;
else
return 0;
}
void TagEditor::NextColumn()
{
CLEAR_FIND_HISTORY;

View File

@@ -46,6 +46,8 @@ class TinyTagEditor : public Screen< Menu<Buffer> >
virtual bool allowsSelection() { return false; }
virtual List *GetList() { return w; }
bool SetEdited(MPD::Song *);
protected:
@@ -74,9 +76,10 @@ class TagEditor : public Screen<Window>
virtual bool allowsSelection() { return w == Tags; }
virtual void ReverseSelection() { Tags->ReverseSelection(); }
virtual bool Deselect() { return Tags->Deselect(); }
virtual void GetSelectedSongs(MPD::SongList &);
virtual List *GetList();
void NextColumn();
void PrevColumn();