diff --git a/src/actions.cpp b/src/actions.cpp index 8c437f8c..34520266 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -761,11 +761,11 @@ void Delete::Run() myPlaylist->Items->GetSelected(list); Mpd.StartCommandsList(); for (std::vector::reverse_iterator it = list.rbegin(); it != list.rend(); ++it) - Mpd.DeleteID((*myPlaylist->Items)[*it].getID()); + Mpd.DeleteID((*myPlaylist->Items)[*it].value().getID()); if (Mpd.CommitCommandsList()) { - for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) - myPlaylist->Items->Select(i, 0); + for (auto it = myPlaylist->Items->Begin(); it != myPlaylist->Items->End(); ++it) + it->setSelected(false); ShowMessage("Selected items deleted"); } } @@ -773,15 +773,15 @@ void Delete::Run() Mpd.DeleteID(myPlaylist->CurrentSong()->getID()); } else if ( - (myScreen == myBrowser && !myBrowser->Main()->Empty() && myBrowser->CurrentDir() == "/" && myBrowser->Main()->Current().type == itPlaylist) + (myScreen == myBrowser && !myBrowser->Main()->Empty() && myBrowser->CurrentDir() == "/" && myBrowser->Main()->Current().value().type == itPlaylist) || (myScreen->ActiveWindow() == myPlaylistEditor->Playlists) ) { std::string name; if (myScreen == myBrowser) - name = myBrowser->Main()->Current().name; + name = myBrowser->Main()->Current().value().name; else - name = myPlaylistEditor->Playlists->Current(); + name = myPlaylistEditor->Playlists->Current().value(); bool yes = AskYesNoQuestion("Delete playlist \"" + Shorten(TO_WSTRING(name), COLS-28) + "\"?", TraceMpdStatus); if (yes) { @@ -804,7 +804,7 @@ void Delete::Run() if (!myBrowser->isLocal() && !isMPDMusicDirSet()) return; - MPD::Item &item = myBrowser->Main()->Current(); + MPD::Item &item = myBrowser->Main()->Current().value(); if (item.type == itSong && !Config.allow_physical_files_deletion) { @@ -841,7 +841,7 @@ void Delete::Run() bool success = 1; for (size_t i = 0; i < list.size(); ++i) { - const MPD::Item &it = (*myBrowser->Main())[list[i]]; + const MPD::Item &it = (*myBrowser->Main())[list[i]].value(); name = it.type == itSong ? it.song->getName() : it.name; if (myBrowser->DeleteItem(it)) { @@ -875,7 +875,7 @@ void Delete::Run() { std::vector list; myPlaylistEditor->Content->GetSelected(list); - std::string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current()); + std::string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current().value()); ShowMessage("Deleting selected items..."); Mpd.StartCommandsList(); for (std::vector::reverse_iterator it = list.rbegin(); it != list.rend(); ++it) @@ -884,11 +884,11 @@ void Delete::Run() myPlaylistEditor->Content->DeleteItem(*it); } Mpd.CommitCommandsList(); - ShowMessage("Selected items deleted from playlist \"%s\"", myPlaylistEditor->Playlists->Current().c_str()); + ShowMessage("Selected items deleted from playlist \"%s\"", myPlaylistEditor->Playlists->Current().value().c_str()); } else { - if (Mpd.Delete(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice())) + if (Mpd.Delete(myPlaylistEditor->Playlists->Current().value(), myPlaylistEditor->Content->Choice())) myPlaylistEditor->Content->DeleteItem(myPlaylistEditor->Content->Choice()); } } @@ -935,7 +935,7 @@ void SavePlaylist::Run() { Mpd.StartCommandsList(); for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) - Mpd.AddToPlaylist(real_playlist_name, (*myPlaylist->Items)[i]); + Mpd.AddToPlaylist(real_playlist_name, (*myPlaylist->Items)[i].value()); Mpd.CommitCommandsList(); if (Mpd.GetErrorMessage().empty()) ShowMessage("Filtered items added to playlist \"%s\"", playlist_name.c_str()); @@ -1061,8 +1061,8 @@ void MoveSelectedItemsTo::Run() i = list.size()-1; for (it = list.rbegin(); it != list.rend(); ++it, --i) { - myPlaylist->Items->Select(*it, false); - myPlaylist->Items->Select(pos+i, true); + myPlaylist->Items->at(*it).setSelected(false); + myPlaylist->Items->at(pos+i).setSelected(true); } } } @@ -1077,8 +1077,8 @@ void MoveSelectedItemsTo::Run() i = 0; for (it = list.begin(); it != list.end(); ++it, ++i) { - myPlaylist->Items->Select(*it, false); - myPlaylist->Items->Select(pos+i, true); + myPlaylist->Items->at(*it).setSelected(false); + myPlaylist->Items->at(pos+i).setSelected(true); } } } @@ -1105,7 +1105,7 @@ void Add::Run() wFooter->Refresh(); if (myScreen == myPlaylistEditor) { - Mpd.AddToPlaylist(myPlaylistEditor->Playlists->Current(), path); + Mpd.AddToPlaylist(myPlaylistEditor->Playlists->Current().value(), path); myPlaylistEditor->Content->Clear(); // make it refetch content of playlist } else @@ -1316,7 +1316,7 @@ bool StartSearching::canBeRun() const void StartSearching::Run() { - if (mySearcher->Main()->isStatic(0)) + if (mySearcher->Main()->at(0).isInactive()) return; mySearcher->Main()->Highlight(SearchEngine::SearchButton); mySearcher->Main()->Highlighting(0); @@ -1422,13 +1422,13 @@ void EditLibraryTag::Run() return; LockStatusbar(); Statusbar() << fmtBold << tagTypeToString(Config.media_lib_primary_tag) << fmtBoldEnd << ": "; - std::string new_tag = wFooter->GetString(myLibrary->Artists->Current()); + std::string new_tag = wFooter->GetString(myLibrary->Artists->Current().value()); UnlockStatusbar(); - if (!new_tag.empty() && new_tag != myLibrary->Artists->Current()) + if (!new_tag.empty() && new_tag != myLibrary->Artists->Current().value()) { ShowMessage("Updating tags..."); Mpd.StartSearch(1); - Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(myLibrary->Artists->Current())); + Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(myLibrary->Artists->Current().value())); MPD::MutableSong::SetFunction set = tagTypeToSetFunction(Config.media_lib_primary_tag); assert(set); bool success = true; @@ -1479,21 +1479,21 @@ void EditLibraryAlbum::Run() return; LockStatusbar(); Statusbar() << fmtBold << "Album: " << fmtBoldEnd; - std::string new_album = wFooter->GetString(myLibrary->Albums->Current().Album); + std::string new_album = wFooter->GetString(myLibrary->Albums->Current().value().Album); UnlockStatusbar(); - if (!new_album.empty() && new_album != myLibrary->Albums->Current().Album) + if (!new_album.empty() && new_album != myLibrary->Albums->Current().value().Album) { bool success = 1; ShowMessage("Updating tags..."); for (size_t i = 0; i < myLibrary->Songs->Size(); ++i) { - ShowMessage("Updating tags in \"%s\"...", (*myLibrary->Songs)[i].getName().c_str()); - std::string path = Config.mpd_music_dir + (*myLibrary->Songs)[i].getURI(); + ShowMessage("Updating tags in \"%s\"...", (*myLibrary->Songs)[i].value().getName().c_str()); + std::string path = Config.mpd_music_dir + (*myLibrary->Songs)[i].value().getURI(); TagLib::FileRef f(path.c_str()); if (f.isNull()) { const char msg[] = "Error while opening file \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].getURI()), COLS-const_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].value().getURI()), COLS-const_strlen(msg)).c_str()); success = 0; break; } @@ -1501,7 +1501,7 @@ void EditLibraryAlbum::Run() if (!f.save()) { const char msg[] = "Error while writing tags in \"%s\""; - ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].getURI()), COLS-const_strlen(msg)).c_str()); + ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].value().getURI()), COLS-const_strlen(msg)).c_str()); success = 0; break; } @@ -1519,7 +1519,7 @@ bool EditDirectoryName::canBeRun() const { return (myScreen == myBrowser && !myBrowser->Main()->Empty() - && myBrowser->Main()->Current().type == MPD::itDirectory) + && myBrowser->Main()->Current().value().type == MPD::itDirectory) # ifdef HAVE_TAGLIB_H || (myScreen->ActiveWindow() == myTagEditor->Dirs && !myTagEditor->Dirs->Empty() @@ -1536,7 +1536,7 @@ void EditDirectoryName::Run() return; if (myScreen == myBrowser) { - std::string old_dir = myBrowser->Main()->Current().name; + std::string old_dir = myBrowser->Main()->Current().value().name; LockStatusbar(); Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; std::string new_dir = wFooter->GetString(old_dir); @@ -1570,7 +1570,7 @@ void EditDirectoryName::Run() # ifdef HAVE_TAGLIB_H else if (myScreen->ActiveWindow() == myTagEditor->Dirs) { - std::string old_dir = myTagEditor->Dirs->Current().first; + std::string old_dir = myTagEditor->Dirs->Current().value().first; LockStatusbar(); Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; std::string new_dir = wFooter->GetString(old_dir); @@ -1601,7 +1601,7 @@ bool EditPlaylistName::canBeRun() const && !myPlaylistEditor->Playlists->Empty()) || (myScreen == myBrowser && !myBrowser->Main()->Empty() - && myBrowser->Main()->Current().type == MPD::itPlaylist); + && myBrowser->Main()->Current().value().type == MPD::itPlaylist); } void EditPlaylistName::Run() @@ -1610,9 +1610,9 @@ void EditPlaylistName::Run() std::string old_name; if (myScreen->ActiveWindow() == myPlaylistEditor->Playlists) - old_name = myPlaylistEditor->Playlists->Current(); + old_name = myPlaylistEditor->Playlists->Current().value(); else - old_name = myBrowser->Main()->Current().name; + old_name = myBrowser->Main()->Current().value().name; LockStatusbar(); Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd; std::string new_name = wFooter->GetString(old_name); @@ -1668,12 +1668,12 @@ void JumpToMediaLibrary::Run() bool JumpToPlaylistEditor::canBeRun() const { return myScreen == myBrowser - && myBrowser->Main()->Current().type == MPD::itPlaylist; + && myBrowser->Main()->Current().value().type == MPD::itPlaylist; } void JumpToPlaylistEditor::Run() { - myPlaylistEditor->Locate(myBrowser->Main()->Current().name); + myPlaylistEditor->Locate(myBrowser->Main()->Current().value().name); } void ToggleScreenLock::Run() @@ -1804,12 +1804,13 @@ bool DeselectItems::canBeRun() const void DeselectItems::Run() { - List *mList = myScreen->GetList(); + // FIXME + /*List *mList = myScreen->GetList(); if (!mList->hasSelected()) return; for (size_t i = 0; i < mList->Size(); ++i) mList->Select(i, 0); - ShowMessage("Items deselected"); + ShowMessage("Items deselected");*/ } bool SelectAlbum::canBeRun() const @@ -1820,7 +1821,8 @@ bool SelectAlbum::canBeRun() const void SelectAlbum::Run() { - List *mList = myScreen->GetList(); + // FIXME + /*List *mList = myScreen->GetList(); assert(mList); size_t pos = mList->Choice(); if (MPD::Song *s = myScreen->GetSong(pos)) @@ -1850,6 +1852,7 @@ void SelectAlbum::Run() } ShowMessage("Album around cursor position selected"); } + */ } void AddSelectedItems::Run() @@ -1872,14 +1875,14 @@ void CropMainPlaylist::Run() for (int i = myPlaylist->Items->Size()-1; i >= 0; --i) { bool delete_i = (delete_all_but_current && i != current) - || (!delete_all_but_current && !myPlaylist->Items->isSelected(i)); + || (!delete_all_but_current && !myPlaylist->Items->at(i).isSelected()); if (delete_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. bool delete_np = (delete_all_but_current && current != myPlaylist->NowPlaying) - || (!delete_all_but_current && !myPlaylist->Items->isSelected(myPlaylist->NowPlaying)); + || (!delete_all_but_current && !myPlaylist->Items->at(myPlaylist->NowPlaying).isSelected()); if (myPlaylist->isPlaying() && delete_np) Mpd.DeleteID(myPlaylist->NowPlayingSong()->getID()); ShowMessage("Cropping playlist..."); @@ -1899,24 +1902,24 @@ void CropPlaylist::Run() return; bool yes = true; if (Config.ask_before_clearing_main_playlist) - yes = AskYesNoQuestion("Do you really want to crop playlist \"" + myPlaylistEditor->Playlists->Current() + "\"?", TraceMpdStatus); + yes = AskYesNoQuestion("Do you really want to crop playlist \"" + myPlaylistEditor->Playlists->Current().value() + "\"?", TraceMpdStatus); if (yes) { bool delete_all_but_current = !myPlaylistEditor->Content->hasSelected(); Mpd.StartCommandsList(); int current = myPlaylistEditor->Content->Choice(); - std::string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current()); + std::string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current().value()); for (int i = myPlaylistEditor->Content->Size()-1; i >= 0; --i) { bool delete_i = (delete_all_but_current && i != current) - || (!delete_all_but_current && !myPlaylistEditor->Content->isSelected(i)); + || (!delete_all_but_current && !myPlaylistEditor->Content->at(i).isSelected()); if (delete_i) Mpd.Delete(playlist, i); } - ShowMessage("Cropping playlist \"%s\"...", myPlaylistEditor->Playlists->Current().c_str()); + ShowMessage("Cropping playlist \"%s\"...", myPlaylistEditor->Playlists->Current().value().c_str()); if (Mpd.CommitCommandsList()) { - ShowMessage("Playlist \"%s\" cropped", myPlaylistEditor->Playlists->Current().c_str()); + ShowMessage("Playlist \"%s\" cropped", myPlaylistEditor->Playlists->Current().value().c_str()); // enforce content update myPlaylistEditor->Content->Clear(); } @@ -1935,7 +1938,7 @@ void ClearMainPlaylist::Run() ShowMessage("Deleting filtered items..."); Mpd.StartCommandsList(); for (int i = myPlaylist->Items->Size()-1; i >= 0; --i) - Mpd.Delete((*myPlaylist->Items)[i].getPosition()); + Mpd.Delete((*myPlaylist->Items)[i].value().getPosition()); if (Mpd.CommitCommandsList()) ShowMessage("Filtered items deleted"); } @@ -1959,13 +1962,12 @@ void ClearPlaylist::Run() return; bool yes = true; if (Config.ask_before_clearing_main_playlist) - yes = AskYesNoQuestion("Do you really want to clear playlist \"" + myPlaylistEditor->Playlists->Current() + "\"?", TraceMpdStatus); + yes = AskYesNoQuestion("Do you really want to clear playlist \"" + myPlaylistEditor->Playlists->Current().value() + "\"?", TraceMpdStatus); if (yes) { - - ShowMessage("Clearing playlist \"%s\"...", myPlaylistEditor->Playlists->Current().c_str()); - if (Mpd.ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current()))) - ShowMessage("Playlist \"%s\" cleared", myPlaylistEditor->Playlists->Current().c_str()); + ShowMessage("Clearing playlist \"%s\"...", myPlaylistEditor->Playlists->Current().value().c_str()); + if (Mpd.ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current().value()))) + ShowMessage("Playlist \"%s\" cleared", myPlaylistEditor->Playlists->Current().value().c_str()); } } @@ -2345,7 +2347,7 @@ void ShowArtistInfo::Run() if (s) artist = s->getArtist(); else if (myScreen == myLibrary && myLibrary->Main() == myLibrary->Artists && !myLibrary->Artists->Empty()) - artist = myLibrary->Artists->Current(); + artist = myLibrary->Artists->Current().value(); if (!artist.empty() && myLastfm->SetArtistInfoArgs(artist, Config.lastfm_preferred_language)) myLastfm->SwitchTo(); diff --git a/src/browser.cpp b/src/browser.cpp index aded1969..5439ea22 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -121,7 +121,7 @@ void Browser::EnterPressed() if (w->Empty()) return; - const MPD::Item &item = w->Current(); + const MPD::Item &item = w->Current().value(); switch (item.type) { case itDirectory: @@ -141,8 +141,9 @@ void Browser::EnterPressed() } case itSong: { - bool res = myPlaylist->Add(*item.song, w->isBold(), 1); - w->Bold(w->Choice(), res); + size_t i = w->Choice(); + bool res = myPlaylist->Add(*item.song, w->at(i).isBold(), 1); + w->at(i).setBold(res); break; } case itPlaylist: @@ -161,9 +162,11 @@ void Browser::SpacePressed() if (w->Empty()) return; - if (Config.space_selects && w->Choice() >= (itsBrowsedDir != "/" ? 1 : 0)) + size_t i = itsBrowsedDir != "/" ? 1 : 0; + if (Config.space_selects && w->Choice() >= i) { - w->Select(w->Choice(), !w->isSelected()); + i = w->Choice(); + w->at(i).setSelected(!w->at(i).isSelected()); w->Scroll(wDown); return; } @@ -171,7 +174,7 @@ void Browser::SpacePressed() if (isParentDir(w->Choice())) return; - const MPD::Item &item = w->Current(); + const MPD::Item &item = w->Current().value(); switch (item.type) { case itDirectory: @@ -198,8 +201,9 @@ void Browser::SpacePressed() } case itSong: { - bool res = myPlaylist->Add(*item.song, w->isBold(), 0); - w->Bold(w->Choice(), res); + i = w->Choice(); + bool res = myPlaylist->Add(*item.song, w->at(i).isBold(), 0); + w->at(i).setBold(res); break; } case itPlaylist: @@ -219,12 +223,12 @@ void Browser::MouseButtonPressed(MEVENT me) if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)) { w->Goto(me.y); - switch (w->Current().type) + switch (w->Current().value().type) { case itDirectory: if (me.bstate & BUTTON1_PRESSED) { - GetDirectory(w->Current().name); + GetDirectory(w->Current().value().name); RedrawHeader = true; } else @@ -255,7 +259,11 @@ void Browser::MouseButtonPressed(MEVENT me) MPD::Song *Browser::CurrentSong() { - return !w->Empty() && w->Current().type == itSong ? w->Current().song.get() : 0; + const MPD::Item &item = w->Current().value(); + if (!w->Empty() && item.type == itSong) + return item.song.get(); + else + return 0; } void Browser::ReverseSelection() @@ -273,7 +281,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v) selected.push_back(w->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) { - const MPD::Item &item = w->at(*it); + const MPD::Item &item = w->at(*it).value(); switch (item.type) { case itDirectory: @@ -341,7 +349,7 @@ void Browser::LocateSong(const MPD::Song &s) GetDirectory(s.getDirectory()); for (size_t i = 0; i < w->Size(); ++i) { - if ((*w)[i].type == itSong && s.getHash() == (*w)[i].song->getHash()) + if ((*w)[i].value().type == itSong && s.getHash() == (*w)[i].value().song->getHash()) { w->Highlight(i); break; @@ -413,7 +421,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir) bool bold = 0; for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) { - if (myPlaylist->Items->at(i).getHash() == it->song->getHash()) + if (myPlaylist->Items->at(i).value().getHash() == it->song->getHash()) { bold = 1; break; @@ -568,8 +576,8 @@ bool Browser::DeleteItem(const MPD::Item &item) void Browser::UpdateItemList() { for (size_t i = 0; i < w->Size(); ++i) - if ((*w)[i].type == itSong) - w->Bold(i, myPlaylist->checkForSong(*(*w)[i].song)); + if ((*w)[i].value().type == itSong) + w->at(i).setBold(myPlaylist->checkForSong(*(*w)[i].value().song)); w->Refresh(); } diff --git a/src/browser.h b/src/browser.h index fcc6e946..a09e416a 100644 --- a/src/browser.h +++ b/src/browser.h @@ -40,7 +40,7 @@ class Browser : public Screen< Menu > virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return w->at(pos).type == MPD::itSong ? (*w)[pos].song.get() : 0; } + virtual MPD::Song *GetSong(size_t pos) { return w->at(pos).value().type == MPD::itSong ? (*w)[pos].value().song.get() : 0; } virtual bool allowsSelection() { return true; } virtual void ReverseSelection(); diff --git a/src/display.cpp b/src/display.cpp index 4eeb5063..6cdb3ad5 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -157,7 +157,7 @@ void Display::SongsInColumns(Menu &menu, const MPD::Song &s, BasicScr int song_pos = menu.isFiltered() ? s.getPosition() : menu.CurrentlyDrawedPosition(); bool is_now_playing = &menu == myPlaylist->Items && song_pos == myPlaylist->NowPlaying; - bool is_selected = menu.isSelected(menu.CurrentlyDrawedPosition()); + bool is_selected = menu[menu.CurrentlyDrawedPosition()].isSelected(); bool discard_colors = Config.discard_colors_if_item_is_selected && is_selected; if (is_now_playing) @@ -287,7 +287,8 @@ void Display::Songs(Menu &menu, const MPD::Song &s, BasicScreen &scre mvwhline(menu.Raw(), menu.Y(), 0, ' ', menu.GetWidth()); } - bool discard_colors = Config.discard_colors_if_item_is_selected && menu.isSelected(menu.CurrentlyDrawedPosition()); + bool discard_colors = Config.discard_colors_if_item_is_selected + && menu[menu.CurrentlyDrawedPosition()].isSelected(); std::string line = s.toString(format, "$"); for (std::string::const_iterator it = line.begin(); it != line.end(); ++it) @@ -313,7 +314,7 @@ void Display::Songs(Menu &menu, const MPD::Song &s, BasicScreen &scre buf.RemoveFormatting(); if (is_now_playing) buf << Config.now_playing_suffix; - menu << XY(menu.GetWidth()-buf.Str().length()-(menu.isSelected(menu.CurrentlyDrawedPosition()) ? Config.selected_item_suffix_length : 0), menu.Y()) << buf; + menu << XY(menu.GetWidth()-buf.Str().length()-(menu[menu.CurrentlyDrawedPosition()].isSelected() ? Config.selected_item_suffix_length : 0), menu.Y()) << buf; if (separate_albums) menu << fmtUnderlineEnd; return; diff --git a/src/helpers.cpp b/src/helpers.cpp index 6fb813aa..52bbcf4c 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -294,13 +294,13 @@ void UpdateSongList(Menu *menu) { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if (myPlaylist->Items->at(j).getHash() == menu->at(i).getHash()) + if (myPlaylist->Items->at(j).value().getHash() == menu->at(i).value().getHash()) { bold = 1; break; } } - menu->Bold(i, bold); + (*menu)[i].setBold(bold); bold = 0; } menu->Refresh(); diff --git a/src/helpers.h b/src/helpers.h index 335dadc7..b037063f 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -177,10 +177,10 @@ template std::string getSharedDirectory(Menu *menu) { assert(!menu->Empty()); std::string dir; - dir = (*menu)[0].getDirectory(); +// dir = (*menu)[0].value().getDirectory(); for (size_t i = 1; i < menu->Size(); ++i) { - dir = getSharedDirectory(dir, (*menu)[i].getDirectory()); + dir = getSharedDirectory(dir, (*menu)[i].value().getDirectory()); if (dir == "/") break; } diff --git a/src/media_library.cpp b/src/media_library.cpp index bf900204..0435f7b1 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -221,9 +221,9 @@ void MediaLibrary::Update() Mpd.BlockIdle(1); Albums->Reset(); MPD::TagList list; - locale_to_utf(Artists->Current()); + locale_to_utf(Artists->Current().value()); Mpd.StartFieldSearch(MPD_TAG_ALBUM); - Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current()); + Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current().value()); Mpd.CommitSearchTags([&list](std::string &&album) { list.push_back(album); }); @@ -232,7 +232,7 @@ void MediaLibrary::Update() if (Config.media_library_display_date) { Mpd.StartFieldSearch(MPD_TAG_DATE); - Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current()); + Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current().value()); Mpd.AddSearch(MPD_TAG_ALBUM, *album); utf_to_locale(*album); Mpd.CommitSearchTags([this, &album](std::string &&date) { @@ -246,7 +246,7 @@ void MediaLibrary::Update() Albums->AddItem(SearchConstraints(*album, "")); } } - utf_to_locale(Artists->Current()); + utf_to_locale(Artists->Current().value()); if (!Albums->Empty()) std::sort(Albums->Begin(), Albums->End(), SearchConstraintsSorting()); if (Albums->Size() > 1) @@ -322,18 +322,18 @@ void MediaLibrary::Update() Songs->Reset(); Mpd.StartSearch(1); - Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(hasTwoColumns ? Albums->Current().PrimaryTag : Artists->Current())); - if (Albums->Current().Date != AllTracksMarker) + Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(hasTwoColumns ? Albums->Current().value().PrimaryTag : Artists->Current().value())); + if (Albums->Current().value().Date != AllTracksMarker) { - Mpd.AddSearch(MPD_TAG_ALBUM, locale_to_utf_cpy(Albums->Current().Album)); + Mpd.AddSearch(MPD_TAG_ALBUM, locale_to_utf_cpy(Albums->Current().value().Album)); if (Config.media_library_display_date) - Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Date)); + Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().value().Date)); } Mpd.CommitSearchSongs([this](MPD::Song &&s) { Songs->AddItem(s, myPlaylist->checkForSong(s)); }); - if (Albums->Current().Date == AllTracksMarker) + if (Albums->Current().value().Date == AllTracksMarker) std::sort(Songs->Begin(), Songs->End(), SortAllTracks); else std::sort(Songs->Begin(), Songs->End(), SortSongsByTrack); @@ -349,20 +349,25 @@ void MediaLibrary::SpacePressed() { if (w == Artists) { - Artists->Select(Artists->Choice(), !Artists->isSelected()); + size_t i = Artists->Choice(); + Artists->at(i).setSelected(!Artists->at(i).isSelected()); Albums->Clear(); Songs->Clear(); } else if (w == Albums) { - if (Albums->Current().Date != AllTracksMarker) + if (Albums->Current().value().Date != AllTracksMarker) { - Albums->Select(Albums->Choice(), !Albums->isSelected()); + size_t i = Albums->Choice(); + Albums->at(i).setSelected(!Albums->at(i).isSelected()); Songs->Clear(); } } else if (w == Songs) - Songs->Select(Songs->Choice(), !Songs->isSelected()); + { + size_t i = Songs->Choice(); + Songs->at(i).setSelected(!Songs->at(i).isSelected()); + } w->Scroll(wDown); } else @@ -440,7 +445,7 @@ void MediaLibrary::MouseButtonPressed(MEVENT me) MPD::Song *MediaLibrary::CurrentSong() { - return w == Songs && !Songs->Empty() ? &Songs->Current() : 0; + return w == Songs && !Songs->Empty() ? &Songs->Current().value() : 0; } List *MediaLibrary::GetList() @@ -477,7 +482,7 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v) { MPD::SongList list; Mpd.StartSearch(1); - Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it))); + Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it).value())); Mpd.CommitSearchSongs([&list](MPD::Song &&s) { list.push_back(s); }); @@ -494,7 +499,7 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v) if (v.empty()) v.reserve(Songs->Size()); for (size_t i = 0; i < Songs->Size(); ++i) - v.push_back((*Songs)[i]); + v.push_back((*Songs)[i].value()); } else { @@ -502,10 +507,10 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v) { Mpd.StartSearch(1); Mpd.AddSearch(Config.media_lib_primary_tag, hasTwoColumns - ? Albums->at(*it).PrimaryTag - : locale_to_utf_cpy(Artists->Current())); - Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).Album); - Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).Date); + ? Albums->at(*it).value().PrimaryTag + : locale_to_utf_cpy(Artists->Current().value())); + Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).value().Album); + Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).value().Date); Mpd.CommitSearchSongs([&v](MPD::Song &&s) { v.push_back(s); }); @@ -518,7 +523,7 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v) if (selected.empty()) selected.push_back(Songs->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) - v.push_back(Songs->at(*it)); + v.push_back(Songs->at(*it).value()); } } @@ -645,11 +650,11 @@ void MediaLibrary::LocateSong(const MPD::Song &s) Artists->ApplyFilter(""); if (Artists->Empty()) Update(); - if (primary_tag != Artists->Current()) + if (primary_tag != Artists->Current().value()) { for (size_t i = 0; i < Artists->Size(); ++i) { - if (primary_tag == (*Artists)[i]) + if (primary_tag == (*Artists)[i].value()) { Artists->Highlight(i); Albums->Clear(); @@ -666,15 +671,15 @@ void MediaLibrary::LocateSong(const MPD::Song &s) std::string album = s.getAlbum(); std::string date = s.getDate(); - if ((hasTwoColumns && Albums->Current().PrimaryTag != primary_tag) - || album != Albums->Current().Album - || date != Albums->Current().Date) + if ((hasTwoColumns && Albums->Current().value().PrimaryTag != primary_tag) + || album != Albums->Current().value().Album + || date != Albums->Current().value().Date) { for (size_t i = 0; i < Albums->Size(); ++i) { - if ((!hasTwoColumns || (*Albums)[i].PrimaryTag == primary_tag) - && album == (*Albums)[i].Album - && date == (*Albums)[i].Date) + if ((!hasTwoColumns || (*Albums)[i].value().PrimaryTag == primary_tag) + && album == (*Albums)[i].value().Album + && date == (*Albums)[i].value().Date) { Albums->Highlight(i); Songs->Clear(); @@ -687,11 +692,11 @@ void MediaLibrary::LocateSong(const MPD::Song &s) if (Songs->Empty()) Update(); - if (s.getHash() != Songs->Current().getHash()) + if (s.getHash() != Songs->Current().value().getHash()) { for (size_t i = 0; i < Songs->Size(); ++i) { - if (s.getHash() == (*Songs)[i].getHash()) + if (s.getHash() == (*Songs)[i].value().getHash()) { Songs->Highlight(i); break; @@ -709,7 +714,10 @@ void MediaLibrary::LocateSong(const MPD::Song &s) void MediaLibrary::AddToPlaylist(bool add_n_play) { if (w == Songs && !Songs->Empty()) - Songs->Bold(Songs->Choice(), myPlaylist->Add(Songs->Current(), Songs->isBold(), add_n_play)); + { + bool res = myPlaylist->Add(Songs->Current().value(), Songs->Current().isBold(), add_n_play); + Songs->Current().setBold(res); + } else { MPD::SongList list; @@ -718,14 +726,14 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) if (myPlaylist->Add(list, add_n_play)) { if ((!Artists->Empty() && w == Artists) - || (w == Albums && Albums->Current().Date == AllTracksMarker)) + || (w == Albums && Albums->Current().value().Date == AllTracksMarker)) { std::string tag_type = tagTypeToString(Config.media_lib_primary_tag); lowercase(tag_type); - ShowMessage("Songs with %s = \"%s\" added", tag_type.c_str(), Artists->Current().c_str()); + ShowMessage("Songs with %s = \"%s\" added", tag_type.c_str(), Artists->Current().value().c_str()); } else if (w == Albums) - ShowMessage("Songs from album \"%s\" added", Albums->Current().Album.c_str()); + ShowMessage("Songs from album \"%s\" added", Albums->Current().value().Album.c_str()); } } diff --git a/src/media_library.h b/src/media_library.h index 3eae6404..d18fc42c 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -28,6 +28,7 @@ class MediaLibrary : public Screen { struct SearchConstraints { + SearchConstraints() { } SearchConstraints(const std::string &tag, const std::string &album, const std::string &date) : PrimaryTag(tag), Album(album), Date(date) { } SearchConstraints(const std::string &album, const std::string &date) : Album(album), Date(date) { } @@ -56,7 +57,7 @@ class MediaLibrary : public Screen virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return w == Songs ? &Songs->at(pos) : 0; } + virtual MPD::Song *GetSong(size_t pos) { return w == Songs ? &Songs->at(pos).value() : 0; } virtual bool allowsSelection() { return true; } virtual void ReverseSelection(); diff --git a/src/menu.h b/src/menu.h index 572a0b99..a0f2f43e 100644 --- a/src/menu.h +++ b/src/menu.h @@ -21,6 +21,7 @@ #ifndef _MENU_H #define _MENU_H +#include #include #include #include @@ -36,14 +37,6 @@ namespace NCurses { /// struct List { - /// @see Menu::Select() - /// - virtual void Select(int pos, bool state) = 0; - - /// @see Menu::isSelected() - /// - virtual bool isSelected(int pos = -1) const = 0; - /// @see Menu::hasSelected() /// virtual bool hasSelected() const = 0; @@ -120,9 +113,12 @@ template struct Menu : public Window, public List /// struct Item { - Item() : m_is_bold(false), m_is_selected(false), m_is_inactive(false) { } + friend class Menu; + + Item() + : m_is_bold(false), m_is_selected(false), m_is_inactive(false), m_is_separator(false) { } Item(const T &value_, bool is_bold, bool is_inactive) - : m_value(value_), m_is_bold(is_bold), m_is_selected(false), m_is_inactive(is_inactive) { } + : m_value(value_), m_is_bold(is_bold), m_is_selected(false), m_is_inactive(is_inactive), m_is_separator(false) { } T &value() { return m_value; } const T &value() const { return m_value; } @@ -130,16 +126,26 @@ template struct Menu : public Window, public List void setBold(bool is_bold) { m_is_bold = is_bold; } void setSelected(bool is_selected) { m_is_selected = is_selected; } void setInactive(bool is_inactive) { m_is_inactive = is_inactive; } + void setSeparator(bool is_separator) { m_is_separator = is_separator; } bool isBold() const { return m_is_bold; } bool isSelected() const { return m_is_selected; } bool isInactive() const { return m_is_inactive; } + bool isSeparator() const { return m_is_separator; } private: + static Item *mkSeparator() + { + Item *i = new Item; + i->m_is_separator = true; + return i; + } + T m_value; bool m_is_bold; bool m_is_selected; bool m_is_inactive; + bool m_is_separator; }; template class ItemIterator @@ -289,11 +295,6 @@ template struct Menu : public Window, public List /// void DeleteItem(size_t pos); - /// Converts the option into separator - /// @param pos position of item to be converted - /// - void IntoSeparator(size_t pos); - /// Swaps the content of two items /// @param one position of first item /// @param two position of second item @@ -312,49 +313,6 @@ template struct Menu : public Window, public List /// bool Goto(size_t y); - /// Checks if the given position has bold attribute set. - /// @param pos position to be checked. -1 = currently highlighted position - /// @return true if the bold is set, false otherwise - /// - bool isBold(int pos = -1); - - /// Sets bols attribute for given position - /// @param pos position of item to be bolded/unbolded - /// @param state state of bold attribute - /// - void Bold(int pos, bool state); - - /// Makes given position static/active. - /// Static positions cannot be highlighted. - /// @param pos position in list - /// @param state state of activity - /// - void Static(int pos, bool state); - - /// Checks whether given position is static or active - /// @param pos position to be checked, -1 checks currently highlighted position - /// @return true if position is static, false otherwise - /// - bool isStatic(int pos = -1) const; - - /// Checks whether given position is separator - /// @param pos position to be checked, -1 checks currently highlighted position - /// @return true if position is separator, false otherwise - /// - bool isSeparator(int pos = -1) const; - - /// Selects/deselects given position - /// @param pos position in list - /// @param state state of selection - /// - virtual void Select(int pos, bool state); - - /// Checks if given position is selected - /// @param pos position to be checked, -1 checks currently highlighted position - /// @return true if position is selected, false otherwise - /// - virtual bool isSelected(int pos = -1) const; - /// Checks whether list contains selected positions /// @return true if it contains them, false otherwise /// @@ -524,48 +482,48 @@ template struct Menu : public Window, public List /// @return reference to last item on the list /// @throw List::InvalidItem if requested item is separator /// - T &Back(); + Menu::Item &Back(); /// @return const reference to last item on the list /// @throw List::InvalidItem if requested item is separator /// - const T &Back() const; + const Menu::Item &Back() const; /// @return reference to curently highlighted object /// @throw List::InvalidItem if requested item is separator /// - T &Current(); + Menu::Item &Current(); /// @return const reference to curently highlighted object /// @throw List::InvalidItem if requested item is separator /// - const T &Current() const; + const Menu::Item &Current() const; /// @param pos requested position /// @return reference to item at given position /// @throw std::out_of_range if given position is out of range /// @throw List::InvalidItem if requested item is separator /// - T &at(size_t pos); + Menu::Item &at(size_t pos); /// @param pos requested position /// @return const reference to item at given position /// @throw std::out_of_range if given position is out of range /// @throw List::InvalidItem if requested item is separator /// - const T &at(size_t pos) const; + const Menu::Item &at(size_t pos) const; /// @param pos requested position /// @return const reference to item at given position /// @throw List::InvalidItem if requested item is separator /// - const T &operator[](size_t pos) const; + const Menu::Item &operator[](size_t pos) const; /// @param pos requested position /// @return const reference to item at given position /// @throw List::InvalidItem if requested item is separator /// - T &operator[](size_t pos); + Menu::Item &operator[](size_t pos); Iterator Begin() { return Iterator(m_options_ptr->begin()); } ConstIterator Begin() const { return ConstIterator(m_options_ptr->begin()); } @@ -691,7 +649,7 @@ template void Menu::AddItem(const T &item, bool is_bold, bool is template void Menu::AddSeparator() { - m_options.push_back(static_cast(0)); + m_options.push_back(Item::mkSeparator()); } template void Menu::InsertItem(size_t pos, const T &item, bool is_bold, bool is_static) @@ -701,13 +659,12 @@ template void Menu::InsertItem(size_t pos, const T &item, bool i template void Menu::InsertSeparator(size_t pos) { - m_options.insert(m_options.begin()+pos, 0); + m_options.insert(m_options.begin()+pos, Item::mkSeparator()); } template void Menu::DeleteItem(size_t pos) { - if (m_options_ptr->empty()) - return; + assert(pos < m_options_ptr->size()); if (m_options_ptr == &m_filtered_options) { delete m_options.at(m_filtered_positions[pos]); @@ -727,19 +684,6 @@ template void Menu::DeleteItem(size_t pos) Window::Clear(); } -template void Menu::IntoSeparator(size_t pos) -{ - delete m_options_ptr->at(pos); - (*m_options_ptr)[pos] = 0; -} - -template void Menu::Bold(int pos, bool state) -{ - if (!m_options_ptr->at(pos)) - return; - (*m_options_ptr)[pos]->setBold(state); -} - template void Menu::Swap(size_t one, size_t two) { std::swap(m_options.at(one), m_options.at(two)); @@ -788,10 +732,10 @@ template void Menu::Refresh() if (!m_options_ptr->empty() && itsHighlight > int(m_options_ptr->size())-1) itsHighlight = m_options_ptr->size()-1; - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) // it shouldn't be here + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) // it shouldn't be here { Scroll(wUp); - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) Scroll(wDown); } @@ -805,7 +749,7 @@ template void Menu::Refresh() mvwhline(itsWindow, line, 0, 32, itsWidth); break; } - if (!(*m_options_ptr)[i]) // separator + if ((*m_options_ptr)[i]->isSeparator()) { mvwhline(itsWindow, line++, 0, 0, itsWidth); continue; @@ -861,7 +805,7 @@ template void Menu::Scroll(Where where) { itsHighlight--; } - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == 0 && !m_cyclic_scroll_enabled ? wDown : wUp); } @@ -883,7 +827,7 @@ template void Menu::Scroll(Where where) { itsHighlight++; } - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == MaxHighlight && !m_cyclic_scroll_enabled ? wUp : wDown); } @@ -901,7 +845,7 @@ template void Menu::Scroll(Where where) if (itsHighlight < 0) itsHighlight = 0; } - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == 0 && !m_cyclic_scroll_enabled ? wDown : wUp); } @@ -919,7 +863,7 @@ template void Menu::Scroll(Where where) if (itsHighlight > MaxHighlight) itsHighlight = MaxHighlight; } - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == MaxHighlight && !m_cyclic_scroll_enabled ? wUp : wDown); } @@ -929,7 +873,7 @@ template void Menu::Scroll(Where where) { itsHighlight = 0; itsBeginning = 0; - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == 0 ? wDown : wUp); } @@ -939,7 +883,7 @@ template void Menu::Scroll(Where where) { itsHighlight = MaxHighlight; itsBeginning = MaxBeginning; - if (!(*m_options_ptr)[itsHighlight] || (*m_options_ptr)[itsHighlight]->isInactive()) + if ((*m_options_ptr)[itsHighlight]->isSeparator() || (*m_options_ptr)[itsHighlight]->isInactive()) { Scroll(itsHighlight == MaxHighlight ? wUp : wDown); } @@ -975,54 +919,10 @@ template void Menu::Clear() Window::Clear(); } -template bool Menu::isBold(int pos) -{ - pos = pos == -1 ? itsHighlight : pos; - if (!m_options_ptr->at(pos)) - return 0; - return (*m_options_ptr)[pos]->isBold(); -} - -template void Menu::Select(int pos, bool state) -{ - if (!m_options_ptr->at(pos)) - return; - (*m_options_ptr)[pos]->setSelected(state); -} - -template void Menu::Static(int pos, bool state) -{ - if (!m_options_ptr->at(pos)) - return; - (*m_options_ptr)[pos]->setInactive(state); -} - -template bool Menu::isSelected(int pos) const -{ - pos = pos == -1 ? itsHighlight : pos; - if (!m_options_ptr->at(pos)) - return 0; - return (*m_options_ptr)[pos]->isSelected(); -} - -template bool Menu::isStatic(int pos) const -{ - pos = pos == -1 ? itsHighlight : pos; - if (!m_options_ptr->at(pos)) - return 1; - return (*m_options_ptr)[pos]->isInactive(); -} - -template bool Menu::isSeparator(int pos) const -{ - pos = pos == -1 ? itsHighlight : pos; - return !m_options_ptr->at(pos); -} - template bool Menu::hasSelected() const { for (auto it = m_options_ptr->begin(); it != m_options_ptr->end(); ++it) - if (*it && (*it)->isSelected()) + if ((*it)->isSelected()) return true; return false; } @@ -1030,7 +930,7 @@ template bool Menu::hasSelected() const template void Menu::GetSelected(std::vector &v) const { for (size_t i = 0; i < m_options_ptr->size(); ++i) - if ((*m_options_ptr)[i] && (*m_options_ptr)[i]->isSelected()) + if ((*m_options_ptr)[i]->isSelected()) v.push_back(i); } @@ -1054,7 +954,7 @@ template size_t Menu::RealChoice() const { size_t result = 0; for (auto it = m_options_ptr->begin(); it != m_options_ptr->begin()+itsHighlight; ++it) - if (*it && !(*it)->isInactive()) + if (!(*it)->isInactive()) result++; return result; } @@ -1063,8 +963,7 @@ template void Menu::ReverseSelection(size_t beginning) { auto it = m_options_ptr->begin()+beginning; for (size_t i = beginning; i < Size(); ++i, ++it) - if (*it) - (*it)->setSelected(!(*it)->isSelected() && !(*it)->isInactive()); + (*it)->setSelected(!(*it)->isSelected() && !(*it)->isInactive()); } template bool Menu::Search(const std::string &constraint, size_t beginning, int flags) @@ -1152,60 +1051,44 @@ template std::string Menu::GetItem(size_t pos) return ""; } -template T &Menu::Back() +template typename Menu::Item &Menu::Back() { - if (!m_options_ptr->back()) - FatalError("Menu::Back() has requested separator!"); - return m_options_ptr->back()->value(); + return *m_options_ptr->back(); } -template const T &Menu::Back() const +template const typename Menu::Item &Menu::Back() const { - if (!m_options_ptr->back()) - FatalError("Menu::Back() has requested separator!"); - return m_options_ptr->back()->value(); + return *m_options_ptr->back(); } -template T &Menu::Current() +template typename Menu::Item &Menu::Current() { - if (!m_options_ptr->at(itsHighlight)) - FatalError("Menu::Current() has requested separator!"); - return (*m_options_ptr)[itsHighlight]->value(); + return *(*m_options_ptr)[itsHighlight]; } -template const T &Menu::Current() const +template const typename Menu::Item &Menu::Current() const { - if (!m_options_ptr->at(itsHighlight)) - FatalError("Menu::Current() const has requested separator!"); - return (*m_options_ptr)[itsHighlight]->value(); + return *(*m_options_ptr)[itsHighlight]; } -template T &Menu::at(size_t pos) +template typename Menu::Item &Menu::at(size_t pos) { - if (!m_options_ptr->at(pos)) - FatalError("Menu::at() has requested separator!"); - return (*m_options_ptr)[pos]->value(); + return *m_options_ptr->at(pos); } -template const T &Menu::at(size_t pos) const +template const typename Menu::Item &Menu::at(size_t pos) const { - if (!m_options->at(pos)) - FatalError("Menu::at() const has requested separator!"); - return (*m_options_ptr)[pos]->value(); + return *m_options_ptr->at(pos); } -template const T &Menu::operator[](size_t pos) const +template const typename Menu::Item &Menu::operator[](size_t pos) const { - if (!(*m_options_ptr)[pos]) - FatalError("Menu::operator[] const has requested separator!"); - return (*m_options_ptr)[pos]->value(); + return *(*m_options_ptr)[pos]; } -template T &Menu::operator[](size_t pos) +template typename Menu::Item &Menu::operator[](size_t pos) { - if (!(*m_options_ptr)[pos]) - FatalError("Menu::operator[] has requested separator!"); - return (*m_options_ptr)[pos]->value(); + return *(*m_options_ptr)[pos]; } } diff --git a/src/outputs.cpp b/src/outputs.cpp index 8441e353..1df0ab26 100644 --- a/src/outputs.cpp +++ b/src/outputs.cpp @@ -83,15 +83,15 @@ std::basic_string Outputs::Title() void Outputs::EnterPressed() { - if (w->Current().isEnabled()) + if (w->Current().value().isEnabled()) { if (Mpd.DisableOutput(w->Choice())) - ShowMessage("Output \"%s\" disabled", w->Current().name().c_str()); + ShowMessage("Output \"%s\" disabled", w->Current().value().name().c_str()); } else { if (Mpd.EnableOutput(w->Choice())) - ShowMessage("Output \"%s\" enabled", w->Current().name().c_str()); + ShowMessage("Output \"%s\" enabled", w->Current().value().name().c_str()); } if (!Mpd.SupportsIdle()) FetchList(); diff --git a/src/playlist.cpp b/src/playlist.cpp index ffa5df3b..55404369 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -157,7 +157,7 @@ void Playlist::EnterPressed() if (w == Items) { if (!Items->Empty()) - Mpd.PlayID(Items->Current().getID()); + Mpd.PlayID(Items->Current().value().getID()); } else if (w == SortDialog) { @@ -190,13 +190,13 @@ void Playlist::EnterPressed() MPD::SongList playlist; playlist.reserve(end-beginning); for (size_t i = beginning; i < end; ++i) - playlist.push_back((*Items)[i]); + playlist.push_back((*Items)[i].value()); std::function iter_swap, quick_sort; auto song_cmp = [](const MPD::Song &a, const MPD::Song &b) { CaseInsensitiveStringComparison cmp; for (size_t i = 0; i < SortOptions; ++i) - if (int ret = cmp(a.getTags((*SortDialog)[i].second), b.getTags((*SortDialog)[i].second))) + if (int ret = cmp(a.getTags((*SortDialog)[i].value().second), b.getTags((*SortDialog)[i].value().second))) return ret < 0; return a.getPosition() < b.getPosition(); }; @@ -235,7 +235,7 @@ void Playlist::SpacePressed() { if (w == Items && !Items->Empty()) { - Items->Select(Items->Choice(), !Items->isSelected()); + Items->Current().setSelected(!Items->Current().isSelected()); Items->Scroll(wDown); } } @@ -268,7 +268,7 @@ void Playlist::MouseButtonPressed(MEVENT me) MPD::Song *Playlist::CurrentSong() { - return w == Items && !Items->Empty() ? &Items->Current() : 0; + return w == Items && !Items->Empty() ? &Items->Current().value() : 0; } void Playlist::GetSelectedSongs(MPD::SongList &v) @@ -280,7 +280,7 @@ void Playlist::GetSelectedSongs(MPD::SongList &v) if (selected.empty()) selected.push_back(Items->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) - v.push_back(Items->at(*it)); + v.push_back(Items->at(*it).value()); } void Playlist::ApplyFilter(const std::string &s) @@ -312,7 +312,7 @@ void Playlist::MoveSelectedItems(Movement where) { case mUp: { - if (myPlaylist->Items->hasSelected()) + if (Items->hasSelected()) { std::vector list; myPlaylist->Items->GetSelected(list); @@ -324,9 +324,9 @@ void Playlist::MoveSelectedItems(Movement where) Mpd.Move(*it-1, *it); if (Mpd.CommitCommandsList()) { - myPlaylist->Items->Select(list.back(), false); - myPlaylist->Items->Select(list.front()-1, true); - myPlaylist->Items->Highlight(list[(list.size()-1)/2]-1); + Items->at(list.back()).setSelected(false); + Items->at(list.front()-1).setSelected(true); + Items->Highlight(list[(list.size()-1)/2]-1); } } } @@ -336,7 +336,7 @@ void Playlist::MoveSelectedItems(Movement where) if (pos > 0) { if (Mpd.Move(pos-1, pos)) - myPlaylist->Items->Scroll(wUp); + Items->Scroll(wUp); } } break; @@ -356,8 +356,8 @@ void Playlist::MoveSelectedItems(Movement where) Mpd.Move(*it, *it+1); if (Mpd.CommitCommandsList()) { - Items->Select(list.front(), false); - Items->Select(list.back()+1, true); + Items->at(list.front()).setSelected(false); + Items->at(list.back()+1).setSelected(true); Items->Highlight(list[(list.size()-1)/2]+1); } } @@ -397,7 +397,7 @@ void Playlist::Reverse() size_t beginning = -1, end = -1; for (size_t i = 0; i < Items->Size(); ++i) { - if (Items->isSelected(i)) + if (Items->at(i).isSelected()) { if (beginning == size_t(-1)) beginning = i; @@ -457,14 +457,14 @@ std::string Playlist::TotalLength() { itsTotalLength = 0; for (size_t i = 0; i < Items->Size(); ++i) - itsTotalLength += (*Items)[i].getDuration(); + itsTotalLength += (*Items)[i].value().getDuration(); ReloadTotalLength = 0; } if (Config.playlist_show_remaining_time && ReloadRemaining && !Items->isFiltered()) { itsRemainingTime = 0; for (size_t i = NowPlaying; i < Items->Size(); ++i) - itsRemainingTime += (*Items)[i].getDuration(); + itsRemainingTime += (*Items)[i].value().getDuration(); ReloadRemaining = false; } @@ -497,7 +497,7 @@ const MPD::Song *Playlist::NowPlayingSong() { bool was_filtered = Items->isFiltered(); Items->ShowAll(); - const MPD::Song *s = isPlaying() ? &Items->at(NowPlaying) : 0; + const MPD::Song *s = isPlaying() ? &Items->at(NowPlaying).value() : 0; if (was_filtered) Items->ShowFiltered(); return s; @@ -522,7 +522,7 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play, int position { for (size_t i = 0; i < Items->Size(); ++i) { - if (Items->at(i).getHash() == hash) + if (Items->at(i).value().getHash() == hash) { Mpd.Play(i); break; @@ -535,7 +535,7 @@ bool Playlist::Add(const MPD::Song &s, bool in_playlist, bool play, int position Mpd.StartCommandsList(); for (size_t i = 0; i < Items->Size(); ++i) { - if ((*Items)[i].getHash() == hash) + if ((*Items)[i].value().getHash() == hash) { Mpd.Delete(i); Items->DeleteItem(i); @@ -606,7 +606,7 @@ void Playlist::SetSelectedItemsPriority(int prio) list.push_back(Items->Choice()); Mpd.StartCommandsList(); for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - Mpd.SetPriority((*Items)[*it], prio); + Mpd.SetPriority((*Items)[*it].value(), prio); if (Mpd.CommitCommandsList()) ShowMessage("Priority set"); } @@ -614,7 +614,7 @@ void Playlist::SetSelectedItemsPriority(int prio) bool Playlist::checkForSong (const MPD::Song &s) { for (size_t i = 0; i < Items->Size(); ++i) - if (s.getHash() == (*Items)[i].getHash()) + if (s.getHash() == (*Items)[i].value().getHash()) return true; return false; } diff --git a/src/playlist.h b/src/playlist.h index 02c3202d..c694b643 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -46,7 +46,7 @@ class Playlist : public Screen virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return w == Items ? &Items->at(pos) : 0; } + virtual MPD::Song *GetSong(size_t pos) { return w == Items ? &Items->at(pos).value() : 0; } virtual bool allowsSelection() { return w == Items; } virtual void ReverseSelection() { Items->ReverseSelection(); } diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 210c015f..89e530ef 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -152,7 +152,7 @@ void PlaylistEditor::Update() { Content->Reset(); size_t plsize = 0; - Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), [this, &plsize](MPD::Song &&s) { + Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current().value()), [this, &plsize](MPD::Song &&s) { Content->AddItem(s, myPlaylist->checkForSong(s)); ++plsize; }); @@ -206,7 +206,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) Mpd.StartCommandsList(); std::vector::const_iterator it = list.begin(); for (; it != list.end(); ++it) - Mpd.Move(Playlists->Current(), *it-1, *it); + Mpd.Move(Playlists->Current().value(), *it-1, *it); if (Mpd.CommitCommandsList()) { for (it = list.begin(); it != list.end(); ++it) @@ -220,7 +220,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) size_t pos = Content->Choice(); if (pos > 0) { - if (Mpd.Move(Playlists->Current(), pos-1, pos)) + if (Mpd.Move(Playlists->Current().value(), pos-1, pos)) { Content->Scroll(wUp); Content->Swap(pos-1, pos); @@ -241,7 +241,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) Mpd.StartCommandsList(); std::vector::const_reverse_iterator it = list.rbegin(); for (; it != list.rend(); ++it) - Mpd.Move(Playlists->Current(), *it, *it+1); + Mpd.Move(Playlists->Current().value(), *it, *it+1); if (Mpd.CommitCommandsList()) { Content->Highlight(list[(list.size()-1)/2]+1); @@ -255,7 +255,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) size_t pos = Content->Choice(); if (pos < Content->Size()-1) { - if (Mpd.Move(Playlists->Current(), pos, pos+1)) + if (Mpd.Move(Playlists->Current().value(), pos, pos+1)) { Content->Scroll(wDown); Content->Swap(pos, pos+1); @@ -330,15 +330,18 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) if (w == Playlists && !Playlists->Empty()) { - if (Mpd.LoadPlaylist(utf_to_locale_cpy(Playlists->Current()))) + if (Mpd.LoadPlaylist(utf_to_locale_cpy(Playlists->Current().value()))) { - ShowMessage("Playlist \"%s\" loaded", Playlists->Current().c_str()); + ShowMessage("Playlist \"%s\" loaded", Playlists->Current().value().c_str()); if (add_n_play) myPlaylist->PlayNewlyAddedSongs(); } } else if (w == Content && !Content->Empty()) - Content->Bold(Content->Choice(), myPlaylist->Add(Content->Current(), Content->isBold(), add_n_play)); + { + bool res = myPlaylist->Add(Content->Current().value(), Content->Current().isBold(), add_n_play); + Content->Current().setBold(res); + } if (!add_n_play) w->Scroll(wDown); @@ -348,7 +351,7 @@ void PlaylistEditor::SpacePressed() { if (Config.space_selects && w == Content) { - Content->Select(Content->Choice(), !Content->isSelected()); + Content->Current().setSelected(!Content->Current().isSelected()); w->Scroll(wDown); } else @@ -400,7 +403,7 @@ void PlaylistEditor::MouseButtonPressed(MEVENT me) MPD::Song *PlaylistEditor::CurrentSong() { - return w == Content && !Content->Empty() ? &Content->Current() : 0; + return w == Content && !Content->Empty() ? &Content->Current().value() : 0; } void PlaylistEditor::GetSelectedSongs(MPD::SongList &v) @@ -410,7 +413,7 @@ void PlaylistEditor::GetSelectedSongs(MPD::SongList &v) if (selected.empty()) selected.push_back(Content->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) - v.push_back(Content->at(*it)); + v.push_back(Content->at(*it).value()); } void PlaylistEditor::ApplyFilter(const std::string &s) @@ -425,7 +428,7 @@ void PlaylistEditor::Locate(const std::string &name) Update(); for (size_t i = 0; i < Playlists->Size(); ++i) { - if (name == (*Playlists)[i]) + if (name == (*Playlists)[i].value()) { Playlists->Highlight(i); Content->Clear(); diff --git a/src/playlist_editor.h b/src/playlist_editor.h index 31d0e245..a55ef01a 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -41,7 +41,7 @@ class PlaylistEditor : public Screen virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return w == Content ? &Content->at(pos) : 0; } + virtual MPD::Song *GetSong(size_t pos) { return w == Content ? &Content->at(pos).value() : 0; } virtual bool allowsSelection() { return w == Content; } virtual void ReverseSelection() { Content->ReverseSelection(); } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 396ce1b6..b844e661 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -113,7 +113,7 @@ void SearchEngine::SwitchTo() myScreen = this; Global::RedrawHeader = true; - if (!w->Back().isSong()) + if (!w->Back().value().isSong()) { *w << XY(0, 0) << "Updating list..."; UpdateFoundList(); @@ -129,7 +129,7 @@ void SearchEngine::EnterPressed() { size_t option = w->Choice(); if (option > ConstraintsNumber && option < SearchButton) - w->Current().buffer().Clear(); + w->Current().value().buffer().Clear(); if (option < SearchButton) LockStatusbar(); @@ -138,21 +138,21 @@ void SearchEngine::EnterPressed() std::string constraint = ConstraintsNames[option]; Statusbar() << fmtBold << constraint << fmtBoldEnd << ": "; itsConstraints[option] = Global::wFooter->GetString(itsConstraints[option]); - w->Current().buffer().Clear(); + w->Current().value().buffer().Clear(); constraint.resize(13, ' '); - w->Current().buffer() << fmtBold << constraint << fmtBoldEnd << ": "; - ShowTag(w->Current().buffer(), itsConstraints[option]); + w->Current().value().buffer() << fmtBold << constraint << fmtBoldEnd << ": "; + ShowTag(w->Current().value().buffer(), itsConstraints[option]); } else if (option == ConstraintsNumber+1) { Config.search_in_db = !Config.search_in_db; - w->Current().buffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); + w->Current().value().buffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); } else if (option == ConstraintsNumber+2) { if (!*++SearchMode) SearchMode = &SearchModes[0]; - w->Current().buffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; + w->Current().value().buffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; } else if (option == SearchButton) { @@ -160,7 +160,7 @@ void SearchEngine::EnterPressed() if (w->Size() > StaticOptions) Prepare(); Search(); - if (w->Back().isSong()) + if (w->Back().value().isSong()) { if (Config.columns_in_search_engine) w->SetTitle(Config.titles_visibility ? Display::Columns(w->GetWidth()) : ""); @@ -168,13 +168,13 @@ void SearchEngine::EnterPressed() found += 3; // don't count options inserted below w->InsertSeparator(ResetButton+1); w->InsertItem(ResetButton+2, SEItem(), 1, 1); - w->at(ResetButton+2).mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault; + w->at(ResetButton+2).value().mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault; w->InsertSeparator(ResetButton+3); UpdateFoundList(); ShowMessage("Searching finished"); if (Config.block_search_constraints_change) for (size_t i = 0; i < StaticOptions-4; ++i) - w->Static(i, 1); + w->at(i).setInactive(true); w->Scroll(wDown); w->Scroll(wDown); } @@ -187,8 +187,8 @@ void SearchEngine::EnterPressed() } else { - bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 1); - w->Bold(w->Choice(), res); + bool res = myPlaylist->Add(w->Current().value().song(), w->Current().isBold(), 1); + w->Current().setBold(res); } if (option < SearchButton) @@ -197,18 +197,18 @@ void SearchEngine::EnterPressed() void SearchEngine::SpacePressed() { - if (!w->Current().isSong()) + if (!w->Current().value().isSong()) return; if (Config.space_selects) { - w->Select(w->Choice(), !w->isSelected()); + w->Current().setSelected(!w->Current().isSelected()); w->Scroll(wDown); return; } - bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 0); - w->Bold(w->Choice(), res); + bool res = myPlaylist->Add(w->Current().value().song(), w->Current().isBold(), 0); + w->Current().setBold(res); w->Scroll(wDown); } @@ -242,7 +242,7 @@ void SearchEngine::MouseButtonPressed(MEVENT me) MPD::Song *SearchEngine::CurrentSong() { - return !w->Empty() && w->Current().isSong() ? &w->Current().song() : 0; + return !w->Empty() && w->Current().value().isSong() ? &w->Current().value().song() : 0; } void SearchEngine::GetSelectedSongs(MPD::SongList &v) @@ -255,8 +255,8 @@ void SearchEngine::GetSelectedSongs(MPD::SongList &v) selected.push_back(w->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) { - assert(w->at(*it).isSong()); - v.push_back(w->at(*it).song()); + assert(w->at(*it).value().isSong()); + v.push_back(w->at(*it).value().song()); } } @@ -272,69 +272,39 @@ void SearchEngine::UpdateFoundList() { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { - if (myPlaylist->Items->at(j).getHash() == w->at(i).song().getHash()) + if (myPlaylist->Items->at(j).value().getHash() == w->at(i).value().song().getHash()) { bold = 1; break; } } - w->Bold(i, bold); + w->at(i).setBold(bold); bold = 0; } } -void SearchEngine::SelectAlbum() -{ - size_t pos = w->Choice(); - if (pos < StaticOptions) - return; // not on a song - - std::string album = w->at(pos).song().getAlbum(); - - // select song under cursor - w->Select(pos, 1); - - // go up - while (pos > StaticOptions) - { - if (w->at(--pos).song().getAlbum() != album) - break; - else - w->Select(pos, 1); - } - - // go down - while (pos < w->Size() - 1) - { - if (w->at(++pos).song().getAlbum() != album) - break; - else - w->Select(pos, 1); - } -} - void SearchEngine::Prepare() { w->SetTitle(""); w->Clear(); w->ResizeList(StaticOptions-3); - w->IntoSeparator(ConstraintsNumber); - w->IntoSeparator(SearchButton-1); + w->at(ConstraintsNumber).setSeparator(true); + w->at(SearchButton-1).setSeparator(true); for (size_t i = 0; i < ConstraintsNumber; ++i) { std::string constraint = ConstraintsNames[i]; constraint.resize(13, ' '); - (*w)[i].mkBuffer() << fmtBold << constraint << fmtBoldEnd << ": "; - ShowTag((*w)[i].buffer(), itsConstraints[i]); + (*w)[i].value().mkBuffer() << fmtBold << constraint << fmtBoldEnd << ": "; + ShowTag((*w)[i].value().buffer(), itsConstraints[i]); } - w->at(ConstraintsNumber+1).mkBuffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); - w->at(ConstraintsNumber+2).mkBuffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; + w->at(ConstraintsNumber+1).value().mkBuffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); + w->at(ConstraintsNumber+2).value().mkBuffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; - w->at(SearchButton).mkBuffer() << "Search"; - w->at(ResetButton).mkBuffer() << "Reset"; + w->at(SearchButton).value().mkBuffer() << "Search"; + w->at(ResetButton).value().mkBuffer() << "Reset"; } void SearchEngine::Reset() @@ -402,7 +372,7 @@ void SearchEngine::Search() { list.reserve(myPlaylist->Items->Size()); for (size_t i = 0; i < myPlaylist->Items->Size(); ++i) - list.push_back((*myPlaylist->Items)[i]); + list.push_back((*myPlaylist->Items)[i].value()); } bool any_found = 1; diff --git a/src/search_engine.h b/src/search_engine.h index 50dd006e..1001cff2 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -86,7 +86,7 @@ class SearchEngine : public Screen< Menu > virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return !w->isSeparator(pos) && w->at(pos).isSong() ? &w->at(pos).song() : 0; } + virtual MPD::Song *GetSong(size_t pos) { return !(*w)[pos].isSeparator() && w->at(pos).value().isSong() ? &w->at(pos).value().song() : 0; } virtual bool allowsSelection() { return w->Choice() >= StaticOptions; } virtual void ReverseSelection() { w->ReverseSelection(StaticOptions); } @@ -99,7 +99,6 @@ class SearchEngine : public Screen< Menu > virtual bool isMergable() { return true; } void UpdateFoundList(); - void SelectAlbum(); static size_t StaticOptions; static size_t SearchButton; diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index 9c9f3de5..ff118f64 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -189,12 +189,12 @@ void SelectedItemsAdder::EnterPressed() } else if (pos > 1 && pos < w->Size()-1) // add items to existing playlist { - std::string playlist = locale_to_utf_cpy(w->Current()); + std::string playlist = locale_to_utf_cpy(w->Current().value()); Mpd.StartCommandsList(); for (auto it = list.begin(); it != list.end(); ++it) Mpd.AddToPlaylist(playlist, *it); if (Mpd.CommitCommandsList()) - ShowMessage("Selected item(s) added to playlist \"%s\"", w->Current().c_str()); + ShowMessage("Selected item(s) added to playlist \"%s\"", w->Current().value().c_str()); } if (pos != w->Size()-1) { @@ -232,7 +232,7 @@ void SelectedItemsAdder::EnterPressed() std::string album = myPlaylist->NowPlayingSong()->getAlbum(); int i; for (i = Mpd.GetCurrentlyPlayingSongPos()+1; i < int(myPlaylist->Items->Size()); ++i) - if ((*myPlaylist->Items)[i].getAlbum() != album) + if ((*myPlaylist->Items)[i].value().getAlbum() != album) break; successful_operation = myPlaylist->Add(list, 0, i); } diff --git a/src/status.cpp b/src/status.cpp index ce7b58f7..bc2804ad 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -238,7 +238,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) if (pos < int(myPlaylist->Items->Size())) { // if song's already in playlist, replace it with a new one - myPlaylist->Items->at(pos) = s; + myPlaylist->Items->at(pos).value() = s; } else { diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 5de34bbd..843f2b85 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -297,7 +297,7 @@ void TagEditor::Update() if (!Albums->Empty()) { Mpd.StartSearch(1); - Mpd.AddSearch(MPD_TAG_ALBUM, Albums->Current().second); + Mpd.AddSearch(MPD_TAG_ALBUM, Albums->Current().value().second); Mpd.CommitSearchSongs([&list](MPD::Song &&s) { list.push_back(s); }); @@ -308,7 +308,7 @@ void TagEditor::Update() } else { - Mpd.GetSongs(Dirs->Current().second, list); + Mpd.GetSongs(Dirs->Current().value().second, list); std::sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (auto it = list.begin(); it != list.end(); ++it) Tags->AddItem(*it); @@ -335,11 +335,11 @@ void TagEditor::EnterPressed() if (w == Dirs) { MPD::TagList test; - Mpd.GetDirectories(LeftColumn->Current().second, test); + Mpd.GetDirectories(LeftColumn->Current().value().second, test); if (!test.empty()) { itsHighlightedDir = itsBrowsedDir; - itsBrowsedDir = LeftColumn->Current().second; + itsBrowsedDir = LeftColumn->Current().value().second; LeftColumn->Clear(); LeftColumn->Reset(); } @@ -418,8 +418,8 @@ void TagEditor::EnterPressed() if (!new_pattern.empty()) { Config.pattern = new_pattern; - FParser->at(0) = "Pattern: "; - FParser->at(0) += Config.pattern; + FParser->at(0).value() = "Pattern: "; + FParser->at(0).value() += Config.pattern; } } else if (pos == 1 || pos == 3) // preview or proceed @@ -490,8 +490,8 @@ void TagEditor::EnterPressed() } else // list of patterns { - Config.pattern = FParser->Current(); - FParser->at(0) = "Pattern: " + Config.pattern; + Config.pattern = FParser->Current().value(); + FParser->at(0).value() = "Pattern: " + Config.pattern; } if (quit) @@ -512,11 +512,11 @@ void TagEditor::EnterPressed() std::vector selected; Tags->GetSelected(selected); for (auto it = selected.begin(); it != selected.end(); ++it) - EditedSongs.push_back(&(*Tags)[*it]); + EditedSongs.push_back(&(*Tags)[*it].value()); } else for (size_t i = 0; i < Tags->Size(); ++i) - EditedSongs.push_back(&(*Tags)[i]); + EditedSongs.push_back(&(*Tags)[i].value()); size_t id = TagTypes->RealChoice(); @@ -547,8 +547,8 @@ void TagEditor::EnterPressed() if (id > 0 && w == TagTypes) { LockStatusbar(); - Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; - std::string new_tag = wFooter->GetString(Tags->Current().getTags(get)); + Statusbar() << fmtBold << TagTypes->Current().value() << fmtBoldEnd << ": "; + std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get)); UnlockStatusbar(); for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it) (*it)->setTag(set, new_tag); @@ -556,11 +556,11 @@ void TagEditor::EnterPressed() else if (w == Tags) { LockStatusbar(); - Statusbar() << fmtBold << TagTypes->Current() << fmtBoldEnd << ": "; - std::string new_tag = wFooter->GetString(Tags->Current().getTags(get)); + Statusbar() << fmtBold << TagTypes->Current().value() << fmtBoldEnd << ": "; + std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get)); UnlockStatusbar(); - if (new_tag != Tags->Current().getTags(get)) - Tags->Current().setTag(set, new_tag); + if (new_tag != Tags->Current().value().getTags(get)) + Tags->Current().value().setTag(set, new_tag); Tags->Scroll(wDown); } } @@ -580,7 +580,7 @@ void TagEditor::EnterPressed() } else if (w == Tags) { - MPD::MutableSong &s = Tags->Current(); + MPD::MutableSong &s = Tags->Current().value(); std::string old_name = s.getNewURI().empty() ? s.getName() : s.getNewURI(); size_t last_dot = old_name.rfind("."); std::string extension = old_name.substr(last_dot); @@ -648,7 +648,7 @@ void TagEditor::SpacePressed() { if (w == Tags && !Tags->Empty()) { - Tags->Select(Tags->Choice(), !Tags->isSelected()); + Tags->Current().setSelected(!Tags->Current().isSelected()); w->Scroll(wDown); return; } @@ -756,7 +756,7 @@ void TagEditor::MouseButtonPressed(MEVENT me) MPD::Song *TagEditor::CurrentSong() { - return w == Tags && !Tags->Empty() ? &Tags->Current() : 0; + return w == Tags && !Tags->Empty() ? &Tags->Current().value() : 0; } void TagEditor::GetSelectedSongs(MPD::SongList &v) @@ -768,7 +768,7 @@ void TagEditor::GetSelectedSongs(MPD::SongList &v) if (selected.empty()) selected.push_back(Tags->Choice()); for (auto it = selected.begin(); it != selected.end(); ++it) - v.push_back(static_cast((*Tags)[*it])); + v.push_back(static_cast((*Tags)[*it].value())); } void TagEditor::ApplyFilter(const std::string &s) @@ -929,7 +929,7 @@ void TagEditor::LocateSong(const MPD::Song &s) std::string dir = getBasename(s.getDirectory()); for (size_t i = 0; i < Dirs->Size(); ++i) { - if ((*Dirs)[i].first == dir) + if ((*Dirs)[i].value().first == dir) { Dirs->Highlight(i); break; @@ -945,7 +945,7 @@ void TagEditor::LocateSong(const MPD::Song &s) // highlight our file for (size_t i = 0; i < Tags->Size(); ++i) { - if ((*Tags)[i].getHash() == s.getHash()) + if ((*Tags)[i].value().getHash() == s.getHash()) { Tags->Highlight(i); break; @@ -1084,7 +1084,7 @@ bool TagEditor::WriteTags(MPD::MutableSong &s) int id = Mpd.AddSong("file://" + new_name); if (id >= 0) { - s = myPlaylist->Items->Back(); + s = myPlaylist->Items->Back().value(); Mpd.Move(s.getPosition(), pos); } Mpd.CommitCommandsList(); diff --git a/src/tag_editor.h b/src/tag_editor.h index dd192115..52a2053c 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -55,7 +55,7 @@ class TagEditor : public Screen virtual bool isTabbable() { return true; } virtual MPD::Song *CurrentSong(); - virtual MPD::Song *GetSong(size_t pos) { return w == Tags ? &Tags->at(pos) : 0; } + virtual MPD::Song *GetSong(size_t pos) { return w == Tags ? &Tags->at(pos).value() : 0; } virtual bool allowsSelection() { return w == Tags; } virtual void ReverseSelection() { Tags->ReverseSelection(); } diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index 948b41d2..53d574fd 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -110,9 +110,9 @@ void TinyTagEditor::EnterPressed() size_t pos = option-8; Statusbar() << fmtBold << SongInfo::Tags[pos].Name << ": " << fmtBoldEnd; itsEdited.setTag(SongInfo::Tags[pos].Set, Global::wFooter->GetString(itsEdited.getTags(SongInfo::Tags[pos].Get))); - w->at(option).Clear(); - w->at(option) << fmtBold << SongInfo::Tags[pos].Name << ':' << fmtBoldEnd << ' '; - ShowTag(w->at(option), itsEdited.getTags(SongInfo::Tags[pos].Get)); + w->at(option).value().Clear(); + w->at(option).value() << fmtBold << SongInfo::Tags[pos].Name << ':' << fmtBoldEnd << ' '; + ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get)); } else if (option == 20) { @@ -123,8 +123,8 @@ void TinyTagEditor::EnterPressed() filename = filename.substr(0, dot); std::string new_name = Global::wFooter->GetString(filename); itsEdited.setNewURI(new_name + extension); - w->at(option).Clear(); - w->at(option) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI()); + w->at(option).value().Clear(); + w->at(option).value() << fmtBold << "Filename:" << fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI()); } UnlockStatusbar(); @@ -139,7 +139,7 @@ void TinyTagEditor::EnterPressed() else { if (myOldScreen == myPlaylist) - myPlaylist->Items->Current() = itsEdited; + myPlaylist->Items->Current().value() = itsEdited; else if (myOldScreen == myBrowser) myBrowser->GetDirectory(myBrowser->CurrentDir()); } @@ -199,41 +199,41 @@ bool TinyTagEditor::getTags() w->ResizeList(24); for (size_t i = 0; i < 7; ++i) - w->Static(i, 1); + w->at(i).setInactive(true); - w->IntoSeparator(7); - w->IntoSeparator(19); - w->IntoSeparator(21); + w->at(7).setSeparator(true); + w->at(19).setSeparator(true); + w->at(21).setSeparator(true); if (!extendedTagsSupported(f.file())) { - w->Static(10, 1); + w->at(10).setInactive(true); for (size_t i = 15; i <= 17; ++i) - w->Static(i, 1); + w->at(i).setInactive(true); } w->Highlight(8); - w->at(0) << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << itsEdited.getName() << clEnd; - w->at(1) << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; - ShowTag(w->at(1), itsEdited.getDirectory()); - w->at(1) << clEnd; - w->at(3) << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << itsEdited.getLength() << clEnd; - w->at(4) << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; - w->at(5) << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << clEnd; - w->at(6) << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; + w->at(0).value() << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << itsEdited.getName() << clEnd; + w->at(1).value() << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; + ShowTag(w->at(1).value(), itsEdited.getDirectory()); + w->at(1).value() << clEnd; + w->at(3).value() << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << itsEdited.getLength() << clEnd; + w->at(4).value() << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; + w->at(5).value() << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << clEnd; + w->at(6).value() << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; unsigned pos = 8; for (const SongInfo::Metadata *m = SongInfo::Tags; m->Name; ++m, ++pos) { - w->at(pos) << fmtBold << m->Name << ":" << fmtBoldEnd << ' '; - ShowTag(w->at(pos), itsEdited.getTags(m->Get)); + w->at(pos).value() << fmtBold << m->Name << ":" << fmtBoldEnd << ' '; + ShowTag(w->at(pos).value(), itsEdited.getTags(m->Get)); } - w->at(20) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << itsEdited.getName(); + w->at(20).value() << fmtBold << "Filename:" << fmtBoldEnd << ' ' << itsEdited.getName(); - w->at(22) << "Save"; - w->at(23) << "Cancel"; + w->at(22).value() << "Save"; + w->at(23).value() << "Cancel"; return true; }