From 5bd24400e187ce37afdf6d283e7e9ca0e5ce5c79 Mon Sep 17 00:00:00 2001 From: "S. Razi Alavizadeh" Date: Sun, 8 Jun 2014 16:26:20 +0430 Subject: [PATCH] [LocationCompleter] Cancel unneeded refresh jobs --- src/lib/navigation/completer/locationcompleter.cpp | 3 +++ src/lib/navigation/completer/locationcompleter.h | 1 + .../completer/locationcompleterrefreshjob.cpp | 12 +++++++++++- .../completer/locationcompleterrefreshjob.h | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) 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