1 /* 2 SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #pragma once 8 9 #include <QList> 10 #include <QMetaType> 11 #include <QString> 12 13 #include "ewstypes.h" 14 15 class QXmlStreamWriter; 16 class QXmlStreamReader; 17 /** 18 * @brief EWS Id wrapper class 19 * 20 * This class wraps an EWS folder or item identifier. 21 * 22 * In the EWS world an id can come in two forms: 23 * - An "actual" id identified by a unique, server-generated string (actually it's a 24 * base64-encoded internal server structure). Optionally this id is accompanied by a change 25 * key, which acts as a version number of the item. Each time something changes with the 26 * item (either the item itself or folder content - not sure if this applies to subfolders) 27 * the change key is updated. This gives you access to an older version of the item and 28 * allows to quickly find out if the item needs synchronizing. 29 * - A "distinguished" folder id which is a string identifying a list of known root folders 30 * such as 'inbox'. This is necessary for the initial query as there is no way to know the 31 * real folder ids beforehand. This applies only to folder identifiers. 32 */ 33 class EwsId 34 { 35 public: 36 enum Type { 37 Distinguished, 38 Real, 39 Unspecified, 40 }; 41 42 typedef QVector<EwsId> List; 43 EwsId(EwsDistinguishedId did)44 explicit EwsId(EwsDistinguishedId did) 45 : mType(Distinguished) 46 , mDid(did) 47 { 48 } 49 50 explicit EwsId(const QString &id, const QString &changeKey = QString()); EwsId(const EwsId & id)51 EwsId(const EwsId &id) 52 { 53 *this = id; 54 } 55 EwsId(EwsId && id)56 EwsId(EwsId &&id) 57 { 58 *this = std::move(id); 59 } 60 EwsId()61 EwsId() 62 : mType(Unspecified) 63 , mDid(EwsDIdCalendar) 64 { 65 } 66 67 explicit EwsId(QXmlStreamReader &reader); 68 type()69 Type type() const 70 { 71 return mType; 72 } 73 id()74 QString id() const 75 { 76 return mId; 77 } 78 changeKey()79 QString changeKey() const 80 { 81 return mChangeKey; 82 } 83 distinguishedId()84 EwsDistinguishedId distinguishedId() const 85 { 86 return mDid; 87 } 88 89 EwsId &operator=(const EwsId &other); 90 EwsId &operator=(EwsId &&other); 91 bool operator==(const EwsId &other) const; 92 bool operator<(const EwsId &other) const; 93 94 void writeFolderIds(QXmlStreamWriter &writer) const; 95 void writeItemIds(QXmlStreamWriter &writer) const; 96 void writeAttributes(QXmlStreamWriter &writer) const; 97 98 friend QDebug operator<<(QDebug debug, const EwsId &id); 99 100 private: 101 Type mType; 102 QString mId; 103 QString mChangeKey; 104 EwsDistinguishedId mDid; 105 }; 106 107 uint qHash(const EwsId &id, uint seed); 108 109 QDebug operator<<(QDebug debug, const EwsId &id); 110 111 Q_DECLARE_METATYPE(EwsId) 112 Q_DECLARE_METATYPE(EwsId::List) 113 114