From bbbda3fe9444eba6795a5490da0425cdf8f26361 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 8 Sep 2015 21:08:54 +0200 Subject: Added support for mails to akonadi and the dummyresource. Adding new types definitely needs to become easier. --- common/domain/applicationdomaintype.cpp | 12 ++++ common/domain/applicationdomaintype.h | 14 ++++- common/domain/mail.cpp | 101 ++++++++++++++++++++++++++++++++ common/domain/mail.fbs | 14 +++++ common/domain/mail.h | 60 +++++++++++++++++++ 5 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 common/domain/mail.cpp create mode 100644 common/domain/mail.fbs create mode 100644 common/domain/mail.h (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 47ff0c3..3cc075b 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -40,6 +40,18 @@ QByteArray getTypeName() return "akonadiresource"; } +template<> +QByteArray getTypeName() +{ + return "mail"; +} + +template<> +QByteArray getTypeName() +{ + return "folder"; +} + } } diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 29bebcf..e0a6de0 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -112,10 +112,14 @@ struct Calendar : public ApplicationDomainType { using ApplicationDomainType::ApplicationDomainType; }; -class Mail : public ApplicationDomainType { +struct Mail : public ApplicationDomainType { + typedef QSharedPointer Ptr; + using ApplicationDomainType::ApplicationDomainType; }; -class Folder : public ApplicationDomainType { +struct Folder : public ApplicationDomainType { + typedef QSharedPointer Ptr; + using ApplicationDomainType::ApplicationDomainType; }; /** @@ -146,6 +150,12 @@ QByteArray getTypeName(); template<> QByteArray getTypeName(); +template<> +QByteArray getTypeName(); + +template<> +QByteArray getTypeName(); + /** * Type implementation. * diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp new file mode 100644 index 0000000..c52bfe0 --- /dev/null +++ b/common/domain/mail.cpp @@ -0,0 +1,101 @@ +/* + * 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 const *buffer) -> QVariant { + return propertyToVariant(buffer->uid()); + }); + propertyMapper->addMapping("sender", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->sender()); + }); + propertyMapper->addMapping("senderName", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->senderName()); + }); + propertyMapper->addMapping("subject", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->subject()); + }); + propertyMapper->addMapping("date", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->date()); + }); + propertyMapper->addMapping("unread", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->unread()); + }); + propertyMapper->addMapping("important", [](Buffer const *buffer) -> QVariant { + return propertyToVariant(buffer->important()); + }); + 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; +} diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs new file mode 100644 index 0000000..654f49c --- /dev/null +++ b/common/domain/mail.fbs @@ -0,0 +1,14 @@ +namespace Akonadi2.ApplicationDomain.Buffer; + +table Mail { + uid:string; + sender:string; + senderName:string; + subject:string; + date:string; + unread:bool = false; + important:bool = false; +} + +root_type Mail; +file_identifier "AKFB"; diff --git a/common/domain/mail.h b/common/domain/mail.h new file mode 100644 index 0000000..b58ce44 --- /dev/null +++ b/common/domain/mail.h @@ -0,0 +1,60 @@ +/* + * 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. + */ +#pragma once + +#include "applicationdomaintype.h" + +#include "storage.h" + +class ResultSet; +class QByteArray; + +template +class ReadPropertyMapper; +template +class WritePropertyMapper; + +namespace Akonadi2 { + class Query; + +namespace ApplicationDomain { + namespace Buffer { + struct Mail; + struct MailBuilder; + } + +template<> +class TypeImplementation { +public: + typedef Akonadi2::ApplicationDomain::Buffer::Mail Buffer; + typedef Akonadi2::ApplicationDomain::Buffer::MailBuilder BufferBuilder; + static QSet indexedProperties(); + /** + * Returns the potential result set based on the indexes. + * + * An empty result set indicates that a full scan is required. + */ + static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); + static void index(const Mail &type, Akonadi2::Storage::Transaction &transaction); + static QSharedPointer > initializeReadPropertyMapper(); + static QSharedPointer > initializeWritePropertyMapper(); +}; + +} +} -- cgit v1.2.3