diff --git a/src/lib/navigation/completer/locationcompleter.cpp b/src/lib/navigation/completer/locationcompleter.cpp index a000d284d..4d7177c38 100644 --- a/src/lib/navigation/completer/locationcompleter.cpp +++ b/src/lib/navigation/completer/locationcompleter.cpp @@ -70,8 +70,11 @@ void LocationCompleter::complete(const QString &string) // Eg. popup was not closed yet this completion session m_popupClosed = false; + emit cancelRefreshJob(); + LocationCompleterRefreshJob* job = new LocationCompleterRefreshJob(trimmedStr); connect(job, SIGNAL(finished()), this, SLOT(refreshJobFinished())); + connect(this, SIGNAL(cancelRefreshJob()), job, SLOT(jobCancelled())); } void LocationCompleter::showMostVisited() diff --git a/src/lib/navigation/completer/locationcompleter.h b/src/lib/navigation/completer/locationcompleter.h index c30354dd6..3ea5f972b 100644 --- a/src/lib/navigation/completer/locationcompleter.h +++ b/src/lib/navigation/completer/locationcompleter.h @@ -51,6 +51,7 @@ signals: void loadCompletion(); void clearCompletion(); void popupClosed(); + void cancelRefreshJob(); private slots: void refreshJobFinished(); diff --git a/src/lib/navigation/completer/locationcompleterrefreshjob.cpp b/src/lib/navigation/completer/locationcompleterrefreshjob.cpp index b0f3b7a5c..a39e59728 100644 --- a/src/lib/navigation/completer/locationcompleterrefreshjob.cpp +++ b/src/lib/navigation/completer/locationcompleterrefreshjob.cpp @@ -36,6 +36,7 @@ LocationCompleterRefreshJob::LocationCompleterRefreshJob(const QString &searchSt : QObject() , m_timestamp(QDateTime::currentMSecsSinceEpoch()) , m_searchString(searchString) + , m_jobCancelled(false) { m_watcher = new QFutureWatcher(this); connect(m_watcher, SIGNAL(finished()), this, SLOT(slotFinished())); @@ -64,6 +65,11 @@ QString LocationCompleterRefreshJob::domainCompletion() const return m_domainCompletion; } +void LocationCompleterRefreshJob::jobCancelled() +{ + m_jobCancelled = true; +} + void LocationCompleterRefreshJob::slotFinished() { emit finished(); @@ -84,7 +90,7 @@ static bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2) void LocationCompleterRefreshJob::runJob() { - if (mApp->isClosing() || !mApp) { + if (m_jobCancelled || mApp->isClosing() || !mApp) { return; } @@ -100,6 +106,10 @@ void LocationCompleterRefreshJob::runJob() query.prepare(QSL("SELECT icon FROM icons WHERE url LIKE ? ESCAPE ? LIMIT 1")); foreach (QStandardItem* item, m_items) { + if (m_jobCancelled) { + return; + } + const QUrl url = item->data(LocationCompleterModel::UrlRole).toUrl(); query.bindValue(0, QString(QL1S("%1%")).arg(QzTools::escapeSqlString(QString::fromUtf8(url.toEncoded(QUrl::RemoveFragment))))); diff --git a/src/lib/navigation/completer/locationcompleterrefreshjob.h b/src/lib/navigation/completer/locationcompleterrefreshjob.h index b7d4e671c..7913fa56e 100644 --- a/src/lib/navigation/completer/locationcompleterrefreshjob.h +++ b/src/lib/navigation/completer/locationcompleterrefreshjob.h @@ -43,6 +43,7 @@ signals: private slots: void slotFinished(); + void jobCancelled(); private: enum Type { @@ -63,6 +64,7 @@ private: QString m_domainCompletion; QList m_items; QFutureWatcher* m_watcher; + bool m_jobCancelled; }; #endif // LOCATIONCOMPLETERREFRESHJOB_H