summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/application.cpp1
-rw-r--r--src/data/wikipedia.xml10
-rw-r--r--src/opensearch/opensearchreader.cpp3
-rw-r--r--src/opensearch/searchengine.cpp17
-rw-r--r--src/opensearch/suggestionparser.cpp7
-rw-r--r--src/urlbar/completionwidget.cpp7
-rw-r--r--src/urlbar/listitem.cpp31
-rw-r--r--src/urlbar/urlresolver.cpp34
-rw-r--r--src/urlbar/urlresolver.h8
9 files changed, 72 insertions, 46 deletions
diff --git a/src/application.cpp b/src/application.cpp
index cadfa50f..2efb62c0 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -310,7 +310,6 @@ OpenSearchManager *Application::opensearchManager()
if (s_opensearchManager.isNull())
{
s_opensearchManager = new OpenSearchManager(instance());
- s_opensearchManager.data()->setSearchProvider("google"); //TODO: use other suggestion engines
}
return s_opensearchManager.data();
}
diff --git a/src/data/wikipedia.xml b/src/data/wikipedia.xml
index 6f200a25..4e152087 100644
--- a/src/data/wikipedia.xml
+++ b/src/data/wikipedia.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
- <ShortName>Wikipédia (fr)</ShortName>
- <Description>Wikipédia (fr)</Description>
- <Url method="get" template="http://fr.wikipedia.org/w/index.php?title=Sp%C3%A9cial:Recherche&amp;search={searchTerms}"/>
- <Url method="get" type="application/x-suggestions+xml" template="http://fr.wikipedia.org/w/api.php?action=opensearch&amp;format=xml&amp;search={searchTerms}&amp;namespace=0"/>
- <Image>http://fr.wikipedia.org/favicon.ico</Image>
+ <ShortName>Wikipedia</ShortName>
+ <Description>Wikipedia</Description>
+ <Url method="get" template="http://en.wikipedia.org/w/index.php?title=Sp%C3%A9cial:Recherche&amp;search={searchTerms}"/>
+ <Url method="get" type="application/x-suggestions+xml" template="http://en.wikipedia.org/w/api.php?action=opensearch&amp;format=xml&amp;search={searchTerms}&amp;namespace=0"/>
+ <Image>http://en.wikipedia.org/favicon.ico</Image>
</OpenSearchDescription>
diff --git a/src/opensearch/opensearchreader.cpp b/src/opensearch/opensearchreader.cpp
index 1c106afa..aff9ff36 100644
--- a/src/opensearch/opensearchreader.cpp
+++ b/src/opensearch/opensearchreader.cpp
@@ -74,7 +74,8 @@ OpenSearchEngine *OpenSearchReader::read()
{
OpenSearchEngine *engine = new OpenSearchEngine();
- while (!isStartElement() && !atEnd()) {
+ while (!isStartElement() && !atEnd())
+ {
readNext();
}
diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp
index 415e5b35..4378a26c 100644
--- a/src/opensearch/searchengine.cpp
+++ b/src/opensearch/searchengine.cpp
@@ -57,7 +57,7 @@ void SearchEngine::reload()
favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines);
KService::List favorites;
KService::Ptr service;
- foreach(const QString &engine, favoriteEngines)
+ Q_FOREACH(const QString &engine, favoriteEngines)
{
service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
if (service)
@@ -74,11 +74,6 @@ void SearchEngine::reload()
//load default engine
QString d = cg.readEntry("DefaultSearchEngine");
m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d));
- if (!m_defaultEngine)
- {
- d = QL1S("google");
- m_defaultEngine = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d));
- }
m_loaded = true;
}
@@ -120,7 +115,7 @@ KService::Ptr SearchEngine::fromString(const QString &text)
while (!found && i < providers.size())
{
QStringList list = providers.at(i)->property("Keys").toStringList();
- foreach(const QString &key, list)
+ Q_FOREACH(const QString &key, list)
{
const QString searchPrefix = key + delimiter();
if (text.startsWith(searchPrefix))
@@ -141,18 +136,14 @@ QString SearchEngine::extractQuery(const QString &text)
QString query = text;
KService::Ptr engine = SearchEngine::fromString(text);
- // WARNING: this lets rekonq hangs on kde: urlbar typing..
-// if (engine)
-// {
-// query = query.remove(0, text.indexOf(SearchEngine::delimiter()) + 1);
-// }
-
return query;
}
QString SearchEngine::buildQuery(KService::Ptr engine, const QString &text)
{
+ if(!engine)
+ return QString();
QString query = engine->property("Query").toString();
query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
return query;
diff --git a/src/opensearch/suggestionparser.cpp b/src/opensearch/suggestionparser.cpp
index 98bb8a69..4ed13e16 100644
--- a/src/opensearch/suggestionparser.cpp
+++ b/src/opensearch/suggestionparser.cpp
@@ -55,7 +55,8 @@ ResponseList XMLParser::parse(const QByteArray &resp)
{
m_reader.readNext();
- if (m_reader.isStartDocument()) continue;
+ if (m_reader.isStartDocument())
+ continue;
if (m_reader.isStartElement() && m_reader.name() == QL1S("Item"))
{
@@ -105,6 +106,7 @@ ResponseList JSONParser::parse(const QByteArray &resp)
if (response.isEmpty())
{
+ kDebug() << "RESPONSE IS EMPTY";
return ResponseList();
}
@@ -112,12 +114,14 @@ ResponseList JSONParser::parse(const QByteArray &resp)
|| !response.endsWith(QL1C(']'))
)
{
+ kDebug() << "RESPONSE is NOT well FORMED";
return ResponseList();
}
// Evaluate the JSON response using QtScript.
if (!m_reader.canEvaluate(response))
{
+ kDebug() << "m_reader cannot evaluate the response";
return ResponseList();
}
@@ -125,6 +129,7 @@ ResponseList JSONParser::parse(const QByteArray &resp)
if (!responseParts.property(1).isArray())
{
+ kDebug() << "RESPONSE is not an array";
return ResponseList();
}
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index f8bf6ee2..fdfd3107 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -311,6 +311,9 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev)
child = findChild<ListItem *>(QString::number(_currentIndex));
if(child && _currentIndex!=0) //the completionwidget is visible and the user had press down
{
+ kDebug() << "USING LISTITEM URL: " << child->url();
+ kDebug() << "USING LISTITEM TITLE: " << child->text();
+
//we can use the url of the listitem
emit chosenUrl(child->url(), Rekonq::CurrentTab);
}
@@ -381,6 +384,8 @@ 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();
+
+ // NOTE: It's important to call this AFTER orderedSearchItems() to let everything work
+ res->computeSuggestions();
}
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 5fa46470..a0462e76 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -58,6 +58,7 @@
#include <QFile>
#include <QTextDocument>
+
ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
: QWidget(parent)
, m_option()
@@ -81,7 +82,6 @@ ListItem::~ListItem()
}
-
void ListItem::activate()
{
m_option.state |= QStyle::State_Selected;
@@ -166,11 +166,16 @@ TypeIconLabel::TypeIconLabel(int type, QWidget *parent)
hLayout->setAlignment(Qt::AlignRight);
setLayout(hLayout);
- if (type & UrlSearchItem::Search) hLayout->addWidget(getIcon("edit-find"));
- if (type & UrlSearchItem::Browse) hLayout->addWidget(getIcon("applications-internet"));
- if (type & UrlSearchItem::Bookmark) hLayout->addWidget(getIcon("rating"));
- if (type & UrlSearchItem::History) hLayout->addWidget(getIcon("view-history"));
- if (type & UrlSearchItem::Suggestion) hLayout->addWidget(getIcon("help-hint"));
+ if (type & UrlSearchItem::Search)
+ hLayout->addWidget(getIcon("edit-find"));
+ if (type & UrlSearchItem::Browse)
+ hLayout->addWidget(getIcon("applications-internet"));
+ if (type & UrlSearchItem::Bookmark)
+ hLayout->addWidget(getIcon("rating"));
+ if (type & UrlSearchItem::History)
+ hLayout->addWidget(getIcon("view-history"));
+ if (type & UrlSearchItem::Suggestion)
+ hLayout->addWidget(getIcon("help-hint"));
}
@@ -204,8 +209,10 @@ IconLabel::IconLabel(const KIcon &icon, QWidget *parent)
setPixmap(pixmapIcon);
}
+
// ---------------------------------------------------------------
+
static QString highlightWordsInText(const QString &text, const QStringList &words)
{
QString ret = text;
@@ -241,6 +248,7 @@ static QString highlightWordsInText(const QString &text, const QStringList &word
return ret;
}
+
TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget *parent)
: QLabel(parent)
{
@@ -274,6 +282,7 @@ 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) ) );
}
+
// ---------------------------------------------------------------
@@ -350,6 +359,7 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p
}
}
+
// ---------------------------------------------------------------
@@ -382,6 +392,7 @@ void ImageLabel::slotResult(KJob *)
setPixmap(pix);
}
+
// ---------------------------------------------------------------
@@ -416,12 +427,6 @@ 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, text));
-// }
-
-
void SearchListItem::changeSearchEngine(KService::Ptr engine)
{
m_titleLabel->setEngineText(engine->name(), m_text);
@@ -575,6 +580,7 @@ QString VisualSuggestionListItem::text()
return m_text;
}
+
// ---------------------------------------------------------------
@@ -627,6 +633,7 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text
if (item.type & UrlSearchItem::Suggestion)
{
+ kDebug() << "ITEM URL: " << item.url;
if (item.description.isEmpty())
{
kDebug() << "Suggestion";
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index c3efb903..57d6ca64 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -70,7 +70,8 @@ UrlResolver::UrlResolver(const QString &typedUrl)
: QObject()
, _typedString(typedUrl.trimmed())
{
- if (!_searchEngine ) setSearchEngine(SearchEngine::defaultEngine());
+ if (!_searchEngine )
+ setSearchEngine(SearchEngine::defaultEngine());
if ( _browseRegexp.isEmpty() )
{
@@ -196,8 +197,8 @@ UrlSearchList UrlResolver::orderLists()
UrlSearchList common;
int commonCount = 0;
- //prefer items which are history items als well bookmarks item
- //if there are more than 1000 bookmark results, the performance impact is noticeable
+ // prefer items which are history items as well bookmarks item
+ // if there are more than 1000 bookmark results, the performance impact is noticeable
if(bookmarksCount < 1000)
{
//add as many items to the common list as there are available entries in the dropdown list
@@ -316,7 +317,7 @@ UrlSearchList UrlResolver::orderLists()
// PRIVATE ENGINES
-//QUrl from User Input (easily the best solution... )
+// QUrl from User Input (easily the best solution... )
void UrlResolver::computeQurlFromUserInput()
{
QString url = _typedString;
@@ -330,7 +331,7 @@ void UrlResolver::computeQurlFromUserInput()
}
-//webSearches
+// webSearches
void UrlResolver::computeWebSearches()
{
QString query = _typedString;
@@ -341,11 +342,17 @@ void UrlResolver::computeWebSearches()
_searchEngine = engine;
}
- _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, SearchEngine::buildQuery(_searchEngine, query), _searchEngine->name()));
+ if(_searchEngine)
+ {
+ UrlSearchItem item = UrlSearchItem(UrlSearchItem::Search, SearchEngine::buildQuery(_searchEngine, query), _searchEngine->name());
+ UrlSearchList list;
+ list << item;
+ _webSearches = list;
+ }
}
-//history
+// history
void UrlResolver::computeHistory()
{
QList<HistoryItem> found = Application::historyManager()->find(_typedString);
@@ -375,7 +382,7 @@ void UrlResolver::computeBookmarks()
}
-//opensearch suggestion
+// opensearch suggestion
void UrlResolver::computeSuggestions()
{
// if a string startsWith /, it is probably a local path
@@ -405,7 +412,16 @@ void UrlResolver::suggestionsReceived(const QString &text, const ResponseList &s
Q_FOREACH(const Response &i, suggestions)
{
- UrlSearchItem gItem(UrlSearchItem::Suggestion, i.url, i.title, i.description, i.image, i.image_width, i.image_height);
+ QString urlString = i.url;
+ if(urlString.isEmpty())
+ {
+ QStringList list;
+ list << QL1S("kuriikwsfilter");
+ urlString = KUriFilter::self()->filteredUri(i.title, list);
+ }
+ kDebug() << "RESPONSE URL: " << i.url;
+
+ UrlSearchItem gItem(UrlSearchItem::Suggestion, urlString, i.title, i.description, i.image, i.image_width, i.image_height);
sugList << gItem;
}
emit suggestionsReady(sugList, _typedString);
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index 3e8e4fce..b3d1c9ff 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -30,6 +30,8 @@
// Rekonq Includes
#include "rekonq_defines.h"
+
+// Locale Includes
#include "application.h"
#include "opensearchmanager.h"
@@ -87,7 +89,7 @@ public:
UrlSearchItem(const int &_type,
const QString &_url,
const QString &_title = QString(),
- const QString &_description = QString(),
+ const QString &_description = QString(),
const QString &_image = QString(),
const int &_image_width = 0,
const int &_image_height = 0
@@ -130,7 +132,8 @@ public:
static void setSearchEngine(KService::Ptr engine)
{
_searchEngine = engine;
- Application::opensearchManager()->setSearchProvider(engine->desktopEntryName());
+ if(engine)
+ Application::opensearchManager()->setSearchProvider(engine->desktopEntryName());
};
void computeSuggestions();
@@ -150,7 +153,6 @@ private:
UrlSearchItem privilegedItem(UrlSearchList* list);
UrlSearchList orderLists();
-
QString _typedString;
UrlSearchList _webSearches;