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

source code of kcontacts/src/nickname.cpp