|
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 // |
|
15 |
|
16 #include <cntdb.h> |
|
17 |
|
18 #include "pbapchexporter.h" |
|
19 #include "pbapserver.h" |
|
20 #include "pbapexporter.h" |
|
21 #include "pbapfolderclient.h" |
|
22 #include "pbapcontactdbviews.h" |
|
23 #include "pbaplogeng.h" |
|
24 |
|
25 #include "btaccesshostlog.h" |
|
26 |
|
27 |
|
28 // |
|
29 // CPbapChExporter |
|
30 // |
|
31 CPbapChExporter::CPbapChExporter(MVirtualFolderClient& aClient, |
|
32 MPbapExporterCallback& aCallback, |
|
33 CPbapChView& aViewToExport, |
|
34 CPbapChView* aReadViewToExport, |
|
35 TUint aStartIndex, |
|
36 TInt aCount) |
|
37 : CPbapExporterBase(aClient, aCallback), |
|
38 iState(EIdle), |
|
39 iStartIndex(aStartIndex), |
|
40 iCount(aCount) |
|
41 { |
|
42 LOG_FUNC |
|
43 |
|
44 // iCurrentEventIndex starts from 0, because CLogView can only start from the first event. |
|
45 iCurrentEventIndex = 0; |
|
46 |
|
47 // get views to export |
|
48 iLogView = aViewToExport.LogView(); |
|
49 |
|
50 // read view optional, used for missed calls only |
|
51 if (aReadViewToExport) |
|
52 { |
|
53 iReadEventView = aReadViewToExport->LogView(); |
|
54 } |
|
55 |
|
56 CActiveScheduler::Add(this); |
|
57 } |
|
58 |
|
59 void CPbapChExporter::ConstructL() |
|
60 { |
|
61 LOG_FUNC |
|
62 |
|
63 iState = EStartExport; |
|
64 |
|
65 // complete ourselves to kick-off the async processing |
|
66 TRequestStatus* status=&iStatus; |
|
67 User::RequestComplete(status, KErrNone); |
|
68 |
|
69 SetActive(); |
|
70 } |
|
71 |
|
72 CPbapChExporter::~CPbapChExporter() |
|
73 { |
|
74 LOG_FUNC |
|
75 |
|
76 Cancel(); |
|
77 } |
|
78 |
|
79 TBool CPbapChExporter::PrepareForFetchingL(TUint aNumberOfEvents) |
|
80 { |
|
81 LOG_FUNC |
|
82 |
|
83 // reset the number of items to be exported based on the view size |
|
84 iCount = Min(iCount, (aNumberOfEvents - iStartIndex)); |
|
85 return (iCount > 0); |
|
86 } |
|
87 |
|
88 void CPbapChExporter::StartExportL() |
|
89 { |
|
90 LOG_FUNC |
|
91 |
|
92 iClient.Exporter().StartExport(); |
|
93 |
|
94 // check to see if we need to export number of unread events |
|
95 if (iReadEventView) |
|
96 { |
|
97 iClient.Exporter().ExportNewMissedCallsL(iLogView->CountL() - iReadEventView->CountL()); |
|
98 } |
|
99 |
|
100 TBool startFetching = PrepareForFetchingL(iLogView->CountL()); |
|
101 if (startFetching && iLogView->FirstL(iStatus)) |
|
102 { |
|
103 iState = EFetchingLogEvents; |
|
104 SetActive(); |
|
105 } |
|
106 else |
|
107 { |
|
108 // no events to fetch |
|
109 FinaliseFetchLogEventsL(); |
|
110 } |
|
111 } |
|
112 |
|
113 void CPbapChExporter::FetchLogEventsL() |
|
114 { |
|
115 LOG_FUNC |
|
116 |
|
117 // call derived class to process fetched event |
|
118 TBool continueFetching = EventFetchedL(iLogView->Event(), iCurrentEventIndex); |
|
119 ++iCurrentEventIndex; |
|
120 if (continueFetching && iLogView->NextL(iStatus)) |
|
121 { |
|
122 SetActive(); |
|
123 } |
|
124 else |
|
125 { |
|
126 // all events fetched |
|
127 FinaliseFetchLogEventsL(); |
|
128 } |
|
129 } |
|
130 |
|
131 void CPbapChExporter::RunL() |
|
132 { |
|
133 LOG_FUNC |
|
134 |
|
135 User::LeaveIfError(iStatus.Int()); |
|
136 |
|
137 switch (iState) |
|
138 { |
|
139 case EStartExport: |
|
140 StartExportL(); |
|
141 break; |
|
142 case EFetchingLogEvents: |
|
143 FetchLogEventsL(); |
|
144 break; |
|
145 default: |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 void CPbapChExporter::DoCancel() |
|
151 { |
|
152 LOG_FUNC |
|
153 |
|
154 iLogView->Cancel(); |
|
155 |
|
156 // export aborted |
|
157 iClient.Exporter().CancelExport(); |
|
158 iCallback.HandleExportComplete(KErrCancel); |
|
159 } |
|
160 |
|
161 |
|
162 TInt CPbapChExporter::RunError(TInt aError) |
|
163 { |
|
164 LOG_FUNC |
|
165 |
|
166 // abort the export |
|
167 iClient.Exporter().CancelExport(); |
|
168 |
|
169 // notify observer |
|
170 iCallback.HandleExportComplete(aError); |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 void CPbapChExporter::FinaliseFetchLogEventsL() |
|
175 { |
|
176 LOG_FUNC |
|
177 |
|
178 // no event to fetch |
|
179 FetchingCompleteL(); |
|
180 iClient.Exporter().FinaliseExportL(); |
|
181 iCallback.HandleExportComplete(KErrNone); |
|
182 } |
|
183 |
|
184 |
|
185 // |
|
186 // CPbapChListingExporter |
|
187 // |
|
188 CPbapChListingExporter* CPbapChListingExporter::NewL(MVirtualFolderClient& aClient, |
|
189 MPbapExporterCallback& aCallback, |
|
190 CPbapChView& aViewToExport, |
|
191 CPbapChView* aReadViewToExport, |
|
192 TUint aStartIndex, |
|
193 TInt aCount) |
|
194 { |
|
195 LOG_STATIC_FUNC |
|
196 CPbapChListingExporter* self = |
|
197 new(ELeave) CPbapChListingExporter(aClient, aCallback, aViewToExport, |
|
198 aReadViewToExport, aStartIndex, aCount); |
|
199 CleanupStack::PushL(self); |
|
200 self->ConstructL(); |
|
201 CleanupStack::Pop(self); |
|
202 return self; |
|
203 } |
|
204 |
|
205 CPbapChListingExporter::CPbapChListingExporter(MVirtualFolderClient& aClient, |
|
206 MPbapExporterCallback& aCallback, |
|
207 CPbapChView& aViewToExport, |
|
208 CPbapChView* aReadViewToExport, |
|
209 TUint aStartIndex, |
|
210 TInt aCount) |
|
211 : CPbapChExporter(aClient, aCallback, aViewToExport, aReadViewToExport, aStartIndex, aCount) |
|
212 { |
|
213 LOG_FUNC |
|
214 } |
|
215 |
|
216 TBool CPbapChListingExporter::PrepareForFetchingL(TUint aNumberOfEvents) |
|
217 { |
|
218 LOG_FUNC |
|
219 // add listing header before first entry is exported |
|
220 iClient.Exporter().ExportListingBeginL(); |
|
221 |
|
222 return CPbapChExporter::PrepareForFetchingL(aNumberOfEvents); |
|
223 } |
|
224 |
|
225 TBool CPbapChListingExporter::EventFetchedL(const CLogEvent& aEvent, TInt aEventIndex) |
|
226 { |
|
227 LOG_FUNC |
|
228 |
|
229 TBool moreItemsToExport = EFalse; |
|
230 |
|
231 if (aEventIndex < iStartIndex) |
|
232 { |
|
233 // skip this event |
|
234 moreItemsToExport = ETrue; |
|
235 } |
|
236 else if (aEventIndex < iStartIndex + iCount) |
|
237 { |
|
238 // export event as a listing entry |
|
239 TInt handle = aEventIndex + 1; // call history handles start from 1 |
|
240 |
|
241 TContactItemId contactId = aEvent.Contact(); |
|
242 if (contactId != KNullContactId) |
|
243 { |
|
244 // a contact is associated with the log event so read its name from the database |
|
245 RBuf name; |
|
246 TRAPD(error , name.Assign(iClient.ContactDbViews().GetContactNameFromIdL(contactId))); |
|
247 if (error != KErrNone || !name.Size()) |
|
248 { |
|
249 // cannot read contact name (e.g. the contact id doesnot exist |
|
250 // anymore) so fallback to using the log events phone number |
|
251 name.Assign(aEvent.Number().AllocL()); |
|
252 } |
|
253 name.CleanupClosePushL(); |
|
254 iClient.Exporter().ExportListingEntryL(handle, name); |
|
255 CleanupStack::PopAndDestroy(&name); |
|
256 |
|
257 } |
|
258 else |
|
259 { |
|
260 // no contact associated with log event so use number instead of name |
|
261 const TDesC& phoneNumber = aEvent.Number(); |
|
262 iClient.Exporter().ExportListingEntryL(handle, phoneNumber); |
|
263 } |
|
264 moreItemsToExport = ETrue; |
|
265 } |
|
266 return moreItemsToExport; |
|
267 } |
|
268 |
|
269 void CPbapChListingExporter::FetchingCompleteL() |
|
270 { |
|
271 LOG_FUNC |
|
272 // no more listing entries to be exported so close listing |
|
273 iClient.Exporter().ExportListingEndL(); |
|
274 } |
|
275 |
|
276 |
|
277 // |
|
278 // CPbapChItemExporter |
|
279 // |
|
280 CPbapChItemExporter* CPbapChItemExporter::NewL(MVirtualFolderClient& aClient, |
|
281 MPbapExporterCallback& aCallback, |
|
282 CPbapChView& aViewToExport, |
|
283 CPbapChView* aReadViewToExport, |
|
284 TUint aStartIndex, |
|
285 TInt aCount, |
|
286 TVCardVersion aFormat, |
|
287 TUint64 aFilter) |
|
288 { |
|
289 LOG_STATIC_FUNC |
|
290 CPbapChItemExporter* self = |
|
291 new(ELeave) CPbapChItemExporter(aClient, aCallback, aViewToExport, aReadViewToExport, |
|
292 aStartIndex, aCount, aFormat, aFilter); |
|
293 CleanupStack::PushL(self); |
|
294 self->ConstructL(); |
|
295 CleanupStack::Pop(self); |
|
296 return self; |
|
297 } |
|
298 |
|
299 CPbapChItemExporter::CPbapChItemExporter(MVirtualFolderClient& aClient, |
|
300 MPbapExporterCallback& aCallback, |
|
301 CPbapChView& aViewToExport, |
|
302 CPbapChView* aReadViewToExport, |
|
303 TUint aStartIndex, |
|
304 TInt aCount, |
|
305 TVCardVersion aFormat, |
|
306 TUint64 aFilter) |
|
307 : CPbapChExporter(aClient, aCallback, aViewToExport, aReadViewToExport, aStartIndex, aCount), |
|
308 iFormat(aFormat), |
|
309 iFilter(aFilter) |
|
310 { |
|
311 LOG_FUNC |
|
312 } |
|
313 |
|
314 TBool CPbapChItemExporter::EventFetchedL(const CLogEvent& aEvent, TInt aEventIndex) |
|
315 { |
|
316 LOG_FUNC |
|
317 |
|
318 TBool moreItemsToExport = EFalse; |
|
319 |
|
320 if(aEventIndex < iStartIndex) |
|
321 { |
|
322 // skip this event |
|
323 moreItemsToExport =ETrue; |
|
324 } |
|
325 else if (aEventIndex < iStartIndex + iCount) |
|
326 { |
|
327 // export the event |
|
328 iClient.Exporter().ExportCallHistoryL(aEvent, iFormat, iFilter); |
|
329 moreItemsToExport = ETrue; |
|
330 } |
|
331 return moreItemsToExport; |
|
332 } |
|
333 |
|
334 void CPbapChItemExporter::FetchingCompleteL() |
|
335 { |
|
336 LOG_FUNC |
|
337 // do nothing |
|
338 } |
|
339 |
|
340 // |
|
341 // CPbapChSingleItemExporter |
|
342 // |
|
343 CPbapChSingleItemExporter* CPbapChSingleItemExporter::NewL(MVirtualFolderClient& aClient, |
|
344 MPbapExporterCallback& aCallback, |
|
345 CPbapChView& aViewToExport, |
|
346 TInt aIndex, |
|
347 TVCardVersion aFormat, |
|
348 TUint64 aFilter) |
|
349 { |
|
350 LOG_STATIC_FUNC |
|
351 CPbapChSingleItemExporter* self = |
|
352 new(ELeave) CPbapChSingleItemExporter(aClient, aCallback, aViewToExport, aIndex, aFormat, aFilter); |
|
353 CleanupStack::PushL(self); |
|
354 self->ConstructL(); |
|
355 CleanupStack::Pop(self); |
|
356 return self; |
|
357 } |
|
358 |
|
359 |
|
360 CPbapChSingleItemExporter::CPbapChSingleItemExporter(MVirtualFolderClient& aClient, |
|
361 MPbapExporterCallback& aCallback, |
|
362 CPbapChView& aViewToExport, |
|
363 TInt aIndex, |
|
364 TVCardVersion aFormat, |
|
365 TUint64 aFilter) |
|
366 : CPbapChExporter(aClient, aCallback, aViewToExport), iIndex(aIndex), iFormat(aFormat), iFilter(aFilter) |
|
367 { |
|
368 LOG_FUNC |
|
369 } |
|
370 |
|
371 TBool CPbapChSingleItemExporter::PrepareForFetchingL(TUint aNumberOfEvents) |
|
372 { |
|
373 LOG_FUNC |
|
374 if (iIndex < 0 || iIndex >= aNumberOfEvents) |
|
375 { |
|
376 // attempting to export an event which doesnot exist |
|
377 User::Leave(KErrNotFound); |
|
378 } |
|
379 return ETrue; |
|
380 } |
|
381 |
|
382 TBool CPbapChSingleItemExporter::EventFetchedL(const CLogEvent& aEvent, TInt aEventIndex) |
|
383 { |
|
384 LOG_FUNC |
|
385 |
|
386 if (aEventIndex == iIndex) |
|
387 { |
|
388 iClient.Exporter().ExportCallHistoryL(aEvent, iFormat, iFilter); |
|
389 return EFalse; |
|
390 } |
|
391 return ETrue; |
|
392 } |
|
393 |
|
394 void CPbapChSingleItemExporter::FetchingCompleteL() |
|
395 { |
|
396 LOG_FUNC |
|
397 // do nothing |
|
398 } |
|
399 |
|
400 // |
|
401 // CPbapChCountExporter |
|
402 // |
|
403 CPbapChCountExporter* CPbapChCountExporter::NewL(MVirtualFolderClient& aClient, |
|
404 MPbapExporterCallback& aCallback, |
|
405 CPbapChView& aViewToExport, |
|
406 CPbapChView* aReadViewToExport) |
|
407 { |
|
408 LOG_STATIC_FUNC |
|
409 CPbapChCountExporter* self = new(ELeave) CPbapChCountExporter(aClient, aCallback, |
|
410 aViewToExport, aReadViewToExport); |
|
411 CleanupStack::PushL(self); |
|
412 self->ConstructL(); |
|
413 CleanupStack::Pop(self); |
|
414 return self; |
|
415 } |
|
416 |
|
417 CPbapChCountExporter::CPbapChCountExporter(MVirtualFolderClient& aClient, |
|
418 MPbapExporterCallback& aCallback, |
|
419 CPbapChView& aViewToExport, |
|
420 CPbapChView* aReadViewToExport) |
|
421 |
|
422 : CPbapChExporter(aClient, aCallback, aViewToExport, aReadViewToExport) |
|
423 { |
|
424 LOG_FUNC |
|
425 } |
|
426 |
|
427 TBool CPbapChCountExporter::PrepareForFetchingL(TUint aNumberOfEvents) |
|
428 { |
|
429 LOG_FUNC |
|
430 |
|
431 // the size of the phonebook is equal to the number of events in the log view |
|
432 iClient.Exporter().ExportPhonebookSizeL(aNumberOfEvents); |
|
433 |
|
434 // the phonebook size has been exported, so abort fetch |
|
435 return EFalse; |
|
436 } |
|
437 |
|
438 TBool CPbapChCountExporter::EventFetchedL(const CLogEvent& /*aEvent*/, TInt /*aEventIndex*/) |
|
439 { |
|
440 LOG_FUNC |
|
441 //Release build should silently ignore the event |
|
442 __ASSERT_DEBUG(EFalse, Panic(EPbapChCountExporterFetchingFails)); |
|
443 // do nothing (fetching should have been aborted) |
|
444 return EFalse; |
|
445 } |
|
446 |
|
447 void CPbapChCountExporter::FetchingCompleteL() |
|
448 { |
|
449 LOG_FUNC |
|
450 // do nothing |
|
451 } |