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 "ewsitem.h" 0013 #include "ewsitemshape.h" 0014 #include "ewsrequest.h" 0015 #include "ewstypes.h" 0016 0017 class QXmlStreamReader; 0018 class QXmlStreamWriter; 0019 0020 class EwsUpdateItemRequest : public EwsRequest 0021 { 0022 Q_OBJECT 0023 public: 0024 class Update 0025 { 0026 public: 0027 bool write(QXmlStreamWriter &writer, EwsItemType itemType) 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 DeleteUpdate(const EwsPropertyField &field) 0071 : Update(field, QVariant(), Delete) 0072 { 0073 } 0074 }; 0075 0076 class ItemChange 0077 { 0078 public: 0079 typedef QList<ItemChange> List; 0080 0081 ItemChange(const EwsId &itemId, EwsItemType type) 0082 : mId(itemId) 0083 , mType(type) 0084 { 0085 } 0086 0087 void addUpdate(const Update *upd) 0088 { 0089 mUpdates.append(QSharedPointer<const Update>(upd)); 0090 } 0091 0092 bool write(QXmlStreamWriter &writer) const; 0093 0094 private: 0095 EwsId mId; 0096 EwsItemType mType; 0097 QList<QSharedPointer<const Update>> mUpdates; 0098 }; 0099 0100 class Response : public EwsRequest::Response 0101 { 0102 public: 0103 typedef QList<Response> List; 0104 0105 const EwsId &itemId() const 0106 { 0107 return mId; 0108 } 0109 0110 unsigned conflictCount() const 0111 { 0112 return mConflictCount; 0113 } 0114 0115 protected: 0116 Response(QXmlStreamReader &reader); 0117 0118 unsigned mConflictCount; 0119 EwsId mId; 0120 0121 friend class EwsUpdateItemRequest; 0122 }; 0123 0124 EwsUpdateItemRequest(EwsClient &client, QObject *parent); 0125 ~EwsUpdateItemRequest() override; 0126 0127 void addItemChange(const ItemChange &change) 0128 { 0129 mChanges.append(change); 0130 } 0131 0132 void addItemChanges(const ItemChange::List::const_iterator &firstChange, const ItemChange::List::const_iterator &lastChange) 0133 { 0134 mChanges.reserve(mChanges.size() + lastChange - firstChange); 0135 for (auto it = firstChange; it != lastChange; ++it) { 0136 mChanges.append(*it); 0137 } 0138 } 0139 0140 void setMessageDisposition(EwsMessageDisposition disp) 0141 { 0142 mMessageDisp = disp; 0143 } 0144 0145 void setConflictResolution(EwsConflictResolution resol) 0146 { 0147 mConflictResol = resol; 0148 } 0149 0150 void setMeetingDisposition(EwsMeetingDisposition disp) 0151 { 0152 mMeetingDisp = disp; 0153 } 0154 0155 void setSavedFolderId(const EwsId &id) 0156 { 0157 mSavedFolderId = id; 0158 } 0159 0160 void start() override; 0161 0162 const Response::List &responses() const 0163 { 0164 return mResponses; 0165 } 0166 0167 protected: 0168 bool parseResult(QXmlStreamReader &reader) override; 0169 bool parseItemsResponse(QXmlStreamReader &reader); 0170 0171 private: 0172 ItemChange::List mChanges; 0173 EwsMessageDisposition mMessageDisp; 0174 EwsConflictResolution mConflictResol; 0175 EwsMeetingDisposition mMeetingDisp; 0176 EwsId mSavedFolderId; 0177 Response::List mResponses; 0178 };