KContacts

nickname.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2016-2019 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "nickname.h"
9 #include <QMap>
10 #include <QStringList>
11 #include <QDataStream>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN NickName::Private : public QSharedData
16 {
17 public:
18  Private()
19  {
20  }
21 
22  Private(const Private &other)
23  : QSharedData(other)
24  {
25  parameters = other.parameters;
26  nickname = other.nickname;
27  }
28 
29  QMap<QString, QStringList> parameters;
30  QString nickname;
31 };
32 
33 NickName::NickName()
34  : d(new Private)
35 {
36 }
37 
38 NickName::NickName(const NickName &other)
39  : d(other.d)
40 {
41 }
42 
43 NickName::NickName(const QString &nickname)
44  : d(new Private)
45 {
46  d->nickname = nickname;
47 }
48 
49 NickName::~NickName()
50 {
51 }
52 
53 void NickName::setNickName(const QString &nickname)
54 {
55  d->nickname = nickname;
56 }
57 
58 QString NickName::nickname() const
59 {
60  return d->nickname;
61 }
62 
63 bool NickName::isValid() const
64 {
65  return !d->nickname.isEmpty();
66 }
67 
68 void NickName::setParameters(const QMap<QString, QStringList> &params)
69 {
70  d->parameters = params;
71 }
72 
73 QMap<QString, QStringList> NickName::parameters() const
74 {
75  return d->parameters;
76 }
77 
78 bool NickName::operator==(const NickName &other) const
79 {
80  return (d->parameters == other.parameters()) && (d->nickname == other.nickname());
81 }
82 
83 bool NickName::operator!=(const NickName &other) const
84 {
85  return !(other == *this);
86 }
87 
88 NickName &NickName::operator=(const NickName &other)
89 {
90  if (this != &other) {
91  d = other.d;
92  }
93 
94  return *this;
95 }
96 
97 QString NickName::toString() const
98 {
99  QString str = QLatin1String("NickName {\n");
100  str += QStringLiteral(" nickname: %1\n").arg(d->nickname);
101  if (!d->parameters.isEmpty()) {
103  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
104  QString param;
105  while (it != end) {
106  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
107  ++it;
108  }
109  str += QStringLiteral(" parameters: %1\n").arg(param);
110  }
111  str += QLatin1String("}\n");
112  return str;
113 }
114 
115 QDataStream &KContacts::operator<<(QDataStream &s, const NickName &nickname)
116 {
117  return s << nickname.d->parameters << nickname.d->nickname;
118 }
119 
120 QDataStream &KContacts::operator>>(QDataStream &s, NickName &nickname)
121 {
122  s >> nickname.d->parameters >> nickname.d->nickname;
123  return s;
124 }
QMap::const_iterator constBegin() const const
bool isEmpty() const const
const Key key(const T &value, const Key &defaultKey) const const
const QList< QKeySequence > & end()
Class that holds a NickName for a contact.
Definition: nickname.h:20
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 22:54:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.