63
|
1 |
/*
|
|
2 |
* Copyright (c) 2009-2009 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: Implementation of MyCard
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "ccappmycard.h"
|
|
20 |
#include "ccappmycardcommon.h"
|
|
21 |
|
|
22 |
// System
|
|
23 |
#include <coemain.h>
|
|
24 |
#include <f32file.h>
|
|
25 |
#include <avkon.hrh>
|
|
26 |
#include <eikenv.h>
|
|
27 |
#include <aknViewAppUi.h>
|
|
28 |
|
|
29 |
// Virtual phonebook
|
|
30 |
#include <CVPbkContactManager.h>
|
|
31 |
#include <CVPbkContactStoreUriArray.h>
|
|
32 |
#include <MVPbkContactStoreProperties.h>
|
|
33 |
#include <VPbkContactStoreUris.h>
|
|
34 |
#include <MVPbkContactStoreList.h>
|
|
35 |
#include <MVPbkContactStore.h>
|
|
36 |
#include <TVPbkContactStoreUriPtr.h>
|
|
37 |
#include <MVPbkContactStore2.h>
|
|
38 |
#include <MVPbkContactOperationBase.h>
|
|
39 |
#include <MVPbkStoreContact2.h>
|
|
40 |
#include <MVPbkStoreContact.h>
|
|
41 |
#include <MVPbkContactLink.h>
|
|
42 |
#include <VPbkEng.rsg>
|
|
43 |
#include <MVPbkFieldType.h>
|
|
44 |
#include <MVPbkContactFieldTextData.h>
|
|
45 |
#include <MVPbkContactFieldUriData.h>
|
|
46 |
|
|
47 |
// Phonebook 2
|
|
48 |
#include <CPbk2StorePropertyArray.h>
|
|
49 |
#include <CPbk2PresentationContact.h>
|
|
50 |
#include <CPbk2StoreSpecificFieldPropertyArray.h>
|
|
51 |
#include <CPbk2FieldPropertyArray.h>
|
|
52 |
#include <CPbk2SortOrderManager.h>
|
|
53 |
#include <Pbk2ContactNameFormatterFactory.h>
|
|
54 |
#include <MPbk2ContactNameFormatter.h>
|
|
55 |
#include <CPbk2ApplicationServices.h>
|
|
56 |
#include <CPbk2StoreManager.h>
|
|
57 |
#include <CPbk2StoreConfiguration.h>
|
|
58 |
#include <CPbk2ContactEditorDlg.h>
|
|
59 |
#include <MVPbkBaseContactField.h>
|
|
60 |
|
|
61 |
// internal
|
|
62 |
#include "ccappmycardplugin.h"
|
|
63 |
#include <ccappmycardpluginrsc.rsg>
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Helper class for making delayed callbacks
|
|
67 |
* @see public methods of CTimer for help
|
|
68 |
*/
|
|
69 |
class CTimerCallBack : public CTimer
|
|
70 |
{
|
|
71 |
public:
|
|
72 |
/**
|
|
73 |
* @param aCallBack called when CTimer is due to run
|
|
74 |
* @param aPriority priority of CTimer
|
|
75 |
*/
|
|
76 |
static CTimerCallBack* NewL(
|
|
77 |
const TCallBack& aCallBack,
|
|
78 |
CActive::TPriority aPriority = CActive::EPriorityIdle );
|
|
79 |
|
|
80 |
protected: // From CActive
|
|
81 |
void RunL();
|
|
82 |
TInt RunError( TInt /*aError*/ );
|
|
83 |
|
|
84 |
protected:
|
|
85 |
CTimerCallBack( const TCallBack& aCallBack, CActive::TPriority aPriority );
|
|
86 |
|
|
87 |
private: // data
|
|
88 |
TCallBack iCallBack;
|
|
89 |
};
|
|
90 |
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// CTimerCallBack::NewL
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
CTimerCallBack* CTimerCallBack::NewL(
|
|
97 |
const TCallBack& aCallBack,
|
|
98 |
CActive::TPriority aPriority )
|
|
99 |
{
|
|
100 |
CTimerCallBack* self = new(ELeave) CTimerCallBack( aCallBack, aPriority );
|
|
101 |
CleanupStack::PushL( self );
|
|
102 |
self->ConstructL();
|
|
103 |
CleanupStack::Pop( self );
|
|
104 |
return self;
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
// CTimerCallBack::RunL
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
CTimerCallBack::CTimerCallBack( const TCallBack& aCallBack, CActive::TPriority aPriority ) :
|
|
112 |
CTimer( aPriority ), iCallBack( aCallBack )
|
|
113 |
{
|
|
114 |
CActiveScheduler::Add( this );
|
|
115 |
}
|
|
116 |
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
// CTimerCallBack::RunL
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
void CTimerCallBack::RunL()
|
|
122 |
{
|
|
123 |
iCallBack.CallBack();
|
|
124 |
}
|
|
125 |
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
// CTimerCallBack::RunError
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
TInt CTimerCallBack::RunError( TInt /*aError*/ )
|
|
131 |
{
|
|
132 |
// Leaves in RunL are ignored
|
|
133 |
return KErrNone;
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
// ======== MEMBER FUNCTIONS ========
|
|
138 |
|
|
139 |
// ---------------------------------------------------------------------------
|
|
140 |
// CCCAppMyCard::NewL
|
|
141 |
// ---------------------------------------------------------------------------
|
|
142 |
//
|
|
143 |
CCCAppMyCard* CCCAppMyCard::NewL( CCCAppMyCardPlugin& aPlugin, RFs* aFs )
|
|
144 |
{
|
|
145 |
CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::NewL()"));
|
|
146 |
|
|
147 |
CCCAppMyCard* self = new ( ELeave ) CCCAppMyCard( aPlugin );
|
|
148 |
CleanupStack::PushL( self );
|
|
149 |
self->ConstructL(aFs);
|
|
150 |
CleanupStack::Pop( self );
|
|
151 |
|
|
152 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::NewL()"));
|
|
153 |
return self;
|
|
154 |
}
|
|
155 |
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
// CCCAppMyCard::~CCCAppMyCard
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
CCCAppMyCard::~CCCAppMyCard()
|
|
161 |
{
|
|
162 |
CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::~CCCAppMyCard()"));
|
|
163 |
|
|
164 |
delete iOperation;
|
|
165 |
delete iFetchOperation;
|
|
166 |
delete iMyCard;
|
|
167 |
delete iPresentationContact;
|
|
168 |
delete iMyCardContact;
|
|
169 |
delete iFieldProperties;
|
|
170 |
delete iSpecificFieldProperties;
|
|
171 |
|
|
172 |
iObservers.Reset();
|
|
173 |
|
|
174 |
if( iAppServices )
|
|
175 |
{
|
|
176 |
iAppServices->StoreManager().DeregisterStoreEvents(*this);
|
|
177 |
}
|
|
178 |
Release(iAppServices);
|
|
179 |
|
|
180 |
delete iCloseCallBack;
|
|
181 |
delete iCreateCallBack;
|
|
182 |
delete iDlgCloseCallBack;
|
|
183 |
delete iStoreCallBack;
|
|
184 |
|
|
185 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::~CCCAppMyCard()"));
|
|
186 |
}
|
|
187 |
|
|
188 |
// ---------------------------------------------------------------------------
|
|
189 |
// CCCAppMyCard::CCCAppMyCard()
|
|
190 |
// ---------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
inline CCCAppMyCard::CCCAppMyCard( CCCAppMyCardPlugin& aPlugin )
|
|
193 |
: iPlugin( aPlugin ), iEvent( MMyCardObserver::EEventContactLoaded )
|
|
194 |
|
|
195 |
{
|
|
196 |
}
|
|
197 |
|
|
198 |
// ---------------------------------------------------------------------------
|
|
199 |
// CCCAppMyCard::ConstructL
|
|
200 |
// ---------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
inline void CCCAppMyCard::ConstructL( RFs* /*aFs*/ )
|
|
203 |
{
|
|
204 |
// Get the AppServices instance
|
|
205 |
iAppServices = CPbk2ApplicationServices::InstanceL();
|
|
206 |
|
|
207 |
CPbk2StoreManager& storeManager = iAppServices->StoreManager();
|
|
208 |
iVPbkContactManager = &iAppServices->ContactManager();
|
|
209 |
storeManager.RegisterStoreEventsL( *this );
|
|
210 |
storeManager.EnsureDefaultSavingStoreIncludedL();
|
|
211 |
|
|
212 |
iCloseCallBack = new(ELeave) CAsyncCallBack(
|
|
213 |
TCallBack( CloseCcaL, this ), CActive::EPriorityIdle );
|
|
214 |
iCreateCallBack = new(ELeave) CAsyncCallBack(
|
|
215 |
TCallBack( CreateMyCardContact, this ), CActive::EPriorityHigh );
|
|
216 |
iDlgCloseCallBack = new(ELeave) CAsyncCallBack(
|
|
217 |
TCallBack( ExitDlgL, this ), CActive::EPriorityHigh );
|
|
218 |
}
|
|
219 |
|
|
220 |
// ---------------------------------------------------------------------------
|
|
221 |
// CCCAppMyCard::PresentationContactL
|
|
222 |
// ---------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
CPbk2PresentationContact& CCCAppMyCard::PresentationContactL()
|
|
225 |
{
|
|
226 |
if( !iPresentationContact )
|
|
227 |
{
|
|
228 |
if( !iMyCardContact )
|
|
229 |
{
|
|
230 |
// own contact not loaded
|
|
231 |
User::Leave( KErrNotReady );
|
|
232 |
}
|
|
233 |
|
|
234 |
const MVPbkContactStoreProperties& storeProperties =
|
|
235 |
iMyCardContact->ParentStore().StoreProperties();
|
|
236 |
const MVPbkFieldTypeList& supportedFieldTypes =
|
|
237 |
storeProperties.SupportedFields();
|
|
238 |
|
|
239 |
if( !iFieldProperties )
|
|
240 |
{
|
|
241 |
iFieldProperties = CPbk2FieldPropertyArray::NewL(
|
|
242 |
supportedFieldTypes, iVPbkContactManager->FsSession() );
|
|
243 |
}
|
|
244 |
|
|
245 |
// Create a field property list of the supported
|
|
246 |
// field types of the used store
|
|
247 |
CPbk2StorePropertyArray* pbk2StoreProperties = CPbk2StorePropertyArray::NewL();
|
|
248 |
CleanupStack::PushL( pbk2StoreProperties );
|
|
249 |
|
|
250 |
if( !iSpecificFieldProperties )
|
|
251 |
{
|
|
252 |
iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL(
|
|
253 |
*iFieldProperties,
|
|
254 |
*pbk2StoreProperties,
|
|
255 |
supportedFieldTypes,
|
|
256 |
iMyCardContact->ParentStore() );
|
|
257 |
}
|
|
258 |
|
|
259 |
iPresentationContact = CPbk2PresentationContact::NewL(
|
|
260 |
*iMyCardContact, *iSpecificFieldProperties );
|
|
261 |
|
|
262 |
CleanupStack::PopAndDestroy( pbk2StoreProperties );
|
|
263 |
}
|
|
264 |
|
|
265 |
return *iPresentationContact;
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------------------------
|
|
269 |
// CCCAppMyCard::StoreContact
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
MVPbkStoreContact& CCCAppMyCard::StoreContact()
|
|
273 |
{
|
|
274 |
__ASSERT_ALWAYS( iMyCardContact, Panic( ECCAppMyCardPanicContactNotReady ) );
|
|
275 |
return *iMyCardContact;
|
|
276 |
}
|
|
277 |
|
|
278 |
// ---------------------------------------------------------------------------
|
|
279 |
// CCCAppMyCard::ContactManager
|
|
280 |
// ---------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
CVPbkContactManager& CCCAppMyCard::ContactManager()
|
|
283 |
{
|
|
284 |
return *iVPbkContactManager;
|
|
285 |
}
|
|
286 |
|
|
287 |
// ---------------------------------------------------------------------------
|
|
288 |
// CCCAppMyCard::IsContactLinkReady
|
|
289 |
// ---------------------------------------------------------------------------
|
|
290 |
//
|
|
291 |
TBool CCCAppMyCard::IsContactLinkReady() const
|
|
292 |
{
|
|
293 |
return iMyCard != NULL;
|
|
294 |
}
|
|
295 |
|
|
296 |
// ---------------------------------------------------------------------------
|
|
297 |
// CCCAppMyCard::ContactLink
|
|
298 |
// ---------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
MVPbkContactLink& CCCAppMyCard::ContactLink()
|
|
301 |
{
|
|
302 |
__ASSERT_ALWAYS( iMyCard, Panic( ECCAppMyCardPanicLinkNotReady ) );
|
|
303 |
return *iMyCard;
|
|
304 |
}
|
|
305 |
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
// CCCAppMyCard::AddObserverL
|
|
308 |
// ---------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void CCCAppMyCard::AddObserverL( MMyCardObserver* aObserver )
|
|
311 |
{
|
|
312 |
if( aObserver )
|
|
313 |
{
|
|
314 |
TInt index = iObservers.Find( aObserver );
|
|
315 |
if( index == KErrNotFound )
|
|
316 |
{
|
|
317 |
iObservers.AppendL( aObserver );
|
|
318 |
if( iMyCardContact )
|
|
319 |
{
|
|
320 |
aObserver->MyCardEventL( MMyCardObserver::EEventContactLoaded );
|
|
321 |
}
|
|
322 |
}
|
|
323 |
}
|
|
324 |
}
|
|
325 |
|
|
326 |
// ---------------------------------------------------------------------------
|
|
327 |
// CCCAppMyCard::RemoveObserver
|
|
328 |
// ---------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
void CCCAppMyCard::RemoveObserver( MMyCardObserver* aObserver )
|
|
331 |
{
|
|
332 |
TInt index = iObservers.Find( aObserver );
|
|
333 |
if( index != KErrNotFound )
|
|
334 |
{
|
|
335 |
iObservers.Remove( index );
|
|
336 |
}
|
|
337 |
}
|
|
338 |
|
|
339 |
// ---------------------------------------------------------------------------
|
|
340 |
// CCCAppMyCard::SetLinkL
|
|
341 |
// ---------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
void CCCAppMyCard::SetLinkL( const MVPbkContactLink& aLink )
|
|
344 |
{
|
|
345 |
MVPbkContactLink* link = aLink.CloneLC();
|
|
346 |
CleanupStack::Pop(); // link
|
|
347 |
delete iMyCard;
|
|
348 |
iMyCard = link;
|
|
349 |
}
|
|
350 |
|
|
351 |
// ---------------------------------------------------------------------------
|
|
352 |
// CCCAppMyCard::FetchMyCardL
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
//
|
|
355 |
void CCCAppMyCard::FetchMyCardL()
|
|
356 |
{
|
|
357 |
if( !iStoreCallBack )
|
|
358 |
{
|
|
359 |
if ( !iMyCard && iForceCreateMyCard )
|
|
360 |
{
|
|
361 |
// Disable LSK if new contact will be created
|
|
362 |
// to avoid opening wrong menu
|
|
363 |
iPlugin.EnableOptionsMenu( EFalse );
|
|
364 |
}
|
|
365 |
|
|
366 |
iStoreCallBack = CTimerCallBack::NewL(
|
|
367 |
TCallBack( &CCCAppMyCard::OpenStoresL, this ) );
|
|
368 |
|
|
369 |
// 200 ms delay before open. Used to prevent system jamming before the
|
|
370 |
// UI is drawn, so that launching of mycard feels a lot faster.
|
|
371 |
iStoreCallBack->After( 200e3 );
|
|
372 |
}
|
|
373 |
}
|
|
374 |
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
// CCCAppMyCard::ForceCreateMyCard
|
|
377 |
// ---------------------------------------------------------------------------
|
|
378 |
//
|
|
379 |
void CCCAppMyCard::ForceCreateMyCard()
|
|
380 |
{
|
|
381 |
iForceCreateMyCard = ETrue;
|
|
382 |
}
|
|
383 |
|
|
384 |
// ---------------------------------------------------------------------------
|
|
385 |
// CCCAppMyCard::HeaderControlBlocked
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
TBool CCCAppMyCard::HeaderControlBlocked()
|
|
389 |
{
|
|
390 |
return iDialogIsRunning;
|
|
391 |
}
|
|
392 |
|
|
393 |
// ---------------------------------------------------------------------------
|
|
394 |
// CCCAppMyCard::NotifyObservers
|
|
395 |
// ---------------------------------------------------------------------------
|
|
396 |
//
|
|
397 |
void CCCAppMyCard::NotifyObservers( MMyCardObserver::TEvent aEvent ) const
|
|
398 |
{
|
|
399 |
TInt count = iObservers.Count();
|
|
400 |
for( TInt i = 0; i < count; i++ )
|
|
401 |
{
|
|
402 |
TRAPD( err, iObservers[i]->MyCardEventL( aEvent ) );
|
|
403 |
if( err )
|
|
404 |
{
|
|
405 |
CCA_DP(KMyCardLogFile,
|
|
406 |
CCA_L("<-CCCAppMyCard::NotifyObservers notify error (%d)"), err );
|
|
407 |
}
|
|
408 |
}
|
|
409 |
}
|
|
410 |
|
|
411 |
// ---------------------------------------------------------------------------
|
|
412 |
// CCCAppMyCard::LoadContact
|
|
413 |
// ---------------------------------------------------------------------------
|
|
414 |
//
|
|
415 |
void CCCAppMyCard::LoadContact()
|
|
416 |
{
|
|
417 |
CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::LoadContact()"));
|
|
418 |
|
|
419 |
if( !iFetchOperation && iMyCard )
|
|
420 |
{
|
|
421 |
TRAPD( err, iFetchOperation =
|
|
422 |
iVPbkContactManager->RetrieveContactL( *iMyCard, *this ) );
|
|
423 |
if( err )
|
|
424 |
{
|
|
425 |
// Cannot load own contact from VPbk
|
|
426 |
CCA_DP(KMyCardLogFile,
|
|
427 |
CCA_L(" CCCAppMyCard::LoadContact load error = %d"), err );
|
|
428 |
|
|
429 |
iPlugin.HandleError( err );
|
|
430 |
}
|
|
431 |
}
|
|
432 |
|
|
433 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::LoadContact()"));
|
|
434 |
}
|
|
435 |
|
|
436 |
// ---------------------------------------------------------------------------
|
|
437 |
// CCCAppMyCard::StoreReady
|
|
438 |
// ---------------------------------------------------------------------------
|
|
439 |
//
|
|
440 |
void CCCAppMyCard::StoreReady( MVPbkContactStore& aContactStore )
|
|
441 |
{
|
|
442 |
CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::StoreReady()"));
|
|
443 |
|
|
444 |
const MVPbkContactStoreProperties& storeProperties =
|
|
445 |
aContactStore.StoreProperties();
|
|
446 |
TVPbkContactStoreUriPtr uri = storeProperties.Uri();
|
|
447 |
TInt isSame = uri.Compare( VPbkContactStoreUris::DefaultCntDbUri(),
|
|
448 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents );
|
|
449 |
|
|
450 |
if( isSame != 0 )
|
|
451 |
{
|
|
452 |
return;
|
|
453 |
}
|
|
454 |
|
|
455 |
if( iMyCard )
|
|
456 |
{
|
|
457 |
// if link is already available then use that
|
|
458 |
LoadContact();
|
|
459 |
}
|
|
460 |
else if( iForceCreateMyCard )
|
|
461 |
{
|
|
462 |
// launch editor because we don't have mycard
|
|
463 |
iCreateCallBack->Call();
|
|
464 |
}
|
|
465 |
else
|
|
466 |
{
|
|
467 |
// MyCard is always created to contact model. So we check that event was
|
|
468 |
// from the correct store.
|
|
469 |
delete iOperation;
|
|
470 |
iOperation = NULL;
|
|
471 |
|
|
472 |
MVPbkContactStore2* phoneStoreExtension =
|
|
473 |
static_cast<MVPbkContactStore2*>(aContactStore.ContactStoreExtension(KMVPbkContactStoreExtension2Uid));
|
|
474 |
if ( phoneStoreExtension )
|
|
475 |
{
|
|
476 |
TRAPD( err, iOperation = phoneStoreExtension->OwnContactLinkL(*this) );
|
|
477 |
if( err )
|
|
478 |
{
|
|
479 |
iPlugin.HandleError( err );
|
|
480 |
}
|
|
481 |
}
|
|
482 |
}
|
|
483 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::StoreReady()"));
|
|
484 |
}
|
|
485 |
|
|
486 |
// ---------------------------------------------------------------------------
|
|
487 |
// CCCAppMyCard::StoreUnavailable
|
|
488 |
// ---------------------------------------------------------------------------
|
|
489 |
//
|
|
490 |
void CCCAppMyCard::StoreUnavailable(
|
|
491 |
MVPbkContactStore& /*aContactStore*/,
|
|
492 |
TInt /*aReason*/)
|
|
493 |
{
|
|
494 |
CCA_DP(KMyCardLogFile, CCA_L(" CCCAppMyCard::StoreUnavailable()"));
|
|
495 |
}
|
|
496 |
|
|
497 |
// ---------------------------------------------------------------------------
|
|
498 |
// CCCAppMyCard::HandleStoreEventL
|
|
499 |
// ---------------------------------------------------------------------------
|
|
500 |
//
|
|
501 |
void CCCAppMyCard::HandleStoreEventL(
|
|
502 |
MVPbkContactStore& /*aContactStore*/,
|
|
503 |
TVPbkContactStoreEvent aStoreEvent )
|
|
504 |
{
|
|
505 |
CCA_DP(KMyCardLogFile,
|
|
506 |
CCA_L("->CCCAppMyCard::HandleStoreEventL Event = %d"),
|
|
507 |
aStoreEvent.iEventType );
|
|
508 |
|
|
509 |
if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged )
|
|
510 |
{
|
|
511 |
if( iMyCard && aStoreEvent.iContactLink->IsSame( *iMyCard ) )
|
|
512 |
{
|
|
513 |
// Own contact has changed. Reload contact to update content
|
|
514 |
iEvent = MMyCardObserver::EEventContactChanged;
|
|
515 |
LoadContact();
|
|
516 |
}
|
|
517 |
}
|
|
518 |
else if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactDeleted )
|
|
519 |
{
|
|
520 |
if( iMyCard && aStoreEvent.iContactLink->IsSame( *iMyCard ) )
|
|
521 |
{
|
|
522 |
if( !iDialogIsRunning )
|
|
523 |
{
|
|
524 |
CEikAppUi* aEikAppUi = CEikonEnv::Static()->EikAppUi();
|
|
525 |
CAknViewAppUi* appUi = static_cast<CAknViewAppUi*> ( aEikAppUi );
|
|
526 |
appUi->RunAppShutter();
|
|
527 |
}
|
|
528 |
}
|
|
529 |
}
|
|
530 |
|
|
531 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::HandleStoreEventL()") );
|
|
532 |
}
|
|
533 |
|
|
534 |
// ---------------------------------------------------------------------------
|
|
535 |
// CCCAppMyCard::VPbkSingleContactLinkOperationComplete
|
|
536 |
// ---------------------------------------------------------------------------
|
|
537 |
//
|
|
538 |
void CCCAppMyCard::VPbkSingleContactLinkOperationComplete(
|
|
539 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
540 |
MVPbkContactLink* aLink )
|
|
541 |
{
|
|
542 |
CCA_DP(KMyCardLogFile,
|
|
543 |
CCA_L("->CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
|
|
544 |
|
|
545 |
delete iMyCard;
|
|
546 |
iMyCard = aLink;
|
|
547 |
|
|
548 |
LoadContact();
|
|
549 |
|
|
550 |
CCA_DP(KMyCardLogFile,
|
|
551 |
CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
|
|
552 |
}
|
|
553 |
|
|
554 |
// ---------------------------------------------------------------------------
|
|
555 |
// CCCAppMyCard::VPbkSingleContactLinkOperationFailed
|
|
556 |
// ---------------------------------------------------------------------------
|
|
557 |
//
|
|
558 |
void CCCAppMyCard::VPbkSingleContactLinkOperationFailed(
|
|
559 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
560 |
TInt aError )
|
|
561 |
{
|
|
562 |
CCA_DP(KMyCardLogFile,
|
|
563 |
CCA_L("->CCCAppMyCard::VPbkSingleContactLinkOperationFailed error = %d"),
|
|
564 |
aError );
|
|
565 |
|
|
566 |
delete iMyCard;
|
|
567 |
iMyCard = NULL;
|
|
568 |
TInt error(aError);
|
|
569 |
// if link is not found
|
|
570 |
if( KErrNotFound == error )
|
|
571 |
{
|
|
572 |
// launch contact editor
|
|
573 |
iCreateCallBack->Call();
|
|
574 |
}
|
|
575 |
if( error != KErrNone && error != KErrNotFound )
|
|
576 |
{
|
|
577 |
iPlugin.HandleError( error );
|
|
578 |
}
|
|
579 |
|
|
580 |
CCA_DP(KMyCardLogFile,
|
|
581 |
CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationFailed()"));
|
|
582 |
}
|
|
583 |
|
|
584 |
// ---------------------------------------------------------------------------
|
|
585 |
// CCCAppMyCard::CreateMyCardContact
|
|
586 |
// ---------------------------------------------------------------------------
|
|
587 |
//
|
|
588 |
TInt CCCAppMyCard::CreateMyCardContact( TAny* aPtr )
|
|
589 |
{
|
|
590 |
CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
|
|
591 |
TRAPD( err, self->LaunchContactEditorL( TPbk2ContactEditorParams::ENewContact |
|
|
592 |
TPbk2ContactEditorParams::EOwnContact ) );
|
|
593 |
|
|
594 |
if( err != KErrNone )
|
|
595 |
{
|
|
596 |
self->iPlugin.HandleError( err );
|
|
597 |
|
|
598 |
if( !self->iMyCard )
|
|
599 |
{
|
|
600 |
self->iCloseCallBack->Call();
|
|
601 |
}
|
|
602 |
else
|
|
603 |
{
|
|
604 |
self->LoadContact();
|
|
605 |
}
|
|
606 |
}
|
|
607 |
|
|
608 |
return err;
|
|
609 |
}
|
|
610 |
|
|
611 |
// ---------------------------------------------------------------------------
|
|
612 |
// CCCAppMyCard::LaunchContactEditorL
|
|
613 |
// ---------------------------------------------------------------------------
|
|
614 |
//
|
|
615 |
void CCCAppMyCard::LaunchContactEditorL( TUint32 aFlags )
|
|
616 |
{
|
|
617 |
// default contact store
|
|
618 |
MVPbkContactStore* store = iVPbkContactManager->ContactStoresL().Find(
|
|
619 |
VPbkContactStoreUris::DefaultCntDbUri() );
|
|
620 |
|
|
621 |
MVPbkBaseContactField* field = NULL;
|
|
622 |
MVPbkStoreContact* contact = NULL;
|
|
623 |
if( aFlags & TPbk2ContactEditorParams::ENewContact )
|
|
624 |
{
|
|
625 |
// create empty store contact and launch editor
|
|
626 |
contact = store->CreateNewContactLC();
|
|
627 |
CleanupStack::Pop(); // contact, whose ownership is taken away
|
|
628 |
}
|
|
629 |
else if( aFlags & TPbk2ContactEditorParams::EModified )
|
|
630 |
{
|
|
631 |
if( iFocusedFieldIndex >= KErrNone )
|
|
632 |
{
|
|
633 |
// focused field
|
|
634 |
field = iMyCardContact->Fields().FieldAtLC( iFocusedFieldIndex );
|
|
635 |
}
|
|
636 |
|
|
637 |
// pass current store contact, ownership is taken
|
|
638 |
contact = iMyCardContact;
|
|
639 |
iMyCardContact = NULL;
|
|
640 |
delete iPresentationContact;
|
|
641 |
iPresentationContact = NULL;
|
|
642 |
}
|
|
643 |
// params for the editor
|
|
644 |
TPbk2ContactEditorParams params( aFlags, field, NULL, this );
|
|
645 |
|
|
646 |
// pass custom title text
|
|
647 |
if ( contact )
|
|
648 |
{
|
|
649 |
HBufC* title = CCoeEnv::Static()->AllocReadResourceLC(
|
|
650 |
R_QTN_CCA_MC_TITLE_EDIT_MY_CARD );
|
|
651 |
// ownership of the title is passed
|
|
652 |
CPbk2ContactEditorDlg* dlg = CPbk2ContactEditorDlg::NewL( params, contact,
|
|
653 |
*this, iAppServices, title, R_SOCIAL_PHONEBOOK_FIELD_PROPERTIES );
|
|
654 |
CleanupStack::Pop( title );
|
|
655 |
iEditorEliminator = dlg;
|
|
656 |
dlg->ResetWhenDestroyed( &iEditorEliminator );
|
|
657 |
|
|
658 |
iDialogIsRunning = ETrue;
|
|
659 |
dlg->ExecuteLD();
|
|
660 |
|
|
661 |
if( aFlags & TPbk2ContactEditorParams::ENewContact )
|
|
662 |
{
|
|
663 |
// Enable LSK in my card view after edit dialog is opened
|
|
664 |
iPlugin.EnableOptionsMenu( ETrue );
|
|
665 |
}
|
|
666 |
}
|
|
667 |
|
|
668 |
// if field was created, destroy it
|
|
669 |
if( field )
|
|
670 |
{
|
|
671 |
CleanupStack::PopAndDestroy( field );
|
|
672 |
}
|
|
673 |
}
|
|
674 |
|
|
675 |
// ---------------------------------------------------------------------------
|
|
676 |
// CCCAppMyCard::EditContactL
|
|
677 |
// ---------------------------------------------------------------------------
|
|
678 |
//
|
|
679 |
void CCCAppMyCard::EditContactL( TInt aFocusedFieldIndex )
|
|
680 |
{
|
|
681 |
// if exists
|
|
682 |
if( iMyCardContact )
|
|
683 |
{
|
|
684 |
// store focused index
|
|
685 |
iFocusedFieldIndex = aFocusedFieldIndex;
|
|
686 |
iMyCardContact->LockL( *this );
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
// ---------------------------------------------------------------------------
|
|
691 |
// CCCAppMyCard::ContactEditingComplete
|
|
692 |
// ---------------------------------------------------------------------------
|
|
693 |
//
|
|
694 |
void CCCAppMyCard::ContactEditingComplete( MVPbkStoreContact* aEditedContact )
|
|
695 |
{
|
|
696 |
// create link of mycard
|
|
697 |
MVPbkContactLink* link = NULL;
|
|
698 |
|
|
699 |
TRAPD( err,
|
|
700 |
{
|
|
701 |
link = aEditedContact->CreateLinkLC();
|
|
702 |
|
|
703 |
if( link )
|
|
704 |
{
|
|
705 |
CleanupStack::Pop(); //link
|
|
706 |
}
|
|
707 |
} );
|
|
708 |
|
|
709 |
delete aEditedContact; // ignore given contact
|
|
710 |
|
|
711 |
if( link && err == KErrNone )
|
|
712 |
{
|
|
713 |
|
|
714 |
delete iMyCard;
|
|
715 |
iMyCard = link;
|
|
716 |
|
|
717 |
// reload mycard to get rid of the empty template fields
|
|
718 |
LoadContact();
|
|
719 |
}
|
|
720 |
else if( !iMyCard )
|
|
721 |
{
|
|
722 |
iCloseCallBack->Call();
|
|
723 |
}
|
|
724 |
|
|
725 |
iDialogIsRunning = EFalse;
|
|
726 |
}
|
|
727 |
|
|
728 |
// ---------------------------------------------------------------------------
|
|
729 |
// CCCAppMyCard::ContactEditingDeletedContact
|
|
730 |
// ---------------------------------------------------------------------------
|
|
731 |
//
|
|
732 |
void CCCAppMyCard::ContactEditingDeletedContact(
|
|
733 |
MVPbkStoreContact* aEditedContact )
|
|
734 |
{
|
|
735 |
// Editing was cancelled, go back to phonebook
|
|
736 |
delete aEditedContact;
|
|
737 |
iCloseCallBack->Call();
|
|
738 |
iDialogIsRunning = EFalse;
|
|
739 |
}
|
|
740 |
|
|
741 |
// ---------------------------------------------------------------------------
|
|
742 |
// CCCAppMyCard::ContactEditingAborted
|
|
743 |
// ---------------------------------------------------------------------------
|
|
744 |
//
|
|
745 |
void CCCAppMyCard::ContactEditingAborted()
|
|
746 |
{
|
|
747 |
iDialogIsRunning = EFalse;
|
|
748 |
// Editing was aborted -> move to pb2
|
|
749 |
}
|
|
750 |
|
|
751 |
// ---------------------------------------------------------------------------
|
|
752 |
// CCCAppMyCard::OkToExitL
|
|
753 |
// ---------------------------------------------------------------------------
|
|
754 |
//
|
|
755 |
TBool CCCAppMyCard::OkToExitL( TInt /*aCommandId*/ )
|
|
756 |
{
|
|
757 |
// Handle exit via callback. Calls CCCAppMyCard::ExitDlg.
|
|
758 |
// Dialog's exit is handled this way to make the address selector's
|
|
759 |
// exit work as it should.
|
|
760 |
iDlgCloseCallBack->Call();
|
|
761 |
return EFalse;
|
|
762 |
}
|
|
763 |
|
|
764 |
// ---------------------------------------------------------------------------
|
|
765 |
// CCCAppMyCard::CloseCcaL
|
|
766 |
// ---------------------------------------------------------------------------
|
|
767 |
//
|
|
768 |
TInt CCCAppMyCard::CloseCcaL( TAny* aPtr )
|
|
769 |
{
|
|
770 |
CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
|
|
771 |
// if fields are empty, and user pushes "Done" or "Exit" this function is
|
|
772 |
// called. Card is not created -> goto pbk2
|
|
773 |
self->DoCloseCCaL();
|
|
774 |
return KErrNone;
|
|
775 |
}
|
|
776 |
|
|
777 |
// ---------------------------------------------------------------------------
|
|
778 |
// CCCAppMyCard::CloseCcaL
|
|
779 |
// ---------------------------------------------------------------------------
|
|
780 |
//
|
|
781 |
TInt CCCAppMyCard::ExitDlgL( TAny* aPtr )
|
|
782 |
{
|
|
783 |
CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
|
|
784 |
if( self->iEditorEliminator )
|
|
785 |
{
|
|
786 |
self->iEditorEliminator->RequestExitL( EAknCmdExit );
|
|
787 |
}
|
|
788 |
return KErrNone;
|
|
789 |
}
|
|
790 |
|
|
791 |
// ---------------------------------------------------------------------------
|
|
792 |
// CCCAppMyCard::OpenStoresL
|
|
793 |
// ---------------------------------------------------------------------------
|
|
794 |
//
|
|
795 |
TInt CCCAppMyCard::OpenStoresL( TAny* aPtr )
|
|
796 |
{
|
|
797 |
CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
|
|
798 |
self->iAppServices->StoreManager().OpenStoresL();
|
|
799 |
return 0;
|
|
800 |
}
|
|
801 |
|
|
802 |
// ---------------------------------------------------------------------------
|
|
803 |
// CCCAppMyCard::DoCloseCCaL
|
|
804 |
// ---------------------------------------------------------------------------
|
|
805 |
//
|
|
806 |
void CCCAppMyCard::DoCloseCCaL()
|
|
807 |
{
|
|
808 |
// close the plugin
|
|
809 |
iPlugin.HandleCommandL( EAknSoftkeyBack );
|
|
810 |
}
|
|
811 |
|
|
812 |
// ---------------------------------------------------------------------------
|
|
813 |
// CCCAppMyCard::ContactOperationCompleted
|
|
814 |
// ---------------------------------------------------------------------------
|
|
815 |
//
|
|
816 |
void CCCAppMyCard::ContactOperationCompleted( TContactOpResult aResult )
|
|
817 |
{
|
|
818 |
CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::ContactOperationCompleted()"));
|
|
819 |
|
|
820 |
// contact locked complete for editing
|
|
821 |
if( aResult.iOpCode == MVPbkContactObserver::EContactLock )
|
|
822 |
{
|
|
823 |
TRAPD( err, LaunchContactEditorL( TPbk2ContactEditorParams::EModified |
|
|
824 |
TPbk2ContactEditorParams::EOwnContact) );
|
|
825 |
|
|
826 |
if( err == KLeaveExit )
|
|
827 |
{
|
|
828 |
iCloseCallBack->Call();
|
|
829 |
}
|
|
830 |
else if( err != KErrNone )
|
|
831 |
{
|
|
832 |
LoadContact();
|
|
833 |
iPlugin.HandleError( err );
|
|
834 |
if( !iMyCard )
|
|
835 |
{
|
|
836 |
iCloseCallBack->Call();
|
|
837 |
}
|
|
838 |
}
|
|
839 |
}
|
|
840 |
else if( aResult.iOpCode == MVPbkContactObserver::EContactDelete )
|
|
841 |
{
|
|
842 |
iCloseCallBack->Call();
|
|
843 |
}
|
|
844 |
|
|
845 |
CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::ContactOperationCompleted()"));
|
|
846 |
}
|
|
847 |
|
|
848 |
// ---------------------------------------------------------------------------
|
|
849 |
// CCCAppMyCard::ContactOperationFailed
|
|
850 |
// ---------------------------------------------------------------------------
|
|
851 |
//
|
|
852 |
void CCCAppMyCard::ContactOperationFailed(
|
|
853 |
TContactOp aOpCode, TInt aErrorCode, TBool /*aErrorNotified*/ )
|
|
854 |
{
|
|
855 |
if ( aErrorCode != KErrNone )
|
|
856 |
{
|
|
857 |
iPlugin.HandleError( aErrorCode );
|
|
858 |
}
|
|
859 |
}
|
|
860 |
|
|
861 |
// ---------------------------------------------------------------------------
|
|
862 |
// CCCAppMyCard::VPbkSingleContactOperationComplete
|
|
863 |
// ---------------------------------------------------------------------------
|
|
864 |
//
|
|
865 |
void CCCAppMyCard::VPbkSingleContactOperationComplete(
|
|
866 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
867 |
MVPbkStoreContact* aContact )
|
|
868 |
{
|
|
869 |
CCA_DP(KMyCardLogFile,
|
|
870 |
CCA_L("->CCCAppMyCard::VPbkSingleContactOperationComplete()") );
|
|
871 |
|
|
872 |
delete iFetchOperation;
|
|
873 |
iFetchOperation = NULL;
|
|
874 |
|
|
875 |
delete iMyCardContact;
|
|
876 |
iMyCardContact = aContact;
|
|
877 |
|
|
878 |
// also delete presentation contact, since it points to old store contact
|
|
879 |
delete iPresentationContact;
|
|
880 |
iPresentationContact = NULL;
|
|
881 |
|
|
882 |
NotifyObservers( iEvent );
|
|
883 |
|
|
884 |
CCA_DP(KMyCardLogFile,
|
|
885 |
CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationComplete()"));
|
|
886 |
}
|
|
887 |
|
|
888 |
// ---------------------------------------------------------------------------
|
|
889 |
// CCCAppMyCard::VPbkSingleContactOperationFailed
|
|
890 |
// ---------------------------------------------------------------------------
|
|
891 |
//
|
|
892 |
void CCCAppMyCard::VPbkSingleContactOperationFailed(
|
|
893 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
894 |
TInt aError )
|
|
895 |
{
|
|
896 |
CCA_DP(KMyCardLogFile,
|
|
897 |
CCA_L("->CCCAppMyCard::VPbkSingleContactOperationFailed error = %d"),
|
|
898 |
aError );
|
|
899 |
|
|
900 |
delete iFetchOperation;
|
|
901 |
iFetchOperation = NULL;
|
|
902 |
|
|
903 |
delete iOperation;
|
|
904 |
iOperation = NULL;
|
|
905 |
|
|
906 |
if( aError != KErrNone )
|
|
907 |
{
|
|
908 |
iPlugin.HandleError( aError );
|
|
909 |
}
|
|
910 |
|
|
911 |
CCA_DP(KMyCardLogFile,
|
|
912 |
CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationFailed()") );
|
|
913 |
}
|
|
914 |
|
|
915 |
// End of File
|