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

0001 /*
0002     SPDX-FileCopyrightText: 2015-2016 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "ewsattendee.h"
0008 
0009 #include <QSharedData>
0010 #include <QXmlStreamReader>
0011 
0012 #include "ewsclient_debug.h"
0013 #include "ewsmailbox.h"
0014 
0015 class EwsAttendeePrivate : public QSharedData
0016 {
0017 public:
0018     EwsAttendeePrivate();
0019     virtual ~EwsAttendeePrivate();
0020 
0021     bool mValid;
0022 
0023     EwsMailbox mMailbox;
0024     EwsEventResponseType mResponse;
0025     QDateTime mResponseTime;
0026 };
0027 
0028 static const QString responseTypeNames[] = {QStringLiteral("Unknown"),
0029                                             QStringLiteral("Organizer"),
0030                                             QStringLiteral("Tentative"),
0031                                             QStringLiteral("Accept"),
0032                                             QStringLiteral("Decline"),
0033                                             QStringLiteral("NoResponseReceived")};
0034 constexpr unsigned responseTypeNameCount = sizeof(responseTypeNames) / sizeof(responseTypeNames[0]);
0035 
0036 EwsAttendeePrivate::EwsAttendeePrivate()
0037     : mValid(false)
0038     , mResponse(EwsEventResponseNotReceived)
0039 {
0040 }
0041 
0042 EwsAttendee::EwsAttendee()
0043     : d(new EwsAttendeePrivate())
0044 {
0045 }
0046 
0047 EwsAttendee::EwsAttendee(QXmlStreamReader &reader)
0048     : d(new EwsAttendeePrivate())
0049 {
0050     while (reader.readNextStartElement()) {
0051         if (reader.namespaceUri() != ewsTypeNsUri) {
0052             qCWarningNC(EWSCLI_LOG) << QStringLiteral("Unexpected namespace in mailbox element:") << reader.namespaceUri();
0053             return;
0054         }
0055         const QStringView readerName = reader.name();
0056         if (readerName == QLatin1StringView("Mailbox")) {
0057             d->mMailbox = EwsMailbox(reader);
0058             if (!d->mMailbox.isValid()) {
0059                 qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read EWS request - invalid attendee %1 element.").arg(readerName.toString());
0060                 return;
0061             }
0062         } else if (readerName == QLatin1StringView("ResponseType")) {
0063             bool ok;
0064             d->mResponse = decodeEnumString<EwsEventResponseType>(reader.readElementText(), responseTypeNames, responseTypeNameCount, &ok);
0065             if (reader.error() != QXmlStreamReader::NoError || !ok) {
0066                 qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read EWS request - invalid attendee %1 element.").arg(readerName.toString());
0067                 return;
0068             }
0069         } else if (readerName == QLatin1StringView("LastResponseTime")) {
0070             // Unsupported - ignore
0071             // qCWarningNC(EWSCLIENT_LOG) << QStringLiteral("Unsupported mailbox element %1").arg(reader.name().toString());
0072             reader.skipCurrentElement();
0073         }
0074     }
0075 
0076     d->mValid = true;
0077 }
0078 
0079 EwsAttendeePrivate::~EwsAttendeePrivate()
0080 {
0081 }
0082 
0083 EwsAttendee::EwsAttendee(const EwsAttendee &other)
0084     : d(other.d)
0085 {
0086 }
0087 
0088 EwsAttendee::EwsAttendee(EwsAttendee &&other)
0089     : d(std::move(other.d))
0090 {
0091 }
0092 
0093 EwsAttendee::~EwsAttendee()
0094 {
0095 }
0096 
0097 EwsAttendee &EwsAttendee::operator=(const EwsAttendee &other)
0098 {
0099     d = other.d;
0100     return *this;
0101 }
0102 
0103 EwsAttendee &EwsAttendee::operator=(EwsAttendee &&other)
0104 {
0105     d = std::move(other.d);
0106     return *this;
0107 }
0108 
0109 bool EwsAttendee::isValid() const
0110 {
0111     return d->mValid;
0112 }
0113 
0114 const EwsMailbox &EwsAttendee::mailbox() const
0115 {
0116     return d->mMailbox;
0117 }
0118 
0119 EwsEventResponseType EwsAttendee::response() const
0120 {
0121     return d->mResponse;
0122 }
0123 
0124 QDateTime EwsAttendee::responseTime() const
0125 {
0126     return d->mResponseTime;
0127 }