File indexing completed on 2024-12-22 04:57:02
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 <QMetaType> 0011 #include <QString> 0012 0013 #include "ewstypes.h" 0014 0015 class QXmlStreamWriter; 0016 class QXmlStreamReader; 0017 /** 0018 * @brief EWS Id wrapper class 0019 * 0020 * This class wraps an EWS folder or item identifier. 0021 * 0022 * In the EWS world an id can come in two forms: 0023 * - An "actual" id identified by a unique, server-generated string (actually it's a 0024 * base64-encoded internal server structure). Optionally this id is accompanied by a change 0025 * key, which acts as a version number of the item. Each time something changes with the 0026 * item (either the item itself or folder content - not sure if this applies to subfolders) 0027 * the change key is updated. This gives you access to an older version of the item and 0028 * allows to quickly find out if the item needs synchronizing. 0029 * - A "distinguished" folder id which is a string identifying a list of known root folders 0030 * such as 'inbox'. This is necessary for the initial query as there is no way to know the 0031 * real folder ids beforehand. This applies only to folder identifiers. 0032 */ 0033 class EwsId 0034 { 0035 public: 0036 enum Type { 0037 Distinguished, 0038 Real, 0039 Unspecified, 0040 }; 0041 0042 typedef QList<EwsId> List; 0043 0044 explicit EwsId(EwsDistinguishedId did) 0045 : mType(Distinguished) 0046 , mDid(did) 0047 { 0048 } 0049 0050 explicit EwsId(const QString &id, const QString &changeKey = QString()); 0051 EwsId(const EwsId &id) 0052 { 0053 *this = id; 0054 } 0055 0056 EwsId(EwsId &&id) 0057 { 0058 *this = std::move(id); 0059 } 0060 0061 EwsId() 0062 : mType(Unspecified) 0063 , mDid(EwsDIdCalendar) 0064 { 0065 } 0066 0067 explicit EwsId(QXmlStreamReader &reader); 0068 0069 Type type() const 0070 { 0071 return mType; 0072 } 0073 0074 QString id() const 0075 { 0076 return mId; 0077 } 0078 0079 QString changeKey() const 0080 { 0081 return mChangeKey; 0082 } 0083 0084 EwsDistinguishedId distinguishedId() const 0085 { 0086 return mDid; 0087 } 0088 0089 EwsId &operator=(const EwsId &other); 0090 EwsId &operator=(EwsId &&other); 0091 bool operator==(const EwsId &other) const; 0092 bool operator<(const EwsId &other) const; 0093 0094 void writeFolderIds(QXmlStreamWriter &writer) const; 0095 void writeItemIds(QXmlStreamWriter &writer) const; 0096 void writeAttributes(QXmlStreamWriter &writer) const; 0097 0098 friend QDebug operator<<(QDebug debug, const EwsId &id); 0099 0100 private: 0101 Type mType; 0102 QString mId; 0103 QString mChangeKey; 0104 EwsDistinguishedId mDid; 0105 }; 0106 0107 uint qHash(const EwsId &id, uint seed); 0108 0109 QDebug operator<<(QDebug debug, const EwsId &id); 0110 0111 Q_DECLARE_METATYPE(EwsId) 0112 Q_DECLARE_METATYPE(EwsId::List)