add field 'Any' to search engine

This commit is contained in:
Andrzej Rybczak
2009-02-05 18:33:56 +01:00
parent 7be920b6ad
commit edeb2fa37d
3 changed files with 87 additions and 36 deletions

View File

@@ -362,7 +362,7 @@ int main(int argc, char *argv[])
Song lyrics_song;
Song edited_song;
Song sought_pattern;
SearchPattern sought_pattern;
bool main_exit = 0;
bool title_allowed = !Config.display_screens_numbers_on_start;
@@ -1266,13 +1266,20 @@ int main(int argc, char *argv[])
size_t option = mSearcher->Choice();
LockStatusbar();
Song &s = sought_pattern;
SearchPattern &s = sought_pattern;
if (option <= 12)
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:
{
Statusbar() << fmtBold << "Artist: " << fmtBoldEnd;
@@ -1364,11 +1371,11 @@ int main(int argc, char *argv[])
mSearcher->SetTitle(DisplayColumns(Config.song_columns_list_format));
size_t found = mSearcher->Size()-search_engine_static_options;
found += 3; // don't count options inserted below
mSearcher->InsertSeparator(16);
mSearcher->InsertOption(17, make_pair((Buffer *)0, (Song *)0), 1, 1);
mSearcher->at(17).first = new Buffer();
*mSearcher->at(17).first << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
mSearcher->InsertSeparator(18);
mSearcher->InsertSeparator(search_engine_reset_button+1);
mSearcher->InsertOption(search_engine_reset_button+2, make_pair((Buffer *)0, (Song *)0), 1, 1);
mSearcher->at(search_engine_reset_button+2).first = new Buffer();
*mSearcher->at(search_engine_reset_button+2).first << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault;
mSearcher->InsertSeparator(search_engine_reset_button+3);
UpdateFoundList();
ShowMessage("Searching finished!");
for (size_t i = 0; i < search_engine_static_options-4; i++)

View File

@@ -68,7 +68,7 @@ void UpdateFoundList()
}
}
void PrepareSearchEngine(Song &s)
void PrepareSearchEngine(SearchPattern &s)
{
for (size_t i = 0; i < mSearcher->Size(); i++)
{
@@ -84,12 +84,12 @@ void PrepareSearchEngine(Song &s)
mSearcher->SetTitle("");
mSearcher->Clear();
mSearcher->Reset();
mSearcher->ResizeBuffer(16);
mSearcher->ResizeBuffer(17);
mSearcher->IntoSeparator(9);
mSearcher->IntoSeparator(13);
mSearcher->IntoSeparator(10);
mSearcher->IntoSeparator(14);
for (size_t i = 0; i < 16; i++)
for (size_t i = 0; i < 17; i++)
{
try
{
@@ -98,25 +98,26 @@ void PrepareSearchEngine(Song &s)
catch (List::InvalidItem) { }
}
*mSearcher->at(0).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist());
*mSearcher->at(1).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle());
*mSearcher->at(2).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum());
*mSearcher->at(3).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName());
*mSearcher->at(4).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer());
*mSearcher->at(5).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer());
*mSearcher->at(6).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre());
*mSearcher->at(7).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(s.GetYear());
*mSearcher->at(8).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(s.GetComment());
*mSearcher->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(s.Any());
*mSearcher->at(1).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist());
*mSearcher->at(2).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle());
*mSearcher->at(3).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum());
*mSearcher->at(4).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName());
*mSearcher->at(5).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer());
*mSearcher->at(6).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer());
*mSearcher->at(7).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre());
*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 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(11).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
*mSearcher->at(12).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (search_match_to_pattern ? search_mode_normal : search_mode_strict);
*mSearcher->at(13).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (search_case_sensitive ? "Yes" : "No");
*mSearcher->at(14).first << "Search";
*mSearcher->at(15).first << "Reset";
*mSearcher->at(15).first << "Search";
*mSearcher->at(16).first << "Reset";
}
void Search(Song &s)
void Search(SearchPattern &s)
{
if (s.Empty())
return;
@@ -131,11 +132,16 @@ void Search(Song &s)
list.push_back(&(*mPlaylist)[i]);
}
bool any_found = 1;
bool found = 1;
if (!search_case_sensitive)
{
string t;
t = s.Any();
ToLower(t);
s.Any(t);
t = s.GetArtist();
ToLower(t);
s.SetArtist(t);
@@ -213,6 +219,18 @@ void Search(Song &s)
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())
found = copy.GetArtist().find(s.GetArtist()) != string::npos;
if (found && !s.GetTitle().empty())
@@ -228,12 +246,24 @@ void Search(Song &s)
if (found && !s.GetGenre().empty())
found = copy.GetGenre().find(s.GetGenre()) != string::npos;
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())
found = copy.GetComment().find(s.GetComment()) != string::npos;
}
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())
found = copy.GetArtist() == s.GetArtist();
if (found && !s.GetTitle().empty())
@@ -249,17 +279,18 @@ void Search(Song &s)
if (found && !s.GetGenre().empty())
found = copy.GetGenre() == s.GetGenre();
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())
found = copy.GetComment() == s.GetComment();
}
if (found)
if (found && any_found)
{
mSearcher->AddOption(make_pair((Buffer *)0, *it));
list[it-list.begin()] = 0;
}
found = 1;
any_found = 1;
}
if (Config.search_in_db) // free song list only if it's database
FreeSongList(list);

View File

@@ -24,14 +24,27 @@
#include "mpdpp.h"
#include "ncmpcpp.h"
const size_t search_engine_static_options = 19;
const size_t search_engine_search_button = 14;
const size_t search_engine_reset_button = 15;
class SearchPattern : public Song
{
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 UpdateFoundList();
void PrepareSearchEngine(Song &s);
void Search(Song &);
void PrepareSearchEngine(SearchPattern &s);
void Search(SearchPattern &);
#endif