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