diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-08-28 20:59:08 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-08-28 20:59:08 +0200 |
commit | 3f137d56176193c2bec7c876eb935612df91475c (patch) | |
tree | 69b1fe311e2e5781768f8a25db39a3e7d1a80a9b | |
parent | Increase xmlgui version number (just to be sure..) (diff) | |
download | rekonq-3f137d56176193c2bec7c876eb935612df91475c.tar.xz |
Restore urlbar responsiveness
Suggestions are now added when ready
-rw-r--r-- | src/search/opensearchmanager.cpp | 4 | ||||
-rw-r--r-- | src/search/opensearchmanager.h | 8 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 56 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 4 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 40 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 7 |
6 files changed, 80 insertions, 39 deletions
diff --git a/src/search/opensearchmanager.cpp b/src/search/opensearchmanager.cpp index 463c0a11..2bb23121 100644 --- a/src/search/opensearchmanager.cpp +++ b/src/search/opensearchmanager.cpp @@ -134,6 +134,8 @@ void OpenSearchManager::requestSuggestion(const QString &searchText) } m_state = REQ_SUGGESTION; + _typedText = searchText; + KUrl url = m_activeEngine->suggestionsUrl(searchText); kDebug() << "Requesting for suggestions: " << url.url(); m_jobData.clear(); @@ -161,7 +163,7 @@ void OpenSearchManager::jobFinished(KJob *job) const QStringList suggestionsList = m_activeEngine->parseSuggestion(m_jobData); kDebug() << "Received suggestion from " << m_activeEngine->name() << ": " << suggestionsList; - emit suggestionReceived(suggestionsList); + emit suggestionReceived(_typedText, suggestionsList); return; } diff --git a/src/search/opensearchmanager.h b/src/search/opensearchmanager.h index 8a45b83c..8a234df2 100644 --- a/src/search/opensearchmanager.h +++ b/src/search/opensearchmanager.h @@ -82,17 +82,17 @@ public: public slots: /** * Ask the specific suggestion engine to request for suggestion for the search text - * @param searchProvider the search provider that provides the suggestion service + * * @param searchText the text to be queried to the suggestion service */ - void requestSuggestion(const QString &searchProvider); + void requestSuggestion(const QString &searchText); private slots: void dataReceived(KIO::Job *job, const QByteArray &data); void jobFinished(KJob *job); signals: - void suggestionReceived(const QStringList &suggestion); + void suggestionReceived(const QString &text, const QStringList &suggestion); void openSearchEngineAdded(const QString &name, const QString &searchUrl, const QString &fileName); private: @@ -103,6 +103,8 @@ private: QMap<QString, OpenSearchEngine*> m_enginesMap; OpenSearchEngine *m_activeEngine; STATE m_state; + + QString _typedText; }; #endif // OPENSEARCHMANAGER_H diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index a9203bf7..c1f5d83b 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -56,6 +56,8 @@ CompletionWidget::CompletionWidget(QWidget *parent) , _parent(parent) , _currentIndex(0) , _searchEngine(SearchEngine::defaultEngine()) + , _suggestionsNumber(0) + , _isSuggesting(false) { setFrameStyle(QFrame::Panel); setLayoutDirection(Qt::LeftToRight); @@ -79,14 +81,61 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString { ListItem *suggestion = ListItemFactory::create(item, text, this); suggestion->setBackgroundRole(i % 2 ? QPalette::AlternateBase : QPalette::Base); - connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton, Qt::KeyboardModifiers))); + 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(i++)); layout()->addWidget(suggestion); } } +void CompletionWidget::updateSearchList(const UrlSearchList &list, const QString& text) +{ + kDebug() << "TYPED STRING: " << _typedString; + kDebug() << "text from suggestion: " << text; + + if(_isSuggesting || !isVisible() || _typedString != text) + return; + + _isSuggesting = true; + + // clean up eventual old suggestions + if(_suggestionsNumber > 0) + { + int offset = _list.count(); + for(int i = offset; i < offset + _suggestionsNumber; ++i) + { + QLayoutItem *item = layout()->takeAt( i ); + delete item; + } + } + + // add new suggestions to the list + int i = _list.count(); + Q_FOREACH(const UrlSearchItem &item, list) + { + ListItem *suggestion = ListItemFactory::create(item, text, this); + suggestion->setBackgroundRole(i % 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(i++)); + layout()->addWidget(suggestion); + } + _suggestionsNumber = list.count(); + _list.append(list); + sizeAndPosition(); + _isSuggesting = false; +} + + void CompletionWidget::sizeAndPosition() { setFixedWidth(_parent->width()); @@ -301,8 +350,9 @@ void CompletionWidget::suggestUrls(const QString &text) return; } - UrlResolver res(text); - UrlSearchList list = res.orderedSearchItems(); + 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(); diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index e14535f4..29f80721 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -65,6 +65,7 @@ public: private slots: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier); + void updateSearchList(const UrlSearchList &list, const QString& text); signals: void chosenUrl(const KUrl &, Rekonq::OpenType); @@ -72,6 +73,7 @@ signals: private: void insertSearchList(const UrlSearchList &list, const QString& text); + void popup(); void clear(); @@ -89,6 +91,8 @@ private: KService::Ptr _searchEngine; QString _typedString; + int _suggestionsNumber; + bool _isSuggesting; }; #endif // COMPLETION_WIDGET_H diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 84c9e20b..300f33ef 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -131,8 +131,6 @@ UrlSearchList UrlResolver::orderedSearchItems() return list; } - _computedListsCount = 0; - //compute lists computeSuggestions(); computeQurlFromUserInput(); @@ -140,14 +138,6 @@ UrlSearchList UrlResolver::orderedSearchItems() computeBookmarks(); computeHistory(); - QTime time; - time.start(); - - while (_computedListsCount < 5 && time.msec() < 1000) - { - Application::instance()->processEvents(QEventLoop::WaitForMoreEvents | QEventLoop::ExcludeUserInputEvents); - } - return orderLists(); } @@ -331,8 +321,6 @@ void UrlResolver::computeQurlFromUserInput() UrlSearchItem gItem(UrlSearchItem::Browse, urlFromUserInput.toString(), gTitle); _qurlFromUserInput << gItem; } - - _computedListsCount++; } @@ -340,7 +328,6 @@ void UrlResolver::computeQurlFromUserInput() void UrlResolver::computeWebSearches() { _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString())); - _computedListsCount++; } @@ -358,8 +345,6 @@ void UrlResolver::computeHistory() _history << gItem; } } - - _computedListsCount++; } @@ -373,8 +358,6 @@ void UrlResolver::computeBookmarks() UrlSearchItem gItem(UrlSearchItem::Bookmark, b.url().url(), b.fullText()); _bookmarks << gItem; } - - _computedListsCount++; } @@ -384,29 +367,29 @@ void UrlResolver::computeSuggestions() if (Application::opensearchManager()->isSuggestionAvailable()) { connect(Application::opensearchManager(), - SIGNAL(suggestionReceived(const QStringList &)), + SIGNAL(suggestionReceived(const QString &, const QStringList &)), this, - SLOT(suggestionsReceived(const QStringList &))); + SLOT(suggestionsReceived(const QString &, const QStringList &))); Application::opensearchManager()->requestSuggestion(_typedString); } - else - { - _computedListsCount++; - } } -void UrlResolver::suggestionsReceived(const QStringList &suggestion) +void UrlResolver::suggestionsReceived(const QString &text, const QStringList &suggestions) { + if(text != _typedString) + return; + + UrlSearchList sugList; - foreach (QString s, suggestion) + Q_FOREACH(const QString &s, suggestions) { UrlSearchItem gItem(UrlSearchItem::Suggestion, s, s); - _suggestions << gItem; + sugList << gItem; } - - _computedListsCount++; + emit suggestionsReady(sugList, _typedString); + this->deleteLater(); } @@ -420,7 +403,6 @@ UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list) for(int i = 0; i<list->count(); i++) { item = list->at(i); - //kDebug() << item.url.host(); //TODO: move this to AwesomeUrlCompletion::substringCompletion and add a priviledged flag to UrlSearchItem if (item.url.contains(test1) || item.url.contains(test2)) { diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index f72d6731..4e85e917 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -119,8 +119,6 @@ private: void computeBookmarks(); void computeSuggestions(); - int _computedListsCount; - UrlSearchItem privilegedItem(UrlSearchList* list); UrlSearchList orderLists(); @@ -128,7 +126,10 @@ private: static QRegExp _searchEnginesRegexp; private slots: - void suggestionsReceived(const QStringList &suggestion); + void suggestionsReceived(const QString &text, const QStringList &suggestions); + +Q_SIGNALS: + void suggestionsReady(const UrlSearchList &, const QString &); }; |