reduce usage of pointers / replace std::pair in SearchEngine
This commit is contained in:
@@ -800,10 +800,10 @@ void Delete::Run()
|
||||
ShowMessage("Deleting directories is disabled by default, see man page for more details");
|
||||
return;
|
||||
}
|
||||
if (item.type == itDirectory && item.song) // parent dir
|
||||
if (myBrowser->isParentDir(myBrowser->Main()->Choice()))
|
||||
return;
|
||||
|
||||
std::string name = item.type == itSong ? item.song->getName() : item.name;
|
||||
std::string name = item.type == itSong ? item.song.getName() : item.name;
|
||||
std::string question;
|
||||
if (myBrowser->Main()->hasSelected())
|
||||
question = "Delete selected items?";
|
||||
@@ -826,7 +826,7 @@ void Delete::Run()
|
||||
for (size_t i = 0; i < list.size(); ++i)
|
||||
{
|
||||
const MPD::Item &it = (*myBrowser->Main())[list[i]];
|
||||
name = it.type == itSong ? it.song->getName() : it.name;
|
||||
name = it.type == itSong ? it.song.getName() : it.name;
|
||||
if (myBrowser->DeleteItem(it))
|
||||
{
|
||||
const char msg[] = "\"%s\" deleted";
|
||||
|
||||
@@ -128,13 +128,22 @@ void Browser::EnterPressed()
|
||||
{
|
||||
case itDirectory:
|
||||
{
|
||||
if (isParentDir(w->Choice()))
|
||||
{
|
||||
size_t slash = itsBrowsedDir.rfind("/");
|
||||
if (slash != std::string::npos)
|
||||
GetDirectory(itsBrowsedDir.substr(0, slash), itsBrowsedDir);
|
||||
else
|
||||
GetDirectory("/", itsBrowsedDir);
|
||||
}
|
||||
else
|
||||
GetDirectory(item.name, itsBrowsedDir);
|
||||
RedrawHeader = true;
|
||||
break;
|
||||
}
|
||||
case itSong:
|
||||
{
|
||||
bool res = myPlaylist->Add(*item.song, w->isBold(), 1);
|
||||
bool res = myPlaylist->Add(item.song, w->isBold(), 1);
|
||||
w->Bold(w->Choice(), res);
|
||||
break;
|
||||
}
|
||||
@@ -161,7 +170,7 @@ void Browser::SpacePressed()
|
||||
return;
|
||||
}
|
||||
|
||||
if (itsBrowsedDir != "/" && w->Choice() == 0 /* parent dir */)
|
||||
if (isParentDir(w->Choice()))
|
||||
return;
|
||||
|
||||
const MPD::Item &item = w->Current();
|
||||
@@ -169,9 +178,6 @@ void Browser::SpacePressed()
|
||||
{
|
||||
case itDirectory:
|
||||
{
|
||||
if (itsBrowsedDir != "/" && !w->Choice())
|
||||
break; // do not let add parent dir.
|
||||
|
||||
bool result;
|
||||
# ifndef WIN32
|
||||
if (isLocal())
|
||||
@@ -184,7 +190,6 @@ void Browser::SpacePressed()
|
||||
for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
|
||||
list.push_back(it->song);
|
||||
result = myPlaylist->Add(list, 0);
|
||||
FreeSongList(list);
|
||||
}
|
||||
else
|
||||
# endif // !WIN32
|
||||
@@ -195,7 +200,7 @@ void Browser::SpacePressed()
|
||||
}
|
||||
case itSong:
|
||||
{
|
||||
bool res = myPlaylist->Add(*item.song, w->isBold(), 0);
|
||||
bool res = myPlaylist->Add(item.song, w->isBold(), 0);
|
||||
w->Bold(w->Choice(), res);
|
||||
break;
|
||||
}
|
||||
@@ -252,7 +257,7 @@ void Browser::MouseButtonPressed(MEVENT me)
|
||||
|
||||
MPD::Song *Browser::CurrentSong()
|
||||
{
|
||||
return !w->Empty() && w->Current().type == itSong ? w->Current().song : 0;
|
||||
return !w->Empty() && w->Current().type == itSong ? &w->Current().song : 0;
|
||||
}
|
||||
|
||||
void Browser::ReverseSelection()
|
||||
@@ -268,7 +273,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
||||
w->GetSelected(selected);
|
||||
if (selected.empty())
|
||||
selected.push_back(w->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
const MPD::Item &item = w->at(*it);
|
||||
switch (item.type)
|
||||
@@ -280,7 +285,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
||||
{
|
||||
MPD::ItemList list;
|
||||
GetLocalDirectory(list, item.name, 1);
|
||||
for (MPD::ItemList::const_iterator j = list.begin(); j != list.end(); ++j)
|
||||
for (auto j = list.begin(); j != list.end(); ++j)
|
||||
v.push_back(j->song);
|
||||
}
|
||||
else
|
||||
@@ -290,7 +295,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
||||
}
|
||||
case itSong:
|
||||
{
|
||||
v.push_back(new MPD::Song(*item.song));
|
||||
v.push_back(item.song);
|
||||
break;
|
||||
}
|
||||
case itPlaylist:
|
||||
@@ -332,7 +337,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].type == itSong && s.getHash() == (*w)[i].song.getHash())
|
||||
{
|
||||
w->Highlight(i);
|
||||
break;
|
||||
@@ -353,20 +358,13 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
||||
|
||||
locale_to_utf(dir);
|
||||
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
if (w->at(i).type == itSong)
|
||||
delete w->at(i).song;
|
||||
|
||||
w->Clear();
|
||||
|
||||
if (dir != "/")
|
||||
{
|
||||
MPD::Item parent;
|
||||
size_t slash = dir.rfind("/");
|
||||
parent.song = reinterpret_cast<MPD::Song *>(1); // in that way we assume that's really parent dir
|
||||
parent.name = slash != std::string::npos ? dir.substr(0, slash) : "/";
|
||||
parent.name = "..";
|
||||
parent.type = itDirectory;
|
||||
utf_to_locale(parent.name);
|
||||
w->AddOption(parent);
|
||||
}
|
||||
|
||||
@@ -377,7 +375,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
||||
Mpd.GetDirectory(dir, list);
|
||||
# endif // !WIN32
|
||||
if (!isLocal()) // local directory is already sorted
|
||||
sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||
std::sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||
|
||||
for (MPD::ItemList::iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
@@ -402,7 +400,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).getHash() == it->song.getHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -463,7 +461,7 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
|
||||
{
|
||||
new_item.type = itSong;
|
||||
mpd_pair file_pair = { "file", full_path.c_str() };
|
||||
new_item.song = new MPD::Song(mpd_song_begin(&file_pair));
|
||||
new_item.song = MPD::Song(mpd_song_begin(&file_pair));
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
if (!recursively)
|
||||
TagEditor::ReadTags(*new_item.song);
|
||||
@@ -533,17 +531,17 @@ void Browser::ChangeBrowseMode()
|
||||
bool Browser::DeleteItem(const MPD::Item &item)
|
||||
{
|
||||
// parent dir
|
||||
if (item.type == itDirectory && item.song)
|
||||
if (item.type == itDirectory && item.name == "..")
|
||||
return false;
|
||||
|
||||
// playlist creatd by mpd
|
||||
// playlist created by mpd
|
||||
if (!isLocal() && item.type == itPlaylist && CurrentDir() == "/")
|
||||
return Mpd.DeletePlaylist(locale_to_utf_cpy(item.name));
|
||||
|
||||
std::string path;
|
||||
if (!isLocal())
|
||||
path = Config.mpd_music_dir;
|
||||
path += item.type == itSong ? item.song->getURI() : item.name;
|
||||
path += item.type == itSong ? item.song.getURI() : item.name;
|
||||
|
||||
if (item.type == itDirectory)
|
||||
ClearDirectory(path);
|
||||
@@ -561,7 +559,7 @@ void Browser::UpdateItemList()
|
||||
{
|
||||
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).getHash() == w->at(i).song.getHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -580,16 +578,14 @@ std::string Browser::ItemToString(const MPD::Item &item, void *)
|
||||
{
|
||||
case MPD::itDirectory:
|
||||
{
|
||||
if (item.song)
|
||||
return "[..]";
|
||||
return "[" + ExtractTopName(item.name) + "]";
|
||||
}
|
||||
case MPD::itSong:
|
||||
{
|
||||
if (!Config.columns_in_browser)
|
||||
return item.song->toString(Config.song_list_format_dollar_free);
|
||||
return item.song.toString(Config.song_list_format_dollar_free);
|
||||
else
|
||||
return Playlist::SongInColumnsToString(*item.song, 0);
|
||||
return Playlist::SongInColumnsToString(item.song, 0);
|
||||
}
|
||||
case MPD::itPlaylist:
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ class Browser : public Screen< Menu<MPD::Item> >
|
||||
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 : 0; }
|
||||
virtual MPD::Song *GetSong(size_t pos) { return w->at(pos).type == MPD::itSong ? &(*w)[pos].song : 0; }
|
||||
|
||||
virtual bool allowsSelection() { return true; }
|
||||
virtual void ReverseSelection();
|
||||
@@ -65,6 +65,8 @@ class Browser : public Screen< Menu<MPD::Item> >
|
||||
# endif // !WIN32
|
||||
void UpdateItemList();
|
||||
|
||||
bool isParentDir(size_t pos) { return itsBrowsedDir != "/" && pos == 0; }
|
||||
|
||||
protected:
|
||||
virtual void Init();
|
||||
virtual bool isLockable() { return true; }
|
||||
|
||||
@@ -360,7 +360,7 @@ void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
||||
{
|
||||
case MPD::itDirectory:
|
||||
{
|
||||
if (item.song)
|
||||
if (!item.song.empty())
|
||||
{
|
||||
*menu << "[..]";
|
||||
return;
|
||||
@@ -370,9 +370,9 @@ void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
||||
}
|
||||
case MPD::itSong:
|
||||
if (!Config.columns_in_browser)
|
||||
Display::Songs(*item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
Display::Songs(item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
else
|
||||
Display::SongsInColumns(*item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
Display::SongsInColumns(item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
return;
|
||||
case MPD::itPlaylist:
|
||||
*menu << Config.browser_playlist_prefix << ExtractTopName(item.name);
|
||||
@@ -382,17 +382,15 @@ void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
||||
}
|
||||
}
|
||||
|
||||
void Display::SearchEngine(const std::pair<Buffer *, MPD::Song *> &pair, void *data, Menu< std::pair<Buffer *, MPD::Song *> > *menu)
|
||||
void Display::SearchEngine(const SEItem &ei, void *data, Menu<SEItem> *menu)
|
||||
{
|
||||
if (pair.second)
|
||||
if (ei.isSong())
|
||||
{
|
||||
if (!Config.columns_in_search_engine)
|
||||
Display::Songs(*pair.second, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
Display::Songs(ei.song(), data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
else
|
||||
Display::SongsInColumns(*pair.second, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
Display::SongsInColumns(ei.song(), data, reinterpret_cast<Menu<MPD::Song> *>(menu));
|
||||
}
|
||||
|
||||
else
|
||||
*menu << *pair.first;
|
||||
*menu << ei.buffer();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "menu.h"
|
||||
#include "mpdpp.h"
|
||||
#include "screen.h"
|
||||
#include "search_engine.h"
|
||||
|
||||
namespace Display
|
||||
{
|
||||
@@ -52,7 +53,7 @@ namespace Display
|
||||
|
||||
void Tags(const MPD::Song &, void *, Menu<MPD::Song> *);
|
||||
|
||||
void SearchEngine(const std::pair<Buffer *, MPD::Song *> &, void *, Menu< std::pair<Buffer *, MPD::Song *> > *);
|
||||
void SearchEngine(const SEItem &, void *, Menu<SEItem> *);
|
||||
|
||||
void Items(const MPD::Item &, void *, Menu<MPD::Item> *);
|
||||
}
|
||||
|
||||
@@ -317,10 +317,10 @@ bool CaseInsensitiveSorting::operator()(const MPD::Item &a, const MPD::Item &b)
|
||||
result = operator()(a.song, b.song);
|
||||
break;
|
||||
case smMTime:
|
||||
result = a.song->getMTime() > b.song->getMTime();
|
||||
result = a.song.getMTime() > b.song.getMTime();
|
||||
break;
|
||||
case smCustomFormat:
|
||||
result = cmp(a.song->toString(Config.browser_sort_format), b.song->toString(Config.browser_sort_format)) < 0;
|
||||
result = cmp(a.song.toString(Config.browser_sort_format), b.song.toString(Config.browser_sort_format)) < 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -55,9 +55,9 @@ class CaseInsensitiveSorting
|
||||
return cmp(a, b) < 0;
|
||||
}
|
||||
|
||||
bool operator()(MPD::Song *a, MPD::Song *b)
|
||||
bool operator()(const MPD::Song &a, const MPD::Song &b)
|
||||
{
|
||||
return cmp(a->getName(), b->getName()) < 0;
|
||||
return cmp(a.getName(), b.getName()) < 0;
|
||||
}
|
||||
|
||||
template <typename A, typename B> bool operator()(const std::pair<A, B> &a, const std::pair<A, B> &b)
|
||||
|
||||
@@ -337,23 +337,22 @@ void MediaLibrary::Update()
|
||||
}
|
||||
Mpd.CommitSearch(list);
|
||||
|
||||
sort(list.begin(), list.end(), Albums->Current().Date == AllTracksMarker ? SortAllTracks : SortSongsByTrack);
|
||||
std::sort(list.begin(), list.end(), Albums->Current().Date == AllTracksMarker ? SortAllTracks : SortSongsByTrack);
|
||||
bool bold = 0;
|
||||
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if ((*it)->getHash() == myPlaylist->Items->at(j).getHash())
|
||||
if (it->getHash() == myPlaylist->Items->at(j).getHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Songs->AddOption(**it, bold);
|
||||
Songs->AddOption(*it, bold);
|
||||
bold = 0;
|
||||
}
|
||||
FreeSongList(list);
|
||||
Songs->Window::Clear();
|
||||
Songs->Refresh();
|
||||
}
|
||||
@@ -489,16 +488,14 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
||||
Artists->GetSelected(selected);
|
||||
if (selected.empty())
|
||||
selected.push_back(Artists->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
MPD::SongList list;
|
||||
Mpd.StartSearch(1);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it)));
|
||||
Mpd.CommitSearch(list);
|
||||
sort(list.begin(), list.end(), SortAllTracks);
|
||||
for (MPD::SongList::const_iterator sIt = list.begin(); sIt != list.end(); ++sIt)
|
||||
v.push_back(new MPD::Song(**sIt));
|
||||
FreeSongList(list);
|
||||
std::sort(list.begin(), list.end(), SortAllTracks);
|
||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
||||
}
|
||||
}
|
||||
else if (w == Albums && !Albums->Empty())
|
||||
@@ -510,11 +507,11 @@ 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(new MPD::Song((*Songs)[i]));
|
||||
v.push_back((*Songs)[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
MPD::SongList list;
|
||||
Mpd.StartSearch(1);
|
||||
@@ -524,9 +521,7 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).Album);
|
||||
Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).Date);
|
||||
Mpd.CommitSearch(list);
|
||||
for (MPD::SongList::const_iterator sIt = list.begin(); sIt != list.end(); ++sIt)
|
||||
v.push_back(new MPD::Song(**sIt));
|
||||
FreeSongList(list);
|
||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,8 +530,8 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
||||
Songs->GetSelected(selected);
|
||||
if (selected.empty())
|
||||
selected.push_back(Songs->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(new MPD::Song(Songs->at(*it)));
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(Songs->at(*it));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,21 +794,21 @@ bool MediaLibrary::SearchConstraintsSorting::operator()(const SearchConstraints
|
||||
return (result == 0 ? cmp(a.Album, b.Album) : result) < 0;
|
||||
}
|
||||
|
||||
bool MediaLibrary::SortSongsByTrack(MPD::Song *a, MPD::Song *b)
|
||||
bool MediaLibrary::SortSongsByTrack(const MPD::Song &a, const MPD::Song &b)
|
||||
{
|
||||
if (a->getDisc() == b->getDisc())
|
||||
return StrToInt(a->getTrack()) < StrToInt(b->getTrack());
|
||||
if (a.getDisc() == b.getDisc())
|
||||
return StrToInt(a.getTrack()) < StrToInt(b.getTrack());
|
||||
else
|
||||
return StrToInt(a->getDisc()) < StrToInt(b->getDisc());
|
||||
return StrToInt(a.getDisc()) < StrToInt(b.getDisc());
|
||||
}
|
||||
|
||||
bool MediaLibrary::SortAllTracks(MPD::Song *a, MPD::Song *b)
|
||||
bool MediaLibrary::SortAllTracks(const MPD::Song &a, const MPD::Song &b)
|
||||
{
|
||||
static MPD::Song::GetFunction gets[] = { &MPD::Song::getDate, &MPD::Song::getAlbum, &MPD::Song::getDisc, 0 };
|
||||
CaseInsensitiveStringComparison cmp;
|
||||
for (MPD::Song::GetFunction *get = gets; *get; ++get)
|
||||
if (int ret = cmp(a->getTags(*get), b->getTags(*get)))
|
||||
if (int ret = cmp(a.getTags(*get), b.getTags(*get)))
|
||||
return ret < 0;
|
||||
return a->getTrack() < b->getTrack();
|
||||
return a.getTrack() < b.getTrack();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ class MediaLibrary : public Screen<Window>
|
||||
static void DisplayAlbums(const SearchConstraints &, void *, Menu<SearchConstraints> *);
|
||||
static void DisplayPrimaryTags(const std::string &artist, void *, Menu<std::string> *menu);
|
||||
|
||||
static bool SortSongsByTrack(MPD::Song *, MPD::Song *);
|
||||
static bool SortAllTracks(MPD::Song *, MPD::Song *);
|
||||
static bool SortSongsByTrack(const MPD::Song &, const MPD::Song &);
|
||||
static bool SortAllTracks(const MPD::Song &, const MPD::Song &);
|
||||
|
||||
static bool hasTwoColumns;
|
||||
static size_t itsLeftColStartX;
|
||||
|
||||
@@ -631,7 +631,7 @@ void MPD::Connection::GetPlaylistChanges(unsigned version, SongList &v)
|
||||
GoBusy();
|
||||
mpd_send_queue_changes_meta(itsConnection, version);
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(new Song(s));
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -677,7 +677,7 @@ void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
||||
GoBusy();
|
||||
mpd_send_list_playlist_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(new Song(s));
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -925,8 +925,8 @@ bool MPD::Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
||||
SongList list;
|
||||
CommitSearch(list);
|
||||
StartCommandsList();
|
||||
for (SongList::const_iterator j = list.begin(); j != list.end(); ++j)
|
||||
AddSong(**j);
|
||||
for (auto j = list.begin(); j != list.end(); ++j)
|
||||
AddSong(*j);
|
||||
CommitCommandsList();
|
||||
}
|
||||
}
|
||||
@@ -1084,7 +1084,6 @@ void MPD::Connection::GetPlaylists(TagList &v)
|
||||
for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
if (it->type == itPlaylist)
|
||||
v.push_back(it->name);
|
||||
FreeItemList(list);
|
||||
}
|
||||
|
||||
void MPD::Connection::GetList(TagList &v, mpd_tag_type type)
|
||||
@@ -1150,7 +1149,7 @@ void MPD::Connection::CommitSearch(SongList &v)
|
||||
GoBusy();
|
||||
mpd_search_commit(itsConnection);
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(new Song(s));
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -1188,7 +1187,7 @@ void MPD::Connection::GetDirectory(const std::string &path, ItemList &v)
|
||||
it.type = itDirectory;
|
||||
goto WRITE;
|
||||
case MPD_ENTITY_TYPE_SONG:
|
||||
it.song = new Song(mpd_song_dup(mpd_entity_get_song(item)));
|
||||
it.song = Song(mpd_song_dup(mpd_entity_get_song(item)));
|
||||
it.type = itSong;
|
||||
goto WRITE;
|
||||
case MPD_ENTITY_TYPE_PLAYLIST:
|
||||
@@ -1215,7 +1214,7 @@ void MPD::Connection::GetDirectoryRecursive(const std::string &path, SongList &v
|
||||
GoBusy();
|
||||
mpd_send_list_all_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(new Song(s));
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -1228,7 +1227,7 @@ void MPD::Connection::GetSongs(const std::string &path, SongList &v)
|
||||
GoBusy();
|
||||
mpd_send_list_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(new Song(s));
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -1351,18 +1350,3 @@ int MPD::Connection::CheckForErrors()
|
||||
}
|
||||
return error_code;
|
||||
}
|
||||
|
||||
void MPD::FreeSongList(SongList &l)
|
||||
{
|
||||
for (SongList::iterator i = l.begin(); i != l.end(); ++i)
|
||||
delete *i;
|
||||
l.clear();
|
||||
}
|
||||
|
||||
void MPD::FreeItemList(ItemList &l)
|
||||
{
|
||||
for (ItemList::iterator i = l.begin(); i != l.end(); ++i)
|
||||
delete i->song;
|
||||
l.clear();
|
||||
}
|
||||
|
||||
|
||||
14
src/mpdpp.h
14
src/mpdpp.h
@@ -29,20 +29,13 @@
|
||||
|
||||
namespace MPD
|
||||
{
|
||||
namespace Message
|
||||
{
|
||||
extern const char *PartOfSongsAdded;
|
||||
extern const char *FullPlaylist;
|
||||
}
|
||||
|
||||
enum ItemType { itDirectory, itSong, itPlaylist };
|
||||
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
||||
enum ReplayGainMode { rgmOff, rgmTrack, rgmAlbum };
|
||||
|
||||
struct Item
|
||||
{
|
||||
Item() : song(0) { }
|
||||
Song *song;
|
||||
Song song;
|
||||
ItemType type;
|
||||
std::string name;
|
||||
};
|
||||
@@ -69,13 +62,10 @@ namespace MPD
|
||||
typedef std::pair<std::string, bool> Output;
|
||||
|
||||
typedef std::vector<Item> ItemList;
|
||||
typedef std::vector<Song *> SongList;
|
||||
typedef std::vector<Song> SongList;
|
||||
typedef std::vector<std::string> TagList;
|
||||
typedef std::vector<Output> OutputList;
|
||||
|
||||
void FreeSongList(SongList &);
|
||||
void FreeItemList(ItemList &);
|
||||
|
||||
class Connection
|
||||
{
|
||||
typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
|
||||
|
||||
@@ -185,15 +185,15 @@ 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]);
|
||||
|
||||
std::function<void(MPD::SongList::iterator, MPD::SongList::iterator)> iter_swap, quick_sort;
|
||||
auto song_cmp = [](MPD::Song *a, MPD::Song *b) {
|
||||
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].second), b.getTags((*SortDialog)[i].second)))
|
||||
return ret < 0;
|
||||
return a->getPosition() < b->getPosition();
|
||||
return a.getPosition() < b.getPosition();
|
||||
};
|
||||
iter_swap = [&playlist](MPD::SongList::iterator a, MPD::SongList::iterator b) {
|
||||
std::iter_swap(a, b);
|
||||
@@ -274,8 +274,8 @@ void Playlist::GetSelectedSongs(MPD::SongList &v)
|
||||
Items->GetSelected(selected);
|
||||
if (selected.empty())
|
||||
selected.push_back(Items->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(new MPD::Song(Items->at(*it)));
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(Items->at(*it));
|
||||
}
|
||||
|
||||
void Playlist::ApplyFilter(const std::string &s)
|
||||
@@ -562,18 +562,16 @@ bool Playlist::Add(const MPD::SongList &l, bool play, int position)
|
||||
return false;
|
||||
|
||||
Mpd.StartCommandsList();
|
||||
MPD::SongList::const_iterator it = l.begin();
|
||||
if (position < 0)
|
||||
{
|
||||
for (; it != l.end(); ++it)
|
||||
if (Mpd.AddSong(**it) < 0)
|
||||
for (auto it = l.begin(); it != l.end(); ++it)
|
||||
if (Mpd.AddSong(*it) < 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
MPD::SongList::const_reverse_iterator j = l.rbegin();
|
||||
for (; j != l.rend(); ++j)
|
||||
if (Mpd.AddSong(**j, position) < 0)
|
||||
for (auto j = l.rbegin(); j != l.rend(); ++j)
|
||||
if (Mpd.AddSong(*j, position) < 0)
|
||||
break;
|
||||
}
|
||||
if (!Mpd.CommitCommandsList())
|
||||
|
||||
@@ -157,20 +157,19 @@ void PlaylistEditor::Update()
|
||||
else
|
||||
Content->SetTitle(Config.titles_visibility ? "Playlist's content" : "");
|
||||
bool bold = 0;
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
for (auto it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if ((*it)->getHash() == myPlaylist->Items->at(j).getHash())
|
||||
if (it->getHash() == myPlaylist->Items->at(j).getHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Content->AddOption(**it, bold);
|
||||
Content->AddOption(*it, bold);
|
||||
bold = 0;
|
||||
}
|
||||
MPD::FreeSongList(list);
|
||||
Content->Window::Clear();
|
||||
Content->Display();
|
||||
}
|
||||
@@ -346,7 +345,6 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
|
||||
else if (w == Content && !Content->Empty())
|
||||
Content->Bold(Content->Choice(), myPlaylist->Add(Content->Current(), Content->isBold(), add_n_play));
|
||||
|
||||
FreeSongList(list);
|
||||
if (!add_n_play)
|
||||
w->Scroll(wDown);
|
||||
}
|
||||
@@ -416,8 +414,8 @@ void PlaylistEditor::GetSelectedSongs(MPD::SongList &v)
|
||||
Content->GetSelected(selected);
|
||||
if (selected.empty())
|
||||
selected.push_back(Content->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(new MPD::Song(Content->at(*it)));
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(Content->at(*it));
|
||||
}
|
||||
|
||||
void PlaylistEditor::ApplyFilter(const std::string &s)
|
||||
|
||||
@@ -64,7 +64,7 @@ void SearchEngine::Init()
|
||||
{
|
||||
static Display::ScreenFormat sf = { this, &Config.song_list_format };
|
||||
|
||||
w = new Menu< std::pair<Buffer *, MPD::Song *> >(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||
w = new Menu<SEItem>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
@@ -115,7 +115,7 @@ void SearchEngine::SwitchTo()
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = true;
|
||||
|
||||
if (!w->Back().first)
|
||||
if (!w->Back().isSong())
|
||||
{
|
||||
*w << XY(0, 0) << "Updating list...";
|
||||
UpdateFoundList();
|
||||
@@ -131,7 +131,7 @@ void SearchEngine::EnterPressed()
|
||||
{
|
||||
size_t option = w->Choice();
|
||||
if (option > ConstraintsNumber && option < SearchButton)
|
||||
w->Current().first->Clear();
|
||||
w->Current().buffer().Clear();
|
||||
if (option < SearchButton)
|
||||
LockStatusbar();
|
||||
|
||||
@@ -139,20 +139,20 @@ void SearchEngine::EnterPressed()
|
||||
{
|
||||
Statusbar() << fmtBold << ConstraintsNames[option] << fmtBoldEnd << ": ";
|
||||
itsConstraints[option] = Global::wFooter->GetString(itsConstraints[option]);
|
||||
w->Current().first->Clear();
|
||||
*w->Current().first << fmtBold << std::setw(13) << std::left << ConstraintsNames[option] << fmtBoldEnd << ": ";
|
||||
ShowTag(*w->Current().first, itsConstraints[option]);
|
||||
w->Current().buffer().Clear();
|
||||
w->Current().buffer() << fmtBold << std::setw(13) << std::left << ConstraintsNames[option] << fmtBoldEnd << ": ";
|
||||
ShowTag(w->Current().buffer(), itsConstraints[option]);
|
||||
}
|
||||
else if (option == ConstraintsNumber+1)
|
||||
{
|
||||
Config.search_in_db = !Config.search_in_db;
|
||||
*w->Current().first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||
w->Current().buffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||
}
|
||||
else if (option == ConstraintsNumber+2)
|
||||
{
|
||||
if (!*++SearchMode)
|
||||
SearchMode = &SearchModes[0];
|
||||
*w->Current().first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode;
|
||||
w->Current().buffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode;
|
||||
}
|
||||
else if (option == SearchButton)
|
||||
{
|
||||
@@ -160,16 +160,15 @@ void SearchEngine::EnterPressed()
|
||||
if (w->Size() > StaticOptions)
|
||||
Prepare();
|
||||
Search();
|
||||
if (!w->Back().first)
|
||||
if (w->Back().isSong())
|
||||
{
|
||||
if (Config.columns_in_search_engine)
|
||||
w->SetTitle(Config.titles_visibility ? Display::Columns(w->GetWidth()) : "");
|
||||
size_t found = w->Size()-SearchEngine::StaticOptions;
|
||||
found += 3; // don't count options inserted below
|
||||
w->InsertSeparator(ResetButton+1);
|
||||
w->InsertOption(ResetButton+2, std::make_pair(static_cast<Buffer *>(0), static_cast<MPD::Song *>(0)), 1, 1);
|
||||
w->at(ResetButton+2).first = new Buffer();
|
||||
*w->at(ResetButton+2).first << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
|
||||
w->InsertOption(ResetButton+2, SEItem(), 1, 1);
|
||||
w->at(ResetButton+2).mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
|
||||
w->InsertSeparator(ResetButton+3);
|
||||
UpdateFoundList();
|
||||
ShowMessage("Searching finished");
|
||||
@@ -187,7 +186,10 @@ void SearchEngine::EnterPressed()
|
||||
Reset();
|
||||
}
|
||||
else
|
||||
w->Bold(w->Choice(), myPlaylist->Add(*w->Current().second, w->isBold(), 1));
|
||||
{
|
||||
bool res = myPlaylist->Add(w->Current().song(), 1, 1);
|
||||
w->Bold(w->Choice(), res);
|
||||
}
|
||||
|
||||
if (option < SearchButton)
|
||||
UnlockStatusbar();
|
||||
@@ -195,7 +197,7 @@ void SearchEngine::EnterPressed()
|
||||
|
||||
void SearchEngine::SpacePressed()
|
||||
{
|
||||
if (w->Current().first)
|
||||
if (!w->Current().isSong())
|
||||
return;
|
||||
|
||||
if (Config.space_selects)
|
||||
@@ -205,7 +207,8 @@ void SearchEngine::SpacePressed()
|
||||
return;
|
||||
}
|
||||
|
||||
w->Bold(w->Choice(), myPlaylist->Add(*w->Current().second, w->isBold(), 0));
|
||||
bool res = myPlaylist->Add(w->Current().song(), 0, 0);
|
||||
w->Bold(w->Choice(), res);
|
||||
w->Scroll(wDown);
|
||||
}
|
||||
|
||||
@@ -234,12 +237,12 @@ void SearchEngine::MouseButtonPressed(MEVENT me)
|
||||
}
|
||||
}
|
||||
else
|
||||
Screen< Menu< std::pair<Buffer *, MPD::Song *> > >::MouseButtonPressed(me);
|
||||
Screen< Menu<SEItem> >::MouseButtonPressed(me);
|
||||
}
|
||||
|
||||
MPD::Song *SearchEngine::CurrentSong()
|
||||
{
|
||||
return !w->Empty() ? w->Current().second : 0;
|
||||
return !w->Empty() && w->Current().isSong() ? &w->Current().song() : 0;
|
||||
}
|
||||
|
||||
void SearchEngine::GetSelectedSongs(MPD::SongList &v)
|
||||
@@ -250,8 +253,11 @@ void SearchEngine::GetSelectedSongs(MPD::SongList &v)
|
||||
w->GetSelected(selected);
|
||||
if (selected.empty() && w->Choice() >= StaticOptions)
|
||||
selected.push_back(w->Choice());
|
||||
for (std::vector<size_t>::const_iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
v.push_back(new MPD::Song(*w->at(*it).second));
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
assert(w->at(*it).isSong());
|
||||
v.push_back(w->at(*it).song());
|
||||
}
|
||||
}
|
||||
|
||||
void SearchEngine::ApplyFilter(const std::string &s)
|
||||
@@ -266,7 +272,7 @@ void SearchEngine::UpdateFoundList()
|
||||
{
|
||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
||||
{
|
||||
if (myPlaylist->Items->at(j).getHash() == w->at(i).second->getHash())
|
||||
if (myPlaylist->Items->at(j).getHash() == w->at(i).song().getHash())
|
||||
{
|
||||
bold = 1;
|
||||
break;
|
||||
@@ -283,7 +289,7 @@ void SearchEngine::SelectAlbum()
|
||||
if (pos < StaticOptions)
|
||||
return; // not on a song
|
||||
|
||||
std::string album = w->at(pos).second->getAlbum();
|
||||
std::string album = w->at(pos).song().getAlbum();
|
||||
|
||||
// select song under cursor
|
||||
w->Select(pos, 1);
|
||||
@@ -291,7 +297,7 @@ void SearchEngine::SelectAlbum()
|
||||
// go up
|
||||
while (pos > StaticOptions)
|
||||
{
|
||||
if (w->at(--pos).second->getAlbum() != album)
|
||||
if (w->at(--pos).song().getAlbum() != album)
|
||||
break;
|
||||
else
|
||||
w->Select(pos, 1);
|
||||
@@ -300,7 +306,7 @@ void SearchEngine::SelectAlbum()
|
||||
// go down
|
||||
while (pos < w->Size() - 1)
|
||||
{
|
||||
if (w->at(++pos).second->getAlbum() != album)
|
||||
if (w->at(++pos).song().getAlbum() != album)
|
||||
break;
|
||||
else
|
||||
w->Select(pos, 1);
|
||||
@@ -309,14 +315,6 @@ void SearchEngine::SelectAlbum()
|
||||
|
||||
void SearchEngine::Prepare()
|
||||
{
|
||||
for (size_t i = 0; i < w->Size(); ++i)
|
||||
{
|
||||
if (i == ConstraintsNumber || i == SearchButton-1 || i == ResetButton+1 || i == ResetButton+3) // separators
|
||||
continue;
|
||||
delete (*w)[i].first;
|
||||
delete (*w)[i].second;
|
||||
}
|
||||
|
||||
w->SetTitle("");
|
||||
w->Clear();
|
||||
w->ResizeList(StaticOptions-3);
|
||||
@@ -324,24 +322,17 @@ void SearchEngine::Prepare()
|
||||
w->IntoSeparator(ConstraintsNumber);
|
||||
w->IntoSeparator(SearchButton-1);
|
||||
|
||||
for (size_t i = 0; i < StaticOptions-3; ++i)
|
||||
{
|
||||
if (i == ConstraintsNumber || i == SearchButton-1) // separators
|
||||
continue;
|
||||
(*w)[i].first = new Buffer();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ConstraintsNumber; ++i)
|
||||
{
|
||||
*(*w)[i].first << fmtBold << std::setw(13) << std::left << ConstraintsNames[i] << fmtBoldEnd << ": ";
|
||||
ShowTag(*(*w)[i].first, itsConstraints[i]);
|
||||
(*w)[i].mkBuffer() << fmtBold << std::setw(13) << std::left << ConstraintsNames[i] << fmtBoldEnd << ": ";
|
||||
ShowTag((*w)[i].buffer(), itsConstraints[i]);
|
||||
}
|
||||
|
||||
*w->at(ConstraintsNumber+1).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||
*w->at(ConstraintsNumber+2).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode;
|
||||
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(SearchButton).first << "Search";
|
||||
*w->at(ResetButton).first << "Reset";
|
||||
w->at(SearchButton).mkBuffer() << "Search";
|
||||
w->at(ResetButton).mkBuffer() << "Reset";
|
||||
}
|
||||
|
||||
void SearchEngine::Reset()
|
||||
@@ -394,8 +385,8 @@ void SearchEngine::Search()
|
||||
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
|
||||
MPD::SongList results;
|
||||
Mpd.CommitSearch(results);
|
||||
for (MPD::SongList::const_iterator it = results.begin(); it != results.end(); ++it)
|
||||
w->AddOption(std::make_pair(static_cast<Buffer *>(0), *it));
|
||||
for (auto it = results.begin(); it != results.end(); ++it)
|
||||
w->AddOption(*it);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -406,7 +397,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]);
|
||||
}
|
||||
|
||||
bool any_found = 1;
|
||||
@@ -422,16 +413,16 @@ void SearchEngine::Search()
|
||||
if (regcomp(&rx, itsConstraints[0].c_str(), REG_ICASE | Config.regex_type) == 0)
|
||||
{
|
||||
any_found =
|
||||
!regexec(&rx, (*it)->getArtist().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getAlbumArtist().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getTitle().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getAlbum().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getName().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getComposer().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getPerformer().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getGenre().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getDate().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, (*it)->getComment().c_str(), 0, 0, 0);
|
||||
!regexec(&rx, it->getArtist().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getAlbumArtist().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getTitle().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getAlbum().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getName().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getComposer().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getPerformer().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getGenre().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getDate().c_str(), 0, 0, 0)
|
||||
|| !regexec(&rx, it->getComment().c_str(), 0, 0, 0);
|
||||
}
|
||||
regfree(&rx);
|
||||
}
|
||||
@@ -439,61 +430,61 @@ void SearchEngine::Search()
|
||||
if (found && !itsConstraints[1].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[1].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getArtist().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getArtist().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[2].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[2].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getAlbumArtist().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getAlbumArtist().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[3].empty())
|
||||
{
|
||||
if(!regcomp(&rx, itsConstraints[3].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getTitle().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getTitle().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[4].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[4].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getAlbum().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getAlbum().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[5].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[5].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getName().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getName().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[6].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[6].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getComposer().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getComposer().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[7].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[7].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getPerformer().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getPerformer().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[8].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[8].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getGenre().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getGenre().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[9].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[9].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getDate().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getDate().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
if (found && !itsConstraints[10].empty())
|
||||
{
|
||||
if (!regcomp(&rx, itsConstraints[10].c_str(), REG_ICASE | Config.regex_type))
|
||||
found = !regexec(&rx, (*it)->getComment().c_str(), 0, 0, 0);
|
||||
found = !regexec(&rx, it->getComment().c_str(), 0, 0, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
}
|
||||
@@ -503,60 +494,57 @@ void SearchEngine::Search()
|
||||
|
||||
if (!itsConstraints[0].empty())
|
||||
any_found =
|
||||
!cmp((*it)->getArtist(), itsConstraints[0])
|
||||
|| !cmp((*it)->getAlbumArtist(), itsConstraints[0])
|
||||
|| !cmp((*it)->getTitle(), itsConstraints[0])
|
||||
|| !cmp((*it)->getAlbum(), itsConstraints[0])
|
||||
|| !cmp((*it)->getName(), itsConstraints[0])
|
||||
|| !cmp((*it)->getComposer(), itsConstraints[0])
|
||||
|| !cmp((*it)->getPerformer(), itsConstraints[0])
|
||||
|| !cmp((*it)->getGenre(), itsConstraints[0])
|
||||
|| !cmp((*it)->getDate(), itsConstraints[0])
|
||||
|| !cmp((*it)->getComment(), itsConstraints[0]);
|
||||
!cmp(it->getArtist(), itsConstraints[0])
|
||||
|| !cmp(it->getAlbumArtist(), itsConstraints[0])
|
||||
|| !cmp(it->getTitle(), itsConstraints[0])
|
||||
|| !cmp(it->getAlbum(), itsConstraints[0])
|
||||
|| !cmp(it->getName(), itsConstraints[0])
|
||||
|| !cmp(it->getComposer(), itsConstraints[0])
|
||||
|| !cmp(it->getPerformer(), itsConstraints[0])
|
||||
|| !cmp(it->getGenre(), itsConstraints[0])
|
||||
|| !cmp(it->getDate(), itsConstraints[0])
|
||||
|| !cmp(it->getComment(), itsConstraints[0]);
|
||||
|
||||
if (found && !itsConstraints[1].empty())
|
||||
found = !cmp((*it)->getArtist(), itsConstraints[1]);
|
||||
found = !cmp(it->getArtist(), itsConstraints[1]);
|
||||
if (found && !itsConstraints[2].empty())
|
||||
found = !cmp((*it)->getAlbumArtist(), itsConstraints[2]);
|
||||
found = !cmp(it->getAlbumArtist(), itsConstraints[2]);
|
||||
if (found && !itsConstraints[3].empty())
|
||||
found = !cmp((*it)->getTitle(), itsConstraints[3]);
|
||||
found = !cmp(it->getTitle(), itsConstraints[3]);
|
||||
if (found && !itsConstraints[4].empty())
|
||||
found = !cmp((*it)->getAlbum(), itsConstraints[4]);
|
||||
found = !cmp(it->getAlbum(), itsConstraints[4]);
|
||||
if (found && !itsConstraints[5].empty())
|
||||
found = !cmp((*it)->getName(), itsConstraints[5]);
|
||||
found = !cmp(it->getName(), itsConstraints[5]);
|
||||
if (found && !itsConstraints[6].empty())
|
||||
found = !cmp((*it)->getComposer(), itsConstraints[6]);
|
||||
found = !cmp(it->getComposer(), itsConstraints[6]);
|
||||
if (found && !itsConstraints[7].empty())
|
||||
found = !cmp((*it)->getPerformer(), itsConstraints[7]);
|
||||
found = !cmp(it->getPerformer(), itsConstraints[7]);
|
||||
if (found && !itsConstraints[8].empty())
|
||||
found = !cmp((*it)->getGenre(), itsConstraints[8]);
|
||||
found = !cmp(it->getGenre(), itsConstraints[8]);
|
||||
if (found && !itsConstraints[9].empty())
|
||||
found = !cmp((*it)->getDate(), itsConstraints[9]);
|
||||
found = !cmp(it->getDate(), itsConstraints[9]);
|
||||
if (found && !itsConstraints[10].empty())
|
||||
found = !cmp((*it)->getComment(), itsConstraints[10]);
|
||||
found = !cmp(it->getComment(), itsConstraints[10]);
|
||||
}
|
||||
|
||||
if (found && any_found)
|
||||
{
|
||||
MPD::Song *ss = Config.search_in_db ? *it : new MPD::Song(**it);
|
||||
w->AddOption(std::make_pair(static_cast<Buffer *>(0), ss));
|
||||
w->AddOption(*it);
|
||||
list[it-list.begin()] = 0;
|
||||
}
|
||||
found = 1;
|
||||
any_found = 1;
|
||||
}
|
||||
if (Config.search_in_db) // free song list only if it's database
|
||||
MPD::FreeSongList(list);
|
||||
}
|
||||
|
||||
std::string SearchEngine::SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &pair, void *)
|
||||
std::string SearchEngine::SearchEngineOptionToString(const SEItem &ei, void *)
|
||||
{
|
||||
if (pair.second)
|
||||
if (!ei.isSong())
|
||||
{
|
||||
if (!Config.columns_in_search_engine)
|
||||
return pair.second->toString(Config.song_list_format_dollar_free);
|
||||
return ei.song().toString(Config.song_list_format_dollar_free);
|
||||
else
|
||||
return Playlist::SongInColumnsToString(*pair.second, 0);
|
||||
return Playlist::SongInColumnsToString(ei.song(), 0);
|
||||
}
|
||||
else
|
||||
return "";
|
||||
|
||||
@@ -21,10 +21,58 @@
|
||||
#ifndef _SEARCH_ENGINE_H
|
||||
#define _SEARCH_ENGINE_H
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "mpdpp.h"
|
||||
#include "ncmpcpp.h"
|
||||
|
||||
class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
|
||||
struct SEItem
|
||||
{
|
||||
SEItem() : isThisSong(false), itsBuffer(0) { }
|
||||
SEItem(Buffer *buf) : isThisSong(false), itsBuffer(buf) { }
|
||||
SEItem(const MPD::Song &s) : isThisSong(true), itsSong(s) { }
|
||||
SEItem(const SEItem &ei) { *this = ei; }
|
||||
~SEItem() {
|
||||
if (!isThisSong)
|
||||
delete itsBuffer;
|
||||
}
|
||||
|
||||
Buffer &mkBuffer() {
|
||||
assert(!isThisSong);
|
||||
delete itsBuffer;
|
||||
itsBuffer = new Buffer();
|
||||
return *itsBuffer;
|
||||
}
|
||||
|
||||
bool isSong() const { return isThisSong; }
|
||||
|
||||
Buffer &buffer() { assert(!isThisSong && itsBuffer); return *itsBuffer; }
|
||||
MPD::Song &song() { assert(isThisSong); return itsSong; }
|
||||
|
||||
const Buffer &buffer() const { assert(!isThisSong && itsBuffer); return *itsBuffer; }
|
||||
const MPD::Song &song() const { assert(isThisSong); return itsSong; }
|
||||
|
||||
SEItem &operator=(const SEItem &se) {
|
||||
if (this == &se)
|
||||
return *this;
|
||||
isThisSong = se.isThisSong;
|
||||
if (se.isThisSong)
|
||||
itsSong = se.itsSong;
|
||||
else if (se.itsBuffer)
|
||||
itsBuffer = new Buffer(*se.itsBuffer);
|
||||
else
|
||||
itsBuffer = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
bool isThisSong;
|
||||
|
||||
Buffer *itsBuffer;
|
||||
MPD::Song itsSong;
|
||||
};
|
||||
|
||||
class SearchEngine : public Screen< Menu<SEItem> >
|
||||
{
|
||||
public:
|
||||
virtual void Resize();
|
||||
@@ -38,7 +86,7 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
|
||||
virtual bool isTabbable() { return true; }
|
||||
|
||||
virtual MPD::Song *CurrentSong();
|
||||
virtual MPD::Song *GetSong(size_t pos) { return !w->isSeparator(pos) ? w->at(pos).second : 0; }
|
||||
virtual MPD::Song *GetSong(size_t pos) { return !w->isSeparator(pos) && w->at(pos).isSong() ? &w->at(pos).song() : 0; }
|
||||
|
||||
virtual bool allowsSelection() { return w->Choice() >= StaticOptions; }
|
||||
virtual void ReverseSelection() { w->ReverseSelection(StaticOptions); }
|
||||
@@ -68,7 +116,7 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
|
||||
|
||||
const char **SearchMode;
|
||||
|
||||
static std::string SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &, void *);
|
||||
static std::string SearchEngineOptionToString(const SEItem &, void *);
|
||||
|
||||
static const char *SearchModes[];
|
||||
|
||||
|
||||
@@ -179,8 +179,8 @@ void SelectedItemsAdder::EnterPressed()
|
||||
{
|
||||
std::string utf_playlist = locale_to_utf_cpy(playlist);
|
||||
Mpd.StartCommandsList();
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
Mpd.AddToPlaylist(utf_playlist, **it);
|
||||
for (auto it = list.begin(); it != list.end(); ++it)
|
||||
Mpd.AddToPlaylist(utf_playlist, *it);
|
||||
if (Mpd.CommitCommandsList())
|
||||
ShowMessage("Selected item(s) added to playlist \"%s\"", playlist.c_str());
|
||||
}
|
||||
@@ -189,8 +189,8 @@ void SelectedItemsAdder::EnterPressed()
|
||||
{
|
||||
std::string playlist = locale_to_utf_cpy(w->Current());
|
||||
Mpd.StartCommandsList();
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
Mpd.AddToPlaylist(playlist, **it);
|
||||
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());
|
||||
}
|
||||
@@ -247,7 +247,6 @@ void SelectedItemsAdder::EnterPressed()
|
||||
if (successful_operation)
|
||||
ShowMessage("Selected item(s) added");
|
||||
}
|
||||
MPD::FreeSongList(list);
|
||||
SwitchTo();
|
||||
}
|
||||
|
||||
|
||||
@@ -234,16 +234,16 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
||||
myPlaylist->Items->Reserve(playlist_length);
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
int pos = (*it)->getPosition();
|
||||
int pos = it->getPosition();
|
||||
if (pos < int(myPlaylist->Items->Size()))
|
||||
{
|
||||
// if song's already in playlist, replace it with a new one
|
||||
myPlaylist->Items->at(pos) = **it;
|
||||
myPlaylist->Items->at(pos) = *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise just add it to playlist
|
||||
myPlaylist->Items->AddOption(**it);
|
||||
myPlaylist->Items->AddOption(*it);
|
||||
}
|
||||
}
|
||||
if (was_filtered)
|
||||
@@ -252,7 +252,6 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
||||
if (myPlaylist->Items->Empty())
|
||||
myPlaylist->Items->ShowAll();
|
||||
}
|
||||
FreeSongList(list);
|
||||
|
||||
Playlist::ReloadTotalLength = true;
|
||||
Playlist::ReloadRemaining = true;
|
||||
|
||||
Reference in New Issue
Block a user