From d4b10a3de396eebc6c815093e9e1725ece270e9e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 15 Nov 2015 11:09:31 +0100 Subject: Working folder tree query --- common/domain/folder.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common/domain') diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 50f73c2..82f6c1f 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -37,15 +37,43 @@ using namespace Akonadi2::ApplicationDomain; ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) { QVector keys; + if (query.propertyFilter.contains("parent")) { + Index index("folder.index.parent", transaction); + auto lookupKey = query.propertyFilter.value("parent").toByteArray(); + if (lookupKey.isEmpty()) { + lookupKey = "toplevel"; + } + index.lookup(lookupKey, [&](const QByteArray &value) { + keys << value; + }, + [](const Index::Error &error) { + Warning() << "Error in uid index: " << error.message; + }); + appliedFilters << "parent"; + } + Trace() << "Index lookup found " << keys.size() << " keys."; return ResultSet(keys); } void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { + const auto parent = bufferAdaptor.getProperty("parent"); + Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); + if (parent.isValid()) { + Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); + } else { + Index("folder.index.parent", transaction).add("toplevel", identifier); + } } void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { + const auto parent = bufferAdaptor.getProperty("parent"); + if (parent.isValid()) { + Index("folder.index.parent", transaction).remove(parent.toByteArray(), identifier); + } else { + Index("folder.index.parent", transaction).remove("toplevel", identifier); + } } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() -- cgit v1.2.3