summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-08-03 01:26:03 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:04 +0100
commit91c709932f8d49323f2834dcfb501fade27a8f6e (patch)
tree028467de1682a3748607e2b2a037456c2f6c7917 /src/urlbar
parentRemoved (FOR NOW) open search feature (diff)
downloadrekonq-91c709932f8d49323f2834dcfb501fade27a8f6e.tar.xz
Clean up url suggestions loading
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/completionwidget.cpp19
-rw-r--r--src/urlbar/listitem.cpp15
-rw-r--r--src/urlbar/urlbar.cpp15
-rw-r--r--src/urlbar/urlsuggester.cpp27
-rw-r--r--src/urlbar/urlsuggester.h2
5 files changed, 36 insertions, 42 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 5ef65fd9..12051f80 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -33,6 +33,7 @@
// Local Includes
#include "searchengine.h"
+#include "urlresolver.h"
#include "listitem.h"
#include "urlbar.h"
@@ -299,7 +300,6 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev)
}
}
- kDebug() << "Suggestion INDEX chosen: " << _currentIndex;
if (_currentIndex == -1)
_currentIndex = 0;
child = findChild<ListItem *>(QString::number(_currentIndex));
@@ -311,16 +311,8 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev)
}
else //the user type too fast (completionwidget not visible or suggestion not downloaded)
{
- UrlSuggester res(w->text());
- UrlSuggestionList list = res.orderedSearchItems();
- if (list.isEmpty())
- {
- emit chosenUrl(KUrl(_typedString), Rekonq::CurrentTab);
- }
- else
- {
- emit chosenUrl(list.first().url, Rekonq::CurrentTab);
- }
+ KUrl u = UrlResolver::urlFromTextTyped(w->text());
+ emit chosenUrl(u, Rekonq::CurrentTab);
}
kev->accept();
hide();
@@ -387,11 +379,6 @@ void CompletionWidget::suggestUrls(const QString &text)
return;
}
- if (!isVisible())
- {
-// FIXME UrlResolver::setSearchEngine(SearchEngine::defaultEngine());
- }
-
UrlSuggester *res = new UrlSuggester(text);
connect(res, SIGNAL(suggestionsReady(UrlSuggestionList, QString)),
this, SLOT(updateSuggestionList(UrlSuggestionList, QString)));
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index b47d23bf..86bd9101 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -425,11 +425,15 @@ SearchListItem::SearchListItem(const UrlSuggestionItem &item, const QString &tex
: ListItem(item, parent)
, m_text(text)
{
- // FIXME
-// m_iconLabel = new IconLabel(SearchEngine::buildQuery(UrlResolver::searchEngine(), ""), this);
-// m_titleLabel = new TextLabel(this);
-// m_titleLabel->setEngineText(UrlResolver::searchEngine()->name(), item.title);
-// m_engineBar = new EngineBar(UrlResolver::searchEngine(), parent);
+ m_iconLabel = new IconLabel(item.url, this);
+ m_titleLabel = new TextLabel(this);
+ m_titleLabel->setEngineText(item.description, item.title);
+
+ KService::Ptr engine = SearchEngine::fromString(text);
+ if (!engine)
+ engine = SearchEngine::defaultEngine();
+
+ m_engineBar = new EngineBar(engine, parent);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setSpacing(4);
@@ -482,6 +486,7 @@ EngineBar::EngineBar(KService::Ptr selectedEngine, QWidget *parent)
if (SearchEngine::defaultEngine().isNull())
return;
+
m_engineGroup->addAction(newEngineAction(SearchEngine::defaultEngine(), selectedEngine));
Q_FOREACH(const KService::Ptr & engine, SearchEngine::favorites())
{
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index c77edeb5..a994ea95 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -47,7 +47,7 @@
#include "favoritewidget.h"
#include "rsswidget.h"
-#include "urlsuggester.h"
+#include "urlresolver.h"
#include "webtab.h"
#include "webpage.h"
@@ -202,16 +202,8 @@ void UrlBar::loadRequestedUrl(const KUrl& url, Rekonq::OpenType type)
void UrlBar::loadDigitedUrl()
{
- UrlSuggester res(text());
- UrlSuggestionList list = res.orderedSearchItems();
- if (list.isEmpty())
- {
- loadRequestedUrl(KUrl(text()));
- }
- else
- {
- loadRequestedUrl(list.first().url);
- }
+ KUrl u = UrlResolver::urlFromTextTyped(text());
+ loadRequestedUrl(u);
}
@@ -651,6 +643,7 @@ void UrlBar::detectTypedString(const QString &typed)
void UrlBar::suggest()
{
+ kDebug() << "SUGGEST ABOUT DIGITED: " << text();
if (!_box.isNull())
_box.data()->suggestUrls(text());
}
diff --git a/src/urlbar/urlsuggester.cpp b/src/urlbar/urlsuggester.cpp
index 52ba7640..83108a36 100644
--- a/src/urlbar/urlsuggester.cpp
+++ b/src/urlbar/urlsuggester.cpp
@@ -73,6 +73,7 @@ QRegExp UrlSuggester::_searchEnginesRegexp;
UrlSuggester::UrlSuggester(const QString &typedUrl)
: QObject()
, _typedString(typedUrl.trimmed())
+ , _webSearchFirst(false)
{
if (_browseRegexp.isEmpty())
{
@@ -178,13 +179,12 @@ UrlSuggestionList UrlSuggester::orderLists()
// You have to add here the "browse & search" options, always available.
const int availableEntries = 8;
- bool webSearchFirst = false;
// Browse & Search results
UrlSuggestionList browseSearch;
QString lowerTypedString = _typedString.toLower();
- if (_browseRegexp.indexIn(lowerTypedString) != -1)
+ if (_webSearchFirst || _browseRegexp.indexIn(lowerTypedString) != -1)
{
- webSearchFirst = true;
+ _webSearchFirst = true;
browseSearch << _webSearches;
}
else
@@ -256,8 +256,8 @@ UrlSuggestionList UrlSuggester::orderLists()
// and finally, results
UrlSuggestionList list;
- if (webSearchFirst)
- list << _qurlFromUserInput;
+// if (_webSearchFirst)
+// list << _qurlFromUserInput;
list += relevant + browseSearch + _history + _bookmarks;
return list;
}
@@ -293,16 +293,23 @@ void UrlSuggester::computeQurlFromUserInput()
void UrlSuggester::computeWebSearches()
{
QString query = _typedString;
+
+ // this result is generated when an user types something like gg:kde
KService::Ptr engine = SearchEngine::fromString(_typedString);
if (engine)
{
+ _webSearchFirst = true;
query = query.remove(0, _typedString.indexOf(SearchEngine::delimiter()) + 1);
-
- UrlSuggestionItem item = UrlSuggestionItem(UrlSuggestionItem::Search, SearchEngine::buildQuery(engine, query), query);
- UrlSuggestionList list;
- list << item;
- _webSearches = list;
}
+ else
+ {
+ engine = SearchEngine::defaultEngine();
+ }
+
+ UrlSuggestionItem item = UrlSuggestionItem(UrlSuggestionItem::Search, SearchEngine::buildQuery(engine, query), query, engine->name());
+ UrlSuggestionList list;
+ list << item;
+ _webSearches = list;
}
diff --git a/src/urlbar/urlsuggester.h b/src/urlbar/urlsuggester.h
index 4f20e701..d7673c3a 100644
--- a/src/urlbar/urlsuggester.h
+++ b/src/urlbar/urlsuggester.h
@@ -146,6 +146,8 @@ private:
UrlSuggestionList _bookmarks;
UrlSuggestionList _suggestions;
+ bool _webSearchFirst;
+
static QRegExp _browseRegexp;
static QRegExp _searchEnginesRegexp;
};