diff options
author | Lionel Chauvin <megabigbug@yahoo.fr> | 2011-01-22 10:34:48 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-01-22 10:34:48 +0100 |
commit | 7e291fdc453a74e76b803057cc99e821ed517e66 (patch) | |
tree | e222fedf0f4327f308fa2572a3581842aab0c2f2 /src/opensearch/opensearchengine.cpp | |
parent | This code fixes new tab button appearing on new window when tabbar is set hidden (diff) | |
download | rekonq-7e291fdc453a74e76b803057cc99e821ed517e66.tar.xz |
Keep downloaded suggestions in memory.
This prevents from downloading it again, letting the completion
list be more reactive.
Diffstat (limited to 'src/opensearch/opensearchengine.cpp')
-rw-r--r-- | src/opensearch/opensearchengine.cpp | 44 |
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); +} |