--- a/src/qtgui/ssearch_w.cpp
+++ b/src/qtgui/ssearch_w.cpp
@@ -65,13 +65,14 @@
queryText->addItems(prefs.ssearchHistory);
queryText->setEditText("");
connect(queryText->lineEdit(), SIGNAL(returnPressed()),
- this, SLOT(startSimpleSearch()));
+ this, SLOT(startSimpleSearch()));
connect(queryText->lineEdit(), SIGNAL(textChanged(const QString&)),
- this, SLOT(searchTextChanged(const QString&)));
+ this, SLOT(searchTextChanged(const QString&)));
connect(clearqPB, SIGNAL(clicked()),
- queryText->lineEdit(), SLOT(clear()));
+ queryText->lineEdit(), SLOT(clear()));
connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch()));
- connect(searchTypCMB, SIGNAL(activated(int)), this, SLOT(searchTypeChanged(int)));
+ connect(searchTypCMB, SIGNAL(activated(int)), this,
+ SLOT(searchTypeChanged(int)));
queryText->installEventFilter(this);
queryText->view()->installEventFilter(this);
@@ -81,7 +82,7 @@
// But the model does not belong to the completer so it's not deleted...
m_savedModel = queryText->completer()->model();
if (prefs.ssearchNoComplete)
- queryText->completer()->setModel(0);
+ queryText->completer()->setModel(0);
// Recoll searches are always case-sensitive because of the use of
// capitalization to suppress stemming
queryText->completer()->setCaseSensitivity(Qt::CaseSensitive);
@@ -96,7 +97,7 @@
void SSearch::takeFocus()
{
- LOGDEB2("SSearch: take focus\n" );
+ LOGDEB2("SSearch: take focus\n");
queryText->setFocus(Qt::ShortcutFocusReason);
// If the focus was already in the search entry, the text is not selected.
// Do it for consistency
@@ -106,58 +107,61 @@
void SSearch::timerDone()
{
QString qs = queryText->currentText();
- LOGDEB1("SSearch::timerDone: qs [" << (qs2utf8s(qs)) << "]\n" );
+ LOGDEB1("SSearch::timerDone: qs [" << qs2utf8s(qs) << "]\n");
searchTextChanged(qs);
}
void SSearch::searchTextChanged(const QString& text)
{
QString qs = queryText->currentText();
- LOGDEB1("SSearch::searchTextChanged. ks " << (m_keystroke) << " qs [" << (qs2utf8s(text)) << "]\n" );
+ LOGDEB1("SSearch::searchTextChanged. ks " << m_keystroke << " qs [" <<
+ qs2utf8s(text) << "]\n");
if (text.isEmpty()) {
- searchPB->setEnabled(false);
- clearqPB->setEnabled(false);
- queryText->setFocus();
- emit clearSearch();
+ searchPB->setEnabled(false);
+ clearqPB->setEnabled(false);
+ queryText->setFocus();
+ emit clearSearch();
} else {
- searchPB->setEnabled(true);
- clearqPB->setEnabled(true);
- if (m_keystroke) {
- m_tstartqs = qs;
- }
- if (prefs.ssearchAsYouType && !m_disableAutosearch &&
- !m_keystroke && m_tstartqs == qs) {
- m_disableAutosearch = true;
- string s;
- int cs = partialWord(s);
- LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << (cs) << " s [" << (s) << "]\n" );
- if (cs < 0) {
- startSimpleSearch();
- } else if (!m_stroketimeout->isActive() && s.size() >= 2) {
- s = qs2utf8s(queryText->currentText());
- s += "*";
- startSimpleSearch(s, 20);
- }
- }
+ searchPB->setEnabled(true);
+ clearqPB->setEnabled(true);
+ if (m_keystroke) {
+ m_tstartqs = qs;
+ }
+ if (prefs.ssearchAsYouType && !m_disableAutosearch &&
+ !m_keystroke && m_tstartqs == qs) {
+ m_disableAutosearch = true;
+ string s;
+ int cs = partialWord(s);
+ LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << cs <<
+ " s [" << s << "]\n");
+ if (cs < 0) {
+ startSimpleSearch();
+ } else if (!m_stroketimeout->isActive() && s.size() >= 2) {
+ s = qs2utf8s(queryText->currentText());
+ s += "*";
+ startSimpleSearch(s, 20);
+ }
+ }
}
m_keystroke = false;
}
void SSearch::searchTypeChanged(int typ)
{
- LOGDEB("Search type now " << (typ) << "\n" );
+ LOGDEB("Search type now " << typ << "\n");
// Adjust context help
- if (typ == SST_LANG)
- HelpClient::installMap((const char *)this->objectName().toUtf8(),
- "RCL.SEARCH.LANG");
- else
- HelpClient::installMap((const char *)this->objectName().toUtf8(),
- "RCL.SEARCH.GUI.SIMPLE");
-
+ if (typ == SST_LANG) {
+ HelpClient::installMap((const char *)this->objectName().toUtf8(),
+ "RCL.SEARCH.LANG");
+ } else {
+ HelpClient::installMap((const char *)this->objectName().toUtf8(),
+ "RCL.SEARCH.GUI.SIMPLE");
+ }
// Also fix tooltips
switch (typ) {
case SST_LANG:
- queryText->setToolTip(tr(
+ queryText->setToolTip(
+ tr(
"Enter query language expression. Cheat sheet:<br>\n"
"<i>term1 term2</i> : 'term1' and 'term2' in any field.<br>\n"
"<i>field:term1</i> : 'term1' in field 'field'.<br>\n"
@@ -170,7 +174,7 @@
"<i>\"term1 term2\"</i> : phrase (must occur exactly). Possible modifiers:<br>\n"
"<i>\"term1 term2\"p</i> : unordered proximity search with default distance.<br>\n"
"Use <b>Show Query</b> link when in doubt about result and see manual (<F1>) for more detail.\n"
- ));
+ ));
break;
case SST_FNM:
queryText->setToolTip(tr("Enter file name wildcard expression."));
@@ -178,29 +182,30 @@
case SST_ANY:
case SST_ALL:
default:
- queryText->setToolTip(tr(
- "Enter search terms here. Type ESC SPC for completions of current term."
- ));
+ queryText->setToolTip(
+ tr(
+ "Enter search terms here. Type ESC SPC for completions of current term."
+ ));
}
}
void SSearch::startSimpleSearch()
{
QString qs = queryText->currentText();
- LOGDEB("SSearch::startSimpleSearch(): qs [" << (qs2utf8s(qs)) << "]\n" );
+ LOGDEB("SSearch::startSimpleSearch(): qs [" << qs2utf8s(qs) << "]\n");
if (qs.length() == 0)
- return;
+ return;
string u8 = (const char *)queryText->currentText().toUtf8();
trimstring(u8);
if (u8.length() == 0)
- return;
+ return;
if (!startSimpleSearch(u8))
- return;
-
- LOGDEB("startSimpleSearch: updating history\n" );
+ return;
+
+ LOGDEB("startSimpleSearch: updating history\n");
// Search terms history:
// We want to have the new text at the top and any older identical
// entry to be erased. There is no standard qt policy to do this ?
@@ -209,11 +214,11 @@
QString txtt = txt.trimmed();
int index = queryText->findText(txtt);
if (index > 0) {
- queryText->removeItem(index);
+ queryText->removeItem(index);
}
if (index != 0) {
- queryText->insertItem(0, txtt);
- queryText->setEditText(txt);
+ queryText->insertItem(0, txtt);
+ queryText->setEditText(txt);
}
m_disableAutosearch = true;
m_stroketimeout->stop();
@@ -222,15 +227,15 @@
// go to disk)
prefs.ssearchHistory.clear();
for (int index = 0; index < queryText->count(); index++) {
- prefs.ssearchHistory.push_back(queryText->itemText(index));
+ prefs.ssearchHistory.push_back(queryText->itemText(index));
}
}
void SSearch::setPrefs()
{
if (prefs.ssearchNoComplete) {
- queryText->completer()->setModel(0);
+ queryText->completer()->setModel(0);
} else {
- queryText->completer()->setModel(m_savedModel);
+ queryText->completer()->setModel(m_savedModel);
}
}
@@ -241,7 +246,7 @@
bool SSearch::startSimpleSearch(const string& u8, int maxexp)
{
- LOGDEB("SSearch::startSimpleSearch(" << (u8) << ")\n" );
+ LOGDEB("SSearch::startSimpleSearch(" << u8 << ")\n");
string stemlang = prefs.stemlang();
ostringstream xml;
@@ -254,51 +259,51 @@
if (tp == SST_LANG) {
xml << " <SM>QL</SM>\n";
- string reason;
+ string reason;
if (prefs.autoSuffsEnable) {
sdata = wasaStringToRcl(theconfig, stemlang, u8, reason,
- (const char *)prefs.autoSuffs.toUtf8());
+ (const char *)prefs.autoSuffs.toUtf8());
if (!prefs.autoSuffs.isEmpty()) {
xml << " <AS>" << qs2utf8s(prefs.autoSuffs) << "</AS>\n";
}
} else {
sdata = wasaStringToRcl(theconfig, stemlang, u8, reason);
}
- if (sdata == 0) {
- QMessageBox::warning(0, "Recoll", tr("Bad query string") + ": " +
- QString::fromUtf8(reason.c_str()));
- return false;
- }
+ if (sdata == 0) {
+ QMessageBox::warning(0, "Recoll", tr("Bad query string") + ": " +
+ QString::fromUtf8(reason.c_str()));
+ return false;
+ }
} else {
- sdata = new Rcl::SearchData(Rcl::SCLT_OR, stemlang);
- if (sdata == 0) {
- QMessageBox::warning(0, "Recoll", tr("Out of memory"));
- return false;
- }
- Rcl::SearchDataClause *clp = 0;
- if (tp == SST_FNM) {
+ sdata = new Rcl::SearchData(Rcl::SCLT_OR, stemlang);
+ if (sdata == 0) {
+ QMessageBox::warning(0, "Recoll", tr("Out of memory"));
+ return false;
+ }
+ Rcl::SearchDataClause *clp = 0;
+ if (tp == SST_FNM) {
xml << " <SM>FN</SM>\n";
- clp = new Rcl::SearchDataClauseFilename(u8);
- } else {
- // ANY or ALL, several words.
- if (tp == SST_ANY) {
+ clp = new Rcl::SearchDataClauseFilename(u8);
+ } else {
+ // ANY or ALL, several words.
+ if (tp == SST_ANY) {
xml << " <SM>OR</SM>\n";
- clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8);
- } else {
+ clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8);
+ } else {
xml << " <SM>AND</SM>\n";
- clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8);
- }
- }
- sdata->addClause(clp);
+ clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8);
+ }
+ }
+ sdata->addClause(clp);
}
if (prefs.ssearchAutoPhrase && rcldb) {
xml << " <AP/>\n";
- sdata->maybeAddAutoPhrase(*rcldb,
- prefs.ssearchAutoPhraseThreshPC / 100.0);
+ sdata->maybeAddAutoPhrase(*rcldb,
+ prefs.ssearchAutoPhraseThreshPC / 100.0);
}
if (maxexp != -1) {
- sdata->setMaxExpand(maxexp);
+ sdata->setMaxExpand(maxexp);
}
for (const auto& dbdir : prefs.activeExtraDbs) {
@@ -307,7 +312,7 @@
xml << "</SD>\n";
m_xml = xml.str();
- LOGDEB("SSearch::startSimpleSearch:xml:[" << (m_xml) << "]\n" );
+ LOGDEB("SSearch::startSimpleSearch:xml:[" << m_xml << "]\n");
std::shared_ptr<Rcl::SearchData> rsdata(sdata);
emit startSearch(rsdata, true);
@@ -393,17 +398,17 @@
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void SSearch::addTerm(QString term)
{
- LOGDEB("SSearch::AddTerm: [" << ((const char *)term.toUtf8()) << "]\n" );
+ LOGDEB("SSearch::AddTerm: [" << qs2utf8s(term) << "]\n");
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
- return;
+ return;
t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct);
if (pos != string::npos)
- t = t.substr(pos);
+ t = t.substr(pos);
if (t.empty())
- return;
+ return;
term = QString::fromUtf8(t.c_str());
QString text = queryText->currentText();
@@ -415,7 +420,8 @@
void SSearch::onWordReplace(const QString& o, const QString& n)
{
- LOGDEB("SSearch::onWordReplace: o [" << (qs2utf8s(o)) << "] n [" << (qs2utf8s(n)) << "]\n" );
+ LOGDEB("SSearch::onWordReplace: o [" << qs2utf8s(o) << "] n [" <<
+ qs2utf8s(n) << "]\n");
QString txt = queryText->currentText();
QRegExp exp = QRegExp(QString("\\b") + o + QString("\\b"));
exp.setCaseSensitivity(Qt::CaseInsensitive);
@@ -425,7 +431,7 @@
m_stroketimeout->stop();
Qt::KeyboardModifiers mods = QApplication::keyboardModifiers ();
if (mods == Qt::NoModifier)
- startSimpleSearch();
+ startSimpleSearch();
}
void SSearch::setAnyTermMode()
@@ -441,11 +447,11 @@
QString txt = queryText->currentText();
int cs = txt.lastIndexOf(" ");
if (cs == -1)
- cs = 0;
+ cs = 0;
else
- cs++;
+ cs++;
if (txt.size() == 0 || cs == txt.size()) {
- return -1;
+ return -1;
}
s = qs2utf8s(txt.right(txt.size() - cs));
return cs;
@@ -456,19 +462,18 @@
int SSearch::completionList(string s, QStringList& lst, int max)
{
if (!rcldb)
- return -1;
+ return -1;
if (s.empty())
- return 0;
- // Query database for completions
+ return 0;
+ // Query database for completions
s += "*";
Rcl::TermMatchResult tmres;
if (!rcldb->termMatch(Rcl::Db::ET_WILD, "", s, tmres, max) ||
- tmres.entries.size() == 0) {
- return 0;
- }
- for (vector<Rcl::TermMatchEntry>::iterator it = tmres.entries.begin();
- it != tmres.entries.end(); it++) {
- lst.push_back(QString::fromUtf8(it->term.c_str()));
+ tmres.entries.size() == 0) {
+ return 0;
+ }
+ for (const auto& entry: tmres.entries) {
+ lst.push_back(u8s2qs(entry.term));
}
return lst.size();
}
@@ -476,25 +481,25 @@
// Complete last word in input by querying db for all possible terms.
void SSearch::completion()
{
- LOGDEB("SSearch::completion\n" );
+ LOGDEB("SSearch::completion\n");
m_disableAutosearch = true;
m_stroketimeout->stop();
if (!rcldb)
- return;
+ return;
if (searchTypCMB->currentIndex() == SST_FNM) {
- // Filename: no completion
- QApplication::beep();
- return;
+ // Filename: no completion
+ QApplication::beep();
+ return;
}
// Extract last word in text
string s;
int cs = partialWord(s);
if (cs < 0) {
- QApplication::beep();
- return;
+ QApplication::beep();
+ return;
}
// Query database for completions
@@ -502,53 +507,53 @@
const int maxdpy = 80;
const int maxwalked = 10000;
if (completionList(s, lst, maxwalked) <= 0) {
- QApplication::beep();
- return;
+ QApplication::beep();
+ return;
}
if (lst.size() >= maxdpy) {
- LOGDEB0("SSearch::completion(): truncating list\n" );
- lst = lst.mid(0, maxdpy);
- lst.append("[...]");
+ LOGDEB0("SSearch::completion(): truncating list\n");
+ lst = lst.mid(0, maxdpy);
+ lst.append("[...]");
}
// If list from db is single word, insert it, else popup the listview
if (lst.size() == 1) {
- QString txt = queryText->currentText();
- txt.truncate(cs);
- txt.append(lst[0]);
- queryText->setEditText(txt);
+ QString txt = queryText->currentText();
+ txt.truncate(cs);
+ txt.append(lst[0]);
+ queryText->setEditText(txt);
} else {
- m_savedEditText = queryText->currentText();
- m_displayingCompletions = true;
- m_chosenCompletion.clear();
- m_completedWordStart = cs;
-
- queryText->clear();
- queryText->addItems(lst);
- queryText->showPopup();
-
- connect(queryText, SIGNAL(activated(const QString&)), this,
- SLOT(completionTermChosen(const QString&)));
+ m_savedEditText = queryText->currentText();
+ m_displayingCompletions = true;
+ m_chosenCompletion.clear();
+ m_completedWordStart = cs;
+
+ queryText->clear();
+ queryText->addItems(lst);
+ queryText->showPopup();
+
+ connect(queryText, SIGNAL(activated(const QString&)), this,
+ SLOT(completionTermChosen(const QString&)));
}
}
void SSearch::completionTermChosen(const QString& text)
{
if (text != "[...]")
- m_chosenCompletion = text;
+ m_chosenCompletion = text;
else
- m_chosenCompletion.clear();
+ m_chosenCompletion.clear();
}
void SSearch::wrapupCompletion()
{
- LOGDEB("SSearch::wrapupCompletion\n" );
+ LOGDEB("SSearch::wrapupCompletion\n");
queryText->clear();
queryText->addItems(prefs.ssearchHistory);
if (!m_chosenCompletion.isEmpty()) {
- m_savedEditText.truncate(m_completedWordStart);
- m_savedEditText.append(m_chosenCompletion);
+ m_savedEditText.truncate(m_completedWordStart);
+ m_savedEditText.append(m_chosenCompletion);
}
queryText->setEditText(m_savedEditText);
m_disableAutosearch = true;
@@ -556,7 +561,7 @@
m_chosenCompletion.clear();
m_displayingCompletions = false;
disconnect(queryText, SIGNAL(activated(const QString&)), this,
- SLOT(completionTermChosen(const QString&)));
+ SLOT(completionTermChosen(const QString&)));
}
#undef SHOWEVENTS
@@ -602,7 +607,7 @@
case 39: return "PaletteChange";
case 40: return "Clipboard";
case 42: return "Speech";
- case 43: return "MetaCall";
+ case 43: return "MetaCall";
case 50: return "SockAct";
case 132: return "WinEventAct";
case 52: return "DeferredDelete";
@@ -704,54 +709,57 @@
{
#if defined(SHOWEVENTS)
if (event->type() == QEvent::Timer ||
- event->type() == QEvent::UpdateRequest ||
- event->type() == QEvent::Paint)
- return false;
- LOGDEB2("SSearch::eventFilter: target " << (target) << " (" << (queryText->lineEdit()) << ") type " << (eventTypeToStr(event->type())) << "\n" );
+ event->type() == QEvent::UpdateRequest ||
+ event->type() == QEvent::Paint)
+ return false;
+ LOGDEB2("SSearch::eventFilter: target " << target << " (" <<
+ queryText->lineEdit() << ") type " <<
+ eventTypeToStr(event->type()) << "\n");
#endif
if (target == (QObject*)(queryText->view())) {
- if (event->type() == QEvent::Hide) {
- // List was closed. If we were displaying completions, need
- // to reset state.
- if (m_displayingCompletions) {
- QTimer::singleShot(0, this, SLOT(wrapupCompletion()));
- }
- }
- return false;
+ if (event->type() == QEvent::Hide) {
+ // List was closed. If we were displaying completions, need
+ // to reset state.
+ if (m_displayingCompletions) {
+ QTimer::singleShot(0, this, SLOT(wrapupCompletion()));
+ }
+ }
+ return false;
}
if (event->type() == QEvent::KeyPress) {
- QKeyEvent *ke = (QKeyEvent *)event;
- LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << (m_escape) << ") key " << (ke->key()) << "\n" );
- if (ke->key() == Qt::Key_Escape) {
- LOGDEB("Escape\n" );
- m_escape = true;
- m_disableAutosearch = true;
- m_stroketimeout->stop();
- return true;
- } else if (m_escape && ke->key() == Qt::Key_Space) {
- LOGDEB("Escape space\n" );
- ke->accept();
- completion();
- m_escape = false;
- m_disableAutosearch = true;
- m_stroketimeout->stop();
- return true;
- } else if (ke->key() == Qt::Key_Space) {
- if (prefs.ssearchOnWS)
- startSimpleSearch();
- } else {
- m_escape = false;
- m_keystroke = true;
- if (prefs.ssearchAsYouType) {
- m_disableAutosearch = false;
- QString qs = queryText->currentText();
- LOGDEB0("SSearch::eventFilter: start timer, qs [" << (qs2utf8s(qs)) << "]\n" );
- m_stroketimeout->start(strokeTimeoutMS);
- }
- }
+ QKeyEvent *ke = (QKeyEvent *)event;
+ LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << m_escape <<
+ ") key " << ke->key() << "\n");
+ if (ke->key() == Qt::Key_Escape) {
+ LOGDEB("Escape\n");
+ m_escape = true;
+ m_disableAutosearch = true;
+ m_stroketimeout->stop();
+ return true;
+ } else if (m_escape && ke->key() == Qt::Key_Space) {
+ LOGDEB("Escape space\n");
+ ke->accept();
+ completion();
+ m_escape = false;
+ m_disableAutosearch = true;
+ m_stroketimeout->stop();
+ return true;
+ } else if (ke->key() == Qt::Key_Space) {
+ if (prefs.ssearchOnWS)
+ startSimpleSearch();
+ } else {
+ m_escape = false;
+ m_keystroke = true;
+ if (prefs.ssearchAsYouType) {
+ m_disableAutosearch = false;
+ QString qs = queryText->currentText();
+ LOGDEB0("SSearch::eventFilter: start timer, qs [" <<
+ qs2utf8s(qs) << "]\n");
+ m_stroketimeout->start(strokeTimeoutMS);
+ }
+ }
}
return false;
}
-