summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-11-07 22:31:43 +0100
committerAndrea Diamantini <adjam7@gmail.com>2010-11-07 22:31:43 +0100
commit23fdf29c98c402e96e7cb14eecba30671bc72d64 (patch)
tree2732854f3ded89546f86ce479654c569549a9ba4 /src
parentFirst bunch of fixes for the suggestions. (diff)
downloadrekonq-23fdf29c98c402e96e7cb14eecba30671bc72d64.tar.xz
Let suggestions work also without search engines ones.
Diffstat (limited to 'src')
-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.cpp4
-rw-r--r--src/urlbar/urlresolver.cpp10
-rw-r--r--src/urlbar/urlresolver.h1
6 files changed, 24 insertions, 18 deletions
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 44e35e33..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 a42433b7..fdfd3107 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -384,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/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index c95557cf..57d6ca64 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -412,8 +412,16 @@ void UrlResolver::suggestionsReceived(const QString &text, const ResponseList &s
Q_FOREACH(const Response &i, suggestions)
{
+ 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, i.url, i.title, i.description, i.image, i.image_width, i.image_height);
+
+ 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 e21e65e8..b3d1c9ff 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -153,7 +153,6 @@ private:
UrlSearchItem privilegedItem(UrlSearchList* list);
UrlSearchList orderLists();
-
QString _typedString;
UrlSearchList _webSearches;