|
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 "pbappbexporter.h" |
|
17 #include "pbapfolderclient.h" |
|
18 #include "pbapexporter.h" |
|
19 #include "pbaperrorreporter.h" |
|
20 #include "pbapcontactdbviews.h" |
|
21 #include "pbappbhandlecache.h" |
|
22 |
|
23 #include "btaccesshostlog.h" |
|
24 |
|
25 |
|
26 // |
|
27 // CPbapPbExporter |
|
28 // |
|
29 // N.B. CPbapPbExporter is a one shot class. |
|
30 CPbapPbExporter::CPbapPbExporter(MVirtualFolderClient& aClient, |
|
31 MPbapExporterCallback& aCallback) |
|
32 : CPbapExporterBase(aClient, aCallback) |
|
33 { |
|
34 LOG_FUNC |
|
35 CActiveScheduler::Add(this); |
|
36 } |
|
37 |
|
38 |
|
39 CPbapPbExporter::~CPbapPbExporter() |
|
40 { |
|
41 LOG_FUNC |
|
42 Cancel(); |
|
43 } |
|
44 |
|
45 |
|
46 void CPbapPbExporter::DoCancel() |
|
47 { |
|
48 LOG_FUNC |
|
49 // export aborted |
|
50 iClient.Exporter().CancelExport(); |
|
51 iCallback.HandleExportComplete(KErrCancel); |
|
52 } |
|
53 |
|
54 |
|
55 void CPbapPbExporter::ConstructL() |
|
56 { |
|
57 LOG_FUNC |
|
58 iClient.Exporter().StartExport(); |
|
59 Queue(); |
|
60 } |
|
61 |
|
62 |
|
63 void CPbapPbExporter::Queue() |
|
64 { |
|
65 LOG_FUNC |
|
66 if(!IsActive()) |
|
67 { |
|
68 TRequestStatus* status=&iStatus; |
|
69 User::RequestComplete(status, KErrNone); |
|
70 SetActive(); |
|
71 } |
|
72 } |
|
73 |
|
74 |
|
75 void CPbapPbExporter::RunL() |
|
76 { |
|
77 LOG_FUNC |
|
78 |
|
79 // call derived class to export a single item |
|
80 TBool moreToExport = DoExportItemL(); |
|
81 if (moreToExport) |
|
82 { |
|
83 // queue another export |
|
84 Queue(); |
|
85 } |
|
86 else |
|
87 { |
|
88 // all items exported |
|
89 iClient.Exporter().FinaliseExportL(); |
|
90 iCallback.HandleExportComplete(KErrNone); |
|
91 } |
|
92 } |
|
93 |
|
94 |
|
95 TInt CPbapPbExporter::RunError(TInt aError) |
|
96 { |
|
97 LOG_FUNC |
|
98 |
|
99 // an export step failed so cancel and report error |
|
100 iClient.Exporter().CancelExport(); |
|
101 iCallback.HandleExportComplete(aError); |
|
102 return KErrNone; |
|
103 } |
|
104 |
|
105 |
|
106 // |
|
107 // CPbapPbListingExporter |
|
108 // |
|
109 /*static*/ CPbapPbListingExporter* CPbapPbListingExporter::NewL(MVirtualFolderClient& aClient, |
|
110 MPbapExporterCallback& aCallback, |
|
111 CPbapPbHandleCache& aHandles, |
|
112 RIndexArray& aCacheIndexesToExport) |
|
113 { |
|
114 LOG_STATIC_FUNC |
|
115 CPbapPbListingExporter* self = new(ELeave) CPbapPbListingExporter(aClient, |
|
116 aCallback, |
|
117 aHandles, |
|
118 aCacheIndexesToExport); |
|
119 CleanupStack::PushL(self); |
|
120 self->ConstructL(); |
|
121 CleanupStack::Pop(self); |
|
122 return self; |
|
123 } |
|
124 |
|
125 CPbapPbListingExporter::CPbapPbListingExporter(MVirtualFolderClient& aClient, |
|
126 MPbapExporterCallback& aCallback, |
|
127 CPbapPbHandleCache& aHandles, |
|
128 RIndexArray& aCacheIndexesToExport) |
|
129 : CPbapPbExporter(aClient, aCallback), iHandles(aHandles), iCacheIndexesToExport(aCacheIndexesToExport) |
|
130 { |
|
131 LOG_FUNC |
|
132 } |
|
133 |
|
134 TBool CPbapPbListingExporter::DoExportItemL() |
|
135 { |
|
136 LOG_FUNC |
|
137 |
|
138 TBool moreItemsToExport = EFalse; |
|
139 if (iCurrentIndex==0) |
|
140 { |
|
141 // add listing header |
|
142 iClient.Exporter().ExportListingBeginL(); |
|
143 } |
|
144 |
|
145 if (iCurrentIndex < iCacheIndexesToExport.Count()) |
|
146 { |
|
147 // get the handle,contact id pair at the current handle cache index |
|
148 TInt handleCacheIndex = iCacheIndexesToExport[iCurrentIndex]; |
|
149 TContactItemId contactId = iHandles.ContactIdAtL(handleCacheIndex); |
|
150 TInt handle = iHandles.HandleAtL(handleCacheIndex); |
|
151 |
|
152 RBuf name; |
|
153 // get the name from the contact database view |
|
154 TRAP_IGNORE(name.Assign(iClient.ContactDbViews().GetContactNameFromIdL(contactId))); |
|
155 //if cannot read contact name, just export empty string instead |
|
156 name.CleanupClosePushL(); |
|
157 iClient.Exporter().ExportListingEntryL(handle, name); |
|
158 CleanupStack::PopAndDestroy(&name); |
|
159 |
|
160 ++iCurrentIndex; |
|
161 moreItemsToExport = ETrue; |
|
162 } |
|
163 else |
|
164 { |
|
165 // last item has been exported so add listing footer |
|
166 iClient.Exporter().ExportListingEndL(); |
|
167 moreItemsToExport = EFalse; |
|
168 } |
|
169 return moreItemsToExport; |
|
170 } |
|
171 |
|
172 |
|
173 // |
|
174 // CPbapPbItemExporter |
|
175 // |
|
176 /*static*/ CPbapPbItemExporter* CPbapPbItemExporter::NewL(MVirtualFolderClient& aClient, |
|
177 MPbapExporterCallback& aCallback, |
|
178 CPbapPbHandleCache& aHandles, |
|
179 TInt aStartIndex, |
|
180 TInt aCount, |
|
181 TVCardVersion aFormat, |
|
182 TUint64 aFilter) |
|
183 { |
|
184 LOG_STATIC_FUNC |
|
185 CPbapPbItemExporter* self = new(ELeave) CPbapPbItemExporter(aClient, |
|
186 aCallback, |
|
187 aHandles, |
|
188 aStartIndex, |
|
189 aCount, |
|
190 aFormat, |
|
191 aFilter); |
|
192 CleanupStack::PushL(self); |
|
193 self->ConstructL(); |
|
194 CleanupStack::Pop(self); |
|
195 return self; |
|
196 } |
|
197 |
|
198 |
|
199 CPbapPbItemExporter::CPbapPbItemExporter(MVirtualFolderClient& aClient, |
|
200 MPbapExporterCallback& aCallback, |
|
201 CPbapPbHandleCache& aHandles, |
|
202 TInt aStartIndex, |
|
203 TInt aCount, |
|
204 TVCardVersion aFormat, |
|
205 TUint64 aFilter) |
|
206 : CPbapPbExporter(aClient, aCallback), |
|
207 iHandles(aHandles), |
|
208 iStartIndex(aStartIndex), |
|
209 iCount(aCount), |
|
210 iFormat(aFormat), |
|
211 iFilter(aFilter) |
|
212 { |
|
213 LOG_FUNC |
|
214 iCurrentIndex = iStartIndex; |
|
215 } |
|
216 |
|
217 |
|
218 TBool CPbapPbItemExporter::DoExportItemL() |
|
219 { |
|
220 LOG_FUNC |
|
221 |
|
222 TBool moreItemsToExport = EFalse; |
|
223 if (iCurrentIndex < (iStartIndex + iCount)) |
|
224 { |
|
225 // retrieve contact id associated with the handle at the current cache index |
|
226 TContactItemId contactId = iHandles.ContactIdAtL(iCurrentIndex); |
|
227 |
|
228 TInt handle = iHandles.HandleAtL(iCurrentIndex); |
|
229 |
|
230 if (handle == KOwnCardHandle && contactId == KNullContactId) |
|
231 { |
|
232 // the own card handle is not associated with a contact in the database |
|
233 // but we must still export a vCard, so create an empty one |
|
234 iClient.Exporter().ExportEmptyVCardL(iFormat); |
|
235 } |
|
236 else |
|
237 { |
|
238 // convert the contact to a vCard |
|
239 iClient.Exporter().ExportContactL(contactId, iFormat, iFilter); |
|
240 } |
|
241 ++iCurrentIndex; |
|
242 moreItemsToExport = ETrue; |
|
243 } |
|
244 return moreItemsToExport; |
|
245 } |
|
246 |
|
247 |
|
248 // |
|
249 // CPbapPbCountExporter |
|
250 // |
|
251 /*static*/ CPbapPbCountExporter* CPbapPbCountExporter::NewL(MVirtualFolderClient& aClient, |
|
252 MPbapExporterCallback& aCallback, |
|
253 TInt aCount) |
|
254 { |
|
255 LOG_STATIC_FUNC |
|
256 CPbapPbCountExporter* self = new(ELeave) CPbapPbCountExporter(aClient, aCallback, aCount); |
|
257 CleanupStack::PushL(self); |
|
258 self->ConstructL(); |
|
259 CleanupStack::Pop(self); |
|
260 return self; |
|
261 } |
|
262 |
|
263 |
|
264 CPbapPbCountExporter::CPbapPbCountExporter(MVirtualFolderClient& aClient, |
|
265 MPbapExporterCallback& aCallback, |
|
266 TInt aCount) |
|
267 : CPbapPbExporter(aClient, aCallback), iCount(aCount) |
|
268 { |
|
269 LOG_FUNC |
|
270 } |
|
271 |
|
272 |
|
273 TBool CPbapPbCountExporter::DoExportItemL() |
|
274 { |
|
275 LOG_FUNC |
|
276 iClient.Exporter().ExportPhonebookSizeL(iCount); |
|
277 return EFalse; |
|
278 } |