|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 #include "cnttransformphonenumber.h" |
|
42 |
|
43 QList<CContactItemField *> CntTransformPhoneNumber::transformDetailL(const QContactDetail &detail) |
|
44 { |
|
45 if(detail.definitionName() != QContactPhoneNumber::DefinitionName) |
|
46 User::Leave(KErrArgument); |
|
47 |
|
48 QList<CContactItemField *> fieldList; |
|
49 |
|
50 //cast to phonenumber |
|
51 const QContactPhoneNumber &phoneNumber(static_cast<const QContactPhoneNumber&>(detail)); |
|
52 |
|
53 //get the subType |
|
54 QStringList subTypes = phoneNumber.subTypes(); |
|
55 |
|
56 //create new field |
|
57 TPtrC fieldText(reinterpret_cast<const TUint16*>(phoneNumber.number().utf16())); |
|
58 if(fieldText.Length()) { |
|
59 CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText); |
|
60 newField->TextStorage()->SetTextL(fieldText); |
|
61 |
|
62 //no subtype |
|
63 if(!subTypes.count()) |
|
64 { |
|
65 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
66 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
67 } |
|
68 |
|
69 //landline |
|
70 else if (subTypes.contains(QContactPhoneNumber::SubTypeLandline)) |
|
71 { |
|
72 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
73 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
74 newField->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
75 } |
|
76 |
|
77 //mobile |
|
78 else if (subTypes.contains(QContactPhoneNumber::SubTypeMobile)) |
|
79 { |
|
80 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
81 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
82 newField->AddFieldTypeL(KUidContactFieldVCardMapCELL); |
|
83 } |
|
84 |
|
85 //fax |
|
86 else if (subTypes.contains(QContactPhoneNumber::SubTypeFacsimile)) |
|
87 { |
|
88 newField->AddFieldTypeL(KUidContactFieldFax); |
|
89 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
90 newField->AddFieldTypeL(KUidContactFieldVCardMapFAX); |
|
91 } |
|
92 |
|
93 //pager |
|
94 else if (subTypes.contains(QContactPhoneNumber::SubTypePager)) |
|
95 { |
|
96 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
97 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
98 newField->AddFieldTypeL(KUidContactFieldVCardMapPAGER); |
|
99 } |
|
100 |
|
101 //bbs |
|
102 else if (subTypes.contains(QContactPhoneNumber::SubTypeBulletinBoardSystem)) |
|
103 { |
|
104 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
105 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
106 newField->AddFieldTypeL(KUidContactFieldVCardMapBBS); |
|
107 } |
|
108 |
|
109 //car |
|
110 else if (subTypes.contains(QContactPhoneNumber::SubTypeCar)) |
|
111 { |
|
112 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
113 newField->SetMapping(KUidContactFieldVCardMapTEL); |
|
114 newField->AddFieldTypeL(KUidContactFieldVCardMapCAR); |
|
115 } |
|
116 |
|
117 //DTMF |
|
118 else if (subTypes.contains(QContactPhoneNumber::SubTypeDtmfMenu)) |
|
119 { |
|
120 newField->AddFieldTypeL(KUidContactFieldDTMF); |
|
121 newField->SetMapping(KUidContactFieldVCardMapUnknown); |
|
122 } |
|
123 |
|
124 // assistant number |
|
125 else if (subTypes.contains(QContactPhoneNumber::SubTypeAssistant)) |
|
126 { |
|
127 newField->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
128 newField->SetMapping(KUidContactFieldVCardMapAssistantTel); |
|
129 } |
|
130 |
|
131 else |
|
132 { |
|
133 User::LeaveIfError(KErrNotSupported); |
|
134 } |
|
135 |
|
136 //contexts |
|
137 setContextsL(phoneNumber, *newField); |
|
138 |
|
139 fieldList.append(newField); |
|
140 CleanupStack::Pop(newField); |
|
141 } |
|
142 |
|
143 return fieldList; |
|
144 } |
|
145 |
|
146 QContactDetail *CntTransformPhoneNumber::transformItemField(const CContactItemField& field, const QContact &contact) |
|
147 { |
|
148 Q_UNUSED(contact); |
|
149 |
|
150 QContactPhoneNumber *phoneNumber = new QContactPhoneNumber(); |
|
151 |
|
152 CContactTextField* storage = field.TextStorage(); |
|
153 QString number = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length()); |
|
154 |
|
155 phoneNumber->setNumber(number); |
|
156 |
|
157 if (field.ContentType().ContainsFieldType(KUidContactFieldPhoneNumber)) { |
|
158 if (field.ContentType().ContainsFieldType(KUidContactFieldVCardMapVOICE)) { |
|
159 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeLandline); |
|
160 } |
|
161 else if (field.ContentType().ContainsFieldType(KUidContactFieldVCardMapCELL)) { |
|
162 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
163 } |
|
164 else if (field.ContentType().ContainsFieldType(KUidContactFieldVCardMapPAGER)) { |
|
165 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypePager); |
|
166 } |
|
167 else if (field.ContentType().ContainsFieldType(KUidContactFieldVCardMapBBS)) { |
|
168 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeBulletinBoardSystem); |
|
169 } |
|
170 else if (field.ContentType().ContainsFieldType(KUidContactFieldVCardMapCAR)) { |
|
171 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeCar); |
|
172 } |
|
173 else if (field.ContentType().Mapping() == KUidContactFieldVCardMapAssistantTel) { |
|
174 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeAssistant); |
|
175 } |
|
176 } |
|
177 else if (field.ContentType().ContainsFieldType(KUidContactFieldFax)) { |
|
178 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeFacsimile); |
|
179 } |
|
180 else if (field.ContentType().ContainsFieldType(KUidContactFieldDTMF)) { |
|
181 phoneNumber->setSubTypes(QContactPhoneNumber::SubTypeDtmfMenu); |
|
182 } |
|
183 |
|
184 // set context |
|
185 for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) { |
|
186 setContexts(field.ContentType().FieldType(i), *phoneNumber); |
|
187 } |
|
188 |
|
189 return phoneNumber; |
|
190 } |
|
191 |
|
192 bool CntTransformPhoneNumber::supportsField(TUint32 fieldType) const |
|
193 { |
|
194 bool ret = false; |
|
195 if (fieldType == KUidContactFieldPhoneNumber.iUid || |
|
196 fieldType == KUidContactFieldFax.iUid || |
|
197 fieldType == KUidContactFieldDTMF.iUid) { |
|
198 ret = true; |
|
199 } |
|
200 return ret; |
|
201 } |
|
202 |
|
203 bool CntTransformPhoneNumber::supportsDetail(QString detailName) const |
|
204 { |
|
205 bool ret = false; |
|
206 if (detailName == QContactPhoneNumber::DefinitionName) { |
|
207 ret = true; |
|
208 } |
|
209 return ret; |
|
210 } |
|
211 |
|
212 QList<TUid> CntTransformPhoneNumber::supportedSortingFieldTypes(QString detailFieldName) const |
|
213 { |
|
214 QList<TUid> uids; |
|
215 if (detailFieldName == QContactPhoneNumber::FieldNumber) { |
|
216 uids << KUidContactFieldPhoneNumber; |
|
217 uids << KUidContactFieldFax; |
|
218 uids << KUidContactFieldDTMF; |
|
219 } |
|
220 return uids; |
|
221 } |
|
222 |
|
223 /*! |
|
224 * Checks whether the subtype is supported |
|
225 * |
|
226 * \a subType The subtype to be checked |
|
227 * \return True if this subtype is supported |
|
228 */ |
|
229 bool CntTransformPhoneNumber::supportsSubType(const QString& subType) const |
|
230 { |
|
231 if(QContactPhoneNumber::FieldSubTypes == subType) |
|
232 return true; |
|
233 else |
|
234 return false; |
|
235 } |
|
236 |
|
237 /*! |
|
238 * Returns the filed id corresponding to a field |
|
239 * |
|
240 * \a fieldName The name of the supported field |
|
241 * \return fieldId for the fieldName, 0 if not supported |
|
242 */ |
|
243 quint32 CntTransformPhoneNumber::getIdForField(const QString& fieldName) const |
|
244 { |
|
245 if (QContactPhoneNumber::FieldNumber == fieldName) |
|
246 return 0; |
|
247 else if (QContactPhoneNumber::SubTypeLandline == fieldName) |
|
248 return 0; |
|
249 else if (QContactPhoneNumber::SubTypeMobile == fieldName) |
|
250 return 0; |
|
251 else if (QContactPhoneNumber::SubTypeFacsimile == fieldName) |
|
252 return KUidContactFieldFax.iUid; |
|
253 else if (QContactPhoneNumber::SubTypePager == fieldName) |
|
254 return 0; |
|
255 else if (QContactPhoneNumber::SubTypeVoice == fieldName) |
|
256 return 0; |
|
257 else if (QContactPhoneNumber::SubTypeModem == fieldName) |
|
258 return 0; |
|
259 else if (QContactPhoneNumber::SubTypeVideo == fieldName) |
|
260 return 0; |
|
261 else if (QContactPhoneNumber::SubTypeCar == fieldName) |
|
262 return 0; |
|
263 else if (QContactPhoneNumber::SubTypeBulletinBoardSystem == fieldName) |
|
264 return 0; |
|
265 else if (QContactPhoneNumber::SubTypeMessagingCapable == fieldName) |
|
266 return 0; |
|
267 else if (QContactPhoneNumber::SubTypeAssistant == fieldName) |
|
268 return 0; |
|
269 else if (QContactPhoneNumber::SubTypeDtmfMenu == fieldName) |
|
270 return KUidContactFieldDTMF.iUid; |
|
271 else |
|
272 return 0; |
|
273 } |
|
274 |
|
275 /*! |
|
276 * Modifies the detail definitions. The default detail definitions are |
|
277 * queried from QContactManagerEngine::schemaDefinitions and then modified |
|
278 * with this function in the transform leaf classes. |
|
279 * |
|
280 * \a definitions The detail definitions to modify. |
|
281 * \a contactType The contact type the definitions apply for. |
|
282 */ |
|
283 void CntTransformPhoneNumber::detailDefinitions(QMap<QString, QContactDetailDefinition> &definitions, const QString& contactType) const |
|
284 { |
|
285 Q_UNUSED(contactType); |
|
286 |
|
287 if(definitions.contains(QContactPhoneNumber::DefinitionName)) { |
|
288 QContactDetailDefinition d = definitions.value(QContactPhoneNumber::DefinitionName); |
|
289 QMap<QString, QContactDetailFieldDefinition> fields = d.fields(); |
|
290 |
|
291 // Don't support "ContextOther" |
|
292 QContactDetailFieldDefinition f; |
|
293 f.setDataType(QVariant::StringList); |
|
294 f.setAllowableValues(QVariantList() |
|
295 << QLatin1String(QContactDetail::ContextHome) |
|
296 << QLatin1String(QContactDetail::ContextWork)); |
|
297 fields[QContactDetail::FieldContext] = f; |
|
298 d.setFields(fields); |
|
299 |
|
300 // Replace original definitions |
|
301 definitions.insert(d.name(), d); |
|
302 } |
|
303 } |