1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtContacts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#ifndef QCONTACTDETAIL_H
35#define QCONTACTDETAIL_H
36
37#include <QtCore/qmap.h>
38#include <QtCore/qshareddata.h>
39#include <QtCore/qstringlist.h>
40#include <QtCore/qvariant.h>
41
42#include <QtContacts/qcontactsglobal.h>
43
44QT_BEGIN_NAMESPACE_CONTACTS
45
46class QContact;
47class QContactActionDescriptor;
48class QContactDetailPrivate;
49class Q_CONTACTS_EXPORT QContactDetail
50{
51public:
52 enum DetailType {
53 TypeUndefined = 0,
54 TypeAddress,
55 TypeAnniversary,
56 TypeAvatar,
57 TypeBirthday,
58 TypeDisplayLabel,
59 TypeEmailAddress,
60 TypeExtendedDetail,
61 TypeFamily,
62 TypeFavorite,
63 TypeGender,
64 TypeGeoLocation,
65 TypeGlobalPresence,
66 TypeGuid,
67 TypeHobby,
68 TypeName,
69 TypeNickname,
70 TypeNote,
71 TypeOnlineAccount,
72 TypeOrganization,
73 TypePhoneNumber,
74 TypePresence,
75 TypeRingtone,
76 TypeSyncTarget,
77 TypeTag,
78 TypeTimestamp,
79 TypeType,
80 TypeUrl,
81 TypeVersion
82 };
83
84 enum DetailContext {
85 ContextHome = 0,
86 ContextWork,
87 ContextOther
88 };
89
90 enum DetailField {
91 FieldContext = 5000, //to avoid clashing with other detail field values from leaf classes
92 FieldDetailUri,
93 FieldLinkedDetailUris,
94 FieldProvenance,
95 FieldMaximumUserVisible = 10000 // keys above this will not be reported to clients via values() etc accessors.
96 };
97
98 enum AccessConstraint {
99 NoConstraint = 0,
100 ReadOnly = 0x01,
101 Irremovable = 0x02
102 };
103 Q_DECLARE_FLAGS(AccessConstraints, AccessConstraint)
104
105protected:
106 QSharedDataPointer<QContactDetailPrivate> d;
107
108public:
109 QContactDetail();
110 explicit QContactDetail(DetailType _type);
111 QContactDetail(const QContactDetail &other);
112 ~QContactDetail();
113 QContactDetail& operator=(const QContactDetail& other);
114
115 bool operator==(const QContactDetail& other) const;
116 bool operator!=(const QContactDetail& other) const { return !(other == *this); }
117
118 DetailType type() const;
119
120 int key() const;
121 void resetKey();
122
123 AccessConstraints accessConstraints() const;
124
125 bool isEmpty() const;
126 bool setValue(int field, const QVariant& value);
127 bool removeValue(int field);
128 bool hasValue(int field) const;
129
130 void setValues(const QMap<int, QVariant> &newValues);
131 QMap<int, QVariant> values() const;
132 QVariant value(int field) const;
133 template <typename T> T value(int field) const {
134 return value(field).value<T>();
135 }
136
137 void setContexts(int newContext)
138 {
139 QList<int> newContexts;
140 newContexts << newContext;
141 setValue(field: FieldContext, value: QVariant::fromValue(value: newContexts));
142 }
143
144 void setContexts(const QList<int>& newContexts)
145 {
146 setValue(field: FieldContext, value: QVariant::fromValue(value: newContexts));
147 }
148
149 QList<int> contexts() const
150 {
151 return value< QList<int> >(field: FieldContext);
152 }
153
154 void setDetailUri(const QString& newDetailUri)
155 {
156 setValue(field: FieldDetailUri, value: newDetailUri);
157 }
158
159 QString detailUri() const
160 {
161 return value(field: FieldDetailUri).toString();
162 }
163
164 void setLinkedDetailUris(const QStringList& newLinkedDetailUris)
165 {
166 setValue(field: FieldLinkedDetailUris, value: newLinkedDetailUris);
167 }
168
169 void setLinkedDetailUris(const QString& linkedDetailUri)
170 {
171 setValue(field: FieldLinkedDetailUris, value: QStringList(linkedDetailUri));
172 }
173
174 QStringList linkedDetailUris() const
175 {
176 return value<QStringList>(field: FieldLinkedDetailUris);
177 }
178
179 QString provenance() const
180 {
181 return value(field: FieldProvenance).toString();
182 }
183
184protected:
185 QContactDetail(const QContactDetail &other, DetailType expectedType);
186 QContactDetail& assign(const QContactDetail &other, DetailType expectedType);
187
188private:
189 friend class QContactDetailPrivate;
190 friend class QContact;
191 friend class QContactManagerEngine;
192#ifndef QT_NO_DATASTREAM
193 Q_CONTACTS_EXPORT friend QDataStream& operator>>(QDataStream& in, QContactDetail& detail);
194#endif
195};
196
197Q_CONTACTS_EXPORT uint qHash(const QContactDetail& key);
198#ifndef QT_NO_DEBUG_STREAM
199Q_CONTACTS_EXPORT QDebug operator<<(QDebug dbg, const QContactDetail& detail);
200#endif
201#ifndef QT_NO_DATASTREAM
202Q_CONTACTS_EXPORT QDataStream& operator<<(QDataStream& out, const QContactDetail& detail);
203Q_CONTACTS_EXPORT QDataStream& operator>>(QDataStream& in, QContactDetail& detail);
204#endif
205
206Q_DECLARE_OPERATORS_FOR_FLAGS(QContactDetail::AccessConstraints)
207
208#define Q_DECLARE_CUSTOM_CONTACT_DETAIL(className) \
209 className() : QContactDetail(Type) {} \
210 className(const QContactDetail &field) : QContactDetail(field, Type) {} \
211 className& operator=(const QContactDetail &other) {assign(other, Type); return *this;} \
212 static const DetailType Type;
213
214QT_END_NAMESPACE_CONTACTS
215
216QT_BEGIN_NAMESPACE
217Q_DECLARE_TYPEINFO(QTCONTACTS_PREPEND_NAMESPACE(QContactDetail), Q_MOVABLE_TYPE);
218QT_END_NAMESPACE
219
220#endif // QCONTACTDETAIL_H
221

source code of qtpim/src/contacts/qcontactdetail.h