|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #ifndef QCONTACTDETAIL_H |
|
44 #define QCONTACTDETAIL_H |
|
45 |
|
46 #include "qtcontactsglobal.h" |
|
47 #include "qcontactactiondescriptor.h" |
|
48 |
|
49 #include <QSharedDataPointer> |
|
50 #include <QStringList> |
|
51 #include <QVariant> |
|
52 |
|
53 QTM_BEGIN_NAMESPACE |
|
54 |
|
55 class QContactDetailPrivate; |
|
56 class Q_CONTACTS_EXPORT QContactDetail |
|
57 { |
|
58 public: |
|
59 QContactDetail(); |
|
60 explicit QContactDetail(const char* definitionName); // possibly internal |
|
61 explicit QContactDetail(const QString& definitionName); |
|
62 ~QContactDetail(); |
|
63 |
|
64 QContactDetail(const QContactDetail& other); |
|
65 QContactDetail& operator=(const QContactDetail& other); |
|
66 |
|
67 enum AccessConstraint { |
|
68 NoConstraint = 0, |
|
69 ReadOnly = 0x01, |
|
70 Irremovable = 0x02 |
|
71 }; |
|
72 Q_DECLARE_FLAGS(AccessConstraints, AccessConstraint) |
|
73 |
|
74 AccessConstraints accessConstraints() const; |
|
75 |
|
76 // Predefined attribute names and values |
|
77 #ifdef Q_QDOC |
|
78 static const QLatin1Constant FieldContext; |
|
79 static const QLatin1Constant ContextHome; |
|
80 static const QLatin1Constant ContextWork; |
|
81 static const QLatin1Constant ContextOther; |
|
82 static const QLatin1Constant FieldDetailUri; |
|
83 static const QLatin1Constant FieldLinkedDetailUris; |
|
84 #else |
|
85 Q_DECLARE_LATIN1_CONSTANT(FieldContext, "Context"); |
|
86 Q_DECLARE_LATIN1_CONSTANT(ContextHome, "Home"); |
|
87 Q_DECLARE_LATIN1_CONSTANT(ContextWork, "Work"); |
|
88 Q_DECLARE_LATIN1_CONSTANT(ContextOther, "Other"); |
|
89 Q_DECLARE_LATIN1_CONSTANT(FieldDetailUri, "DetailUri"); |
|
90 Q_DECLARE_LATIN1_CONSTANT(FieldLinkedDetailUris, "LinkedDetailUris"); |
|
91 #endif |
|
92 |
|
93 bool operator==(const QContactDetail& other) const; |
|
94 bool operator!=(const QContactDetail& other) const {return !(other == *this);} |
|
95 |
|
96 QString definitionName() const; |
|
97 bool isEmpty() const; |
|
98 |
|
99 int key() const; |
|
100 void resetKey(); |
|
101 |
|
102 QString value(const QString& key) const; |
|
103 bool setValue(const QString& key, const QVariant& value); |
|
104 bool removeValue(const QString& key); |
|
105 bool hasValue(const QString& key) const; |
|
106 |
|
107 QVariantMap variantValues() const; |
|
108 QVariant variantValue(const QString& key) const; |
|
109 template <typename T> T value(const QString& key) const |
|
110 { |
|
111 return variantValue(key).value<T>(); |
|
112 } |
|
113 |
|
114 /* These are probably internal */ |
|
115 QString value(const char* key) const; |
|
116 bool setValue(const char* key, const QVariant& value); |
|
117 bool removeValue(const char* key); |
|
118 bool hasValue(const char* key) const; |
|
119 QVariant variantValue(const char *key) const; |
|
120 template<typename T> T value(const char *key) const |
|
121 { |
|
122 return variantValue(key).value<T>(); |
|
123 } |
|
124 #ifdef Q_QDOC |
|
125 QString value(const QLatin1Constant& key) const; |
|
126 bool setValue(const QLatin1Constant& key, const QVariant& value); |
|
127 bool removeValue(const QLatin1Constant& key); |
|
128 bool hasValue(const QLatin1Constant& key) const; |
|
129 QVariant variantValue(const QLatin1Constant& key) const; |
|
130 T value(const QLatin1Constant& key) const; |
|
131 #else |
|
132 template<int N> QString value(const QLatin1Constant<N>& key) const |
|
133 { |
|
134 return value(key.latin1()); |
|
135 } |
|
136 template<int N> bool setValue(const QLatin1Constant<N>& key, const QVariant& value) |
|
137 { |
|
138 return setValue(key.latin1(), value); |
|
139 } |
|
140 template<int N> bool removeValue(const QLatin1Constant<N>& key) |
|
141 { |
|
142 return removeValue(key.latin1()); |
|
143 } |
|
144 template<int N> bool hasValue(const QLatin1Constant<N>& key) const |
|
145 { |
|
146 return hasValue(key.latin1()); |
|
147 } |
|
148 template<int N> QVariant variantValue(const QLatin1Constant<N>& key) const |
|
149 { |
|
150 return variantValue(key.latin1()); |
|
151 } |
|
152 template<typename T, int N> T value(const QLatin1Constant<N>& key) const |
|
153 { |
|
154 return value<T>(key.latin1()); |
|
155 } |
|
156 #endif |
|
157 |
|
158 void setContexts(const QStringList& contexts) |
|
159 { |
|
160 setValue(FieldContext, contexts); |
|
161 } |
|
162 |
|
163 void setContexts(const QString& context) |
|
164 { |
|
165 setValue(FieldContext, QStringList(context)); |
|
166 } |
|
167 |
|
168 QStringList contexts() const |
|
169 { |
|
170 return value<QStringList>(FieldContext); |
|
171 } |
|
172 |
|
173 void setDetailUri(const QString& detailUri) |
|
174 { |
|
175 setValue(FieldDetailUri, detailUri); |
|
176 } |
|
177 |
|
178 QString detailUri() const |
|
179 { |
|
180 return value(FieldDetailUri); |
|
181 } |
|
182 |
|
183 void setLinkedDetailUris(const QStringList& linkedDetailUris) |
|
184 { |
|
185 setValue(FieldLinkedDetailUris, linkedDetailUris); |
|
186 } |
|
187 |
|
188 void setLinkedDetailUris(const QString& linkedDetailUri) |
|
189 { |
|
190 setValue(FieldLinkedDetailUris, QStringList(linkedDetailUri)); |
|
191 } |
|
192 |
|
193 QStringList linkedDetailUris() const |
|
194 { |
|
195 return value<QStringList>(FieldLinkedDetailUris); |
|
196 } |
|
197 |
|
198 protected: |
|
199 QContactDetail(const QContactDetail &other, const QString& expectedDefinitionId); |
|
200 QContactDetail& assign(const QContactDetail &other, const QString& expectedDefinitionId); |
|
201 QContactDetail(const QContactDetail &other, const char* expectedDefinitionId); |
|
202 QContactDetail& assign(const QContactDetail &other, const char* expectedDefinitionId); |
|
203 |
|
204 private: |
|
205 friend class QContact; |
|
206 friend class QContactDetailPrivate; |
|
207 QSharedDataPointer<QContactDetailPrivate> d; |
|
208 }; |
|
209 |
|
210 Q_CONTACTS_EXPORT uint qHash(const QContactDetail& key); |
|
211 #ifndef QT_NO_DEBUG_STREAM |
|
212 Q_CONTACTS_EXPORT QDebug operator<<(QDebug dbg, const QContactDetail& detail); |
|
213 #endif |
|
214 |
|
215 Q_DECLARE_OPERATORS_FOR_FLAGS(QContactDetail::AccessConstraints); |
|
216 |
|
217 #define Q_DECLARE_CUSTOM_CONTACT_DETAIL(className, definitionNameString) \ |
|
218 className() : QContactDetail(DefinitionName.latin1()) {} \ |
|
219 className(const QContactDetail& field) : QContactDetail(field, DefinitionName.latin1()) {} \ |
|
220 className& operator=(const QContactDetail& other) {assign(other, DefinitionName.latin1()); return *this;} \ |
|
221 \ |
|
222 Q_DECLARE_LATIN1_CONSTANT(DefinitionName, definitionNameString); |
|
223 |
|
224 #define Q_IMPLEMENT_CUSTOM_CONTACT_DETAIL(className, definitionNameString) \ |
|
225 Q_DEFINE_LATIN1_CONSTANT(className::DefinitionName, definitionNameString) |
|
226 |
|
227 QTM_END_NAMESPACE |
|
228 |
|
229 Q_DECLARE_TYPEINFO(QTM_PREPEND_NAMESPACE(QContactDetail), Q_MOVABLE_TYPE); |
|
230 |
|
231 |
|
232 #endif |
|
233 |