get rid of case sensivity switch in search engine
I don't think anybody was using it.
This commit is contained in:
@@ -50,12 +50,11 @@ const char *SearchEngine::ConstraintsNames[] =
|
|||||||
const char *SearchEngine::NormalMode = "Match if tag contains searched phrase (regexes supported)";
|
const char *SearchEngine::NormalMode = "Match if tag contains searched phrase (regexes supported)";
|
||||||
const char *SearchEngine::StrictMode = "Match only if both values are the same";
|
const char *SearchEngine::StrictMode = "Match only if both values are the same";
|
||||||
|
|
||||||
size_t SearchEngine::StaticOptions = 20;
|
size_t SearchEngine::StaticOptions = 19;
|
||||||
size_t SearchEngine::SearchButton = 15;
|
size_t SearchEngine::ResetButton = 15;
|
||||||
size_t SearchEngine::ResetButton = 16;
|
size_t SearchEngine::SearchButton = 14;
|
||||||
|
|
||||||
bool SearchEngine::MatchToPattern = 1;
|
bool SearchEngine::MatchToPattern = 1;
|
||||||
int SearchEngine::CaseSensitive = REG_ICASE;
|
|
||||||
|
|
||||||
void SearchEngine::Init()
|
void SearchEngine::Init()
|
||||||
{
|
{
|
||||||
@@ -125,21 +124,16 @@ void SearchEngine::EnterPressed()
|
|||||||
*w->Current().first << fmtBold << std::setw(10) << std::left << ConstraintsNames[option] << fmtBoldEnd << ' ';
|
*w->Current().first << fmtBold << std::setw(10) << std::left << ConstraintsNames[option] << fmtBoldEnd << ' ';
|
||||||
ShowTag(*w->Current().first, itsConstraints[option]);
|
ShowTag(*w->Current().first, itsConstraints[option]);
|
||||||
}
|
}
|
||||||
else if (option == 11)
|
else if (option == ConstraintsNumber+1)
|
||||||
{
|
{
|
||||||
Config.search_in_db = !Config.search_in_db;
|
Config.search_in_db = !Config.search_in_db;
|
||||||
*w->Current().first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
*w->Current().first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||||
}
|
}
|
||||||
else if (option == 12)
|
else if (option == ConstraintsNumber+2)
|
||||||
{
|
{
|
||||||
MatchToPattern = !MatchToPattern;
|
MatchToPattern = !MatchToPattern;
|
||||||
*w->Current().first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (MatchToPattern ? NormalMode : StrictMode);
|
*w->Current().first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (MatchToPattern ? NormalMode : StrictMode);
|
||||||
}
|
}
|
||||||
else if (option == 13)
|
|
||||||
{
|
|
||||||
CaseSensitive = !CaseSensitive * REG_ICASE;
|
|
||||||
*w->Current().first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (!CaseSensitive ? "Yes" : "No");
|
|
||||||
}
|
|
||||||
else if (option == SearchButton)
|
else if (option == SearchButton)
|
||||||
{
|
{
|
||||||
ShowMessage("Searching...");
|
ShowMessage("Searching...");
|
||||||
@@ -269,7 +263,7 @@ void SearchEngine::Prepare()
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < w->Size(); ++i)
|
for (size_t i = 0; i < w->Size(); ++i)
|
||||||
{
|
{
|
||||||
if (i == 10 || i == 14 || i == ResetButton+1 || i == ResetButton+3) // separators
|
if (i == ConstraintsNumber || i == SearchButton-1 || i == ResetButton+1 || i == ResetButton+3) // separators
|
||||||
continue;
|
continue;
|
||||||
delete (*w)[i].first;
|
delete (*w)[i].first;
|
||||||
delete (*w)[i].second;
|
delete (*w)[i].second;
|
||||||
@@ -277,14 +271,14 @@ void SearchEngine::Prepare()
|
|||||||
|
|
||||||
w->SetTitle("");
|
w->SetTitle("");
|
||||||
w->Clear();
|
w->Clear();
|
||||||
w->ResizeList(17);
|
w->ResizeList(StaticOptions-3);
|
||||||
|
|
||||||
w->IntoSeparator(10);
|
w->IntoSeparator(ConstraintsNumber);
|
||||||
w->IntoSeparator(14);
|
w->IntoSeparator(SearchButton-1);
|
||||||
|
|
||||||
for (size_t i = 0; i < 17; ++i)
|
for (size_t i = 0; i < StaticOptions-3; ++i)
|
||||||
{
|
{
|
||||||
if (i == 10 || i == 14) // separators
|
if (i == ConstraintsNumber || i == SearchButton-1) // separators
|
||||||
continue;
|
continue;
|
||||||
(*w)[i].first = new Buffer();
|
(*w)[i].first = new Buffer();
|
||||||
}
|
}
|
||||||
@@ -295,9 +289,8 @@ void SearchEngine::Prepare()
|
|||||||
ShowTag(*(*w)[i].first, itsConstraints[i]);
|
ShowTag(*(*w)[i].first, itsConstraints[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
*w->at(11).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
*w->at(ConstraintsNumber+1).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
|
||||||
*w->at(12).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (MatchToPattern ? NormalMode : StrictMode);
|
*w->at(ConstraintsNumber+2).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (MatchToPattern ? NormalMode : StrictMode);
|
||||||
*w->at(13).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (!CaseSensitive ? "Yes" : "No");
|
|
||||||
|
|
||||||
*w->at(SearchButton).first << "Search";
|
*w->at(SearchButton).first << "Search";
|
||||||
*w->at(ResetButton).first << "Reset";
|
*w->at(ResetButton).first << "Reset";
|
||||||
@@ -337,7 +330,7 @@ void SearchEngine::Search()
|
|||||||
regex_t rx;
|
regex_t rx;
|
||||||
if (!itsConstraints[0].empty())
|
if (!itsConstraints[0].empty())
|
||||||
{
|
{
|
||||||
if (regcomp(&rx, itsConstraints[0].c_str(), CaseSensitive | Config.regex_type) == 0)
|
if (regcomp(&rx, itsConstraints[0].c_str(), REG_ICASE | Config.regex_type) == 0)
|
||||||
{
|
{
|
||||||
any_found =
|
any_found =
|
||||||
!regexec(&rx, (*it)->GetArtist().c_str(), 0, 0, 0)
|
!regexec(&rx, (*it)->GetArtist().c_str(), 0, 0, 0)
|
||||||
@@ -355,91 +348,93 @@ void SearchEngine::Search()
|
|||||||
|
|
||||||
if (found && !itsConstraints[1].empty())
|
if (found && !itsConstraints[1].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[1].c_str(), CaseSensitive | Config.regex_type))
|
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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[2].empty())
|
if (found && !itsConstraints[2].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[2].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[2].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[3].empty())
|
if (found && !itsConstraints[3].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[3].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[3].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[4].empty())
|
if (found && !itsConstraints[4].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[4].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[4].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[5].empty())
|
if (found && !itsConstraints[5].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[5].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[5].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[6].empty())
|
if (found && !itsConstraints[6].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[6].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[6].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[7].empty())
|
if (found && !itsConstraints[7].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[7].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[7].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[8].empty())
|
if (found && !itsConstraints[8].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[8].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[8].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
if (found && !itsConstraints[9].empty())
|
if (found && !itsConstraints[9].empty())
|
||||||
{
|
{
|
||||||
if (!regcomp(&rx, itsConstraints[9].c_str(), CaseSensitive | Config.regex_type))
|
if (!regcomp(&rx, itsConstraints[9].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);
|
regfree(&rx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
CaseInsensitiveStringComparison cmp;
|
||||||
|
|
||||||
if (!itsConstraints[0].empty())
|
if (!itsConstraints[0].empty())
|
||||||
any_found =
|
any_found =
|
||||||
SEStringComparison((*it)->GetArtist(), itsConstraints[0], CaseSensitive)
|
!cmp((*it)->GetArtist(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetTitle(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetTitle(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetAlbum(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetAlbum(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetName(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetName(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetComposer(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetComposer(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetPerformer(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetPerformer(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetGenre(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetGenre(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetDate(), itsConstraints[0], CaseSensitive)
|
|| !cmp((*it)->GetDate(), itsConstraints[0])
|
||||||
|| SEStringComparison((*it)->GetComment(), itsConstraints[0], CaseSensitive);
|
|| !cmp((*it)->GetComment(), itsConstraints[0]);
|
||||||
|
|
||||||
if (found && !itsConstraints[1].empty())
|
if (found && !itsConstraints[1].empty())
|
||||||
found = SEStringComparison((*it)->GetArtist(), itsConstraints[1], CaseSensitive);
|
found = !cmp((*it)->GetArtist(), itsConstraints[1]);
|
||||||
if (found && !itsConstraints[2].empty())
|
if (found && !itsConstraints[2].empty())
|
||||||
found = SEStringComparison((*it)->GetTitle(), itsConstraints[2], CaseSensitive);
|
found = !cmp((*it)->GetTitle(), itsConstraints[2]);
|
||||||
if (found && !itsConstraints[3].empty())
|
if (found && !itsConstraints[3].empty())
|
||||||
found = SEStringComparison((*it)->GetAlbum(), itsConstraints[3], CaseSensitive);
|
found = !cmp((*it)->GetAlbum(), itsConstraints[3]);
|
||||||
if (found && !itsConstraints[4].empty())
|
if (found && !itsConstraints[4].empty())
|
||||||
found = SEStringComparison((*it)->GetName(), itsConstraints[4], CaseSensitive);
|
found = !cmp((*it)->GetName(), itsConstraints[4]);
|
||||||
if (found && !itsConstraints[5].empty())
|
if (found && !itsConstraints[5].empty())
|
||||||
found = SEStringComparison((*it)->GetComposer(), itsConstraints[5], CaseSensitive);
|
found = !cmp((*it)->GetComposer(), itsConstraints[5]);
|
||||||
if (found && !itsConstraints[6].empty())
|
if (found && !itsConstraints[6].empty())
|
||||||
found = SEStringComparison((*it)->GetPerformer(), itsConstraints[6], CaseSensitive);
|
found = !cmp((*it)->GetPerformer(), itsConstraints[6]);
|
||||||
if (found && !itsConstraints[7].empty())
|
if (found && !itsConstraints[7].empty())
|
||||||
found = SEStringComparison((*it)->GetGenre(), itsConstraints[7], CaseSensitive);
|
found = !cmp((*it)->GetGenre(), itsConstraints[7]);
|
||||||
if (found && !itsConstraints[8].empty())
|
if (found && !itsConstraints[8].empty())
|
||||||
found = SEStringComparison((*it)->GetDate(), itsConstraints[8], CaseSensitive);
|
found = !cmp((*it)->GetDate(), itsConstraints[8]);
|
||||||
if (found && !itsConstraints[9].empty())
|
if (found && !itsConstraints[9].empty())
|
||||||
found = SEStringComparison((*it)->GetComment(), itsConstraints[9], CaseSensitive);
|
found = !cmp((*it)->GetComment(), itsConstraints[9]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found && any_found)
|
if (found && any_found)
|
||||||
@@ -455,11 +450,6 @@ void SearchEngine::Search()
|
|||||||
MPD::FreeSongList(list);
|
MPD::FreeSongList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchEngine::SEStringComparison(const std::string &a, const std::string &b, bool case_sensitive)
|
|
||||||
{
|
|
||||||
return case_sensitive ? a == b : !CaseInsensitiveStringComparison()(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string SearchEngine::SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &pair, void *)
|
std::string SearchEngine::SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &pair, void *)
|
||||||
{
|
{
|
||||||
if (!Config.columns_in_search_engine)
|
if (!Config.columns_in_search_engine)
|
||||||
|
|||||||
@@ -64,14 +64,12 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
|
|||||||
void Search();
|
void Search();
|
||||||
|
|
||||||
static std::string SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &, void *);
|
static std::string SearchEngineOptionToString(const std::pair<Buffer *, MPD::Song *> &, void *);
|
||||||
static bool SEStringComparison(const std::string &a, const std::string &b, bool case_sensitive);
|
|
||||||
|
|
||||||
static const size_t ConstraintsNumber = 10;
|
static const size_t ConstraintsNumber = 10;
|
||||||
static const char *ConstraintsNames[];
|
static const char *ConstraintsNames[];
|
||||||
std::string itsConstraints[ConstraintsNumber];
|
std::string itsConstraints[ConstraintsNumber];
|
||||||
|
|
||||||
static bool MatchToPattern;
|
static bool MatchToPattern;
|
||||||
static int CaseSensitive;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SearchEngine *mySearcher;
|
extern SearchEngine *mySearcher;
|
||||||
|
|||||||
Reference in New Issue
Block a user