File indexing completed on 2024-04-28 11:34:06

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org>
0006 
0007   SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 /**
0010   @file
0011   This file is part of the API for handling calendar data and
0012   defines the FreeBusyPeriod class.
0013 
0014   @brief
0015   Represents a period of time.
0016 
0017   @author Cornelius Schumacher \<schumacher@kde.org\>
0018 */
0019 
0020 #include "freebusyperiod.h"
0021 
0022 using namespace KCalendarCore;
0023 
0024 //@cond PRIVATE
0025 class Q_DECL_HIDDEN KCalendarCore::FreeBusyPeriod::Private
0026 {
0027 public:
0028     Private()
0029         : mType(Unknown)
0030     {
0031     }
0032 
0033     QString mSummary;
0034     QString mLocation;
0035     FreeBusyType mType;
0036 };
0037 //@endcond
0038 
0039 FreeBusyPeriod::FreeBusyPeriod()
0040     : Period()
0041     , d(new KCalendarCore::FreeBusyPeriod::Private())
0042 {
0043 }
0044 
0045 FreeBusyPeriod::FreeBusyPeriod(const QDateTime &start, const QDateTime &end)
0046     : Period(start, end)
0047     , d(new KCalendarCore::FreeBusyPeriod::Private())
0048 {
0049 }
0050 
0051 FreeBusyPeriod::FreeBusyPeriod(const QDateTime &start, const Duration &duration)
0052     : Period(start, duration)
0053     , d(new KCalendarCore::FreeBusyPeriod::Private())
0054 {
0055 }
0056 
0057 FreeBusyPeriod::FreeBusyPeriod(const FreeBusyPeriod &period)
0058     : Period(period)
0059     , d(new KCalendarCore::FreeBusyPeriod::Private(*period.d))
0060 {
0061 }
0062 
0063 FreeBusyPeriod::FreeBusyPeriod(const Period &period)
0064     : Period(period)
0065     , d(new KCalendarCore::FreeBusyPeriod::Private())
0066 {
0067 }
0068 
0069 FreeBusyPeriod::~FreeBusyPeriod()
0070 {
0071     delete d;
0072 }
0073 
0074 FreeBusyPeriod &FreeBusyPeriod::operator=(const FreeBusyPeriod &other)
0075 {
0076     // check for self assignment
0077     if (&other == this) {
0078         return *this;
0079     }
0080 
0081     Period::operator=(other);
0082     *d = *other.d;
0083     return *this;
0084 }
0085 
0086 QString FreeBusyPeriod::summary() const
0087 {
0088     return d->mSummary;
0089 }
0090 
0091 void FreeBusyPeriod::setSummary(const QString &summary)
0092 {
0093     d->mSummary = summary;
0094 }
0095 
0096 QString FreeBusyPeriod::location() const
0097 {
0098     return d->mLocation;
0099 }
0100 
0101 void FreeBusyPeriod::setLocation(const QString &location)
0102 {
0103     d->mLocation = location;
0104 }
0105 
0106 FreeBusyPeriod::FreeBusyType FreeBusyPeriod::type() const
0107 {
0108     return d->mType;
0109 }
0110 
0111 void FreeBusyPeriod::setType(FreeBusyPeriod::FreeBusyType type)
0112 {
0113     d->mType = type;
0114 }
0115 
0116 QDataStream &KCalendarCore::operator<<(QDataStream &stream, const KCalendarCore::FreeBusyPeriod &period)
0117 {
0118     KCalendarCore::Period periodParent = static_cast<KCalendarCore::Period>(period);
0119     stream << periodParent;
0120     stream << period.summary() << period.location() << static_cast<int>(period.type());
0121     return stream;
0122 }
0123 
0124 QDataStream &KCalendarCore::operator>>(QDataStream &stream, FreeBusyPeriod &period)
0125 {
0126     KCalendarCore::Period periodParent;
0127     QString summary;
0128     QString location;
0129     int type;
0130 
0131     stream >> periodParent >> summary >> location >> type;
0132 
0133     period = periodParent;
0134     period.setLocation(location);
0135     period.setSummary(summary);
0136     period.setType(static_cast<FreeBusyPeriod::FreeBusyType>(type));
0137     return stream;
0138 }