| 1 | /* |
|---|---|
| 2 | This file is part of the KContacts framework. |
| 3 | SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include "timezone.h" |
| 9 | |
| 10 | #include <QDataStream> |
| 11 | #include <QSharedData> |
| 12 | |
| 13 | using namespace KContacts; |
| 14 | |
| 15 | class Q_DECL_HIDDEN TimeZone::Private : public QSharedData |
| 16 | { |
| 17 | public: |
| 18 | Private(int offset = 0, bool valid = false) |
| 19 | : mOffset(offset) |
| 20 | , mValid(valid) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | Private(const Private &other) |
| 25 | : QSharedData(other) |
| 26 | { |
| 27 | mOffset = other.mOffset; |
| 28 | mValid = other.mValid; |
| 29 | } |
| 30 | |
| 31 | int mOffset; |
| 32 | bool mValid; |
| 33 | }; |
| 34 | |
| 35 | TimeZone::TimeZone() |
| 36 | : d(new Private) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | TimeZone::TimeZone(int offset) |
| 41 | : d(new Private(offset, true)) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | TimeZone::TimeZone(const TimeZone &other) |
| 46 | : d(other.d) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | TimeZone::~TimeZone() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | void TimeZone::setOffset(int offset) |
| 55 | { |
| 56 | d->mOffset = offset; |
| 57 | d->mValid = true; |
| 58 | } |
| 59 | |
| 60 | int TimeZone::offset() const |
| 61 | { |
| 62 | return d->mOffset; |
| 63 | } |
| 64 | |
| 65 | bool TimeZone::isValid() const |
| 66 | { |
| 67 | return d->mValid; |
| 68 | } |
| 69 | |
| 70 | bool TimeZone::operator==(const TimeZone &t) const |
| 71 | { |
| 72 | if (!t.isValid() && !isValid()) { |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | if (!t.isValid() || !isValid()) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | if (t.d->mOffset == d->mOffset) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | bool TimeZone::operator!=(const TimeZone &t) const |
| 88 | { |
| 89 | return !(*this == t); |
| 90 | } |
| 91 | |
| 92 | TimeZone &TimeZone::operator=(const TimeZone &other) |
| 93 | { |
| 94 | if (this != &other) { |
| 95 | d = other.d; |
| 96 | } |
| 97 | |
| 98 | return *this; |
| 99 | } |
| 100 | |
| 101 | QString TimeZone::toString() const |
| 102 | { |
| 103 | QString str = QLatin1String("TimeZone {\n"); |
| 104 | str += QStringLiteral(" Offset: %1\n").arg(a: d->mOffset); |
| 105 | str += QLatin1String("}\n"); |
| 106 | |
| 107 | return str; |
| 108 | } |
| 109 | |
| 110 | QDataStream &KContacts::operator<<(QDataStream &s, const TimeZone &zone) |
| 111 | { |
| 112 | return s << zone.d->mOffset << zone.d->mValid; |
| 113 | } |
| 114 | |
| 115 | QDataStream &KContacts::operator>>(QDataStream &s, TimeZone &zone) |
| 116 | { |
| 117 | s >> zone.d->mOffset >> zone.d->mValid; |
| 118 | |
| 119 | return s; |
| 120 | } |
| 121 |
