File indexing completed on 2024-11-17 04:44:57
0001 /* 0002 SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <functional> 0010 0011 #include <QSharedPointer> 0012 0013 #include "ewspropertyfield.h" 0014 #include "ewstypes.h" 0015 0016 namespace Akonadi 0017 { 0018 class Collection; 0019 class Item; 0020 } 0021 class EwsClient; 0022 class EwsFetchItemDetailJob; 0023 class EwsModifyItemJob; 0024 class EwsCreateItemJob; 0025 class EwsItem; 0026 class EwsTagStore; 0027 class EwsResource; 0028 0029 class EwsItemHandler 0030 { 0031 public: 0032 virtual ~EwsItemHandler(); 0033 0034 virtual EwsFetchItemDetailJob *fetchItemDetailJob(EwsClient &client, QObject *parent, const Akonadi::Collection &collection) = 0; 0035 virtual void setSeenFlag(Akonadi::Item &item, bool value) = 0; 0036 virtual QString mimeType() = 0; 0037 virtual bool setItemPayload(Akonadi::Item &item, const EwsItem &ewsItem) = 0; 0038 virtual EwsModifyItemJob *modifyItemJob(EwsClient &client, const QList<Akonadi::Item> &items, const QSet<QByteArray> &parts, QObject *parent) = 0; 0039 virtual EwsCreateItemJob * 0040 createItemJob(EwsClient &client, const Akonadi::Item &item, const Akonadi::Collection &collection, EwsTagStore *tagStore, EwsResource *parent) = 0; 0041 0042 using ItemHandlerFactory = std::function<EwsItemHandler *()>; 0043 static void registerItemHandler(EwsItemType type, const ItemHandlerFactory &factory); 0044 static EwsItemHandler *itemHandler(EwsItemType type); 0045 static EwsItemType mimeToItemType(const QString &mimeType); 0046 static QHash<EwsPropertyField, QVariant> writeFlags(const QSet<QByteArray> &flags); 0047 static QSet<QByteArray> readFlags(const EwsItem &item); 0048 static QList<EwsPropertyField> flagsProperties(); 0049 static QList<EwsPropertyField> tagsProperties(); 0050 0051 private: 0052 struct HandlerFactory { 0053 EwsItemType type; 0054 ItemHandlerFactory factory; 0055 }; 0056 }; 0057 0058 #define EWS_DECLARE_ITEM_HANDLER(clsname, type) \ 0059 class type##_itemhandler_registrar \ 0060 { \ 0061 public: \ 0062 type##_itemhandler_registrar() \ 0063 { \ 0064 EwsItemHandler::registerItemHandler(type, &clsname::factory); \ 0065 } \ 0066 }; \ 0067 const type##_itemhandler_registrar type##_itemhandler_registrar_object;