|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // pbapvcardexporterimpl.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "pbapvcardexporterutil.h" |
|
19 |
|
20 #include <cntitem.h> |
|
21 #include <s32strm.h> |
|
22 #include <vprop.h> |
|
23 #include <vcard.h> |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include "vcard3.h" |
|
26 #include "cntdb_internal.h" |
|
27 #endif |
|
28 #include <vtoken.h> |
|
29 #include "pbaplogeng.h" |
|
30 #include "btaccesshostlog.h" |
|
31 |
|
32 |
|
33 //constants |
|
34 _LIT8(KVersitTokenCALLDATETIME,"X-IRMC-CALL-DATETIME"); |
|
35 _LIT8(KVersitParamMISSED,"MISSED"); |
|
36 _LIT8(KVersitParamRECEIVED,"RECEIVED"); |
|
37 _LIT8(KVersitParamDIALED,"DIALED"); // US English spelling to conform with spec |
|
38 |
|
39 |
|
40 /*static*/ CPbapVCardExporterUtil* CPbapVCardExporterUtil::NewL(CContactDatabase& aDatabase, |
|
41 CPbapLogWrapper* aLogWrapper) |
|
42 { |
|
43 LOG_STATIC_FUNC |
|
44 CPbapVCardExporterUtil* self = new(ELeave) CPbapVCardExporterUtil(aDatabase, aLogWrapper); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CPbapVCardExporterUtil::CPbapVCardExporterUtil(CContactDatabase& aDatabase, CPbapLogWrapper* aLogWrapper) |
|
52 : iDatabase(aDatabase), iLogWrapper(aLogWrapper) |
|
53 { |
|
54 LOG_FUNC |
|
55 } |
|
56 |
|
57 void CPbapVCardExporterUtil::ConstructL() |
|
58 { |
|
59 LOG_FUNC |
|
60 CVersitTlsData::VersitTlsDataL(); |
|
61 User::LeaveIfError(iTzClient.Connect()); |
|
62 } |
|
63 |
|
64 CPbapVCardExporterUtil::~CPbapVCardExporterUtil() |
|
65 { |
|
66 LOG_FUNC |
|
67 iTzClient.Close(); |
|
68 CVersitTlsData::CloseVersitTlsData(); |
|
69 } |
|
70 |
|
71 /** |
|
72 Export a contact as vCard. |
|
73 |
|
74 @param aContactId Contact item ID to export. If this value is set to KNullContactId an empty vCard |
|
75 containing only the mandatory properties defined in the PBAP specification will be exported |
|
76 @param aWriteStream Stream to externalize vCard data to |
|
77 @param aFormat Version of vCard specification 2.1 or 3.0 |
|
78 @param aFilter Defines properties to be exported |
|
79 */ |
|
80 void CPbapVCardExporterUtil::ExportContactL(TContactItemId aContactId, |
|
81 RWriteStream& aWriteStream, |
|
82 TVCardVersion aFormat, |
|
83 TUint64 aFilter) |
|
84 { |
|
85 LOG_FUNC |
|
86 CContactIdArray* contactIdArray = CContactIdArray::NewLC(); |
|
87 contactIdArray->AddL(aContactId); |
|
88 iDatabase.ExportSelectedContactsL(TUid::Uid(KUidPBAPVCardConvImpl), *contactIdArray, aWriteStream, |
|
89 0, aFilter, NULL, aFormat, ETrue); |
|
90 CleanupStack::PopAndDestroy(contactIdArray); |
|
91 } |
|
92 |
|
93 |
|
94 /** |
|
95 Export log engine event as a vCard. |
|
96 |
|
97 @param aEvent Log engine event to be exported |
|
98 @param aWriteStream Stream to externalize vCard data to |
|
99 @param aFormat Version of vCard specification 2.1 or 3.0 |
|
100 @param aFilter Defines properties to be exported |
|
101 */ |
|
102 void CPbapVCardExporterUtil::ExportCallHistoryL(const CLogEvent& aLogEvent, |
|
103 RWriteStream& aWriteStream, |
|
104 TVCardVersion aFormat, |
|
105 TUint64 aFilter) |
|
106 { |
|
107 LOG_FUNC |
|
108 TContactItemId contactId = aLogEvent.Contact(); |
|
109 |
|
110 if (ContactExistsL(contactId)) |
|
111 { |
|
112 // store the log event, format and filter parameters to use in the callback |
|
113 // from the contacts vCard converter |
|
114 iLogEvent = &aLogEvent; |
|
115 iFormat = aFormat; |
|
116 iFilter = aFilter; |
|
117 |
|
118 CContactIdArray* contactIdArray = CContactIdArray::NewLC(); |
|
119 contactIdArray->AddL(contactId); |
|
120 iDatabase.ExportSelectedContactsL(TUid::Uid(KUidPBAPVCardConvImpl), *contactIdArray, aWriteStream, 0, aFilter, this, aFormat, EFalse); |
|
121 CleanupStack::PopAndDestroy(contactIdArray); |
|
122 } |
|
123 else |
|
124 { |
|
125 //no associated contact so only export properties which map to log entry fields |
|
126 CParserVCard* vCard = CreateVCardParserLC(aFormat); |
|
127 vCard->SetDefaultCharSet(Versit::EUTF8CharSet); |
|
128 |
|
129 // N property mandated by vCard 2.1 and 3.0 specifications |
|
130 vCard->AddPropertyL(EmptyNamePropertyL()); |
|
131 |
|
132 // FN property mandated by vCard 3.0 specification |
|
133 if (aFormat==EPBAPVCard30) |
|
134 { |
|
135 //add empty FN property |
|
136 vCard->AddPropertyL(DesPropertyL(KVersitTokenFN, KNullDesC)); |
|
137 } |
|
138 |
|
139 // add mandatory TEL property using number from call log |
|
140 vCard->AddPropertyL(DesPropertyL(KVersitTokenTEL, aLogEvent.Number())); |
|
141 |
|
142 // add the X-IRMC-CALL-DATETIME property |
|
143 if (aFilter == SymbianPBAP::KPbapAttributeAll || aFilter&SymbianPBAP::KPbapAttributeMaskCallDateTime) |
|
144 { |
|
145 vCard->AddPropertyL(CallDateTimePropertyL(aLogEvent, aFormat)); |
|
146 } |
|
147 |
|
148 vCard->ExternalizeL(aWriteStream); |
|
149 CleanupStack::PopAndDestroy(vCard); |
|
150 } |
|
151 } |
|
152 |
|
153 /** |
|
154 Writes a vCard to the stream containing only the mandatory properties defined in the PBAP specification |
|
155 with all properties set to empty (null) values |
|
156 */ |
|
157 void CPbapVCardExporterUtil::ExportEmptyVCardL(RWriteStream& aWriteStream, TVCardVersion aFormat) |
|
158 { |
|
159 LOG_FUNC |
|
160 CParserVCard* vCard = CreateVCardParserLC(aFormat); |
|
161 vCard->SetDefaultCharSet(Versit::EUTF8CharSet); |
|
162 |
|
163 vCard->AddPropertyL(EmptyNamePropertyL()); |
|
164 |
|
165 if (aFormat == EPBAPVCard30) |
|
166 { |
|
167 vCard->AddPropertyL(DesPropertyL(KVersitTokenFN, KNullDesC)); |
|
168 } |
|
169 |
|
170 vCard->AddPropertyL(DesPropertyL(KVersitTokenTEL, KNullDesC)); |
|
171 |
|
172 vCard->ExternalizeL(aWriteStream); |
|
173 CleanupStack::PopAndDestroy(vCard); |
|
174 } |
|
175 |
|
176 /** |
|
177 PBAP clients are supposed to provide any information regarding the contact item represented by aContactId. |
|
178 This information should be in form of standard vCard property, all such properties should be appended to the array aPropertyList. |
|
179 */ |
|
180 void CPbapVCardExporterUtil::AddIntraContactPropertiesL(const TContactItemId& aContactId, |
|
181 CArrayPtr<CParserProperty>* aPropertyList) |
|
182 { |
|
183 LOG_FUNC |
|
184 if(iLogEvent && iLogEvent->Contact() == aContactId) |
|
185 { |
|
186 CParserProperty* property; |
|
187 |
|
188 // add mandatory TEL property using number from log event |
|
189 property = DesPropertyL(KVersitTokenTEL, iLogEvent->Number()); |
|
190 CleanupStack::PushL(property); |
|
191 aPropertyList->AppendL(property); |
|
192 CleanupStack::Pop(property); //ownership passed |
|
193 |
|
194 // add X-IRMC-CALL-DATETIME property |
|
195 if (iFilter == SymbianPBAP::KPbapAttributeAll || iFilter&SymbianPBAP::KPbapAttributeMaskCallDateTime) |
|
196 { |
|
197 property = CallDateTimePropertyL(*iLogEvent, iFormat); |
|
198 CleanupStack::PushL(property); |
|
199 aPropertyList->AppendL(property); |
|
200 CleanupStack::Pop(property); //ownership passed |
|
201 } |
|
202 |
|
203 iLogEvent = NULL; |
|
204 } |
|
205 } |
|
206 |
|
207 TBool CPbapVCardExporterUtil::ContactExistsL(TContactItemId aContactId) |
|
208 { |
|
209 LOG_FUNC |
|
210 TBool exists = EFalse; |
|
211 if (aContactId != KNullContactId) |
|
212 { |
|
213 CContactItem* contactItem=NULL; |
|
214 TRAPD(error, contactItem=iDatabase.ReadMinimalContactL(aContactId)); |
|
215 if (error==KErrNone) |
|
216 { |
|
217 if (contactItem && (contactItem->Type()== KUidContactCard || contactItem->Type()== KUidContactOwnCard)) |
|
218 { |
|
219 // the contact item exists in the pb phone book |
|
220 exists = ETrue; |
|
221 delete contactItem; |
|
222 } |
|
223 } |
|
224 else if (error != KErrNotFound && error!=KErrNotReady) |
|
225 { |
|
226 User::Leave(error); |
|
227 } |
|
228 } |
|
229 return exists; |
|
230 } |
|
231 |
|
232 CParserVCard* CPbapVCardExporterUtil::CreateVCardParserLC(TVCardVersion aFormat) |
|
233 { |
|
234 LOG_FUNC |
|
235 CParserVCard* parser=NULL; |
|
236 switch (aFormat) |
|
237 { |
|
238 case EPBAPVCard21: |
|
239 parser=CParserVCard::NewL(); //create vCard 2.1 parser |
|
240 break; |
|
241 case EPBAPVCard30: |
|
242 parser=CParserVCard3::NewL(); //create vCard 3.0 parser |
|
243 break; |
|
244 default: |
|
245 User::Leave(KErrNotSupported); |
|
246 break; |
|
247 } |
|
248 CleanupStack::PushL(parser); |
|
249 |
|
250 return parser; |
|
251 } |
|
252 |
|
253 CParserProperty* CPbapVCardExporterUtil::EmptyNamePropertyL() |
|
254 { |
|
255 LOG_FUNC |
|
256 CDesCArrayFlat* desArray =new (ELeave) CDesCArrayFlat(4); |
|
257 CleanupStack::PushL(desArray); |
|
258 desArray->AppendL(KNullDesC); |
|
259 CParserPropertyValue* value = new(ELeave) CParserPropertyValueCDesCArray(desArray); |
|
260 CleanupStack::Pop(desArray); //ownership passed |
|
261 CleanupStack::PushL(value); |
|
262 CParserGroupedProperty* property = CParserGroupedProperty::NewL(*value, KVersitTokenN, NULL, NULL); |
|
263 CleanupStack::Pop(value); //ownership passed |
|
264 return property; |
|
265 } |
|
266 |
|
267 |
|
268 CParserProperty* CPbapVCardExporterUtil::DesPropertyL(const TDesC8& aToken, const TDesC& aDes) |
|
269 { |
|
270 LOG_FUNC |
|
271 CParserPropertyValue* value = CParserPropertyValueHBufC::NewL(aDes); |
|
272 CleanupStack::PushL(value); |
|
273 CParserGroupedProperty* property = CParserGroupedProperty::NewL(*value, aToken, NULL, NULL); |
|
274 CleanupStack::Pop(value); //ownership passed |
|
275 return property; |
|
276 } |
|
277 |
|
278 CParserProperty* CPbapVCardExporterUtil::CallDateTimePropertyL(const CLogEvent& aLogEvent, TVCardVersion aFormat) |
|
279 { |
|
280 LOG_FUNC |
|
281 TTime localTime = aLogEvent.Time(); |
|
282 TVersitDateTime::TRelativeTime relativeTime = TVersitDateTime::EIsUTC; |
|
283 if (iTzClient.ConvertToLocalTime(localTime) == KErrNone) |
|
284 { |
|
285 relativeTime = TVersitDateTime::EIsMachineLocal; |
|
286 } |
|
287 |
|
288 TVersitDateTime* dateTime= new(ELeave) TVersitDateTime(localTime.DateTime(), relativeTime); |
|
289 CleanupStack::PushL(dateTime); |
|
290 CParserPropertyValueDateTime* value = new(ELeave) CParserPropertyValueDateTime(dateTime); |
|
291 CleanupStack::Pop(dateTime); //ownership passed |
|
292 CleanupStack::PushL(value); |
|
293 CParserGroupedProperty* property = CParserGroupedProperty::NewL(*value, KVersitTokenCALLDATETIME, NULL, NULL); |
|
294 CleanupStack::Pop(value); //ownership passed |
|
295 CleanupStack::PushL(property); |
|
296 |
|
297 TPtrC8 paramValue(ParameterValueFromEventL(aLogEvent)); |
|
298 |
|
299 if (paramValue.Length()) |
|
300 { |
|
301 CParserParam* param; |
|
302 if (aFormat == EPBAPVCard30) |
|
303 { |
|
304 //nameless parameters not allowed for vCard 3.0, so add "TYPE" parameter name |
|
305 param= CParserParam::NewL(KVersitTokenTYPE, paramValue); |
|
306 } |
|
307 else |
|
308 { |
|
309 param= CParserParam::NewL(paramValue, KNullDesC); |
|
310 } |
|
311 CleanupStack::PushL(param); |
|
312 property->AddParamL(param); |
|
313 CleanupStack::Pop(param); //ownership passed |
|
314 } |
|
315 |
|
316 CleanupStack::Pop(property); |
|
317 return property; |
|
318 } |
|
319 |
|
320 |
|
321 TPtrC8 CPbapVCardExporterUtil::ParameterValueFromEventL(const CLogEvent& aLogEvent) |
|
322 { |
|
323 LOG_FUNC |
|
324 if (iLogWrapper) |
|
325 { |
|
326 TLogString logString; |
|
327 User::LeaveIfError(iLogWrapper->GetString(logString, R_LOG_DIR_MISSED)); |
|
328 if (aLogEvent.Direction()==logString) |
|
329 { |
|
330 return KVersitParamMISSED(); |
|
331 } |
|
332 User::LeaveIfError(iLogWrapper->GetString(logString, R_LOG_DIR_IN)); |
|
333 if (aLogEvent.Direction()==logString) |
|
334 { |
|
335 return KVersitParamRECEIVED(); |
|
336 } |
|
337 User::LeaveIfError(iLogWrapper->GetString(logString, R_LOG_DIR_OUT)); |
|
338 if (aLogEvent.Direction()==logString) |
|
339 { |
|
340 return KVersitParamDIALED(); |
|
341 } |
|
342 } |
|
343 //unknown log type, just set parameter value to empty string |
|
344 return KNullDesC8(); |
|
345 } |