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 <QDataStream>
10 #include <QStringList>
11 
12 using namespace KContacts;
13 
14 class Q_DECL_HIDDEN Org::Private : public QSharedData
15 {
16 public:
17  Private()
18  {
19  }
20 
21  Private(const Private &other)
22  : QSharedData(other)
23  {
24  parameters = other.parameters;
25  organization = other.organization;
26  }
27 
28  QMap<QString, QStringList> parameters;
29  QString organization;
30 };
31 
32 Org::Org()
33  : d(new Private)
34 {
35 }
36 
37 Org::Org(const Org &other)
38  : d(other.d)
39 {
40 }
41 
42 Org::Org(const QString &org)
43  : d(new Private)
44 {
45  d->organization = org;
46 }
47 
48 Org::~Org()
49 {
50 }
51 
52 void Org::setOrganization(const QString &org)
53 {
54  d->organization = org;
55 }
56 
57 QString Org::organization() const
58 {
59  return d->organization;
60 }
61 
62 bool Org::isValid() const
63 {
64  return !d->organization.isEmpty();
65 }
66 
67 void Org::setParameters(const QMap<QString, QStringList> &params)
68 {
69  d->parameters = params;
70 }
71 
72 QMap<QString, QStringList> Org::parameters() const
73 {
74  return d->parameters;
75 }
76 
77 bool Org::operator==(const Org &other) const
78 {
79  return (d->parameters == other.parameters()) && (d->organization == other.organization());
80 }
81 
82 bool Org::operator!=(const Org &other) const
83 {
84  return !(other == *this);
85 }
86 
87 Org &Org::operator=(const Org &other)
88 {
89  if (this != &other) {
90  d = other.d;
91  }
92 
93  return *this;
94 }
95 
96 QString Org::toString() const
97 {
98  QString str = QLatin1String("Org {\n");
99  str += QStringLiteral(" organization: %1\n").arg(d->organization);
100  if (!d->parameters.isEmpty()) {
101  QString param;
102  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
103  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
104  while (it != end) {
105  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
106  ++it;
107  }
108  str += QStringLiteral(" parameters: %1\n").arg(param);
109  }
110  str += QLatin1String("}\n");
111  return str;
112 }
113 
114 QDataStream &KContacts::operator<<(QDataStream &s, const Org &org)
115 {
116  return s << org.d->parameters << org.d->organization;
117 }
118 
119 QDataStream &KContacts::operator>>(QDataStream &s, Org &org)
120 {
121  s >> org.d->parameters >> org.d->organization;
122  return s;
123 }
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:21
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 26 2021 22:55:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.