5
|
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 export observer for the Contacts Service API.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include "exportstorelistobserver.h"
|
|
21 |
|
|
22 |
#include <cvpbkvcardeng.h>//for the vcard engin
|
|
23 |
#include <cvpbkcontactmanager.h>// for iContactManager
|
|
24 |
#include <mvpbkcontactstore.h>// for iContactStore
|
|
25 |
#include <tvpbkcontactstoreuriPtr.h>//used in SetupL
|
|
26 |
#include <mvpbkcontactstorelist.h>//used in SetupL to get contact stores
|
|
27 |
#include <mvpbkstorecontactfield.h>//used in AddFieldToContactL
|
|
28 |
#include <mvpbkstorecontact.h>// used in many function to get the store contact
|
|
29 |
#include <mvpbkcontactfieldtextdata.h>//for the field text data
|
|
30 |
#include <tvpbkfieldtypemapping.h>//used in CreateFieldTypeL()
|
|
31 |
#include <mvpbkfieldtype.h>//return type of CreateFieldTypeL()
|
|
32 |
#include <mvpbkcontactoperationbase.h>//for observer
|
|
33 |
#include <mvpbkcontactfielddatetimedata.h>//Used in AddDateFieldToContactL
|
|
34 |
#include <mvpbkcontactlink.h>//for param in ContactsSaved()
|
|
35 |
#include <cvpbkcontactstoreuriarray.h>//used in SetupL
|
|
36 |
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// Static method to create an instance of the export store list observer.
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CExportStoreListObserver* CExportStoreListObserver::NewL(CContactService* aContactService,RFs &aFs,const TFileName& aFileName, const TDesC8& aContactId,MContactCallback *aCallback, TInt aTransId)
|
|
43 |
{
|
|
44 |
CExportStoreListObserver* self = new( ELeave ) CExportStoreListObserver( );
|
|
45 |
CleanupStack::PushL(self);
|
|
46 |
self->ConstructL(aContactService,aFs,aFileName,aContactId,aCallback, aTransId );
|
|
47 |
CleanupStack::Pop(self);
|
|
48 |
return self;
|
|
49 |
|
|
50 |
}
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
// Destructor
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
CExportStoreListObserver::~CExportStoreListObserver()
|
|
56 |
{
|
|
57 |
iDest.Close();
|
|
58 |
delete iLinkArray;
|
|
59 |
if(iOp)
|
|
60 |
{
|
|
61 |
delete iOp;
|
|
62 |
}
|
|
63 |
if(iContactStore)
|
|
64 |
{
|
|
65 |
iContactStore->Close(*this);
|
|
66 |
}
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
// Constructor
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
CExportStoreListObserver::CExportStoreListObserver()
|
|
74 |
{
|
|
75 |
|
|
76 |
}
|
|
77 |
|
|
78 |
//----------------------------------------------------------------------------
|
|
79 |
// Symbian Second phase constructor
|
|
80 |
//----------------------------------------------------------------------------
|
|
81 |
|
|
82 |
void CExportStoreListObserver::ConstructL( CContactService* aContactService, RFs &aFs,const TFileName& aFileName,const TDesC8& aContactId,MContactCallback *aCallback, TInt aTransId)
|
|
83 |
{
|
|
84 |
iFs=aFs;
|
|
85 |
iFileName=aFileName;
|
|
86 |
|
|
87 |
iLinkArray = (&(aContactService->GetContactManager()))->CreateLinksLC(aContactId);
|
|
88 |
iContactLink = &(iLinkArray->At(0));
|
|
89 |
|
|
90 |
iCallback=aCallback;
|
|
91 |
iTransId = aTransId;
|
|
92 |
iOp = NULL;
|
|
93 |
CleanupStack::Pop(); //iLinkArray
|
|
94 |
}
|
|
95 |
/*
|
|
96 |
-------------------------------------------------------------------------------------
|
|
97 |
CExportStoreListObserver::Cancel()
|
|
98 |
Description : Cancel implementation relevant to Export Observer
|
|
99 |
Return values : KErrorNone on Success and KErrGeneral on Failure
|
|
100 |
-------------------------------------------------------------------------------------
|
|
101 |
*/
|
|
102 |
|
|
103 |
void CExportStoreListObserver::Cancel()
|
|
104 |
{
|
|
105 |
iCallback->HandleReturnValue(EOpCancel, KErrNone, iTransId);
|
|
106 |
delete this;
|
|
107 |
}
|
|
108 |
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
// Method to set vcard engine.
|
|
111 |
// ---------------------------------------------------------------------------
|
|
112 |
|
|
113 |
void CExportStoreListObserver::SetEngine(CVPbkVCardEng* aEngine)
|
|
114 |
{
|
|
115 |
iEngine=aEngine;
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
// Method to set the contact store.
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
|
|
122 |
void CExportStoreListObserver::SetContactStore(MVPbkContactStore* aContactStore)
|
|
123 |
{
|
|
124 |
iContactStore=aContactStore;
|
|
125 |
}
|
|
126 |
|
|
127 |
//----------------------------------------------------------------------------
|
|
128 |
// Method to set the contact service
|
|
129 |
//----------------------------------------------------------------------------
|
|
130 |
void CExportStoreListObserver::SetContactService(CContactService* aContactService)
|
|
131 |
{
|
|
132 |
iContactService = aContactService;
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
// Called when OpenL async call is successfull.
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
|
|
139 |
void CExportStoreListObserver::StoreReady( MVPbkContactStore& /* aContactStore */)
|
|
140 |
{
|
|
141 |
TInt error;
|
|
142 |
error = iDest.Create( iFs, iFileName, EFileWrite );
|
|
143 |
if(error != KErrNone)
|
|
144 |
{
|
|
145 |
iContactService->RequestComplete(iTransId);
|
|
146 |
iCallback->HandleReturnValue( EOpComplete, error, iTransId );
|
|
147 |
delete this;
|
|
148 |
}
|
|
149 |
else
|
|
150 |
{
|
|
151 |
TRAPD(err,iOp = iEngine->ExportVCardL( iDest, *iContactLink, *this ));
|
|
152 |
if( err!=KErrNone )
|
|
153 |
{
|
|
154 |
iContactService->RequestComplete(iTransId);
|
|
155 |
iCallback->HandleReturnValue(EOpComplete, err,iTransId);
|
|
156 |
delete this;
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
// ---------------------------------------------------------------------------
|
|
162 |
// Called when OpenL is failed.
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
|
|
165 |
void CExportStoreListObserver::StoreUnavailable(
|
|
166 |
MVPbkContactStore& /*aContactStore*/,
|
|
167 |
TInt aReason )
|
|
168 |
{
|
|
169 |
iContactService->RequestComplete(iTransId);
|
|
170 |
iCallback->HandleReturnValue(EOpError, aReason, iTransId );
|
|
171 |
delete this;
|
|
172 |
}
|
|
173 |
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
// ---------------------------------------------------------------------------
|
|
177 |
|
|
178 |
void CExportStoreListObserver::HandleStoreEventL(
|
|
179 |
MVPbkContactStore& /*aContactStore*/,
|
|
180 |
TVPbkContactStoreEvent /*aStoreEvent*/ )
|
|
181 |
{
|
|
182 |
// Indication not needed.
|
|
183 |
}
|
|
184 |
|
|
185 |
void CExportStoreListObserver::OpenComplete()
|
|
186 |
{
|
|
187 |
// Indication not needed.
|
|
188 |
}
|
|
189 |
|
|
190 |
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
// Delete the completed operation object and close the write stream.
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
|
|
195 |
void CExportStoreListObserver::VPbkSingleContactOperationComplete(
|
|
196 |
MVPbkContactOperationBase& aOperation,
|
|
197 |
MVPbkStoreContact* )
|
|
198 |
{
|
|
199 |
delete &aOperation;
|
|
200 |
iOp = NULL;
|
|
201 |
iContactService->RequestComplete(iTransId);
|
|
202 |
iCallback->HandleReturnValue(EOpComplete, KErrNone,iTransId);
|
|
203 |
delete this;
|
|
204 |
}
|
|
205 |
|
|
206 |
// ---------------------------------------------------------------------------
|
|
207 |
// Delete the completed operation object and close the write stream.
|
|
208 |
// ---------------------------------------------------------------------------
|
|
209 |
|
|
210 |
void CExportStoreListObserver::VPbkSingleContactOperationFailed(
|
|
211 |
MVPbkContactOperationBase& aOperation, TInt aError )
|
|
212 |
{
|
|
213 |
delete &aOperation;
|
|
214 |
iOp = NULL;
|
|
215 |
iContactService->RequestComplete(iTransId);
|
|
216 |
iCallback->HandleReturnValue( EOpError, aError, iTransId );
|
|
217 |
delete this;
|
|
218 |
}
|