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

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 <QDateTime>
0010 #include <QList>
0011 #include <QSharedPointer>
0012 
0013 #include "ewsid.h"
0014 #include "ewsrequest.h"
0015 #include "ewstypes.h"
0016 
0017 class QXmlStreamReader;
0018 
0019 class EwsEventRequestBase : public EwsRequest
0020 {
0021     Q_OBJECT
0022 public:
0023     class Notification;
0024     class Response;
0025 
0026     class Event
0027     {
0028     public:
0029         typedef QList<Event> List;
0030 
0031         EwsEventType type() const
0032         {
0033             return mType;
0034         }
0035 
0036         const QString &watermark() const
0037         {
0038             return mWatermark;
0039         }
0040 
0041         const QDateTime &timestamp() const
0042         {
0043             return mTimestamp;
0044         }
0045 
0046         const EwsId &itemId() const
0047         {
0048             return mId;
0049         }
0050 
0051         const EwsId &parentFolderId() const
0052         {
0053             return mParentFolderId;
0054         }
0055 
0056         uint unreadCount() const
0057         {
0058             return mUnreadCount;
0059         }
0060 
0061         const EwsId &oldItemId() const
0062         {
0063             return mOldId;
0064         }
0065 
0066         const EwsId &oldParentFolderId() const
0067         {
0068             return mOldParentFolderId;
0069         }
0070 
0071         bool itemIsFolder() const
0072         {
0073             return mIsFolder;
0074         }
0075 
0076         bool operator==(const Event &other) const;
0077 
0078     protected:
0079         Event(QXmlStreamReader &reader);
0080         bool isValid() const
0081         {
0082             return mType != EwsUnknownEvent;
0083         }
0084 
0085         EwsEventType mType;
0086         QString mWatermark;
0087         QDateTime mTimestamp;
0088         EwsId mId;
0089         EwsId mParentFolderId;
0090         uint mUnreadCount = 0;
0091         EwsId mOldId;
0092         EwsId mOldParentFolderId;
0093         bool mIsFolder;
0094 
0095         friend class EwsEventRequestBase::Notification;
0096     };
0097 
0098     class Notification
0099     {
0100     public:
0101         typedef QList<Notification> List;
0102 
0103         const QString &subscriptionId() const
0104         {
0105             return mSubscriptionId;
0106         }
0107 
0108         const QString &previousWatermark() const
0109         {
0110             return mWatermark;
0111         }
0112 
0113         bool hasMoreEvents() const
0114         {
0115             return mMoreEvents;
0116         }
0117 
0118         const Event::List &events() const
0119         {
0120             return mEvents;
0121         }
0122 
0123         bool operator==(const Notification &other) const;
0124 
0125     protected:
0126         Notification(QXmlStreamReader &reader);
0127 
0128         bool isValid() const
0129         {
0130             return !mSubscriptionId.isNull();
0131         }
0132 
0133         static bool eventsReader(QXmlStreamReader &reader, QVariant &val);
0134 
0135         QString mSubscriptionId;
0136         QString mWatermark;
0137         bool mMoreEvents;
0138         Event::List mEvents;
0139 
0140         friend class EwsEventRequestBase::Response;
0141     };
0142 
0143     class Response : public EwsRequest::Response
0144     {
0145     public:
0146         const Notification::List &notifications() const
0147         {
0148             return mNotifications;
0149         }
0150 
0151         bool operator==(const Response &other) const;
0152 
0153     protected:
0154         Response(QXmlStreamReader &reader);
0155 
0156         Notification::List mNotifications;
0157 
0158         friend class EwsEventRequestBase;
0159     };
0160 
0161     ~EwsEventRequestBase() override;
0162 
0163     void setSubscriptionId(const QString &id)
0164     {
0165         mSubscriptionId = id;
0166     }
0167 
0168     const QList<Response> &responses() const
0169     {
0170         return mResponses;
0171     }
0172 
0173 protected:
0174     EwsEventRequestBase(EwsClient &client, const QString &reqName, QObject *parent);
0175     bool parseResult(QXmlStreamReader &reader) override;
0176     bool parseNotificationsResponse(QXmlStreamReader &reader);
0177 
0178     QString mSubscriptionId;
0179     QList<Response> mResponses;
0180     const QString mReqName;
0181 };
0182 
0183 Q_DECLARE_METATYPE(EwsEventRequestBase::Event::List)