diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-10-03 10:38:33 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-10-03 10:41:16 +0200 |
commit | 2868f5d0d2f1a773a49f4d8d2b980214dcd0931d (patch) | |
tree | 82896756a7fd9418d633bb36ea15beaf93cb35bd /src | |
parent | Merge branch 'AdBlockImprovements' (diff) | |
download | rekonq-2868f5d0d2f1a773a49f4d8d2b980214dcd0931d.tar.xz |
Fix OpenSearchManager behavior to work in every case (also the disconnected ones)
I hope this fix bug #250263
Applied in rekonq 0.6.1 and in master
CCBUG:250263
Diffstat (limited to 'src')
-rw-r--r-- | src/opensearch/opensearchmanager.cpp | 56 | ||||
-rw-r--r-- | src/opensearch/opensearchmanager.h | 4 |
2 files changed, 33 insertions, 27 deletions
diff --git a/src/opensearch/opensearchmanager.cpp b/src/opensearch/opensearchmanager.cpp index 8e024951..d0d47f63 100644 --- a/src/opensearch/opensearchmanager.cpp +++ b/src/opensearch/opensearchmanager.cpp @@ -59,9 +59,6 @@ OpenSearchManager::~OpenSearchManager() { qDeleteAll(m_enginesMap.values()); m_enginesMap.clear(); - - if(m_currentJob) - m_currentJob->kill(); } @@ -113,22 +110,13 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl { Q_UNUSED(title); - if (m_currentJob) - { - disconnect(m_currentJob); - m_currentJob->kill(); - delete m_currentJob; - } - - m_jobData.clear(); - if (m_state != IDLE) { - // TODO: cancel job + idleJob(); } - m_state = REQ_DESCRIPTION; m_currentJob = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); + m_state = REQ_DESCRIPTION; connect(m_currentJob, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(dataReceived(KIO::Job *, const QByteArray &))); connect(m_currentJob, SIGNAL(result(KJob *)), this, SLOT(jobFinished(KJob *))); } @@ -141,23 +129,20 @@ void OpenSearchManager::requestSuggestion(const QString &searchText) if (m_state != IDLE) { - // TODO: cancel job + // NOTE: + // changing OpenSearchManager behavior + // using idleJob here lets opensearchmanager to start another search, while + // if we want in any case lets it finish its previous job we can just return here. + idleJob(); } - m_state = REQ_SUGGESTION; - + _typedText = searchText; KUrl url = m_activeEngine->suggestionsUrl(searchText); kDebug() << "Requesting for suggestions: " << url.url(); - if (m_currentJob) - { - disconnect(m_currentJob); - m_currentJob->kill(); - } - m_jobData.clear(); - m_currentJob = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); + m_state = REQ_SUGGESTION; connect(m_currentJob, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(dataReceived(KIO::Job *, const QByteArray &))); connect(m_currentJob, SIGNAL(result(KJob *)), this, SLOT(jobFinished(KJob *))); } @@ -173,15 +158,19 @@ void OpenSearchManager::dataReceived(KIO::Job *job, const QByteArray &data) void OpenSearchManager::jobFinished(KJob *job) { if (job->error()) + { + emit suggestionReceived(_typedText, QStringList()); + m_state = IDLE; return; // just silently return - + } + if (m_state == REQ_SUGGESTION) { const QStringList suggestionsList = m_activeEngine->parseSuggestion(m_jobData); kDebug() << "Received suggestions in "<< _typedText << " from " << m_activeEngine->name() << ": " << suggestionsList; - m_currentJob = NULL; emit suggestionReceived(_typedText, suggestionsList); + idleJob(); return; } @@ -206,6 +195,8 @@ void OpenSearchManager::jobFinished(KJob *job) { kFatal() << "Error while adding new open search engine"; } + + idleJob(); } } @@ -232,3 +223,16 @@ QString OpenSearchManager::trimmedEngineName(const QString &engineName) const return trimmed; } + + +void OpenSearchManager::idleJob() +{ + if (m_currentJob) + { + disconnect(m_currentJob); + m_currentJob->kill(); + } + + m_jobData.clear(); + m_state = IDLE; +} diff --git a/src/opensearch/opensearchmanager.h b/src/opensearch/opensearchmanager.h index 224ada08..fd4b3820 100644 --- a/src/opensearch/opensearchmanager.h +++ b/src/opensearch/opensearchmanager.h @@ -97,7 +97,9 @@ signals: private: QString trimmedEngineName(const QString &engineName) const; - + + void idleJob(); + // QString substitutueSearchText(const QString &searchText, const QString &requestURL) const; QByteArray m_jobData; QMap<QString, OpenSearchEngine*> m_enginesMap; |