summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/search/opensearchmanager.cpp4
-rw-r--r--src/search/searchengine.cpp20
-rw-r--r--src/search/searchengine.h7
-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.cpp27
-rw-r--r--src/urlbar/urlresolver.h28
9 files changed, 111 insertions, 84 deletions
diff --git a/src/search/opensearchmanager.cpp b/src/search/opensearchmanager.cpp
index 9670a6a2..c2ac1ddb 100644
--- a/src/search/opensearchmanager.cpp
+++ b/src/search/opensearchmanager.cpp
@@ -114,6 +114,7 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl
{
disconnect(m_currentJob);
m_currentJob->kill();
+ delete m_currentJob;
}
m_jobData.clear();
@@ -149,7 +150,8 @@ void OpenSearchManager::requestSuggestion(const QString &searchText)
if (m_currentJob)
{
disconnect(m_currentJob);
- m_currentJob->kill();
+ m_currentJob->kill();
+ delete m_currentJob;
}
m_jobData.clear();
diff --git a/src/search/searchengine.cpp b/src/search/searchengine.cpp
index 38f063a4..89e62dee 100644
--- a/src/search/searchengine.cpp
+++ b/src/search/searchengine.cpp
@@ -111,7 +111,7 @@ KService::Ptr SearchEngine::defaultEngine()
}
-KService::Ptr SearchEngine::fromString(QString text)
+KService::Ptr SearchEngine::fromString(const QString &text)
{
KService::List providers = KServiceTypeTrader::self()->query("SearchProvider");
int i = 0;
@@ -136,12 +136,22 @@ KService::Ptr SearchEngine::fromString(QString text)
}
-QString SearchEngine::buildQuery(KService::Ptr engine, QString text)
+QString SearchEngine::extractQuery(const QString &text)
{
- QString query = engine->property("Query").toString();
- query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
+ QString query = text;
+ KService::Ptr engine = SearchEngine::fromString(text);
+ if (engine)
+ {
+ query = query.remove(0, text.indexOf(SearchEngine::delimiter()) + 1);
+ }
+
return query;
}
-
+QString SearchEngine::buildQuery(KService::Ptr engine, const QString &text)
+{
+ QString query = engine->property("Query").toString();
+ query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
+ return query;
+}
diff --git a/src/search/searchengine.h b/src/search/searchengine.h
index e57b1a5c..d813666b 100644
--- a/src/search/searchengine.h
+++ b/src/search/searchengine.h
@@ -45,9 +45,10 @@ public:
static QString delimiter();
static KService::Ptr defaultEngine();
static KService::List favorites();
- static KService::Ptr fromString(QString text);
- static QString buildQuery(KService::Ptr engine, QString text);
-
+ static KService::Ptr fromString(const QString &text);
+ static QString buildQuery(KService::Ptr engine, const QString &text);
+ static QString extractQuery(const QString &text);
+
private:
static bool m_loaded;
static QString m_delimiter;
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..dfb3289f 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -59,14 +59,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 +111,6 @@ UrlResolver::UrlResolver(const QString &typedUrl)
}
_searchEnginesRegexp = QRegExp(reg);
}
-
- computeSuggestions();
}
@@ -330,7 +332,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 +377,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 +394,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..700fd460 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,24 @@ public:
UrlSearchList orderedSearchItems();
+ static KService::Ptr searchEngine()
+ {
+ return _searchEngine;
+ };
+
+ 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:
QString _typedString;
@@ -117,20 +135,14 @@ private:
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);
-Q_SIGNALS:
- void suggestionsReady(const UrlSearchList &, const QString &);
-
+ static KService::Ptr _searchEngine;
};
// ------------------------------------------------------------------------------