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 #include "ewsoccurrence.h" 0008 0009 #include <QSharedData> 0010 #include <QXmlStreamReader> 0011 0012 #include "ewsclient_debug.h" 0013 #include "ewsid.h" 0014 0015 class EwsOccurrencePrivate : public QSharedData 0016 { 0017 public: 0018 EwsOccurrencePrivate(); 0019 virtual ~EwsOccurrencePrivate(); 0020 0021 bool mValid; 0022 0023 EwsId mItemId; 0024 QDateTime mStart; 0025 QDateTime mEnd; 0026 QDateTime mOriginalStart; 0027 }; 0028 0029 EwsOccurrencePrivate::EwsOccurrencePrivate() 0030 : mValid(false) 0031 { 0032 } 0033 0034 EwsOccurrence::EwsOccurrence() 0035 : d(new EwsOccurrencePrivate()) 0036 { 0037 } 0038 0039 EwsOccurrence::EwsOccurrence(QXmlStreamReader &reader) 0040 : d(new EwsOccurrencePrivate()) 0041 { 0042 while (reader.readNextStartElement()) { 0043 if (reader.namespaceUri() != ewsTypeNsUri) { 0044 qCWarningNC(EWSCLI_LOG) << QStringLiteral("Unexpected namespace in mailbox element:") << reader.namespaceUri(); 0045 return; 0046 } 0047 0048 if (reader.name() == QLatin1StringView("ItemId")) { 0049 d->mItemId = EwsId(reader); 0050 reader.skipCurrentElement(); 0051 } else if (reader.name() == QLatin1StringView("Start")) { 0052 d->mStart = QDateTime::fromString(reader.readElementText(), Qt::ISODate); 0053 if (reader.error() != QXmlStreamReader::NoError || !d->mStart.isValid()) { 0054 qCWarning(EWSCLI_LOG) 0055 << QStringLiteral("Failed to read %1 element - invalid %2 element.").arg(QStringLiteral("Occurrence"), QStringLiteral("Start")); 0056 return; 0057 } 0058 } else if (reader.name() == QLatin1StringView("End")) { 0059 d->mEnd = QDateTime::fromString(reader.readElementText(), Qt::ISODate); 0060 if (reader.error() != QXmlStreamReader::NoError || !d->mStart.isValid()) { 0061 qCWarning(EWSCLI_LOG) 0062 << QStringLiteral("Failed to read %1 element - invalid %2 element.").arg(QStringLiteral("Occurrence"), QStringLiteral("End")); 0063 return; 0064 } 0065 } else if (reader.name() == QLatin1StringView("OriginalStart")) { 0066 d->mStart = QDateTime::fromString(reader.readElementText(), Qt::ISODate); 0067 if (reader.error() != QXmlStreamReader::NoError || !d->mStart.isValid()) { 0068 qCWarning(EWSCLI_LOG) 0069 << QStringLiteral("Failed to read %1 element - invalid %2 element.").arg(QStringLiteral("Occurrence"), QStringLiteral("OriginalStart")); 0070 return; 0071 } 0072 } else { 0073 qCWarning(EWSCLI_LOG) 0074 << QStringLiteral("Failed to read %1 element - unknown element: %2.").arg(QStringLiteral("Occurrence"), reader.name().toString()); 0075 return; 0076 } 0077 } 0078 0079 d->mValid = true; 0080 } 0081 0082 EwsOccurrencePrivate::~EwsOccurrencePrivate() 0083 { 0084 } 0085 0086 EwsOccurrence::EwsOccurrence(const EwsOccurrence &other) 0087 : d(other.d) 0088 { 0089 } 0090 0091 EwsOccurrence::EwsOccurrence(EwsOccurrence &&other) 0092 : d(std::move(other.d)) 0093 { 0094 } 0095 0096 EwsOccurrence::~EwsOccurrence() 0097 { 0098 } 0099 0100 EwsOccurrence &EwsOccurrence::operator=(const EwsOccurrence &other) 0101 { 0102 d = other.d; 0103 return *this; 0104 } 0105 0106 EwsOccurrence &EwsOccurrence::operator=(EwsOccurrence &&other) 0107 { 0108 d = std::move(other.d); 0109 return *this; 0110 } 0111 0112 bool EwsOccurrence::isValid() const 0113 { 0114 return d->mValid; 0115 } 0116 0117 const EwsId &EwsOccurrence::itemId() const 0118 { 0119 return d->mItemId; 0120 } 0121 0122 QDateTime EwsOccurrence::start() const 0123 { 0124 return d->mStart; 0125 } 0126 0127 QDateTime EwsOccurrence::end() const 0128 { 0129 return d->mEnd; 0130 } 0131 0132 QDateTime EwsOccurrence::originalStart() const 0133 { 0134 return d->mOriginalStart; 0135 }