summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/completionwidget.cpp21
-rw-r--r--src/urlbar/completionwidget.h10
-rw-r--r--src/urlbar/listitem.cpp73
-rw-r--r--src/urlbar/listitem.h5
-rw-r--r--src/urlbar/urlresolver.cpp28
-rw-r--r--src/urlbar/urlresolver.h46
6 files changed, 100 insertions, 83 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 2199dfdf..a2bf5dbc 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();
@@ -320,10 +320,15 @@ void CompletionWidget::setVisible(bool visible)
void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button, Qt::KeyboardModifiers modifier)
{
- if (button == Qt::MidButton || modifier == Qt::ControlModifier)
+ if (button == Qt::MidButton
+ || modifier == Qt::ControlModifier)
+ {
emit chosenUrl(item->url(), Rekonq::NewFocusedTab);
+ }
else
+ {
emit chosenUrl(item->url(), Rekonq::CurrentTab);
+ }
hide();
}
@@ -344,6 +349,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 &)));
+ res->computeSuggestions();
_resList = res->orderedSearchItems();
-
}
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..5ff90056 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -212,12 +212,11 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget
const bool wasItalic = t.startsWith("<i>");
if (wasItalic)
t.remove(QRegExp("<[/ib]*>"));
+
t = Qt::escape(t);
- QStringList words = textToPointOut.split(" ");
- foreach (const QString &wordToPointOut, words) {
- if (!wordToPointOut.isEmpty())
- t.replace(QRegExp('(' + wordToPointOut + ')', Qt::CaseInsensitive), "<b>\\1</b>");
- }
+ QString ss = Qt::escape(textToPointOut);
+ t.replace(QRegExp('(' + ss + ')', Qt::CaseInsensitive), "<b>\\1</b>");
+
if (wasItalic)
t = QL1S("<i>") + t + QL1S("</i>");
@@ -226,6 +225,19 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget
}
+TextLabel::TextLabel(QWidget *parent)
+ : QLabel(parent)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+}
+
+
+void TextLabel::setEngineText(const QString &engine, const QString &text)
+{
+ setText( i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for <b>%2</b>", engine, Qt::escape(text) ) );
+}
+
+
//--------------------------------------------------------------------------------------------
@@ -290,23 +302,11 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q
: ListItem(item, parent)
, 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(this);
+ m_titleLabel->setEngineText(item.title, query);
+ m_engineBar = new EngineBar(UrlResolver::searchEngine(), parent);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setSpacing(4);
@@ -329,18 +329,18 @@ QString SearchListItem::text()
}
-QString SearchListItem::searchItemTitle(QString engine, QString text)
-{
- return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for %2", engine, Qt::escape(text)));
-}
+// QString SearchListItem::searchItemTitle(QString engine, QString text)
+// {
+// return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for %2", engine, text));
+// }
void SearchListItem::changeSearchEngine(KService::Ptr engine)
{
- m_titleLabel->setText(searchItemTitle(engine->name(), m_text));
+ m_titleLabel->setEngineText(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 +429,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/listitem.h b/src/urlbar/listitem.h
index 37b22f47..be5a2569 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -121,6 +121,9 @@ class TextLabel : public QLabel
public:
explicit TextLabel(const QString &text, const QString &textToPointOut = QString(), QWidget *parent = 0);
+ explicit TextLabel(QWidget *parent = 0);
+
+ void setEngineText(const QString &engine, const QString &text);
};
@@ -165,8 +168,6 @@ private slots:
void changeSearchEngine(KService::Ptr engine);
private:
- QString searchItemTitle(QString engine, QString text);
-
TextLabel* m_titleLabel;
IconLabel* m_iconLabel;
EngineBar* m_engineBar;
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index b6d7e598..7f6a7f4f 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -26,6 +26,7 @@
// Self Includes
#include "urlresolver.h"
+#include "urlresolver.moc"
// Local Includes
#include "application.h"
@@ -59,14 +60,18 @@
// ------------------------------------------------------------------------
+KService::Ptr UrlResolver::_searchEngine;
QRegExp UrlResolver::_browseRegexp;
QRegExp UrlResolver::_searchEnginesRegexp;
+
UrlResolver::UrlResolver(const QString &typedUrl)
: QObject()
, _typedString(typedUrl.trimmed())
{
+ if (!_searchEngine ) _searchEngine = SearchEngine::defaultEngine();
+
if ( _browseRegexp.isEmpty() )
{
kDebug() << "browse regexp empty. Setting value..";
@@ -107,8 +112,6 @@ 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()));
}
@@ -367,6 +378,15 @@ void UrlResolver::computeBookmarks()
//opensearch suggestion
void UrlResolver::computeSuggestions()
{
+ // if a string startsWith /, it is probably a local path
+ // so, no need for suggestions...
+ if(_typedString.startsWith('/'))
+ {
+ UrlSearchList list;
+ emit suggestionsReady(list, _typedString);
+ return;
+ }
+
if (Application::opensearchManager()->isSuggestionAvailable())
{
connect(Application::opensearchManager(),
@@ -375,7 +395,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..f16c44f8 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -33,13 +33,14 @@
// KDE Includes
#include <KUrl>
-
+#include <KService>
// Qt Includes
#include <QString>
#include <QList>
#include <QStringList>
+
class UrlSearchItem
{
public:
@@ -104,33 +105,46 @@ public:
UrlSearchList orderedSearchItems();
-private:
- QString _typedString;
+ static KService::Ptr searchEngine()
+ {
+ return _searchEngine;
+ };
- UrlSearchList _webSearches;
- UrlSearchList _qurlFromUserInput;
- UrlSearchList _history;
- UrlSearchList _bookmarks;
- UrlSearchList _suggestions;
-
+ static void setSearchEngine(KService::Ptr engine)
+ {
+ _searchEngine = engine;
+ };
+
+ void computeSuggestions();
+
+private Q_SLOTS:
+ void suggestionsReceived(const QString &text, const QStringList &suggestions);
+
+Q_SIGNALS:
+ void suggestionsReady(const UrlSearchList &, const QString &);
+
+private:
void computeWebSearches();
void computeHistory();
void computeQurlFromUserInput();
void computeBookmarks();
- void computeSuggestions();
UrlSearchItem privilegedItem(UrlSearchList* list);
UrlSearchList orderLists();
- static QRegExp _browseRegexp;
- static QRegExp _searchEnginesRegexp;
-private slots:
- void suggestionsReceived(const QString &text, const QStringList &suggestions);
+ QString _typedString;
-Q_SIGNALS:
- void suggestionsReady(const UrlSearchList &, const QString &);
+ UrlSearchList _webSearches;
+ UrlSearchList _qurlFromUserInput;
+ UrlSearchList _history;
+ UrlSearchList _bookmarks;
+ UrlSearchList _suggestions;
+ static QRegExp _browseRegexp;
+ static QRegExp _searchEnginesRegexp;
+
+ static KService::Ptr _searchEngine;
};
// ------------------------------------------------------------------------------