diff options
-rw-r--r-- | src/search/opensearchmanager.cpp | 33 | ||||
-rw-r--r-- | src/search/opensearchmanager.h | 2 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 54 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 2 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 5 |
5 files changed, 60 insertions, 36 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; }; diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 12d34ad8..2199dfdf 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -94,29 +94,38 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString void CompletionWidget::updateSearchList(const UrlSearchList &list, const QString& text) { - if(_hasSuggestions || _typedString != text || !isVisible()) + static int counter = 0; + counter++; + kDebug() << counter; + if(_hasSuggestions || _typedString != text) return; _hasSuggestions = true; - UrlSearchList sugList = list.mid(0,4); - - // add new suggestions to the list - int offset = _list.count(); - Q_FOREACH(const UrlSearchItem &item, sugList) + if (_resList.count() > 0) { - ListItem *suggestion = ListItemFactory::create(item, text, this); - suggestion->setBackgroundRole(offset % 2 ? QPalette::AlternateBase : QPalette::Base); - connect(suggestion, - SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)), - this, - SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers))); - connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); - - suggestion->setObjectName(QString::number(offset++)); - layout()->addWidget(suggestion); + clear(); + insertSearchList(_resList, text); + + UrlSearchList sugList = list.mid(0,4); + + // add new suggestions to the list + int offset = _list.count(); + Q_FOREACH(const UrlSearchItem &item, sugList) + { + ListItem *suggestion = ListItemFactory::create(item, text, this); + suggestion->setBackgroundRole(offset % 2 ? QPalette::AlternateBase : QPalette::Base); + connect(suggestion, + SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)), + this, + SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers))); + connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); + + suggestion->setObjectName(QString::number(offset++)); + layout()->addWidget(suggestion); + } + _list.append(sugList); + popup(); } - _list.append(sugList); - sizeAndPosition(); } @@ -335,11 +344,6 @@ void CompletionWidget::suggestUrls(const QString &text) UrlResolver *res = new UrlResolver(text); connect(res, SIGNAL(suggestionsReady(const UrlSearchList &, const QString &)), this, SLOT(updateSearchList(const UrlSearchList &, const QString &))); - UrlSearchList list = res->orderedSearchItems(); - if (list.count() > 0) - { - clear(); - insertSearchList(list, text); - popup(); - } + _resList = res->orderedSearchItems(); + } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index d9f9be49..7f6c93f0 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -92,6 +92,8 @@ private: QString _typedString; bool _hasSuggestions; + + UrlSearchList _resList; }; #endif // COMPLETION_WIDGET_H diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 787546cd..b6d7e598 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -107,12 +107,14 @@ UrlResolver::UrlResolver(const QString &typedUrl) } _searchEnginesRegexp = QRegExp(reg); } + + computeSuggestions(); } UrlSearchList UrlResolver::orderedSearchItems() { - if( _typedString == QL1S("about:") ) + if( _typedString.startsWith( QL1S("about:") ) ) { UrlSearchList list; UrlSearchItem home(UrlSearchItem::Browse, QString("about:home"), QL1S("home") ); @@ -132,7 +134,6 @@ UrlSearchList UrlResolver::orderedSearchItems() } //compute lists - computeSuggestions(); computeHistory(); computeQurlFromUserInput(); computeWebSearches(); |