summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/index.cpp b/common/index.cpp
new file mode 100644
index 0000000..7b0c682
--- /dev/null
+++ b/common/index.cpp
@@ -0,0 +1,30 @@
1#include "index.h"
2#include <QDebug>
3
4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode)
5 : mStorage(storageRoot, name, mode, true)
6{
7
8}
9
10void Index::add(const QByteArray &key, const QByteArray &value)
11{
12 mStorage.startTransaction(Akonadi2::Storage::ReadWrite);
13 mStorage.write(key.data(), key.size(), value.data(), value.size());
14 mStorage.commitTransaction();
15}
16
17void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
18 const std::function<void(const Error &error)> &errorHandler)
19{
20 mStorage.scan(key.data(), key.size(), [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool {
21 resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize));
22 return true;
23 },
24 [errorHandler](const Akonadi2::Storage::Error &error) {
25 qDebug() << "Error while retrieving value" << QString::fromStdString(error.message);
26 errorHandler(Error(error.store, error.code, error.message));
27 }
28 );
29}
30