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
34Secrecy::Secrecy(Type type)
35 : d(new PrivateData)
36{
37 d->mType = type;
38}
39
40Secrecy::Secrecy(const Secrecy &other)
41 : d(other.d)
42{
43}
44
45Secrecy::~Secrecy()
46{
47}
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
73void Secrecy::setType(Type type)
74{
75 d->mType = type;
76}
77
78Secrecy::Type Secrecy::type() const
79{
80 return d->mType;
81}
82
83Secrecy::TypeList Secrecy::typeList()
84{
85 static TypeList list;
86
87 if (list.isEmpty()) {
88 list << Public << Private << Confidential;
89 }
90
91 return list;
92}
93
94QString Secrecy::typeLabel(Type type)
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
112QString Secrecy::toString() const
113{
114 QString str = QLatin1String("Secrecy {\n");
115 str += QStringLiteral(" Type: %1\n").arg(a: typeLabel(type: 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}
148

source code of kcontacts/src/secrecy.cpp