From aba4f61e42332cfabf48bfd03431cf413471127f Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 22 Feb 2013 10:51:12 +0100 Subject: [PATCH] fixed crash with autosearch caused by starting several simultaneous queries --- src/qtgui/main.cpp | 1 + src/qtgui/rclmain_w.cpp | 12 +++++++++--- src/qtgui/ssearch_w.cpp | 13 ++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index ac954974..8f1b0fc1 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -108,6 +108,7 @@ void startManual(const string& helpindex) bool maybeOpenDb(string &reason, bool force, bool *maindberror) { + LOGDEB2(("maybeOpenDb: force %d\n", force)); if (!rcldb) { reason = "Internal error: db not created"; return false; diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 5e98e312..0128288c 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -769,7 +769,13 @@ void RclMain::rebuildIndex() // Start a db query and set the reslist docsource void RclMain::startSearch(RefCntr sdata) { - LOGDEB(("RclMain::startSearch. Indexing %s\n", m_idxproc?"on":"off")); + LOGDEB(("RclMain::startSearch. Indexing %s Active %d\n", + m_idxproc?"on":"off", m_queryActive)); + if (m_queryActive) { + LOGDEB(("startSearch: already active\n")); + return; + } + m_queryActive = true; m_source = RefCntr(); // The db may have been closed at the end of indexing @@ -777,6 +783,7 @@ void RclMain::startSearch(RefCntr sdata) // If indexing is being performed, we reopen the db at each query. if (!maybeOpenDb(reason, m_idxproc != 0)) { QMessageBox::critical(0, "Recoll", QString(reason.c_str())); + m_queryActive = false; return; } @@ -818,9 +825,8 @@ class QueryThread : public QThread { void RclMain::initiateQuery() { - if (m_queryActive || m_source.isNull()) + if (m_source.isNull()) return; - m_queryActive = true; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QueryThread qthr(m_source); diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 98359fa0..e623f7c6 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -36,6 +36,10 @@ #include "wasatorcl.h" #include "rclhelp.h" +// Typing interval after which we consider starting autosearch: no sense to do +// this is user is typing fast and continuously +static const int strokeTimeoutMS = 250; + void SSearch::init() { // See enum above and keep in order ! @@ -103,12 +107,13 @@ void SSearch::searchTextChanged(const QString& text) if (prefs.ssearchAsYouType && !m_disableAutosearch && !m_keystroke && m_tstartqs == qs) { m_disableAutosearch = true; - LOGDEB0(("SSearch::searchTextChanged: autosearch\n")); string s; int cs = partialWord(s); + LOGDEB0(("SSearch::searchTextChanged: autosearch. cs %d s [%s]\n", + cs, s.c_str())); if (cs < 0) { startSimpleSearch(); - } else if (!m_stroketimeout->isActive()) { + } else if (!m_stroketimeout->isActive() && s.size() >= 2) { s = qs2utf8s(queryText->currentText()); s += "*"; startSimpleSearch(s, 20); @@ -328,6 +333,8 @@ void SSearch::setAnyTermMode() searchTypCMB->setCurrentIndex(SST_ANY); } +// If text does not end with space, return last (partial) word and >0 +// else return -1 int SSearch::partialWord(string& s) { // Extract last word in text @@ -648,7 +655,7 @@ bool SSearch::eventFilter(QObject *target, QEvent *event) QString qs = queryText->currentText(); LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n", qs2utf8s(qs).c_str())); - m_stroketimeout->start(200); + m_stroketimeout->start(strokeTimeoutMS); } } }