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 <QDataStream>
10 #include <QStringList>
11 
12 using namespace KContacts;
13 
14 class Q_DECL_HIDDEN Lang::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  language = other.language;
26  }
27 
28  QMap<QString, QStringList> parameters;
29  QString language;
30 };
31 
32 Lang::Lang()
33  : d(new Private)
34 {
35 }
36 
37 Lang::Lang(const Lang &other)
38  : d(other.d)
39 {
40 }
41 
42 Lang::Lang(const QString &language)
43  : d(new Private)
44 {
45  d->language = language;
46 }
47 
48 Lang::~Lang()
49 {
50 }
51 
52 void Lang::setLanguage(const QString &lang)
53 {
54  d->language = lang;
55 }
56 
57 QString Lang::language() const
58 {
59  return d->language;
60 }
61 
62 bool Lang::isValid() const
63 {
64  return !d->language.isEmpty();
65 }
66 
67 void Lang::setParameters(const QMap<QString, QStringList> &params)
68 {
69  d->parameters = params;
70 }
71 
72 QMap<QString, QStringList> Lang::parameters() const
73 {
74  return d->parameters;
75 }
76 
77 bool Lang::operator==(const Lang &other) const
78 {
79  return (d->parameters == other.parameters()) && (d->language == other.language());
80 }
81 
82 bool Lang::operator!=(const Lang &other) const
83 {
84  return !(other == *this);
85 }
86 
87 Lang &Lang::operator=(const Lang &other)
88 {
89  if (this != &other) {
90  d = other.d;
91  }
92 
93  return *this;
94 }
95 
96 QString Lang::toString() const
97 {
98  QString str = QLatin1String("Lang {\n");
99  str += QStringLiteral(" language: %1\n").arg(d->language);
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 Lang &lang)
115 {
116  return s << lang.d->parameters << lang.d->language;
117 }
118 
119 QDataStream &KContacts::operator>>(QDataStream &s, Lang &lang)
120 {
121  s >> lang.d->parameters >> lang.d->language;
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 Language for a contact.
Definition: lang.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 Mon Sep 20 2021 22:56:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.