KContacts

org.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 "org.h"
9 #include <QMap>
10 #include <QStringList>
11 #include <QDataStream>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN Org::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  organization = other.organization;
27  }
28 
29  QMap<QString, QStringList> parameters;
30  QString organization;
31 };
32 
33 Org::Org()
34  : d(new Private)
35 {
36 }
37 
38 Org::Org(const Org &other)
39  : d(other.d)
40 {
41 }
42 
43 Org::Org(const QString &org)
44  : d(new Private)
45 {
46  d->organization = org;
47 }
48 
49 Org::~Org()
50 {
51 }
52 
53 void Org::setOrganization(const QString &org)
54 {
55  d->organization = org;
56 }
57 
58 QString Org::organization() const
59 {
60  return d->organization;
61 }
62 
63 bool Org::isValid() const
64 {
65  return !d->organization.isEmpty();
66 }
67 
68 void Org::setParameters(const QMap<QString, QStringList> &params)
69 {
70  d->parameters = params;
71 }
72 
73 QMap<QString, QStringList> Org::parameters() const
74 {
75  return d->parameters;
76 }
77 
78 bool Org::operator==(const Org &other) const
79 {
80  return (d->parameters == other.parameters()) && (d->organization == other.organization());
81 }
82 
83 bool Org::operator!=(const Org &other) const
84 {
85  return !(other == *this);
86 }
87 
88 Org &Org::operator=(const Org &other)
89 {
90  if (this != &other) {
91  d = other.d;
92  }
93 
94  return *this;
95 }
96 
97 QString Org::toString() const
98 {
99  QString str = QLatin1String("Org {\n");
100  str += QStringLiteral(" organization: %1\n").arg(d->organization);
101  if (!d->parameters.isEmpty()) {
102  QString param;
103  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
104  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
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 Org &org)
116 {
117  return s << org.d->parameters << org.d->organization;
118 }
119 
120 QDataStream &KContacts::operator>>(QDataStream &s, Org &org)
121 {
122  s >> org.d->parameters >> org.d->organization;
123  return s;
124 }
const Key key(const T &value, const Key &defaultKey) const const
const QList< QKeySequence > & end()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Class that holds a Organization for a contact.
Definition: org.h:20
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 Wed Jul 8 2020 22:53:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.