author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: Implementation of import observer for Contacts Service API. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
#include "importstorelistobserver.h" |
|
22 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
23 |
#include <CVPbkVCardEng.h>//for the vcard engin |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
#include <CVPbkContactManager.h>// for iContactManager |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
25 |
#include <MVPbkContactStore.h>// for iContactStore |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
26 |
#include <TVPbkContactStoreUriPtr.h>//used in SetupL |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
27 |
#include <MVPbkContactStoreList.h>//used in SetupL to get contact stores |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
28 |
#include <MVPbkStoreContactField.h>//used in AddFieldToContactL |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
29 |
#include <MVPbkStoreContact.h>// used in many function to get the store contact |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
30 |
#include <MVPbkContactFieldTextData.h>//for the field text data |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
31 |
#include <TVPbkFieldTypeMapping.h>//used in CreateFieldTypeL() |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
32 |
#include <MVPbkFieldType.h>//return type of CreateFieldTypeL() |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
33 |
#include <MVPbkContactOperationBase.h>//for observer |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
34 |
#include <MVPbkContactFieldDateTimeData.h>//Used in AddDateFieldToContactL |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
35 |
#include <MVPbkContactLink.h>//for param in ContactsSaved() |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
36 |
#include <CVPbkContactStoreUriArray.h>//used in SetupL |
19 | 37 |
|
38 |
||
39 |
||
40 |
// --------------------------------------------------------------------------- |
|
41 |
// Static method to create an instance of the import store list observer. |
|
42 |
// --------------------------------------------------------------------------- |
|
43 |
||
44 |
CImportStoreListObserver* CImportStoreListObserver:: |
|
45 |
NewL(RFs &aFs, |
|
46 |
const TFileName& aFileName, |
|
47 |
MContactCallback *aCallback, |
|
48 |
TInt32 aTransId) |
|
49 |
{ |
|
50 |
return new( ELeave ) CImportStoreListObserver(aFs, |
|
51 |
aFileName, |
|
52 |
aCallback, |
|
53 |
aTransId); |
|
54 |
} |
|
55 |
||
56 |
||
57 |
// --------------------------------------------------------------------------- |
|
58 |
// Destructor |
|
59 |
// --------------------------------------------------------------------------- |
|
60 |
||
61 |
CImportStoreListObserver::~CImportStoreListObserver() |
|
62 |
{ |
|
63 |
iSource.Close(); |
|
64 |
if(iOp) |
|
65 |
{ |
|
66 |
delete iOp; |
|
67 |
} |
|
68 |
if(iContactStore) |
|
69 |
{ |
|
70 |
iContactStore->Close(*this); |
|
71 |
} |
|
72 |
||
73 |
} |
|
74 |
/* |
|
75 |
------------------------------------------------------------------------------------- |
|
76 |
CImportStoreListObserver::Cancel() |
|
77 |
Description : Cancel implementation relevant to ImportObserver |
|
78 |
Return values : KErrorNone on Success and KErrGeneral on Failure |
|
79 |
------------------------------------------------------------------------------------- |
|
80 |
*/ |
|
81 |
||
82 |
void CImportStoreListObserver::Cancel() |
|
83 |
{ |
|
84 |
iCallback->HandleReturnValue(EOpCancel, KErrNone, iTransId); |
|
85 |
delete this; |
|
86 |
} |
|
87 |
||
88 |
// --------------------------------------------------------------------------- |
|
89 |
// Constructor |
|
90 |
// --------------------------------------------------------------------------- |
|
91 |
||
92 |
CImportStoreListObserver:: |
|
93 |
CImportStoreListObserver(RFs &aFs, |
|
94 |
const TFileName& aFileName, |
|
95 |
MContactCallback *aCallback, |
|
96 |
TInt32 aTransId) |
|
97 |
{ |
|
98 |
iFs=aFs; |
|
99 |
iFileName=aFileName; |
|
100 |
iCallback=aCallback; |
|
101 |
iTransId=aTransId; |
|
102 |
iOp = NULL; |
|
103 |
} |
|
104 |
||
105 |
// --------------------------------------------------------------------------- |
|
106 |
// Method to set the vcard engine. |
|
107 |
// --------------------------------------------------------------------------- |
|
108 |
||
109 |
void CImportStoreListObserver::SetEngine(CVPbkVCardEng* aEngine) |
|
110 |
{ |
|
111 |
iEngine=aEngine; |
|
112 |
} |
|
113 |
||
114 |
// --------------------------------------------------------------------------- |
|
115 |
// Method to set the contact store. |
|
116 |
// --------------------------------------------------------------------------- |
|
117 |
||
118 |
void CImportStoreListObserver::SetContactStore(MVPbkContactStore* aContactStore) |
|
119 |
{ |
|
120 |
iContactStore = aContactStore; |
|
121 |
} |
|
122 |
||
123 |
//---------------------------------------------------------------------------- |
|
124 |
// Method to set the contact service |
|
125 |
//---------------------------------------------------------------------------- |
|
126 |
void CImportStoreListObserver::SetContactService(CContactService* aContactService) |
|
127 |
{ |
|
128 |
iContactService = aContactService; |
|
129 |
} |
|
130 |
// --------------------------------------------------------------------------- |
|
131 |
// Called By MVPbkContactStoreListObserver indicate the |
|
132 |
// the store is ready |
|
133 |
// --------------------------------------------------------------------------- |
|
134 |
||
135 |
void CImportStoreListObserver::StoreReady( MVPbkContactStore& aContactStore ) |
|
136 |
{ |
|
137 |
TInt error; |
|
138 |
error = iSource.Open( iFs, iFileName, EFileRead ); |
|
139 |
if(error !=KErrNone ) |
|
140 |
{ |
|
141 |
iContactService->RequestComplete(iTransId); |
|
142 |
iCallback->HandleReturnValue(EOpComplete, error,iTransId); |
|
143 |
delete this; |
|
144 |
} |
|
145 |
else |
|
146 |
{ |
|
147 |
TRAPD(err,iOp = iEngine->ImportVCardL( aContactStore, iSource, *this )); |
|
148 |
if( err!=KErrNone ) |
|
149 |
{ |
|
150 |
iContactService->RequestComplete(iTransId); |
|
151 |
iCallback->HandleReturnValue(EOpComplete, err,iTransId); |
|
152 |
delete this; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
// --------------------------------------------------------------------------- |
|
158 |
// Called when OpenL is failed |
|
159 |
// --------------------------------------------------------------------------- |
|
160 |
||
161 |
void CImportStoreListObserver::StoreUnavailable( |
|
162 |
MVPbkContactStore& aContactStore, |
|
163 |
TInt aReason ) |
|
164 |
{ |
|
165 |
if(aReason == KErrNotFound) |
|
166 |
{ |
|
167 |
TRAPD(err,aContactStore.ReplaceL(*this)); |
|
168 |
if(err != KErrNone) |
|
169 |
{ |
|
170 |
iContactService->RequestComplete(iTransId); |
|
171 |
iCallback->HandleReturnValue(EOpComplete, err,iTransId); |
|
172 |
delete this; |
|
173 |
} |
|
174 |
} |
|
175 |
else |
|
176 |
{ |
|
177 |
iContactService->RequestComplete(iTransId); |
|
178 |
iCallback->HandleReturnValue(EOpError, aReason,iTransId); |
|
179 |
delete this; |
|
180 |
} |
|
181 |
||
182 |
} |
|
183 |
||
184 |
void CImportStoreListObserver::HandleStoreEventL( |
|
185 |
MVPbkContactStore& /*aContactStore*/, |
|
186 |
TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
187 |
{ |
|
188 |
// Indication not needed. |
|
189 |
} |
|
190 |
||
191 |
void CImportStoreListObserver::OpenComplete() |
|
192 |
{ |
|
193 |
// Indication not needed. |
|
194 |
} |
|
195 |
||
196 |
||
197 |
// --------------------------------------------------------------------------- |
|
198 |
// Called when field adding to the contact is successful. |
|
199 |
// --------------------------------------------------------------------------- |
|
200 |
||
201 |
void CImportStoreListObserver::FieldAddedToContact( |
|
202 |
MVPbkContactOperationBase& /*aOperation*/ ) |
|
203 |
{ |
|
204 |
// Indication not needed. Occurs when setting up the example data. |
|
205 |
} |
|
206 |
||
207 |
// --------------------------------------------------------------------------- |
|
208 |
// Called when field adding to the contact is failed. |
|
209 |
// --------------------------------------------------------------------------- |
|
210 |
||
211 |
void CImportStoreListObserver::FieldAddingFailed( |
|
212 |
MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/ ) |
|
213 |
{ |
|
214 |
// Indication not needed. Failures in adding example data fields can |
|
215 |
// be ignored. |
|
216 |
} |
|
217 |
||
218 |
// --------------------------------------------------------------------------- |
|
219 |
// Delete the completed operation object and close the read stream. |
|
220 |
// --------------------------------------------------------------------------- |
|
221 |
||
222 |
void CImportStoreListObserver::ContactsSaved( MVPbkContactOperationBase& aOp, |
|
223 |
MVPbkContactLinkArray* aResults ) |
|
224 |
{ |
|
225 |
delete &aOp; |
|
226 |
iOp = NULL; |
|
227 |
iContactService->RequestComplete(iTransId); |
|
228 |
delete aResults; |
|
229 |
iCallback->HandleReturnValue(EOpComplete, KErrNone,iTransId); |
|
230 |
delete this; |
|
231 |
} |
|
232 |
||
233 |
||
234 |
// --------------------------------------------------------------------------- |
|
235 |
// Delete the completed operation object and close the read stream. |
|
236 |
// --------------------------------------------------------------------------- |
|
237 |
||
238 |
void CImportStoreListObserver::ContactsSavingFailed( |
|
239 |
MVPbkContactOperationBase& aOperation, TInt aError ) |
|
240 |
{ |
|
241 |
delete &aOperation; |
|
242 |
iOp = NULL; |
|
243 |
iContactService->RequestComplete(iTransId); |
|
244 |
iCallback->HandleReturnValue(EOpError, aError,iTransId); |
|
245 |
delete this; |
|
246 |
} |