diff options
author | lionelc <megabigbug@yahoo.fr> | 2010-09-01 19:32:44 +0200 |
---|---|---|
committer | lionelc <megabigbug@yahoo.fr> | 2010-09-01 19:32:44 +0200 |
commit | 3e527d1d33fc147989942d03ee59497e6f3e42d0 (patch) | |
tree | 5c398b70f754e6c48b5c05e3c50ce5b667930951 /src/urlbar | |
parent | This should improve adblock retrieving by NOT asking for SSL confirmations (diff) | |
download | rekonq-3e527d1d33fc147989942d03ee59497e6f3e42d0.tar.xz |
big commit: fix fast typing
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/completionwidget.cpp | 12 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 10 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 44 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 17 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 14 |
5 files changed, 42 insertions, 55 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 2199dfdf..1b931535 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -55,7 +55,6 @@ CompletionWidget::CompletionWidget(QWidget *parent) : QFrame(parent, Qt::ToolTip) , _parent(parent) , _currentIndex(0) - , _searchEngine(SearchEngine::defaultEngine()) , _hasSuggestions(false) { setFrameStyle(QFrame::Panel); @@ -71,7 +70,7 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString { if (!isVisible()) { - _searchEngine = SearchEngine::defaultEngine(); + UrlResolver::setSearchEngine(SearchEngine::defaultEngine()); } _list = list; @@ -278,14 +277,15 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) if( _currentIndex == -1) _currentIndex = 0; child = findChild<ListItem *>(QString::number(_currentIndex)); - if(child) + if(child && _currentIndex!=0) //the completionwidget is visible and the user had press down { + //we can use the url of the listitem emit chosenUrl(child->url(), Rekonq::CurrentTab); } - else + else //the user type too fast (completionwidget not visible or suggestion not downloaded) { - // this will be used just on fast typing.. - emit chosenUrl(KUrl(w->text()), Rekonq::CurrentTab); + UrlResolver res(w->text()); + emit chosenUrl(res.orderedSearchItems().first().url, Rekonq::CurrentTab); } kev->accept(); hide(); diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 7f6c93f0..6545b11d 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -51,16 +51,6 @@ public: virtual bool eventFilter(QObject *obj, QEvent *ev); void setVisible(bool visible); - KService::Ptr searchEngine() - { - return _searchEngine; - }; - - void setSearchEngine(KService::Ptr engine) - { - _searchEngine = engine; - }; - void suggestUrls(const QString &text); private slots: diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 6c09f9a5..75b47949 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -286,27 +286,14 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p // --------------------------------------------------------------- -SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) - : ListItem(item, parent) +SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *paren) + : ListItem(item, paren) , m_text(text) { - QString query = text; - KService::Ptr engine = SearchEngine::fromString(text); - if (engine) - { - query = query.remove(0, text.indexOf(SearchEngine::delimiter()) + 1); - } - else - { - engine = qobject_cast<CompletionWidget *>(parent)->searchEngine(); - } - - m_url = SearchEngine::buildQuery(engine, query); - - KIcon icon = Application::iconManager()->iconForUrl( SearchEngine::defaultEngine()->property("Query").toUrl() ); - m_iconLabel = new IconLabel(icon, this); //TODO: get the default engine icon (will be easy in KDE SC 4.5) - m_titleLabel = new TextLabel(searchItemTitle(engine->name(), query), query, this); - m_engineBar = new EngineBar(engine, parent); + m_iconLabel = new IconLabel(SearchEngine::buildQuery(UrlResolver::searchEngine(), ""), this); + QString query = SearchEngine::extractQuery(text); + m_titleLabel = new TextLabel(searchItemTitle(item.title, query), query, this); + m_engineBar = new EngineBar(UrlResolver::searchEngine(), paren); QHBoxLayout *hLayout = new QHBoxLayout; hLayout->setSpacing(4); @@ -340,7 +327,7 @@ void SearchListItem::changeSearchEngine(KService::Ptr engine) m_titleLabel->setText(searchItemTitle(engine->name(), m_text)); m_iconLabel->setPixmap( Application::iconManager()->iconForUrl(KUrl(engine->property("Query").toString())).pixmap(16) ); m_url = SearchEngine::buildQuery(engine, m_text); - qobject_cast<CompletionWidget *>(parent())->setSearchEngine(engine); + UrlResolver::setSearchEngine(engine); } @@ -429,21 +416,8 @@ SuggestionListItem::SuggestionListItem(const UrlSearchItem &item, const QString QHBoxLayout *hLayout = new QHBoxLayout; hLayout->setSpacing(4); - QString query = item.title; - KService::Ptr engine = SearchEngine::fromString(query); - if (engine) - { - query = query.remove(0, text.indexOf(SearchEngine::delimiter()) + 1); - } - else - { - engine = qobject_cast<CompletionWidget *>(parent)->searchEngine(); - } - - m_url = SearchEngine::buildQuery(engine, query); - - hLayout->addWidget(new IconLabel(SearchEngine::buildQuery(engine, ""), this)); - hLayout->addWidget(new TextLabel(item.title, text, this)); + hLayout->addWidget(new IconLabel(SearchEngine::buildQuery(UrlResolver::searchEngine(), ""), this)); + hLayout->addWidget(new TextLabel(item.title, SearchEngine::extractQuery(text), this)); hLayout->addWidget(new TypeIconLabel(item.type, this)); setLayout(hLayout); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index b6d7e598..6743727b 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -59,6 +59,7 @@ // ------------------------------------------------------------------------ +KService::Ptr UrlResolver::_searchEngine; QRegExp UrlResolver::_browseRegexp; QRegExp UrlResolver::_searchEnginesRegexp; @@ -67,6 +68,8 @@ UrlResolver::UrlResolver(const QString &typedUrl) : QObject() , _typedString(typedUrl.trimmed()) { + if (!_searchEngine ) _searchEngine = SearchEngine::defaultEngine(); + if ( _browseRegexp.isEmpty() ) { kDebug() << "browse regexp empty. Setting value.."; @@ -107,7 +110,7 @@ UrlResolver::UrlResolver(const QString &typedUrl) } _searchEnginesRegexp = QRegExp(reg); } - + computeSuggestions(); } @@ -330,7 +333,15 @@ void UrlResolver::computeQurlFromUserInput() //webSearches void UrlResolver::computeWebSearches() { - _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString())); + QString query = _typedString; + KService::Ptr engine = SearchEngine::fromString(_typedString); + if (engine) + { + query = query.remove(0, _typedString.indexOf(SearchEngine::delimiter()) + 1); + _searchEngine = engine; + } + + _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, SearchEngine::buildQuery(_searchEngine, query), _searchEngine->name())); } @@ -375,7 +386,7 @@ void UrlResolver::computeSuggestions() SLOT(suggestionsReceived(const QString &, const QStringList &))); Application::opensearchManager()->requestSuggestion(_typedString); - } + } } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 4e85e917..dc579e0e 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -33,7 +33,7 @@ // KDE Includes #include <KUrl> - +#include <KService> // Qt Includes #include <QString> @@ -104,6 +104,16 @@ public: UrlSearchList orderedSearchItems(); + static KService::Ptr searchEngine() + { + return _searchEngine; + }; + + static void setSearchEngine(KService::Ptr engine) + { + _searchEngine = engine; + }; + private: QString _typedString; @@ -124,6 +134,8 @@ private: static QRegExp _browseRegexp; static QRegExp _searchEnginesRegexp; + + static KService::Ptr _searchEngine; private slots: void suggestionsReceived(const QString &text, const QStringList &suggestions); |