KContacts

secrecy.cpp
1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "secrecy.h"
9
10#include <KLocalizedString>
11
12#include <QDataStream>
13#include <QSharedData>
14
15using namespace KContacts;
16
17class Q_DECL_HIDDEN Secrecy::PrivateData : public QSharedData
18{
19public:
20 PrivateData()
21 : mType(Secrecy::Invalid)
22 {
23 }
24
25 PrivateData(const PrivateData &other)
26 : QSharedData(other)
27 {
28 mType = other.mType;
29 }
30
31 Type mType;
32};
33
35 : d(new PrivateData)
36{
37 d->mType = type;
38}
39
41 : d(other.d)
42{
43}
44
48
49Secrecy &Secrecy::operator=(const Secrecy &other)
50{
51 if (this != &other) {
52 d = other.d;
53 }
54
55 return *this;
56}
57
58bool Secrecy::operator==(const Secrecy &other) const
59{
60 return d->mType == other.d->mType;
61}
62
63bool Secrecy::operator!=(const Secrecy &other) const
64{
65 return !(*this == other);
66}
67
68bool Secrecy::isValid() const
69{
70 return d->mType != Invalid;
71}
72
74{
75 d->mType = type;
76}
77
79{
80 return d->mType;
81}
82
84{
85 static TypeList list;
86
87 if (list.isEmpty()) {
88 list << Public << Private << Confidential;
89 }
90
91 return list;
92}
93
95{
96 switch (type) {
97 case Public:
98 return i18nc("access is for everyone", "Public");
99 break;
100 case Private:
101 return i18nc("access is by owner only", "Private");
102 break;
103 case Confidential:
104 return i18nc("access is by owner and a controlled group", "Confidential");
105 break;
106 default:
107 return i18nc("unknown secrecy type", "Unknown type");
108 break;
109 }
110}
111
113{
114 QString str = QLatin1String("Secrecy {\n");
115 str += QStringLiteral(" Type: %1\n").arg(typeLabel(d->mType));
116 str += QLatin1String("}\n");
117
118 return str;
119}
120
121QDataStream &KContacts::operator<<(QDataStream &s, const Secrecy &secrecy)
122{
123 return s << (uint)secrecy.d->mType;
124}
125
126QDataStream &KContacts::operator>>(QDataStream &s, Secrecy &secrecy)
127{
128 uint type;
129 s >> type;
130
131 switch (type) {
132 case 0:
133 secrecy.d->mType = Secrecy::Public;
134 break;
135 case 1:
136 secrecy.d->mType = Secrecy::Private;
137 break;
138 case 2:
139 secrecy.d->mType = Secrecy::Confidential;
140 break;
141 default:
142 secrecy.d->mType = Secrecy::Invalid;
143 break;
144 }
145
146 return s;
147}
Describes the confidentiality of an addressee.
Definition secrecy.h:19
static TypeList typeList()
Returns a list of all available secrecy types.
Definition secrecy.cpp:83
bool isValid() const
Returns if the Secrecy object has a valid value.
Definition secrecy.cpp:68
Secrecy(Type type=Invalid)
Creates a new secrecy of the given type.
Definition secrecy.cpp:34
~Secrecy()
Destroys the secrecy.
Definition secrecy.cpp:45
static QString typeLabel(Type type)
Returns a translated label for a given secrecy type.
Definition secrecy.cpp:94
Type type() const
Returns the type.
Definition secrecy.cpp:78
void setType(Type type)
Sets the type.
Definition secrecy.cpp:73
QString toString() const
Returns a string representation of the secrecy.
Definition secrecy.cpp:112
Type
Secrecy types.
Definition secrecy.h:31
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isEmpty() const const
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:08 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.