diff options
Diffstat (limited to 'src/search')
-rw-r--r-- | src/search/opensearchmanager.cpp | 33 | ||||
-rw-r--r-- | src/search/opensearchmanager.h | 2 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/search/opensearchmanager.cpp b/src/search/opensearchmanager.cpp index 2bb23121..9670a6a2 100644 --- a/src/search/opensearchmanager.cpp +++ b/src/search/opensearchmanager.cpp @@ -49,6 +49,7 @@ OpenSearchManager::OpenSearchManager(QObject *parent) : QObject(parent) , m_activeEngine(0) + , m_currentJob(0) { m_state = IDLE; } @@ -109,6 +110,12 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl { Q_UNUSED(title); + if (m_currentJob) + { + disconnect(m_currentJob); + m_currentJob->kill(); + } + m_jobData.clear(); if (m_state != IDLE) @@ -117,9 +124,9 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl } m_state = REQ_DESCRIPTION; - KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); - connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(dataReceived(KIO::Job *, const QByteArray &))); - connect(job, SIGNAL(result(KJob *)), this, SLOT(jobFinished(KJob *))); + m_currentJob = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); + 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 *))); } @@ -135,14 +142,20 @@ void OpenSearchManager::requestSuggestion(const QString &searchText) 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(); - - KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); - connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(dataReceived(KIO::Job *, const QByteArray &))); - connect(job, SIGNAL(result(KJob *)), this, SLOT(jobFinished(KJob *))); + + m_currentJob = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); + 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 *))); } @@ -161,8 +174,9 @@ void OpenSearchManager::jobFinished(KJob *job) if (m_state == REQ_SUGGESTION) { const QStringList suggestionsList = m_activeEngine->parseSuggestion(m_jobData); - kDebug() << "Received suggestion from " << m_activeEngine->name() << ": " << suggestionsList; + kDebug() << "Received suggestions in "<< _typedText << " from " << m_activeEngine->name() << ": " << suggestionsList; + m_currentJob = NULL; emit suggestionReceived(_typedText, suggestionsList); return; } @@ -181,6 +195,7 @@ void OpenSearchManager::jobFinished(KJob *job) writer.write(&file, engine); QString searchUrl = OpenSearchEngine::parseTemplate("\\{@}", engine->searchUrlTemplate()); + m_currentJob = NULL; emit openSearchEngineAdded(engine->name(), searchUrl, fileName); } else diff --git a/src/search/opensearchmanager.h b/src/search/opensearchmanager.h index 8a234df2..224ada08 100644 --- a/src/search/opensearchmanager.h +++ b/src/search/opensearchmanager.h @@ -104,6 +104,8 @@ private: OpenSearchEngine *m_activeEngine; STATE m_state; + KIO::TransferJob *m_currentJob; + QString _typedText; }; |