add field 'Any' to search engine
This commit is contained in:
@@ -362,7 +362,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Song lyrics_song;
|
Song lyrics_song;
|
||||||
Song edited_song;
|
Song edited_song;
|
||||||
Song sought_pattern;
|
SearchPattern sought_pattern;
|
||||||
|
|
||||||
bool main_exit = 0;
|
bool main_exit = 0;
|
||||||
bool title_allowed = !Config.display_screens_numbers_on_start;
|
bool title_allowed = !Config.display_screens_numbers_on_start;
|
||||||
@@ -1266,13 +1266,20 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
size_t option = mSearcher->Choice();
|
size_t option = mSearcher->Choice();
|
||||||
LockStatusbar();
|
LockStatusbar();
|
||||||
Song &s = sought_pattern;
|
SearchPattern &s = sought_pattern;
|
||||||
|
|
||||||
if (option <= 12)
|
if (option <= 12)
|
||||||
mSearcher->Current().first->Clear();
|
mSearcher->Current().first->Clear();
|
||||||
|
|
||||||
switch (option+1)
|
switch (option)
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
Statusbar() << fmtBold << "Any: " << fmtBoldEnd;
|
||||||
|
s.Any(wFooter->GetString(s.Any()));
|
||||||
|
*mSearcher->Current().first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(s.Any());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
Statusbar() << fmtBold << "Artist: " << fmtBoldEnd;
|
Statusbar() << fmtBold << "Artist: " << fmtBoldEnd;
|
||||||
@@ -1364,11 +1371,11 @@ int main(int argc, char *argv[])
|
|||||||
mSearcher->SetTitle(DisplayColumns(Config.song_columns_list_format));
|
mSearcher->SetTitle(DisplayColumns(Config.song_columns_list_format));
|
||||||
size_t found = mSearcher->Size()-search_engine_static_options;
|
size_t found = mSearcher->Size()-search_engine_static_options;
|
||||||
found += 3; // don't count options inserted below
|
found += 3; // don't count options inserted below
|
||||||
mSearcher->InsertSeparator(16);
|
mSearcher->InsertSeparator(search_engine_reset_button+1);
|
||||||
mSearcher->InsertOption(17, make_pair((Buffer *)0, (Song *)0), 1, 1);
|
mSearcher->InsertOption(search_engine_reset_button+2, make_pair((Buffer *)0, (Song *)0), 1, 1);
|
||||||
mSearcher->at(17).first = new Buffer();
|
mSearcher->at(search_engine_reset_button+2).first = new Buffer();
|
||||||
*mSearcher->at(17).first << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
|
*mSearcher->at(search_engine_reset_button+2).first << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
|
||||||
mSearcher->InsertSeparator(18);
|
mSearcher->InsertSeparator(search_engine_reset_button+3);
|
||||||
UpdateFoundList();
|
UpdateFoundList();
|
||||||
ShowMessage("Searching finished!");
|
ShowMessage("Searching finished!");
|
||||||
for (size_t i = 0; i < search_engine_static_options-4; i++)
|
for (size_t i = 0; i < search_engine_static_options-4; i++)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ void UpdateFoundList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrepareSearchEngine(Song &s)
|
void PrepareSearchEngine(SearchPattern &s)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < mSearcher->Size(); i++)
|
for (size_t i = 0; i < mSearcher->Size(); i++)
|
||||||
{
|
{
|
||||||
@@ -84,12 +84,12 @@ void PrepareSearchEngine(Song &s)
|
|||||||
mSearcher->SetTitle("");
|
mSearcher->SetTitle("");
|
||||||
mSearcher->Clear();
|
mSearcher->Clear();
|
||||||
mSearcher->Reset();
|
mSearcher->Reset();
|
||||||
mSearcher->ResizeBuffer(16);
|
mSearcher->ResizeBuffer(17);
|
||||||
|
|
||||||
mSearcher->IntoSeparator(9);
|
mSearcher->IntoSeparator(10);
|
||||||
mSearcher->IntoSeparator(13);
|
mSearcher->IntoSeparator(14);
|
||||||
|
|
||||||
for (size_t i = 0; i < 16; i++)
|
for (size_t i = 0; i < 17; i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -98,25 +98,26 @@ void PrepareSearchEngine(Song &s)
|
|||||||
catch (List::InvalidItem) { }
|
catch (List::InvalidItem) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
*mSearcher->at(0).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist());
|
*mSearcher->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(s.Any());
|
||||||
*mSearcher->at(1).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle());
|
*mSearcher->at(1).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist());
|
||||||
*mSearcher->at(2).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum());
|
*mSearcher->at(2).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle());
|
||||||
*mSearcher->at(3).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName());
|
*mSearcher->at(3).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum());
|
||||||
*mSearcher->at(4).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer());
|
*mSearcher->at(4).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName());
|
||||||
*mSearcher->at(5).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer());
|
*mSearcher->at(5).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer());
|
||||||
*mSearcher->at(6).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre());
|
*mSearcher->at(6).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer());
|
||||||
*mSearcher->at(7).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(s.GetYear());
|
*mSearcher->at(7).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre());
|
||||||
*mSearcher->at(8).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(s.GetComment());
|
*mSearcher->at(8).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(s.GetYear());
|
||||||
|
*mSearcher->at(9).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(s.GetComment());
|
||||||
|
|
||||||
*mSearcher->at(10).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
*mSearcher->at(11).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||||
*mSearcher->at(11).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (search_match_to_pattern ? search_mode_normal : search_mode_strict);
|
*mSearcher->at(12).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (search_match_to_pattern ? search_mode_normal : search_mode_strict);
|
||||||
*mSearcher->at(12).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (search_case_sensitive ? "Yes" : "No");
|
*mSearcher->at(13).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (search_case_sensitive ? "Yes" : "No");
|
||||||
|
|
||||||
*mSearcher->at(14).first << "Search";
|
*mSearcher->at(15).first << "Search";
|
||||||
*mSearcher->at(15).first << "Reset";
|
*mSearcher->at(16).first << "Reset";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Search(Song &s)
|
void Search(SearchPattern &s)
|
||||||
{
|
{
|
||||||
if (s.Empty())
|
if (s.Empty())
|
||||||
return;
|
return;
|
||||||
@@ -131,11 +132,16 @@ void Search(Song &s)
|
|||||||
list.push_back(&(*mPlaylist)[i]);
|
list.push_back(&(*mPlaylist)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool any_found = 1;
|
||||||
bool found = 1;
|
bool found = 1;
|
||||||
|
|
||||||
if (!search_case_sensitive)
|
if (!search_case_sensitive)
|
||||||
{
|
{
|
||||||
string t;
|
string t;
|
||||||
|
t = s.Any();
|
||||||
|
ToLower(t);
|
||||||
|
s.Any(t);
|
||||||
|
|
||||||
t = s.GetArtist();
|
t = s.GetArtist();
|
||||||
ToLower(t);
|
ToLower(t);
|
||||||
s.SetArtist(t);
|
s.SetArtist(t);
|
||||||
@@ -213,6 +219,18 @@ void Search(Song &s)
|
|||||||
|
|
||||||
if (search_match_to_pattern)
|
if (search_match_to_pattern)
|
||||||
{
|
{
|
||||||
|
if (!s.Any().empty())
|
||||||
|
any_found =
|
||||||
|
copy.GetArtist().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetTitle().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetAlbum().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetFile().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetComposer().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetPerformer().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetGenre().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetYear().find(s.Any()) != string::npos
|
||||||
|
|| copy.GetComment().find(s.Any()) != string::npos;
|
||||||
|
|
||||||
if (found && !s.GetArtist().empty())
|
if (found && !s.GetArtist().empty())
|
||||||
found = copy.GetArtist().find(s.GetArtist()) != string::npos;
|
found = copy.GetArtist().find(s.GetArtist()) != string::npos;
|
||||||
if (found && !s.GetTitle().empty())
|
if (found && !s.GetTitle().empty())
|
||||||
@@ -228,12 +246,24 @@ void Search(Song &s)
|
|||||||
if (found && !s.GetGenre().empty())
|
if (found && !s.GetGenre().empty())
|
||||||
found = copy.GetGenre().find(s.GetGenre()) != string::npos;
|
found = copy.GetGenre().find(s.GetGenre()) != string::npos;
|
||||||
if (found && !s.GetYear().empty())
|
if (found && !s.GetYear().empty())
|
||||||
found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear());
|
found = copy.GetYear().find(s.GetYear()) != string::npos;
|
||||||
if (found && !s.GetComment().empty())
|
if (found && !s.GetComment().empty())
|
||||||
found = copy.GetComment().find(s.GetComment()) != string::npos;
|
found = copy.GetComment().find(s.GetComment()) != string::npos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!s.Any().empty())
|
||||||
|
any_found =
|
||||||
|
copy.GetArtist() == s.Any()
|
||||||
|
|| copy.GetTitle() == s.Any()
|
||||||
|
|| copy.GetAlbum() == s.Any()
|
||||||
|
|| copy.GetFile() == s.Any()
|
||||||
|
|| copy.GetComposer() == s.Any()
|
||||||
|
|| copy.GetPerformer() == s.Any()
|
||||||
|
|| copy.GetGenre() == s.Any()
|
||||||
|
|| copy.GetYear() == s.Any()
|
||||||
|
|| copy.GetComment() == s.Any();
|
||||||
|
|
||||||
if (found && !s.GetArtist().empty())
|
if (found && !s.GetArtist().empty())
|
||||||
found = copy.GetArtist() == s.GetArtist();
|
found = copy.GetArtist() == s.GetArtist();
|
||||||
if (found && !s.GetTitle().empty())
|
if (found && !s.GetTitle().empty())
|
||||||
@@ -249,17 +279,18 @@ void Search(Song &s)
|
|||||||
if (found && !s.GetGenre().empty())
|
if (found && !s.GetGenre().empty())
|
||||||
found = copy.GetGenre() == s.GetGenre();
|
found = copy.GetGenre() == s.GetGenre();
|
||||||
if (found && !s.GetYear().empty())
|
if (found && !s.GetYear().empty())
|
||||||
found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear());
|
found = copy.GetYear() == s.GetYear();
|
||||||
if (found && !s.GetComment().empty())
|
if (found && !s.GetComment().empty())
|
||||||
found = copy.GetComment() == s.GetComment();
|
found = copy.GetComment() == s.GetComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
if (found && any_found)
|
||||||
{
|
{
|
||||||
mSearcher->AddOption(make_pair((Buffer *)0, *it));
|
mSearcher->AddOption(make_pair((Buffer *)0, *it));
|
||||||
list[it-list.begin()] = 0;
|
list[it-list.begin()] = 0;
|
||||||
}
|
}
|
||||||
found = 1;
|
found = 1;
|
||||||
|
any_found = 1;
|
||||||
}
|
}
|
||||||
if (Config.search_in_db) // free song list only if it's database
|
if (Config.search_in_db) // free song list only if it's database
|
||||||
FreeSongList(list);
|
FreeSongList(list);
|
||||||
|
|||||||
@@ -24,14 +24,27 @@
|
|||||||
#include "mpdpp.h"
|
#include "mpdpp.h"
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
|
|
||||||
const size_t search_engine_static_options = 19;
|
class SearchPattern : public Song
|
||||||
const size_t search_engine_search_button = 14;
|
{
|
||||||
const size_t search_engine_reset_button = 15;
|
public:
|
||||||
|
const string &Any() { return itsAnyField; }
|
||||||
|
const string &Any(const string &s) { itsAnyField = s; return itsAnyField; }
|
||||||
|
|
||||||
|
void Clear() { Song::Clear(); itsAnyField.clear(); }
|
||||||
|
bool Empty() { return Song::Empty() && itsAnyField.empty(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
string itsAnyField;
|
||||||
|
};
|
||||||
|
|
||||||
|
const size_t search_engine_static_options = 20;
|
||||||
|
const size_t search_engine_search_button = 15;
|
||||||
|
const size_t search_engine_reset_button = 16;
|
||||||
|
|
||||||
void SearchEngineDisplayer(const std::pair<Buffer *, Song *> &, void *, Menu< std::pair<Buffer *, Song *> > *);
|
void SearchEngineDisplayer(const std::pair<Buffer *, Song *> &, void *, Menu< std::pair<Buffer *, Song *> > *);
|
||||||
void UpdateFoundList();
|
void UpdateFoundList();
|
||||||
void PrepareSearchEngine(Song &s);
|
void PrepareSearchEngine(SearchPattern &s);
|
||||||
void Search(Song &);
|
void Search(SearchPattern &);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user