1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[LocationCompleter] Cancel unneeded refresh jobs

This commit is contained in:
S. Razi Alavizadeh 2014-06-08 16:26:20 +04:30
parent a32e809bf6
commit 5bd24400e1
4 changed files with 17 additions and 1 deletions

View File

@ -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()

View File

@ -51,6 +51,7 @@ signals:
void loadCompletion();
void clearCompletion();
void popupClosed();
void cancelRefreshJob();
private slots:
void refreshJobFinished();

View File

@ -36,6 +36,7 @@ LocationCompleterRefreshJob::LocationCompleterRefreshJob(const QString &searchSt
: QObject()
, m_timestamp(QDateTime::currentMSecsSinceEpoch())
, m_searchString(searchString)
, m_jobCancelled(false)
{
m_watcher = new QFutureWatcher<void>(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)))));

View File

@ -43,6 +43,7 @@ signals:
private slots:
void slotFinished();
void jobCancelled();
private:
enum Type {
@ -63,6 +64,7 @@ private:
QString m_domainCompletion;
QList<QStandardItem*> m_items;
QFutureWatcher<void>* m_watcher;
bool m_jobCancelled;
};
#endif // LOCATIONCOMPLETERREFRESHJOB_H