KContacts

lang.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2015-2019 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "lang.h"
9 #include <QMap>
10 #include <QStringList>
11 #include <QDataStream>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN Lang::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  language = other.language;
27  }
28 
29  QMap<QString, QStringList> parameters;
30  QString language;
31 };
32 
33 Lang::Lang()
34  : d(new Private)
35 {
36 }
37 
38 Lang::Lang(const Lang &other)
39  : d(other.d)
40 {
41 }
42 
43 Lang::Lang(const QString &language)
44  : d(new Private)
45 {
46  d->language = language;
47 }
48 
49 Lang::~Lang()
50 {
51 }
52 
53 void Lang::setLanguage(const QString &lang)
54 {
55  d->language = lang;
56 }
57 
58 QString Lang::language() const
59 {
60  return d->language;
61 }
62 
63 bool Lang::isValid() const
64 {
65  return !d->language.isEmpty();
66 }
67 
68 void Lang::setParameters(const QMap<QString, QStringList> &params)
69 {
70  d->parameters = params;
71 }
72 
73 QMap<QString, QStringList> Lang::parameters() const
74 {
75  return d->parameters;
76 }
77 
78 bool Lang::operator==(const Lang &other) const
79 {
80  return (d->parameters == other.parameters()) && (d->language == other.language());
81 }
82 
83 bool Lang::operator!=(const Lang &other) const
84 {
85  return !(other == *this);
86 }
87 
88 Lang &Lang::operator=(const Lang &other)
89 {
90  if (this != &other) {
91  d = other.d;
92  }
93 
94  return *this;
95 }
96 
97 QString Lang::toString() const
98 {
99  QString str = QLatin1String("Lang {\n");
100  str += QStringLiteral(" language: %1\n").arg(d->language);
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 Lang &lang)
116 {
117  return s << lang.d->parameters << lang.d->language;
118 }
119 
120 QDataStream &KContacts::operator>>(QDataStream &s, Lang &lang)
121 {
122  s >> lang.d->parameters >> lang.d->language;
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 Language for a contact.
Definition: lang.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 Thu Dec 3 2020 22:55:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.