fixed crash with autosearch caused by starting several simultaneous queries

This commit is contained in:
Jean-Francois Dockes 2013-02-22 10:51:12 +01:00
parent 7130edd5cb
commit aba4f61e42
3 changed files with 20 additions and 6 deletions

View File

@ -108,6 +108,7 @@ void startManual(const string& helpindex)
bool maybeOpenDb(string &reason, bool force, bool *maindberror) bool maybeOpenDb(string &reason, bool force, bool *maindberror)
{ {
LOGDEB2(("maybeOpenDb: force %d\n", force));
if (!rcldb) { if (!rcldb) {
reason = "Internal error: db not created"; reason = "Internal error: db not created";
return false; return false;

View File

@ -769,7 +769,13 @@ void RclMain::rebuildIndex()
// Start a db query and set the reslist docsource // Start a db query and set the reslist docsource
void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata) void RclMain::startSearch(RefCntr<Rcl::SearchData> 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<DocSequence>(); m_source = RefCntr<DocSequence>();
// The db may have been closed at the end of indexing // The db may have been closed at the end of indexing
@ -777,6 +783,7 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
// If indexing is being performed, we reopen the db at each query. // If indexing is being performed, we reopen the db at each query.
if (!maybeOpenDb(reason, m_idxproc != 0)) { if (!maybeOpenDb(reason, m_idxproc != 0)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str())); QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
m_queryActive = false;
return; return;
} }
@ -818,9 +825,8 @@ class QueryThread : public QThread {
void RclMain::initiateQuery() void RclMain::initiateQuery()
{ {
if (m_queryActive || m_source.isNull()) if (m_source.isNull())
return; return;
m_queryActive = true;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QueryThread qthr(m_source); QueryThread qthr(m_source);

View File

@ -36,6 +36,10 @@
#include "wasatorcl.h" #include "wasatorcl.h"
#include "rclhelp.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() void SSearch::init()
{ {
// See enum above and keep in order ! // See enum above and keep in order !
@ -103,12 +107,13 @@ void SSearch::searchTextChanged(const QString& text)
if (prefs.ssearchAsYouType && !m_disableAutosearch && if (prefs.ssearchAsYouType && !m_disableAutosearch &&
!m_keystroke && m_tstartqs == qs) { !m_keystroke && m_tstartqs == qs) {
m_disableAutosearch = true; m_disableAutosearch = true;
LOGDEB0(("SSearch::searchTextChanged: autosearch\n"));
string s; string s;
int cs = partialWord(s); int cs = partialWord(s);
LOGDEB0(("SSearch::searchTextChanged: autosearch. cs %d s [%s]\n",
cs, s.c_str()));
if (cs < 0) { if (cs < 0) {
startSimpleSearch(); startSimpleSearch();
} else if (!m_stroketimeout->isActive()) { } else if (!m_stroketimeout->isActive() && s.size() >= 2) {
s = qs2utf8s(queryText->currentText()); s = qs2utf8s(queryText->currentText());
s += "*"; s += "*";
startSimpleSearch(s, 20); startSimpleSearch(s, 20);
@ -328,6 +333,8 @@ void SSearch::setAnyTermMode()
searchTypCMB->setCurrentIndex(SST_ANY); 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) int SSearch::partialWord(string& s)
{ {
// Extract last word in text // Extract last word in text
@ -648,7 +655,7 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
QString qs = queryText->currentText(); QString qs = queryText->currentText();
LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n", LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n",
qs2utf8s(qs).c_str())); qs2utf8s(qs).c_str()));
m_stroketimeout->start(200); m_stroketimeout->start(strokeTimeoutMS);
} }
} }
} }