63
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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 "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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "cpbk2openmycardcmd.h"
|
|
21 |
#include "cpbk2mycard.h"
|
|
22 |
#include <CPbk2NamesListControl.h>
|
|
23 |
#include <MPbk2CommandObserver.h>
|
|
24 |
#include <MVPbkBaseContact.h>
|
|
25 |
#include <ccappmycardpluginuids.hrh>
|
|
26 |
#include <spbcontactdatamodel.h>
|
|
27 |
#include <pbk2exnameslistres.rsg>
|
|
28 |
#include <CPbk2FieldPropertyArray.h>
|
|
29 |
#include <CPbk2StoreSpecificFieldPropertyArray.h>
|
|
30 |
#include <CPbk2PresentationContact.h>
|
|
31 |
#include <CPbk2StorePropertyArray.h>
|
|
32 |
#include <MVPbkContactStoreProperties.h>
|
|
33 |
#include <MVPbkContactStore.h>
|
|
34 |
|
|
35 |
//Cca
|
|
36 |
#include <mccaparameter.h>
|
|
37 |
#include <mccaconnection.h>
|
|
38 |
#include <ccafactory.h>
|
|
39 |
|
|
40 |
#include <s32mem.h>
|
|
41 |
|
|
42 |
// Debugging headers
|
|
43 |
#include <Pbk2Debug.h>
|
|
44 |
#include <Pbk2Profile.h>
|
|
45 |
|
|
46 |
// --------------------------------------------------------------------------
|
|
47 |
// CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd
|
|
48 |
// --------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CPbk2OpenMyCardCmd::CPbk2OpenMyCardCmd(
|
|
51 |
MPbk2ContactUiControl* aUiControl,
|
|
52 |
CPbk2MyCard* aMyCard,
|
|
53 |
MCCAConnection*& aCCAConnection ) :
|
|
54 |
CActive( EPriorityStandard ),
|
|
55 |
iUiControl( aUiControl ),
|
|
56 |
iConnectionRef(aCCAConnection),
|
|
57 |
iViewUid( TUid::Uid( KCCAMyCardPluginImplmentationUid ) ), // default mycard view
|
|
58 |
iMyCard( aMyCard )
|
|
59 |
{
|
|
60 |
CActiveScheduler::Add( this );
|
|
61 |
}
|
|
62 |
|
|
63 |
// --------------------------------------------------------------------------
|
|
64 |
// CPbk2OpenMyCardCmd::~CPbk2OpenMyCardCmd
|
|
65 |
// --------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CPbk2OpenMyCardCmd::~CPbk2OpenMyCardCmd()
|
|
68 |
{
|
|
69 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
70 |
("CPbk2OpenMyCardCmd(%x)::~CPbk2OpenMyCardCmd()"), this);
|
|
71 |
Cancel();
|
|
72 |
|
|
73 |
if( iUiControl )
|
|
74 |
{
|
|
75 |
iUiControl->RegisterCommand( NULL );
|
|
76 |
}
|
|
77 |
delete iPresentationContact;
|
|
78 |
delete iSpecificFieldProperties;
|
|
79 |
delete iFieldProperties;
|
|
80 |
}
|
|
81 |
|
|
82 |
// --------------------------------------------------------------------------
|
|
83 |
// CPbk2OpenMyCardCmd::NewL
|
|
84 |
// --------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
CPbk2OpenMyCardCmd* CPbk2OpenMyCardCmd::NewL(
|
|
87 |
MCCAConnection*& aCCAConnection,
|
|
88 |
CPbk2MyCard* aMyCard,
|
|
89 |
MPbk2ContactUiControl* aUiControl )
|
|
90 |
{
|
|
91 |
CPbk2OpenMyCardCmd* self = new ( ELeave ) CPbk2OpenMyCardCmd(
|
|
92 |
aUiControl, aMyCard, aCCAConnection );
|
|
93 |
CleanupStack::PushL( self );
|
|
94 |
self->ConstructL();
|
|
95 |
CleanupStack::Pop( self );
|
|
96 |
return self;
|
|
97 |
}
|
|
98 |
|
|
99 |
// --------------------------------------------------------------------------
|
|
100 |
// CPbk2OpenMyCardCmd::ConstructL
|
|
101 |
// --------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
void CPbk2OpenMyCardCmd::ConstructL()
|
|
104 |
{
|
|
105 |
if( iUiControl )
|
|
106 |
{
|
|
107 |
iUiControl->RegisterCommand( this );
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
// --------------------------------------------------------------------------
|
|
112 |
// CPbk2OpenMyCardCmd::SetViewUid
|
|
113 |
// --------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
void CPbk2OpenMyCardCmd::SetViewUid( TUid aViewUid )
|
|
116 |
{
|
|
117 |
iViewUid = aViewUid;
|
|
118 |
}
|
|
119 |
|
|
120 |
// --------------------------------------------------------------------------
|
|
121 |
// CPbk2OpenMyCardCmd::ExecuteLD
|
|
122 |
// --------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
void CPbk2OpenMyCardCmd::ExecuteLD()
|
|
125 |
{
|
|
126 |
iState = ELaunching;
|
|
127 |
IssueRequest();
|
|
128 |
}
|
|
129 |
|
|
130 |
// --------------------------------------------------------------------------
|
|
131 |
// CPbk2OpenMyCardCmd::ResetUiControl
|
|
132 |
// --------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void CPbk2OpenMyCardCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl )
|
|
135 |
{
|
|
136 |
if ( iUiControl == &aUiControl )
|
|
137 |
{
|
|
138 |
iUiControl = NULL;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
// --------------------------------------------------------------------------
|
|
143 |
// CPbk2OpenMyCardCmd::AddObserver
|
|
144 |
// --------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CPbk2OpenMyCardCmd::AddObserver( MPbk2CommandObserver& aObserver )
|
|
147 |
{
|
|
148 |
iCommandObserver = &aObserver;
|
|
149 |
}
|
|
150 |
|
|
151 |
// --------------------------------------------------------------------------
|
|
152 |
// CPbk2OpenMyCardCmd::LaunchCcaL
|
|
153 |
// --------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CPbk2OpenMyCardCmd::LaunchCcaL()
|
|
156 |
{
|
|
157 |
if(!iConnectionRef)
|
|
158 |
{
|
|
159 |
iConnectionRef = TCCAFactory::NewConnectionL();
|
|
160 |
}
|
|
161 |
|
|
162 |
MCCAParameter* parameter = TCCAFactory::NewParameterL();
|
|
163 |
CleanupClosePushL( *parameter );
|
|
164 |
parameter->SetConnectionFlag( MCCAParameter::ENormal );
|
|
165 |
parameter->SetLaunchedViewUid( iViewUid );
|
|
166 |
|
|
167 |
if( iMyCard )
|
|
168 |
{
|
|
169 |
// Speed up mycard launching by constructing the view model here.
|
|
170 |
// This information is not mandatory for mycard launching however.
|
|
171 |
if( iMyCard->MyCardState() == CPbk2MyCard::EExisting )
|
|
172 |
{
|
|
173 |
CPbk2PresentationContact* contact = PresentationContactL();
|
|
174 |
if( contact )
|
|
175 |
{
|
|
176 |
// preset contact data model to contain my cards data.
|
|
177 |
SetContactDataL( *parameter, contact );
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
// special case when we have mycard but it's not loaded yet.
|
|
182 |
SetContactDataL( *parameter, iMyCard->MyCardLink() );
|
|
183 |
}
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
// My card does not exist. Give empty model as parameter.
|
|
188 |
SetContactDataL( *parameter );
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
// Sync call
|
|
193 |
iConnectionRef->LaunchAppL( *parameter );
|
|
194 |
CleanupStack::Pop();// parameter is taken care by iConnectionRef
|
|
195 |
|
|
196 |
iState = ERunning;
|
|
197 |
IssueRequest();
|
|
198 |
}
|
|
199 |
|
|
200 |
// --------------------------------------------------------------------------
|
|
201 |
// CPbk2OpenMyCardCmd::SetContactDataL
|
|
202 |
// --------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
void CPbk2OpenMyCardCmd::SetContactDataL( MCCAParameter& aParam, MVPbkContactLink* aLink )
|
|
205 |
{
|
|
206 |
if( aLink )
|
|
207 |
{
|
|
208 |
HBufC8* link8 = aLink->PackLC();
|
|
209 |
HBufC16* link16 = HBufC16::NewLC( link8->Length() );
|
|
210 |
link16->Des().Copy( *link8 );
|
|
211 |
aParam.SetContactDataFlag( MCCAParameter::EContactLink );
|
|
212 |
aParam.SetContactDataL( link16->Des() );
|
|
213 |
CleanupStack::PopAndDestroy( 2, link8 );
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
// --------------------------------------------------------------------------
|
|
218 |
// CPbk2OpenMyCardCmd::SetContactDataL
|
|
219 |
// --------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
void CPbk2OpenMyCardCmd::SetContactDataL( MCCAParameter& aParam, CPbk2PresentationContact* aContact )
|
|
222 |
{
|
|
223 |
CBufFlat* buffer = CBufFlat::NewL( KKilo );
|
|
224 |
CleanupStack::PushL( buffer );
|
|
225 |
RBufWriteStream stream( *buffer );
|
|
226 |
CleanupClosePushL( stream );
|
|
227 |
|
|
228 |
// create model and dump it into stream
|
|
229 |
CSpbContactDataModel* model = CSpbContactDataModel::NewL(
|
|
230 |
iMyCard->ContactManager(), *CCoeEnv::Static(),
|
|
231 |
R_PBK2_MYCARD_FIELD_CLIP_SELECTOR );
|
|
232 |
CleanupStack::PushL( model );
|
|
233 |
|
|
234 |
if( aContact )
|
|
235 |
{
|
|
236 |
model->SetDataL( *aContact, NULL );
|
|
237 |
}
|
|
238 |
|
|
239 |
model->ExternalizeL( stream );
|
|
240 |
CleanupStack::PopAndDestroy( 2, &stream ); // model
|
|
241 |
|
|
242 |
// set model dump as parameter
|
|
243 |
TPtrC8 buf( buffer->Ptr( 0 ) );
|
|
244 |
TPtrC16 data( (TUint16*)buf.Ptr(), ( buf.Size() + 1 ) / 2 );
|
|
245 |
aParam.SetContactDataFlag( MCCAParameter::EContactDataModel );
|
|
246 |
aParam.SetContactDataL( data );
|
|
247 |
CleanupStack::PopAndDestroy( buffer );
|
|
248 |
}
|
|
249 |
|
|
250 |
// --------------------------------------------------------------------------
|
|
251 |
// CPbk2OpenMyCardCmd::IssueRequest
|
|
252 |
// --------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
void CPbk2OpenMyCardCmd::IssueRequest()
|
|
255 |
{
|
|
256 |
TRequestStatus* status = &iStatus;
|
|
257 |
User::RequestComplete( status, KErrNone );
|
|
258 |
SetActive();
|
|
259 |
}
|
|
260 |
|
|
261 |
// ---------------------------------------------------------------------------
|
|
262 |
// CPbk2OpenMyCardCmd::PresentationContactL
|
|
263 |
// ---------------------------------------------------------------------------
|
|
264 |
//
|
|
265 |
CPbk2PresentationContact* CPbk2OpenMyCardCmd::PresentationContactL()
|
|
266 |
{
|
|
267 |
if( !iPresentationContact )
|
|
268 |
{
|
|
269 |
if( !iMyCard )
|
|
270 |
{
|
|
271 |
return NULL;
|
|
272 |
}
|
|
273 |
|
|
274 |
MVPbkStoreContact* storeContact = iMyCard->MyCardStoreContact();
|
|
275 |
if( !storeContact )
|
|
276 |
{
|
|
277 |
return NULL;
|
|
278 |
}
|
|
279 |
|
|
280 |
const MVPbkContactStoreProperties& storeProperties =
|
|
281 |
storeContact->ParentStore().StoreProperties();
|
|
282 |
const MVPbkFieldTypeList& supportedFieldTypes =
|
|
283 |
storeProperties.SupportedFields();
|
|
284 |
|
|
285 |
if( !iFieldProperties )
|
|
286 |
{
|
|
287 |
iFieldProperties = CPbk2FieldPropertyArray::NewL(
|
|
288 |
supportedFieldTypes, CCoeEnv::Static()->FsSession() );
|
|
289 |
}
|
|
290 |
|
|
291 |
// Create a field property list of the supported
|
|
292 |
// field types of the used store
|
|
293 |
CPbk2StorePropertyArray* pbk2StoreProperties = CPbk2StorePropertyArray::NewL();
|
|
294 |
CleanupStack::PushL( pbk2StoreProperties );
|
|
295 |
|
|
296 |
if( !iSpecificFieldProperties )
|
|
297 |
{
|
|
298 |
iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL(
|
|
299 |
*iFieldProperties,
|
|
300 |
*pbk2StoreProperties,
|
|
301 |
supportedFieldTypes,
|
|
302 |
storeContact->ParentStore() );
|
|
303 |
}
|
|
304 |
|
|
305 |
iPresentationContact = CPbk2PresentationContact::NewL(
|
|
306 |
*storeContact, *iSpecificFieldProperties );
|
|
307 |
|
|
308 |
CleanupStack::PopAndDestroy( pbk2StoreProperties );
|
|
309 |
}
|
|
310 |
return iPresentationContact;
|
|
311 |
}
|
|
312 |
|
|
313 |
|
|
314 |
// --------------------------------------------------------------------------
|
|
315 |
// CPbk2OpenMyCardCmd::IssueRequest
|
|
316 |
// --------------------------------------------------------------------------
|
|
317 |
//
|
|
318 |
void CPbk2OpenMyCardCmd::RunL()
|
|
319 |
{
|
|
320 |
if ( iState == ELaunching )
|
|
321 |
{
|
|
322 |
LaunchCcaL(); //Sync
|
|
323 |
}
|
|
324 |
else if ( iState == ERunning )
|
|
325 |
{
|
|
326 |
if ( iUiControl )
|
|
327 |
{
|
|
328 |
iUiControl->UpdateAfterCommandExecution();
|
|
329 |
}
|
|
330 |
// Asynchronous delete of this command object
|
|
331 |
if( iCommandObserver )
|
|
332 |
{
|
|
333 |
iCommandObserver->CommandFinished( *this );
|
|
334 |
}
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
// --------------------------------------------------------------------------
|
|
339 |
// CPbk2OpenMyCardCmd::IssueRequest
|
|
340 |
// --------------------------------------------------------------------------
|
|
341 |
//
|
|
342 |
void CPbk2OpenMyCardCmd::DoCancel()
|
|
343 |
{
|
|
344 |
// Do nothing
|
|
345 |
}
|
|
346 |
|
|
347 |
// --------------------------------------------------------------------------
|
|
348 |
// CPbk2OpenMyCardCmd::RunError
|
|
349 |
// --------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
TInt CPbk2OpenMyCardCmd::RunError(TInt aError)
|
|
352 |
{
|
|
353 |
// Forward all errors to the framework. They will be
|
|
354 |
// displayed on screen to the user. Typically there
|
|
355 |
// should not be any errors.
|
|
356 |
|
|
357 |
return aError;
|
|
358 |
}
|
|
359 |
|
|
360 |
// End of File
|