File indexing completed on 2025-01-19 03:39:53
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "timezone.h" 0009 0010 #include <QDataStream> 0011 #include <QSharedData> 0012 0013 using namespace KContacts; 0014 0015 class Q_DECL_HIDDEN TimeZone::Private : public QSharedData 0016 { 0017 public: 0018 Private(int offset = 0, bool valid = false) 0019 : mOffset(offset) 0020 , mValid(valid) 0021 { 0022 } 0023 0024 Private(const Private &other) 0025 : QSharedData(other) 0026 { 0027 mOffset = other.mOffset; 0028 mValid = other.mValid; 0029 } 0030 0031 int mOffset; 0032 bool mValid; 0033 }; 0034 0035 TimeZone::TimeZone() 0036 : d(new Private) 0037 { 0038 } 0039 0040 TimeZone::TimeZone(int offset) 0041 : d(new Private(offset, true)) 0042 { 0043 } 0044 0045 TimeZone::TimeZone(const TimeZone &other) 0046 : d(other.d) 0047 { 0048 } 0049 0050 TimeZone::~TimeZone() 0051 { 0052 } 0053 0054 void TimeZone::setOffset(int offset) 0055 { 0056 d->mOffset = offset; 0057 d->mValid = true; 0058 } 0059 0060 int TimeZone::offset() const 0061 { 0062 return d->mOffset; 0063 } 0064 0065 bool TimeZone::isValid() const 0066 { 0067 return d->mValid; 0068 } 0069 0070 bool TimeZone::operator==(const TimeZone &t) const 0071 { 0072 if (!t.isValid() && !isValid()) { 0073 return true; 0074 } 0075 0076 if (!t.isValid() || !isValid()) { 0077 return false; 0078 } 0079 0080 if (t.d->mOffset == d->mOffset) { 0081 return true; 0082 } 0083 0084 return false; 0085 } 0086 0087 bool TimeZone::operator!=(const TimeZone &t) const 0088 { 0089 return !(*this == t); 0090 } 0091 0092 TimeZone &TimeZone::operator=(const TimeZone &other) 0093 { 0094 if (this != &other) { 0095 d = other.d; 0096 } 0097 0098 return *this; 0099 } 0100 0101 QString TimeZone::toString() const 0102 { 0103 QString str = QLatin1String("TimeZone {\n"); 0104 str += QStringLiteral(" Offset: %1\n").arg(d->mOffset); 0105 str += QLatin1String("}\n"); 0106 0107 return str; 0108 } 0109 0110 QDataStream &KContacts::operator<<(QDataStream &s, const TimeZone &zone) 0111 { 0112 return s << zone.d->mOffset << zone.d->mValid; 0113 } 0114 0115 QDataStream &KContacts::operator>>(QDataStream &s, TimeZone &zone) 0116 { 0117 s >> zone.d->mOffset >> zone.d->mValid; 0118 0119 return s; 0120 }