/* * Copyright (C) 2015 Christian Mollekopf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "mail.h" #include #include #include #include "../resultset.h" #include "../index.h" #include "../storage.h" #include "../log.h" #include "../propertymapper.h" #include "../query.h" #include "../definitions.h" #include "mail_generated.h" 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("uid")) { Index uidIndex("mail.index.uid", transaction); uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { keys << value; }, [](const Index::Error &error) { Warning() << "Error in uid index: " << error.message; }); appliedFilters << "uid"; } return ResultSet(keys); } void TypeImplementation::index(const Mail &type, Akonadi2::Storage::Transaction &transaction) { const auto uid = type.getProperty("uid"); if (uid.isValid()) { Index uidIndex("mail.index.uid", transaction); uidIndex.add(uid.toByteArray(), type.identifier()); } } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() { auto propertyMapper = QSharedPointer >::create(); propertyMapper->addMapping("uid", &Buffer::uid); propertyMapper->addMapping("sender", &Buffer::sender); propertyMapper->addMapping("senderName", &Buffer::senderName); propertyMapper->addMapping("subject", &Buffer::subject); propertyMapper->addMapping("date", &Buffer::date); propertyMapper->addMapping("unread", &Buffer::unread); propertyMapper->addMapping("important", &Buffer::important); propertyMapper->addMapping("folder", &Buffer::folder); return propertyMapper; } QSharedPointer::BufferBuilder> > TypeImplementation::initializeWritePropertyMapper() { auto propertyMapper = QSharedPointer >::create(); // propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { // auto offset = variantToProperty(value, fbb); // return [offset](BufferBuilder &builder) { builder.add_summary(offset); }; // }); propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { auto offset = variantToProperty(value, fbb); return [offset](BufferBuilder &builder) { builder.add_uid(offset); }; }); return propertyMapper; }