|
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 #ifdef SYMBIAN_BACKEND_USE_SQLITE |
|
42 |
|
43 #include "cnttransformpresence.h" |
|
44 #include "cntmodelextuids.h" |
|
45 |
|
46 CntTransformPresence::CntTransformPresence() : |
|
47 m_detailCounter(0) |
|
48 { |
|
49 } |
|
50 |
|
51 QList<CContactItemField *> CntTransformPresence::transformDetailL(const QContactDetail &detail) |
|
52 { |
|
53 if(detail.definitionName() != QContactPresence::DefinitionName) |
|
54 User::Leave(KErrArgument); |
|
55 |
|
56 QList<CContactItemField *> fieldList; |
|
57 |
|
58 //cast to presence |
|
59 const QContactPresence &presenceDetail(static_cast<const QContactPresence&>(detail)); |
|
60 |
|
61 // Transform presence informaiton |
|
62 if(presenceDetail.presenceState() != QContactPresence::PresenceUnknown) { |
|
63 QString presence = QString::number(presenceDetail.presenceState()); |
|
64 CContactItemField* presenceField = CContactItemField::NewLC(KStorageTypeText); |
|
65 TPtrC presenceEncodedText(reinterpret_cast<const TUint16*>(presence.utf16())); |
|
66 presenceField->TextStorage()->SetTextL(presenceEncodedText); |
|
67 presenceField->AddFieldTypeL(KUidContactFieldPresence); |
|
68 presenceField->SetUserFlags(m_detailCounter); |
|
69 fieldList.append(presenceField); |
|
70 CleanupStack::Pop(presenceField); |
|
71 } |
|
72 |
|
73 // Transform statusMessage |
|
74 TPtrC statusMsgText(reinterpret_cast<const TUint16*>(presenceDetail.presenceStateText().utf16())); |
|
75 if(statusMsgText.Length()) { |
|
76 CContactItemField* statusMsgField = CContactItemField::NewLC(KStorageTypeText); |
|
77 statusMsgField->TextStorage()->SetTextL(statusMsgText); |
|
78 statusMsgField->AddFieldTypeL(KUidContactFieldStatusMsg); |
|
79 statusMsgField->SetUserFlags(m_detailCounter); |
|
80 fieldList.append(statusMsgField); |
|
81 CleanupStack::Pop(statusMsgField); |
|
82 } |
|
83 |
|
84 if(fieldList.count() > 0) { |
|
85 m_detailCounter++; |
|
86 } |
|
87 |
|
88 return fieldList; |
|
89 } |
|
90 |
|
91 QContactDetail *CntTransformPresence::transformItemField(const CContactItemField& field, const QContact &contact) |
|
92 { |
|
93 QList<QContactDetail> presenceDetails = contact.details(QContactPresence::DefinitionName); |
|
94 //check what presence detail the provided field belongs to. if there is no such detail yet, |
|
95 //let's create it. |
|
96 if (presenceDetails.count() <= field.UserFlags()) { |
|
97 for (int i = presenceDetails.count(); i <= field.UserFlags(); i++) { |
|
98 QContactPresence *presence = new QContactPresence(); |
|
99 QContact& currentContact = const_cast<QContact&>(contact); |
|
100 currentContact.saveDetail(presence); |
|
101 } |
|
102 presenceDetails = contact.details(QContactPresence::DefinitionName); |
|
103 } |
|
104 QContactPresence *presenceDetail = new QContactPresence(presenceDetails.at(field.UserFlags())); |
|
105 |
|
106 CContactTextField* storage = field.TextStorage(); |
|
107 QString presenceString = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length()); |
|
108 |
|
109 for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) { |
|
110 //Presence |
|
111 if (field.ContentType().FieldType(i) == KUidContactFieldPresence) { |
|
112 QContactPresence::PresenceState presenceState = decodePresence(presenceString); |
|
113 presenceDetail->setPresenceState(presenceState); |
|
114 } |
|
115 //Status Message |
|
116 else if (field.ContentType().FieldType(i) == KUidContactFieldStatusMsg) { |
|
117 presenceDetail->setPresenceStateText(presenceString); |
|
118 } |
|
119 } |
|
120 |
|
121 // set context |
|
122 for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) { |
|
123 setContexts(field.ContentType().FieldType(i), *presenceDetail); |
|
124 } |
|
125 |
|
126 return presenceDetail; |
|
127 } |
|
128 |
|
129 bool CntTransformPresence::supportsField(TUint32 fieldType) const |
|
130 { |
|
131 bool ret = false; |
|
132 if (fieldType == KUidContactFieldPresence.iUid || |
|
133 fieldType == KUidContactFieldStatusMsg.iUid ) |
|
134 { |
|
135 ret = true; |
|
136 } |
|
137 return ret; |
|
138 } |
|
139 |
|
140 bool CntTransformPresence::supportsDetail(QString detailName) const |
|
141 { |
|
142 bool ret = false; |
|
143 if (detailName == QContactPresence::DefinitionName) { |
|
144 ret = true; |
|
145 } |
|
146 return ret; |
|
147 } |
|
148 |
|
149 QList<TUid> CntTransformPresence::supportedSortingFieldTypes(QString /*detailFieldName*/) const |
|
150 { |
|
151 // Sorting not supported |
|
152 return QList<TUid>(); |
|
153 } |
|
154 |
|
155 |
|
156 /*! |
|
157 * Checks whether the subtype is supported |
|
158 * |
|
159 * \a subType The subtype to be checked |
|
160 * \return True if this subtype is supported |
|
161 */ |
|
162 bool CntTransformPresence::supportsSubType(const QString& /*subType*/) const |
|
163 { |
|
164 return false; |
|
165 } |
|
166 |
|
167 /*! |
|
168 * Returns the filed id corresponding to a field |
|
169 * |
|
170 * \a fieldName The name of the supported field |
|
171 * \return fieldId for the fieldName, 0 if not supported |
|
172 */ |
|
173 quint32 CntTransformPresence::getIdForField(const QString& fieldName) const |
|
174 { |
|
175 if (QContactPresence::FieldPresenceState == fieldName) |
|
176 return KUidContactFieldPresence.iUid; |
|
177 if (QContactPresence::FieldPresenceStateText == fieldName) |
|
178 return KUidContactFieldStatusMsg.iUid; |
|
179 else |
|
180 return 0; |
|
181 } |
|
182 |
|
183 /*! |
|
184 * Modifies the detail definitions. The default detail definitions are |
|
185 * queried from QContactManagerEngine::schemaDefinitions and then modified |
|
186 * with this function in the transform leaf classes. |
|
187 * |
|
188 * \a definitions The detail definitions to modify. |
|
189 * \a contactType The contact type the definitions apply for. |
|
190 */ |
|
191 void CntTransformPresence::detailDefinitions(QMap<QString, QContactDetailDefinition> &definitions, const QString& contactType) const |
|
192 { |
|
193 Q_UNUSED(contactType); |
|
194 |
|
195 if(definitions.contains(QContactPresence::DefinitionName)) { |
|
196 QContactDetailDefinition d = definitions.value(QContactPresence::DefinitionName); |
|
197 QMap<QString, QContactDetailFieldDefinition> fields = d.fields(); |
|
198 QContactDetailFieldDefinition f; |
|
199 |
|
200 // Don't support "ContextOther" |
|
201 f.setDataType(QVariant::StringList); |
|
202 f.setAllowableValues(QVariantList() |
|
203 << QLatin1String(QContactDetail::ContextHome) |
|
204 << QLatin1String(QContactDetail::ContextWork)); |
|
205 fields[QContactDetail::FieldContext] = f; |
|
206 d.setFields(fields); |
|
207 |
|
208 // Replace original definitions |
|
209 definitions.insert(d.name(), d); |
|
210 } |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Reset internal variables. |
|
215 */ |
|
216 void CntTransformPresence::reset() |
|
217 { |
|
218 m_detailCounter = 0; |
|
219 } |
|
220 |
|
221 /*! |
|
222 * Decode the presence information. |
|
223 * \a aPresence |
|
224 */ |
|
225 QContactPresence::PresenceState CntTransformPresence::decodePresence(QString presence) |
|
226 { |
|
227 bool ok = false; |
|
228 int presenceInt = presence.toInt(&ok); |
|
229 if (!ok){ |
|
230 return QContactPresence::PresenceUnknown; |
|
231 } |
|
232 |
|
233 if (presenceInt == QContactPresence::PresenceAvailable) |
|
234 return QContactPresence::PresenceAvailable; |
|
235 else if (presenceInt == QContactPresence::PresenceHidden) |
|
236 return QContactPresence::PresenceHidden; |
|
237 else if (presenceInt == QContactPresence::PresenceBusy) |
|
238 return QContactPresence::PresenceBusy; |
|
239 else if (presenceInt == QContactPresence::PresenceAway) |
|
240 return QContactPresence::PresenceAway; |
|
241 else if (presenceInt == QContactPresence::PresenceExtendedAway) |
|
242 return QContactPresence::PresenceExtendedAway; |
|
243 else if (presenceInt == QContactPresence::PresenceOffline) |
|
244 return QContactPresence::PresenceOffline; |
|
245 else |
|
246 return QContactPresence::PresenceUnknown; |
|
247 } |
|
248 |
|
249 #endif // SYMBIAN_BACKEND_USE_SQLITE |
|
250 |
|
251 // End of file |