phonebookui/Phonebook2/ccapplication/ccamycardplugin/src/ccappmycard.cpp
branchRCL_3
changeset 15 e8e3147d53eb
parent 3 04ab22b956c2
child 21 b3431bff8c19
equal deleted inserted replaced
14:81f8547efd4f 15:e8e3147d53eb
    21 
    21 
    22 // System
    22 // System
    23 #include <coemain.h>
    23 #include <coemain.h>
    24 #include <f32file.h>
    24 #include <f32file.h>
    25 #include <avkon.hrh>
    25 #include <avkon.hrh>
       
    26 #include <eikenv.h>
       
    27 #include <aknViewAppUi.h>
    26 
    28 
    27 // Virtual phonebook
    29 // Virtual phonebook
    28 #include <CVPbkContactManager.h>
    30 #include <CVPbkContactManager.h>
    29 #include <CVPbkContactStoreUriArray.h>
    31 #include <CVPbkContactStoreUriArray.h>
    30 #include <MVPbkContactStoreProperties.h>
    32 #include <MVPbkContactStoreProperties.h>
    48 #include <CPbk2StoreSpecificFieldPropertyArray.h>
    50 #include <CPbk2StoreSpecificFieldPropertyArray.h>
    49 #include <CPbk2FieldPropertyArray.h>
    51 #include <CPbk2FieldPropertyArray.h>
    50 #include <CPbk2SortOrderManager.h>
    52 #include <CPbk2SortOrderManager.h>
    51 #include <Pbk2ContactNameFormatterFactory.h>
    53 #include <Pbk2ContactNameFormatterFactory.h>
    52 #include <MPbk2ContactNameFormatter.h>
    54 #include <MPbk2ContactNameFormatter.h>
    53 #include <CPbk2ApplicationServices.h>	
    55 #include <CPbk2ApplicationServices.h>
    54 #include <CPbk2StoreManager.h>
    56 #include <CPbk2StoreManager.h>
    55 #include <CPbk2StoreConfiguration.h>	
    57 #include <CPbk2StoreConfiguration.h>
    56 #include <CPbk2ContactEditorDlg.h>
    58 #include <CPbk2ContactEditorDlg.h>
    57 #include <MVPbkBaseContactField.h>
    59 #include <MVPbkBaseContactField.h>
       
    60 
    58 // internal
    61 // internal
    59 #include "ccappmycardplugin.h"
    62 #include "ccappmycardplugin.h"
    60 #include <ccappmycardpluginrsc.rsg>
    63 #include <ccappmycardpluginrsc.rsg>
    61 
    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 
    62 
   136 
    63 // ======== MEMBER FUNCTIONS ========
   137 // ======== MEMBER FUNCTIONS ========
    64 
   138 
    65 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
    66 // CCCAppMyCard::NewL
   140 // CCCAppMyCard::NewL
    67 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
    68 //
   142 //
    69 CCCAppMyCard* CCCAppMyCard::NewL( CCCAppMyCardPlugin& aPlugin, RFs* aFs )
   143 CCCAppMyCard* CCCAppMyCard::NewL( CCCAppMyCardPlugin& aPlugin, RFs* aFs )
    70     {
   144     {
    71     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::NewL()"));
   145     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::NewL()"));
    72     
   146 
    73     CCCAppMyCard* self = new ( ELeave ) CCCAppMyCard( aPlugin );
   147     CCCAppMyCard* self = new ( ELeave ) CCCAppMyCard( aPlugin );
    74     CleanupStack::PushL( self );
   148     CleanupStack::PushL( self );
    75     self->ConstructL(aFs);
   149     self->ConstructL(aFs);
    76     CleanupStack::Pop( self );
   150     CleanupStack::Pop( self );
    77     
   151 
    78     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::NewL()"));
   152     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::NewL()"));
    79     return self;
   153     return self;
    80     }
   154     }
    81 
   155 
    82 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
    92     delete iMyCard;
   166     delete iMyCard;
    93     delete iPresentationContact;
   167     delete iPresentationContact;
    94     delete iMyCardContact;
   168     delete iMyCardContact;
    95     delete iFieldProperties;
   169     delete iFieldProperties;
    96     delete iSpecificFieldProperties;
   170     delete iSpecificFieldProperties;
    97     
   171 
    98     iObservers.Reset();
   172     iObservers.Reset();
    99 
   173 
   100     if( iAppServices )
   174     if( iAppServices )
   101 	   {
   175 	   {
   102 	   iAppServices->StoreManager().DeregisterStoreEvents(*this);
   176 	   iAppServices->StoreManager().DeregisterStoreEvents(*this);
   103 	   }
   177 	   }
   104 	Release(iAppServices);
   178 	Release(iAppServices);
   105     
   179 
   106 	delete iCloseCallBack;
   180 	delete iCloseCallBack;
   107     delete iCreateCallBack;
   181     delete iCreateCallBack;
   108     delete iDlgCloseCallBack;
   182     delete iDlgCloseCallBack;
       
   183     delete iStoreCallBack;
   109 
   184 
   110 	CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::~CCCAppMyCard()"));
   185 	CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::~CCCAppMyCard()"));
   111     }
   186     }
   112 
   187 
   113 // ---------------------------------------------------------------------------
   188 // ---------------------------------------------------------------------------
   114 // CCCAppMyCard::CCCAppMyCard()
   189 // CCCAppMyCard::CCCAppMyCard()
   115 // ---------------------------------------------------------------------------
   190 // ---------------------------------------------------------------------------
   116 //
   191 //
   117 inline CCCAppMyCard::CCCAppMyCard( CCCAppMyCardPlugin& aPlugin )
   192 inline CCCAppMyCard::CCCAppMyCard( CCCAppMyCardPlugin& aPlugin )
   118 : iPlugin( aPlugin )
   193 : iPlugin( aPlugin ), iEvent( MMyCardObserver::EEventContactLoaded )
       
   194 
   119 	{
   195 	{
   120     }
   196     }
   121 
   197 
   122 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   123 // CCCAppMyCard::ConstructL
   199 // CCCAppMyCard::ConstructL
   125 //
   201 //
   126 inline void CCCAppMyCard::ConstructL( RFs* /*aFs*/ )
   202 inline void CCCAppMyCard::ConstructL( RFs* /*aFs*/ )
   127     {
   203     {
   128     // Get the AppServices instance
   204     // Get the AppServices instance
   129 	iAppServices = CPbk2ApplicationServices::InstanceL();
   205 	iAppServices = CPbk2ApplicationServices::InstanceL();
   130 	
   206 
   131 	CPbk2StoreManager& storeManager = iAppServices->StoreManager();
   207 	CPbk2StoreManager& storeManager = iAppServices->StoreManager();
   132 	iVPbkContactManager = &iAppServices->ContactManager();
   208 	iVPbkContactManager = &iAppServices->ContactManager();
   133 	storeManager.RegisterStoreEventsL( *this );
   209 	storeManager.RegisterStoreEventsL( *this );
   134 	storeManager.EnsureDefaultSavingStoreIncludedL();
   210 	storeManager.EnsureDefaultSavingStoreIncludedL();
   135 	// open stores
   211 
   136 	storeManager.OpenStoresL();
   212 	iCloseCallBack = new(ELeave) CAsyncCallBack(
   137 	
   213         TCallBack( CloseCcaL, this ), CActive::EPriorityIdle );
   138 	iCloseCallBack = new(ELeave) CAsyncCallBack( 
   214     iCreateCallBack = new(ELeave) CAsyncCallBack(
   139         TCallBack( CloseCcaL, this ), CActive::EPriorityIdle );	
   215         TCallBack( CreateMyCardContact, this ), CActive::EPriorityHigh );
   140     iCreateCallBack = new(ELeave) CAsyncCallBack( 
   216     iDlgCloseCallBack = new(ELeave) CAsyncCallBack(
   141         TCallBack( CreateMyCardContact, this ), CActive::EPriorityHigh );  
       
   142     iDlgCloseCallBack = new(ELeave) CAsyncCallBack( 
       
   143         TCallBack( ExitDlgL, this ), CActive::EPriorityHigh );
   217         TCallBack( ExitDlgL, this ), CActive::EPriorityHigh );
   144 	}
   218 	}
   145 
   219 
   146 // ---------------------------------------------------------------------------
   220 // ---------------------------------------------------------------------------
   147 // CCCAppMyCard::PresentationContactL
   221 // CCCAppMyCard::PresentationContactL
   154         if( !iMyCardContact )
   228         if( !iMyCardContact )
   155             {
   229             {
   156             // own contact not loaded
   230             // own contact not loaded
   157             User::Leave( KErrNotReady );
   231             User::Leave( KErrNotReady );
   158             }
   232             }
   159         
   233 
   160         const MVPbkContactStoreProperties& storeProperties =
   234         const MVPbkContactStoreProperties& storeProperties =
   161             iMyCardContact->ParentStore().StoreProperties();
   235             iMyCardContact->ParentStore().StoreProperties();
   162         const MVPbkFieldTypeList& supportedFieldTypes =
   236         const MVPbkFieldTypeList& supportedFieldTypes =
   163             storeProperties.SupportedFields();
   237             storeProperties.SupportedFields();
   164     
   238 
   165         if( !iFieldProperties )
   239         if( !iFieldProperties )
   166             {
   240             {
   167             iFieldProperties = CPbk2FieldPropertyArray::NewL(
   241             iFieldProperties = CPbk2FieldPropertyArray::NewL(
   168                 supportedFieldTypes, iVPbkContactManager->FsSession() );
   242                 supportedFieldTypes, iVPbkContactManager->FsSession() );
   169             }
   243             }
   170     
   244 
   171         // Create a field property list of the supported
   245         // Create a field property list of the supported
   172         // field types of the used store
   246         // field types of the used store
   173         CPbk2StorePropertyArray* pbk2StoreProperties = CPbk2StorePropertyArray::NewL();
   247         CPbk2StorePropertyArray* pbk2StoreProperties = CPbk2StorePropertyArray::NewL();
   174         CleanupStack::PushL( pbk2StoreProperties );
   248         CleanupStack::PushL( pbk2StoreProperties );
   175     
   249 
   176         if( !iSpecificFieldProperties )
   250         if( !iSpecificFieldProperties )
   177             {
   251             {
   178             iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL(
   252             iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL(
   179                 *iFieldProperties,
   253                 *iFieldProperties,
   180                 *pbk2StoreProperties,
   254                 *pbk2StoreProperties,
   181                 supportedFieldTypes,
   255                 supportedFieldTypes,
   182                 iMyCardContact->ParentStore() );
   256                 iMyCardContact->ParentStore() );
   183             }
   257             }
   184 
   258 
   185         iPresentationContact = CPbk2PresentationContact::NewL( 
   259         iPresentationContact = CPbk2PresentationContact::NewL(
   186             *iMyCardContact, *iSpecificFieldProperties );
   260             *iMyCardContact, *iSpecificFieldProperties );
   187         
   261 
   188         CleanupStack::PopAndDestroy( pbk2StoreProperties );
   262         CleanupStack::PopAndDestroy( pbk2StoreProperties );
   189         }
   263         }
   190     
   264 
   191     return *iPresentationContact;
   265     return *iPresentationContact;
   192     }
   266     }
   193 
   267 
   194 // ---------------------------------------------------------------------------
   268 // ---------------------------------------------------------------------------
   195 // CCCAppMyCard::StoreContact
   269 // CCCAppMyCard::StoreContact
   241         if( index == KErrNotFound )
   315         if( index == KErrNotFound )
   242             {
   316             {
   243             iObservers.AppendL( aObserver );
   317             iObservers.AppendL( aObserver );
   244             if( iMyCardContact )
   318             if( iMyCardContact )
   245                 {
   319                 {
   246                 aObserver->MyCardEventL( MMyCardObserver::EEventContactLoaded ); 
   320                 aObserver->MyCardEventL( MMyCardObserver::EEventContactLoaded );
   247                 }
   321                 }
   248             }
   322             }
   249         }
   323         }
   250     }
   324     }
   251 
   325 
   258     TInt index = iObservers.Find( aObserver );
   332     TInt index = iObservers.Find( aObserver );
   259     if( index != KErrNotFound )
   333     if( index != KErrNotFound )
   260         {
   334         {
   261         iObservers.Remove( index );
   335         iObservers.Remove( index );
   262         }
   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         iStoreCallBack = CTimerCallBack::NewL(
       
   360             TCallBack( &CCCAppMyCard::OpenStoresL, this ) );
       
   361 
       
   362         // 200 ms delay before open. Used to prevent system jamming before the
       
   363         // UI is drawn, so that launching of mycard feels a lot faster.
       
   364         iStoreCallBack->After( 200e3 );
       
   365         }
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CCCAppMyCard::ForceCreateMyCard
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 void CCCAppMyCard::ForceCreateMyCard()
       
   373     {
       
   374     iForceCreateMyCard = ETrue;
   263     }
   375     }
   264 
   376 
   265 // ---------------------------------------------------------------------------
   377 // ---------------------------------------------------------------------------
   266 // CCCAppMyCard::NotifyObservers
   378 // CCCAppMyCard::NotifyObservers
   267 // ---------------------------------------------------------------------------
   379 // ---------------------------------------------------------------------------
   272     for( TInt i = 0; i < count; i++ )
   384     for( TInt i = 0; i < count; i++ )
   273         {
   385         {
   274         TRAPD( err, iObservers[i]->MyCardEventL( aEvent ) );
   386         TRAPD( err, iObservers[i]->MyCardEventL( aEvent ) );
   275         if( err )
   387         if( err )
   276             {
   388             {
   277             CCA_DP(KMyCardLogFile, 
   389             CCA_DP(KMyCardLogFile,
   278                 CCA_L("<-CCCAppMyCard::NotifyObservers notify error (%d)"), err );
   390                 CCA_L("<-CCCAppMyCard::NotifyObservers notify error (%d)"), err );
   279             }
   391             }
   280         }
   392         }
   281     }
   393     }
   282 
   394 
   284 // CCCAppMyCard::LoadContact
   396 // CCCAppMyCard::LoadContact
   285 // ---------------------------------------------------------------------------
   397 // ---------------------------------------------------------------------------
   286 //
   398 //
   287 void CCCAppMyCard::LoadContact()
   399 void CCCAppMyCard::LoadContact()
   288     {
   400     {
   289     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::LoadContact()"));    
   401     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::LoadContact()"));
   290 
   402 
   291     if( !iFetchOperation && iMyCard )
   403     if( !iFetchOperation && iMyCard )
   292         {
   404         {
   293         TRAPD( err, iFetchOperation = 
   405         TRAPD( err, iFetchOperation =
   294             iVPbkContactManager->RetrieveContactL( *iMyCard, *this ) );
   406             iVPbkContactManager->RetrieveContactL( *iMyCard, *this ) );
   295         if( err )
   407         if( err )
   296             {
   408             {
   297             // Cannot load own contact from VPbk  
   409             // Cannot load own contact from VPbk
   298             CCA_DP(KMyCardLogFile, 
   410             CCA_DP(KMyCardLogFile,
   299                 CCA_L("  CCCAppMyCard::LoadContact load error = %d"), err ); 
   411                 CCA_L("  CCCAppMyCard::LoadContact load error = %d"), err );
   300     
   412 
   301             // TODO: How is this handled. show error on UI?
   413             iPlugin.HandleError( err );
   302             }
   414             }
   303         }
   415         }
   304     
   416 
   305     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::LoadContact()"));    
   417     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::LoadContact()"));
   306     }
   418     }
   307 
   419 
   308 // ---------------------------------------------------------------------------
   420 // ---------------------------------------------------------------------------
   309 // CCCAppMyCard::StoreReady
   421 // CCCAppMyCard::StoreReady
   310 // ---------------------------------------------------------------------------
   422 // ---------------------------------------------------------------------------
   311 //
   423 //
   312 void CCCAppMyCard::StoreReady( MVPbkContactStore& aContactStore )
   424 void CCCAppMyCard::StoreReady( MVPbkContactStore& aContactStore )
   313 	{
   425 	{
   314     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::StoreReady()"));
   426     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCard::StoreReady()"));
   315     
   427 
   316     // MyCard is always created to contact model. So we check that event was
   428 	const MVPbkContactStoreProperties& storeProperties =
   317     // from the correct store.
   429 		aContactStore.StoreProperties();
   318     const MVPbkContactStoreProperties& storeProperties = 
   430 	TVPbkContactStoreUriPtr uri = storeProperties.Uri();
   319 				aContactStore.StoreProperties();
   431 	TInt isSame = uri.Compare( VPbkContactStoreUris::DefaultCntDbUri(),
   320     TVPbkContactStoreUriPtr uri = storeProperties.Uri();
   432 		TVPbkContactStoreUriPtr::EContactStoreUriAllComponents );
   321     TInt isSame = uri.Compare( VPbkContactStoreUris::DefaultCntDbUri(), 
   433 
   322     		TVPbkContactStoreUriPtr::EContactStoreUriAllComponents );
   434 	if( isSame != 0 )
   323 	if( isSame == 0 )
   435 		{
   324 		{				
   436 		return;
       
   437 		}
       
   438 
       
   439     if( iMyCard )
       
   440         {
       
   441         // if link is already available then use that
       
   442         LoadContact();
       
   443         }
       
   444     else if( iForceCreateMyCard )
       
   445         {
       
   446         // launch editor because we don't have mycard
       
   447         iCreateCallBack->Call();
       
   448         }
       
   449     else
       
   450         {
       
   451         // MyCard is always created to contact model. So we check that event was
       
   452         // from the correct store.
   325 		delete iOperation;
   453 		delete iOperation;
   326 		iOperation = NULL;
   454 		iOperation = NULL;
   327 		
   455 
   328 		MVPbkContactStore2* phoneStoreExtension =
   456 		MVPbkContactStore2* phoneStoreExtension =
   329 			static_cast<MVPbkContactStore2*>(aContactStore.ContactStoreExtension(KMVPbkContactStoreExtension2Uid));
   457 			static_cast<MVPbkContactStore2*>(aContactStore.ContactStoreExtension(KMVPbkContactStoreExtension2Uid));
   330 		if ( phoneStoreExtension )
   458 		if ( phoneStoreExtension )
   331 			{
   459 			{
   332 			TRAPD( err, iOperation = phoneStoreExtension->OwnContactLinkL(*this) );
   460 			TRAPD( err, iOperation = phoneStoreExtension->OwnContactLinkL(*this) );
   333 			if( err )
   461 			if( err )
   334 				{
   462 				{
   335 				// TODO: how is this handled?
   463                 iPlugin.HandleError( err );
   336 				}
   464 				}
   337 			}
   465 			}
   338 		}
   466         }
   339     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::StoreReady()"));    
   467     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::StoreReady()"));
   340 	}
   468 	}
   341 
   469 
   342 // ---------------------------------------------------------------------------
   470 // ---------------------------------------------------------------------------
   343 // CCCAppMyCard::StoreUnavailable
   471 // CCCAppMyCard::StoreUnavailable
   344 // ---------------------------------------------------------------------------
   472 // ---------------------------------------------------------------------------
   345 //
   473 //
   346 void CCCAppMyCard::StoreUnavailable(
   474 void CCCAppMyCard::StoreUnavailable(
   347 		MVPbkContactStore& /*aContactStore*/, 
   475 		MVPbkContactStore& /*aContactStore*/,
   348         TInt /*aReason*/)
   476         TInt /*aReason*/)
   349 	{
   477 	{
   350     CCA_DP(KMyCardLogFile, CCA_L("  CCCAppMyCard::StoreUnavailable()"));    
   478     CCA_DP(KMyCardLogFile, CCA_L("  CCCAppMyCard::StoreUnavailable()"));
   351 	}
   479 	}
   352 
   480 
   353 // ---------------------------------------------------------------------------
   481 // ---------------------------------------------------------------------------
   354 // CCCAppMyCard::HandleStoreEventL
   482 // CCCAppMyCard::HandleStoreEventL
   355 // ---------------------------------------------------------------------------
   483 // ---------------------------------------------------------------------------
   356 //
   484 //
   357 void CCCAppMyCard::HandleStoreEventL(
   485 void CCCAppMyCard::HandleStoreEventL(
   358         MVPbkContactStore& /*aContactStore*/, 
   486         MVPbkContactStore& /*aContactStore*/,
   359         TVPbkContactStoreEvent aStoreEvent )
   487         TVPbkContactStoreEvent aStoreEvent )
   360 	{
   488 	{
   361     CCA_DP(KMyCardLogFile, 
   489     CCA_DP(KMyCardLogFile,
   362         CCA_L("->CCCAppMyCard::HandleStoreEventL Event = %d"), 
   490         CCA_L("->CCCAppMyCard::HandleStoreEventL Event = %d"),
   363         aStoreEvent.iEventType );
   491         aStoreEvent.iEventType );
   364     
   492 
   365     if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged )
   493     if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged )
   366         {
   494         {
   367         if( iMyCard && aStoreEvent.iContactLink->IsSame( *iMyCard ) )
   495         if( iMyCard && aStoreEvent.iContactLink->IsSame( *iMyCard ) )
   368             {
   496             {
   369             // Own contact has changed. Reload contact to update content
   497             // Own contact has changed. Reload contact to update content
       
   498             iEvent = MMyCardObserver::EEventContactChanged;
   370             LoadContact();
   499             LoadContact();
   371             }
   500             }
   372         }
   501         }
   373 
   502     else if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactDeleted )
   374     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::HandleStoreEventL()") ); 
   503         {
       
   504         if( iMyCard && aStoreEvent.iContactLink->IsSame( *iMyCard ) )
       
   505             {
       
   506             if( !iDialogIsRunning )
       
   507                 {
       
   508                 CEikAppUi* aEikAppUi = CEikonEnv::Static()->EikAppUi();
       
   509                 CAknViewAppUi* appUi = static_cast<CAknViewAppUi*> ( aEikAppUi );
       
   510                 appUi->RunAppShutter();
       
   511                 }
       
   512             }
       
   513         }
       
   514 
       
   515     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::HandleStoreEventL()") );
   375 	}
   516 	}
   376 
   517 
   377 // ---------------------------------------------------------------------------
   518 // ---------------------------------------------------------------------------
   378 // CCCAppMyCard::VPbkSingleContactLinkOperationComplete
   519 // CCCAppMyCard::VPbkSingleContactLinkOperationComplete
   379 // ---------------------------------------------------------------------------
   520 // ---------------------------------------------------------------------------
   380 //
   521 //
   381 void CCCAppMyCard::VPbkSingleContactLinkOperationComplete(
   522 void CCCAppMyCard::VPbkSingleContactLinkOperationComplete(
   382         MVPbkContactOperationBase& /*aOperation*/,
   523         MVPbkContactOperationBase& /*aOperation*/,
   383         MVPbkContactLink* aLink )
   524         MVPbkContactLink* aLink )
   384 	{
   525 	{
   385     CCA_DP(KMyCardLogFile, 
   526     CCA_DP(KMyCardLogFile,
   386         CCA_L("->CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
   527         CCA_L("->CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
   387     
   528 
   388     delete iMyCard;
   529     delete iMyCard;
   389 	iMyCard = aLink;
   530 	iMyCard = aLink;
   390 	
   531 
   391 	LoadContact();
   532 	LoadContact();
   392 
   533 
   393 	CCA_DP(KMyCardLogFile, 
   534 	CCA_DP(KMyCardLogFile,
   394         CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
   535         CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationComplete()") );
   395 	}
   536 	}
   396 
   537 
   397 // ---------------------------------------------------------------------------
   538 // ---------------------------------------------------------------------------
   398 // CCCAppMyCard::VPbkSingleContactLinkOperationFailed
   539 // CCCAppMyCard::VPbkSingleContactLinkOperationFailed
   413 	if( KErrNotFound == error )
   554 	if( KErrNotFound == error )
   414 	    {
   555 	    {
   415         // launch contact editor
   556         // launch contact editor
   416         iCreateCallBack->Call();
   557         iCreateCallBack->Call();
   417         }
   558         }
   418 	if( error )
   559 	if( error != KErrNone && error != KErrNotFound )
   419 	    {
   560 	    {
   420 	    // TODO handle error
   561         iPlugin.HandleError( error );
   421 	    }
   562 	    }
   422 	
   563 	
   423 	CCA_DP(KMyCardLogFile, 
   564 	CCA_DP(KMyCardLogFile, 
   424         CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationFailed()"));    
   565         CCA_L("<-CCCAppMyCard::VPbkSingleContactLinkOperationFailed()"));    
   425 	}
   566 	}
   431 TInt CCCAppMyCard::CreateMyCardContact( TAny* aPtr )
   572 TInt CCCAppMyCard::CreateMyCardContact( TAny* aPtr )
   432 	{
   573 	{
   433 	CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
   574 	CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
   434 	TRAPD( err, self->LaunchContactEditorL( TPbk2ContactEditorParams::ENewContact | 
   575 	TRAPD( err, self->LaunchContactEditorL( TPbk2ContactEditorParams::ENewContact | 
   435         TPbk2ContactEditorParams::EOwnContact ) );
   576         TPbk2ContactEditorParams::EOwnContact ) );
       
   577 	
       
   578 	if( err != KErrNone )
       
   579         {
       
   580         self->iPlugin.HandleError( err );
       
   581         }
       
   582 	
   436 	return err;
   583 	return err;
   437 	}
   584 	}
   438 
   585 
   439 // ---------------------------------------------------------------------------
   586 // ---------------------------------------------------------------------------
   440 // CCCAppMyCard::LaunchContactEditorL
   587 // CCCAppMyCard::LaunchContactEditorL
   474         CPbk2ContactEditorDlg* dlg = CPbk2ContactEditorDlg::NewL( params, contact, 
   621         CPbk2ContactEditorDlg* dlg = CPbk2ContactEditorDlg::NewL( params, contact, 
   475             *this, iAppServices, title, R_SOCIAL_PHONEBOOK_FIELD_PROPERTIES );
   622             *this, iAppServices, title, R_SOCIAL_PHONEBOOK_FIELD_PROPERTIES );
   476         CleanupStack::Pop( title );
   623         CleanupStack::Pop( title );
   477         iEditorEliminator = dlg;
   624         iEditorEliminator = dlg;
   478         dlg->ResetWhenDestroyed( &iEditorEliminator );
   625         dlg->ResetWhenDestroyed( &iEditorEliminator );
       
   626         
       
   627         iDialogIsRunning = ETrue;
   479         dlg->ExecuteLD();
   628         dlg->ExecuteLD();
   480         }
   629         }
   481 	
   630 	
   482 	// if field was created, destroy it
   631 	// if field was created, destroy it
   483 	if( field )
   632 	if( field )
   521         // reload mycard to get rid of the empty template fields
   670         // reload mycard to get rid of the empty template fields
   522         LoadContact();
   671         LoadContact();
   523         }
   672         }
   524     
   673     
   525     delete aEditedContact; // ignore given contact
   674     delete aEditedContact; // ignore given contact
       
   675     iDialogIsRunning = EFalse;
   526 	}
   676 	}
   527 
   677 
   528 // ---------------------------------------------------------------------------
   678 // ---------------------------------------------------------------------------
   529 // CCCAppMyCard::ContactEditingDeletedContact
   679 // CCCAppMyCard::ContactEditingDeletedContact
   530 // ---------------------------------------------------------------------------
   680 // ---------------------------------------------------------------------------
   533     MVPbkStoreContact* aEditedContact )
   683     MVPbkStoreContact* aEditedContact )
   534 	{
   684 	{
   535 	// Editing was cancelled, go back to phonebook
   685 	// Editing was cancelled, go back to phonebook
   536 	delete aEditedContact;	
   686 	delete aEditedContact;	
   537 	iCloseCallBack->Call();
   687 	iCloseCallBack->Call();
       
   688 	iDialogIsRunning = EFalse;
   538 	}
   689 	}
   539 
   690 
   540 // ---------------------------------------------------------------------------
   691 // ---------------------------------------------------------------------------
   541 // CCCAppMyCard::ContactEditingAborted
   692 // CCCAppMyCard::ContactEditingAborted
   542 // ---------------------------------------------------------------------------
   693 // ---------------------------------------------------------------------------
   543 //
   694 //
   544 void CCCAppMyCard::ContactEditingAborted()
   695 void CCCAppMyCard::ContactEditingAborted()
   545 	{
   696 	{
       
   697     iDialogIsRunning = EFalse;
   546 	// Editing was aborted -> move to pb2
   698 	// Editing was aborted -> move to pb2
   547 	}
   699 	}
   548 
   700 
   549 // ---------------------------------------------------------------------------
   701 // ---------------------------------------------------------------------------
   550 // CCCAppMyCard::OkToExitL
   702 // CCCAppMyCard::OkToExitL
   582     if( self->iEditorEliminator )
   734     if( self->iEditorEliminator )
   583         {
   735         {
   584         self->iEditorEliminator->RequestExitL( EAknCmdExit );
   736         self->iEditorEliminator->RequestExitL( EAknCmdExit );
   585         }
   737         }
   586     return KErrNone;
   738     return KErrNone;
       
   739     }
       
   740 
       
   741 // ---------------------------------------------------------------------------
       
   742 // CCCAppMyCard::OpenStoresL
       
   743 // ---------------------------------------------------------------------------
       
   744 //
       
   745 TInt CCCAppMyCard::OpenStoresL( TAny* aPtr )
       
   746     {
       
   747     CCCAppMyCard* self = static_cast<CCCAppMyCard*>( aPtr );
       
   748     self->iAppServices->StoreManager().OpenStoresL();
       
   749     return 0;
   587     }
   750     }
   588 
   751 
   589 // ---------------------------------------------------------------------------
   752 // ---------------------------------------------------------------------------
   590 // CCCAppMyCard::DoCloseCCaL
   753 // CCCAppMyCard::DoCloseCCaL
   591 // ---------------------------------------------------------------------------
   754 // ---------------------------------------------------------------------------
   609     	{
   772     	{
   610     	TRAPD( err, LaunchContactEditorL( TPbk2ContactEditorParams::EModified | 
   773     	TRAPD( err, LaunchContactEditorL( TPbk2ContactEditorParams::EModified | 
   611             TPbk2ContactEditorParams::EOwnContact) );
   774             TPbk2ContactEditorParams::EOwnContact) );
   612     	if( err != KErrNone )
   775     	if( err != KErrNone )
   613 			{
   776 			{
   614 			//TODO handle errors
   777             iPlugin.HandleError( err );
   615 			}
   778 			}
   616     	}    
   779     	}    
   617     else if( aResult.iOpCode == MVPbkContactObserver::EContactDelete )
   780     else if( aResult.iOpCode == MVPbkContactObserver::EContactDelete )
   618     	{
   781     	{
   619 		iCloseCallBack->Call();
   782 		iCloseCallBack->Call();
   620     	}
   783     	}   
   621     else
       
   622     	{
       
   623     	//TODO handle errors
       
   624     	}
       
   625         
   784         
   626     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::ContactOperationCompleted()")); 
   785     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCard::ContactOperationCompleted()")); 
   627     }
   786     }
   628 
   787 
   629 // ---------------------------------------------------------------------------
   788 // ---------------------------------------------------------------------------
   630 // CCCAppMyCard::ContactOperationFailed
   789 // CCCAppMyCard::ContactOperationFailed
   631 // ---------------------------------------------------------------------------
   790 // ---------------------------------------------------------------------------
   632 //
   791 //
   633 void CCCAppMyCard::ContactOperationFailed(
   792 void CCCAppMyCard::ContactOperationFailed(
   634     TContactOp /*aOpCode*/, TInt /*aErrorCode*/, TBool /*aErrorNotified*/)    
   793     TContactOp aOpCode, TInt aErrorCode, TBool /*aErrorNotified*/ )    
   635     {
   794     {
   636     // TODO handle error
   795     if ( aErrorCode != KErrNone )          
       
   796         {                                  
       
   797         iPlugin.HandleError( aErrorCode );    
       
   798         }        
   637     }
   799     }
   638 
   800 
   639 // ---------------------------------------------------------------------------
   801 // ---------------------------------------------------------------------------
   640 // CCCAppMyCard::VPbkSingleContactOperationComplete
   802 // CCCAppMyCard::VPbkSingleContactOperationComplete
   641 // ---------------------------------------------------------------------------
   803 // ---------------------------------------------------------------------------
   655     
   817     
   656     // also delete presentation contact, since it points to old store contact
   818     // also delete presentation contact, since it points to old store contact
   657     delete iPresentationContact;
   819     delete iPresentationContact;
   658     iPresentationContact = NULL;
   820     iPresentationContact = NULL;
   659     
   821     
   660     NotifyObservers( MMyCardObserver::EEventContactLoaded );
   822     NotifyObservers( iEvent );
   661 
   823 
   662     CCA_DP(KMyCardLogFile, 
   824     CCA_DP(KMyCardLogFile, 
   663         CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationComplete()"));    
   825         CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationComplete()"));    
   664     }
   826     }
   665 
   827 
   679     iFetchOperation = NULL;
   841     iFetchOperation = NULL;
   680 
   842 
   681     delete iOperation;
   843     delete iOperation;
   682     iOperation = NULL;
   844     iOperation = NULL;
   683     
   845     
   684     // TODO: How to handle loading error?
   846     if( aError != KErrNone )
       
   847         {
       
   848         iPlugin.HandleError( aError );
       
   849         }
   685 
   850 
   686     CCA_DP(KMyCardLogFile, 
   851     CCA_DP(KMyCardLogFile, 
   687         CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationFailed()") );    
   852         CCA_L("<-CCCAppMyCard::VPbkSingleContactOperationFailed()") );    
   688     }
   853     }
   689 
   854