File indexing completed on 2024-12-22 04:57:04

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 <QList>
0010 #include <QSharedPointer>
0011 
0012 #include "ewsfolder.h"
0013 #include "ewsfoldershape.h"
0014 #include "ewsrequest.h"
0015 #include "ewstypes.h"
0016 
0017 class QXmlStreamReader;
0018 class QXmlStreamWriter;
0019 
0020 class EwsUpdateFolderRequest : public EwsRequest
0021 {
0022     Q_OBJECT
0023 public:
0024     class Update
0025     {
0026     public:
0027         bool write(QXmlStreamWriter &writer, EwsFolderType folderType) const;
0028 
0029     protected:
0030         enum Type {
0031             Append = 0,
0032             Set,
0033             Delete,
0034             Unknown,
0035         };
0036 
0037         Update(const EwsPropertyField &field, const QVariant &val, Type type)
0038             : mField(field)
0039             , mValue(val)
0040             , mType(type)
0041         {
0042         }
0043 
0044         EwsPropertyField mField;
0045         QVariant mValue;
0046         Type mType;
0047     };
0048 
0049     class AppendUpdate : public Update
0050     {
0051     public:
0052         AppendUpdate(const EwsPropertyField &field, const QVariant &val)
0053             : Update(field, val, Append)
0054         {
0055         }
0056     };
0057 
0058     class SetUpdate : public Update
0059     {
0060     public:
0061         SetUpdate(const EwsPropertyField &field, const QVariant &val)
0062             : Update(field, val, Set)
0063         {
0064         }
0065     };
0066 
0067     class DeleteUpdate : public Update
0068     {
0069     public:
0070         explicit DeleteUpdate(const EwsPropertyField &field)
0071             : Update(field, QVariant(), Delete)
0072         {
0073         }
0074     };
0075 
0076     class FolderChange
0077     {
0078     public:
0079         FolderChange(const EwsId &folderId, EwsFolderType type)
0080             : mId(folderId)
0081             , mType(type)
0082         {
0083         }
0084 
0085         void addUpdate(const Update *upd)
0086         {
0087             mUpdates.append(QSharedPointer<const Update>(upd));
0088         }
0089 
0090         bool write(QXmlStreamWriter &writer) const;
0091 
0092     private:
0093         EwsId mId;
0094         EwsFolderType mType;
0095         QList<QSharedPointer<const Update>> mUpdates;
0096     };
0097 
0098     class Response : public EwsRequest::Response
0099     {
0100     public:
0101         const EwsId &folderId() const
0102         {
0103             return mId;
0104         }
0105 
0106     protected:
0107         Response(QXmlStreamReader &reader);
0108 
0109         EwsId mId;
0110 
0111         friend class EwsUpdateFolderRequest;
0112     };
0113 
0114     EwsUpdateFolderRequest(EwsClient &client, QObject *parent);
0115     ~EwsUpdateFolderRequest() override;
0116 
0117     void addFolderChange(const FolderChange &change)
0118     {
0119         mChanges.append(change);
0120     }
0121 
0122     void start() override;
0123 
0124     const QList<Response> &responses() const
0125     {
0126         return mResponses;
0127     }
0128 
0129 protected:
0130     bool parseResult(QXmlStreamReader &reader) override;
0131     bool parseItemsResponse(QXmlStreamReader &reader);
0132 
0133 private:
0134     QList<FolderChange> mChanges;
0135     QList<Response> mResponses;
0136 };