summaryrefslogtreecommitdiff
path: root/src/opensearch/opensearchengine.cpp
diff options
context:
space:
mode:
authormegabigbug <megabigbug@yahoo.fr>2010-10-04 08:32:21 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-10-30 11:38:06 +0200
commit72af78494652e97cf2caaf05a4ac1613359400f6 (patch)
treea3968f159fd075a10c20ad2165ecef66b14b9eef /src/opensearch/opensearchengine.cpp
parentAdded CtestConfig.cmake (diff)
downloadrekonq-72af78494652e97cf2caaf05a4ac1613359400f6.tar.xz
add an xml parser to the opensearch engine.
Diffstat (limited to 'src/opensearch/opensearchengine.cpp')
-rw-r--r--src/opensearch/opensearchengine.cpp58
1 files changed, 14 insertions, 44 deletions
diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp
index 9b0d7d03..88016ab0 100644
--- a/src/opensearch/opensearchengine.cpp
+++ b/src/opensearch/opensearchengine.cpp
@@ -30,25 +30,22 @@
// Self Includes
#include "opensearchengine.h"
+#include "suggestionparser.h"
// Qt Includes
#include <QtCore/QRegExp>
-#include <QtCore/QStringList>
-#include <QtScript/QScriptEngine>
-#include <QtScript/QScriptValue>
-
OpenSearchEngine::OpenSearchEngine(QObject *)
- : m_scriptEngine(0)
+ : m_parser(0)
{
}
OpenSearchEngine::~OpenSearchEngine()
{
- if (m_scriptEngine)
+ if (m_parser)
{
- delete m_scriptEngine;
+ delete m_parser;
}
}
@@ -187,6 +184,12 @@ void OpenSearchEngine::setSuggestionsParameters(const QList<Parameter> &suggesti
}
+void OpenSearchEngine::setSuggestionParser(SuggestionParser *parser)
+{
+ m_parser = parser;
+}
+
+
QString OpenSearchEngine::imageUrl() const
{
return m_imageUrl;
@@ -235,43 +238,10 @@ bool OpenSearchEngine::operator<(const OpenSearchEngine &other) const
}
-QStringList OpenSearchEngine::parseSuggestion(const QByteArray &resp)
+ResponseList OpenSearchEngine::parseSuggestion(const QByteArray &resp)
{
- QString response = QString::fromLocal8Bit(resp);
- response = response.trimmed();
-
- if (response.isEmpty())
- {
- return QStringList();
- }
-
- if ( !response.startsWith(QL1C('['))
- || !response.endsWith(QL1C(']'))
- )
- {
- return QStringList();
- }
-
- if (!m_scriptEngine)
- {
- m_scriptEngine = new QScriptEngine();
- }
-
- // Evaluate the JSON response using QtScript.
- if (!m_scriptEngine->canEvaluate(response))
- {
- return QStringList();
- }
-
- QScriptValue responseParts = m_scriptEngine->evaluate(response);
-
- if (!responseParts.property(1).isArray())
- {
- return QStringList();
- }
-
- QStringList suggestionsList;
- qScriptValueToSequence(responseParts.property(1), suggestionsList);
+ if (!m_parser)
+ return ResponseList();
- return suggestionsList;
+ return m_parser->parse(resp);
}