summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormegabigbug <megabigbug@yahoo.fr>2010-10-17 16:23:39 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-10-30 11:43:22 +0200
commitee71d4a5cef8544bff1c57cc7b81870982d55c93 (patch)
tree286f4d0701fa1af6c2c3fd2e71ae9120197cd39e
parentremove warnings (diff)
downloadrekonq-ee71d4a5cef8544bff1c57cc7b81870982d55c93.tar.xz
adapt opensearch reader and writer for xml suggestions
-rw-r--r--src/opensearch/opensearchengine.cpp6
-rw-r--r--src/opensearch/opensearchengine.h2
-rw-r--r--src/opensearch/opensearchreader.cpp15
-rw-r--r--src/opensearch/opensearchwriter.cpp2
-rw-r--r--src/opensearch/suggestionparser.cpp2
-rw-r--r--src/opensearch/suggestionparser.h3
6 files changed, 21 insertions, 9 deletions
diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp
index 88016ab0..f100bb60 100644
--- a/src/opensearch/opensearchengine.cpp
+++ b/src/opensearch/opensearchengine.cpp
@@ -245,3 +245,9 @@ ResponseList OpenSearchEngine::parseSuggestion(const QByteArray &resp)
return m_parser->parse(resp);
}
+
+
+QString OpenSearchEngine::type()
+{
+ return m_parser->type();
+}
diff --git a/src/opensearch/opensearchengine.h b/src/opensearch/opensearchengine.h
index d755fc95..03be1212 100644
--- a/src/opensearch/opensearchengine.h
+++ b/src/opensearch/opensearchengine.h
@@ -94,6 +94,8 @@ public:
static QString parseTemplate(const QString &searchTerm, const QString &searchTemplate);
+ QString type();
+
private:
QString m_name;
QString m_description;
diff --git a/src/opensearch/opensearchreader.cpp b/src/opensearch/opensearchreader.cpp
index 7da4113f..ebca7877 100644
--- a/src/opensearch/opensearchreader.cpp
+++ b/src/opensearch/opensearchreader.cpp
@@ -145,16 +145,17 @@ OpenSearchEngine *OpenSearchReader::read()
}
else
{
- engine->setSuggestionsUrlTemplate(url);
- engine->setSuggestionsParameters(parameters);
-
- if (type == QL1S("application/x-suggestions+xml"))
+ if (engine->suggestionsUrlTemplate().isEmpty() && type == QL1S("application/x-suggestions+json")) //note: xml is prefered
{
- engine->setSuggestionParser(new XMLParser());
+ engine->setSuggestionsUrlTemplate(url);
+ engine->setSuggestionsParameters(parameters);
+ engine->setSuggestionParser(new JSONParser());
}
- else if (type == QL1S("application/x-suggestions+json"))
+ else if (type == QL1S("application/x-suggestions+xml"))
{
- engine->setSuggestionParser(new JSONParser());
+ engine->setSuggestionsUrlTemplate(url);
+ engine->setSuggestionsParameters(parameters);
+ engine->setSuggestionParser(new XMLParser());
}
}
diff --git a/src/opensearch/opensearchwriter.cpp b/src/opensearch/opensearchwriter.cpp
index 81ce022c..00a2f0cd 100644
--- a/src/opensearch/opensearchwriter.cpp
+++ b/src/opensearch/opensearchwriter.cpp
@@ -105,7 +105,7 @@ void OpenSearchWriter::write(OpenSearchEngine *engine)
{
writeStartElement(QL1S("Url"));
writeAttribute(QL1S("method"), QL1S("get"));
- writeAttribute(QL1S("type"), QL1S("application/x-suggestions+json"));
+ writeAttribute(QL1S("type"), engine->type());
writeAttribute(QL1S("template"), engine->suggestionsUrlTemplate());
if (!engine->suggestionsParameters().empty())
diff --git a/src/opensearch/suggestionparser.cpp b/src/opensearch/suggestionparser.cpp
index 8f0e7ba2..3b656a3f 100644
--- a/src/opensearch/suggestionparser.cpp
+++ b/src/opensearch/suggestionparser.cpp
@@ -56,7 +56,7 @@ ResponseList XMLParser::parse(const QByteArray &resp)
while (!m_reader.atEnd() && !m_reader.hasError())
{
- QXmlStreamReader::TokenType token = m_reader.readNext();
+ m_reader.readNext();
if (m_reader.isStartDocument()) continue;
diff --git a/src/opensearch/suggestionparser.h b/src/opensearch/suggestionparser.h
index 59c788b1..3b72c5d3 100644
--- a/src/opensearch/suggestionparser.h
+++ b/src/opensearch/suggestionparser.h
@@ -88,6 +88,7 @@ class SuggestionParser
public:
virtual ~SuggestionParser();
virtual ResponseList parse(const QByteArray &resp);
+ virtual QString type(){ return ""; }
};
@@ -98,6 +99,7 @@ protected:
public:
ResponseList parse(const QByteArray &resp);
+ QString type(){ return "application/x-suggestions+xml"; }
};
class JSONParser : public SuggestionParser
@@ -107,6 +109,7 @@ private:
public:
ResponseList parse(const QByteArray &resp);
+ QString type(){ return "application/x-suggestions+json"; }
};
#endif //SUGGESTIONPARSER_H