summaryrefslogtreecommitdiff
path: root/src/opensearch/opensearchengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opensearch/opensearchengine.cpp')
-rw-r--r--src/opensearch/opensearchengine.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp
index ef0f3f74..15228455 100644
--- a/src/opensearch/opensearchengine.cpp
+++ b/src/opensearch/opensearchengine.cpp
@@ -34,6 +34,10 @@
// Qt Includes
#include <QtCore/QRegExp>
+#include <QtCore/QFile>
+
+// KDE Includes
+#include <KStandardDirs>
OpenSearchEngine::OpenSearchEngine(QObject *parent)
@@ -246,6 +250,19 @@ bool OpenSearchEngine::operator<(const OpenSearchEngine &other) const
}
+ResponseList OpenSearchEngine::parseSuggestion(const QString &searchTerm, const QByteArray &resp)
+{
+ QFile file(suggestionPathFor(searchTerm));
+ if (file.open(QIODevice::WriteOnly | QIODevice::Text))
+ {
+ file.write(resp, resp.size());
+ file.close();
+ }
+
+ return parseSuggestion(resp);
+}
+
+
ResponseList OpenSearchEngine::parseSuggestion(const QByteArray &resp)
{
if (!m_parser)
@@ -259,3 +276,30 @@ QString OpenSearchEngine::type()
{
return m_parser->type();
}
+
+
+QString OpenSearchEngine::suggestionPathFor(const QString &searchTerm)
+{
+ return KStandardDirs::locateLocal("cache", QString("opensearch/") + m_name + QString("/") + searchTerm, true);
+}
+
+
+bool OpenSearchEngine::hasCachedSuggestionsFor(const QString &searchTerm)
+{
+ return QFile::exists(suggestionPathFor(searchTerm));
+}
+
+
+ResponseList OpenSearchEngine::cachedSuggestionsFor(const QString &searchTerm)
+{
+ QFile file(suggestionPathFor(searchTerm));
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return ResponseList();
+
+ QByteArray resp;
+ while (!file.atEnd())
+ {
+ resp += file.readLine();
+ }
+ return parseSuggestion(resp);
+}