diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2009-02-17 07:30:26 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2009-02-17 07:30:26 +0100 |
commit | 2c6617866368f867e2c511929a113d00f5bb9a96 (patch) | |
tree | ea990f790224030b318f95a6121f6a26e86ce6a7 | |
parent | ab2c9256547e52ecb2ef62f883ccde347fdf8b56 (diff) |
get rid of this awful casting to List *
-rw-r--r-- | src/browser.h | 3 | ||||
-rw-r--r-- | src/clock.h | 2 | ||||
-rw-r--r-- | src/help.h | 2 | ||||
-rw-r--r-- | src/info.h | 2 | ||||
-rw-r--r-- | src/lyrics.h | 2 | ||||
-rw-r--r-- | src/media_library.cpp | 12 | ||||
-rw-r--r-- | src/media_library.h | 3 | ||||
-rw-r--r-- | src/ncmpcpp.cpp | 106 | ||||
-rw-r--r-- | src/playlist.h | 3 | ||||
-rw-r--r-- | src/playlist_editor.cpp | 54 | ||||
-rw-r--r-- | src/playlist_editor.h | 5 | ||||
-rw-r--r-- | src/screen.h | 3 | ||||
-rw-r--r-- | src/search_engine.h | 3 | ||||
-rw-r--r-- | src/tag_editor.cpp | 10 | ||||
-rw-r--r-- | src/tag_editor.h | 5 |
15 files changed, 129 insertions, 86 deletions
diff --git a/src/browser.h b/src/browser.h index 91fbfd1e..1da91caf 100644 --- a/src/browser.h +++ b/src/browser.h @@ -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 = "/"); diff --git a/src/clock.h b/src/clock.h index ada4c480..b2fec4af 100644 --- a/src/clock.h +++ b/src/clock.h @@ -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); @@ -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(); @@ -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(); diff --git a/src/lyrics.h b/src/lyrics.h index c9ffe60d..40968169 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -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 diff --git a/src/media_library.cpp b/src/media_library.cpp index 13815899..d89e5418 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -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; diff --git a/src/media_library.h b/src/media_library.h index d682c0c5..6d227bcb 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -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(); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 2430c784..168dc76d 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -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(Keypressed(input, Key.NextFoundPosition) ? ++found_pos : --found_pos)); - } - catch (std::out_of_range) + mList->Highlight(vFoundPositions.at(next ? ++found_pos : --found_pos)); + } + catch (std::out_of_range) + { + if (Config.wrapped_search) { - 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)) diff --git a/src/playlist.h b/src/playlist.h index d45dc70b..00c74227 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -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(); diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 92fdc8ed..c06b9ec2 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -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; +} + diff --git a/src/playlist_editor.h b/src/playlist_editor.h index f71f9113..b046ec45 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -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: diff --git a/src/screen.h b/src/screen.h index 9c6956ca..c847f3b4 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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; }; diff --git a/src/search_engine.h b/src/search_engine.h index 81fd7c29..13135000 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -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; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 3e342b37..5947718a 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -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; diff --git a/src/tag_editor.h b/src/tag_editor.h index 78b3f52c..5a4f6ff9 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -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(); |