emailcontacts/contactactionservice/saveascontactplugin/src/cfscsaveascontactpluginimpl.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2008 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 the class CfscsaveascontactpluginImpl.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <bautils.h>
       
    22 #include <aknnotewrappers.h>
       
    23 #include <fscsaveascontactplugin.rsg>
       
    24 #include <fscsaveascontactplugin.mbg>
       
    25 #include <AknsConstants.h>
       
    26 //<cmail>
       
    27 #include "mfsccontactset.h"
       
    28 #include "mfscactionutils.h"
       
    29 #include "cfsccontactaction.h"
       
    30 #include "fsccontactactionservicedefines.h"
       
    31 #include <MVPbkStoreContact.h>
       
    32 #include <MVPbkContactObserver.h>
       
    33 #include <CPbk2StoreConfiguration.h>
       
    34 #include <TVPbkContactStoreUriPtr.h>
       
    35 #include <MVPbkContactStoreList.h>
       
    36 #include <e32cmn.h>
       
    37 #include "mfsccontactactionpluginobserver.h"
       
    38 //</cmail>
       
    39 #include <CVPbkContactManager.h>
       
    40 #include <MVPbkContactStore.h>
       
    41 #include <MVPbkStoreContactField.h>
       
    42 #include <MVPbkContactFieldData.h>
       
    43 #include <VPbkContactStoreUris.h>
       
    44 #include <AknWaitDialog.h>
       
    45 
       
    46 #include "fsccontactactionserviceuids.hrh"
       
    47 #include "fscactionpluginactionuids.h"
       
    48 #include "fscactionplugincrkeys.h"
       
    49 #include "cfscsaveascontactpluginimpl.h"
       
    50 // <cmail>
       
    51 #include "FscActionPluginUtils.h"
       
    52 // </cmail>
       
    53 
       
    54 
       
    55 // CONSTANTS DECLARATIONS
       
    56 const TInt KActionCount = 1;
       
    57 const TInt KInvalidReasonId = 0;
       
    58 
       
    59 _LIT( KSaveAsContactPluginIconPath,
       
    60         "\\resource\\apps\\fscsaveascontactplugin.mif" );
       
    61 _LIT( KResourceFilePath, "\\resource\\apps\\fscsaveascontactplugin.rsc" );
       
    62 
       
    63 const TImplementationProxy ImplementationTable[] =
       
    64     {
       
    65             IMPLEMENTATION_PROXY_ENTRY(
       
    66                     KFscSaveAsContactPluginImplImpUid,
       
    67                     CFscSaveAsContactPluginImpl::NewL )
       
    68     };
       
    69 
       
    70 // ======== MEMBER FUNCTIONS ========
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CFscSaveAsContactPluginImpl::NewL
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CFscSaveAsContactPluginImpl* CFscSaveAsContactPluginImpl::NewL(
       
    77         TAny* aParams)
       
    78     {
       
    79     FUNC_LOG;
       
    80 
       
    81     TFscContactActionPluginParams* params =
       
    82             reinterpret_cast< TFscContactActionPluginParams* >(aParams );
       
    83 
       
    84     CFscSaveAsContactPluginImpl* self = new (ELeave) CFscSaveAsContactPluginImpl( *params );
       
    85     CleanupStack::PushL(self);
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop(self);
       
    88 
       
    89     return self;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CFscSaveAsContactPluginImpl::~CFscSaveAsContactPluginImpl
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CFscSaveAsContactPluginImpl::~CFscSaveAsContactPluginImpl()
       
    97     {
       
    98     FUNC_LOG;
       
    99     DismissWaitNote();
       
   100     delete iNewStoreContact;
       
   101     delete iContactSaveAsContactAction;
       
   102     delete iActionList;
       
   103     CCoeEnv::Static()->DeleteResourceFile(iResourceHandle);
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CFscSaveAsContactPluginImpl::Uid
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 TUid CFscSaveAsContactPluginImpl::Uid() const
       
   111     {
       
   112     FUNC_LOG;
       
   113     TUid uid =
       
   114         {
       
   115          KFscSaveAsContactPluginImplImpUid
       
   116         };
       
   117     return uid;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CFscSaveAsContactPluginImpl::ActionList
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 const CArrayFix<TUid>* CFscSaveAsContactPluginImpl::ActionList() const
       
   125     {
       
   126     return iActionList;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CFscSaveAsContactPluginImpl::GetActionL
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 const MFscContactAction& CFscSaveAsContactPluginImpl::GetActionL(
       
   134         TUid aActionUid) const
       
   135     {
       
   136     FUNC_LOG;
       
   137 
       
   138     const MFscContactAction* action= NULL;
       
   139     if (aActionUid == KFscActionUidSaveAsContact)
       
   140         {
       
   141         action = iContactSaveAsContactAction;
       
   142         }
       
   143     else
       
   144         {
       
   145         User::Leave(KErrNotFound);
       
   146         }
       
   147 
       
   148     return *action;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CFscSaveAsContactPluginImpl::PriorityForContactSetL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CFscSaveAsContactPluginImpl::PriorityForContactSetL(
       
   156         TUid aActionUid,
       
   157         MFscContactSet& aContactSet,
       
   158         TFscContactActionVisibility& aActionMenuVisibility,
       
   159         TFscContactActionVisibility& aOptionsMenuVisibility,
       
   160         MFscContactActionPluginObserver* aObserver)
       
   161     {
       
   162     FUNC_LOG;
       
   163     iActionUid = aActionUid;
       
   164     iContactSet = &aContactSet;
       
   165     iActionMenuVisibility = &aActionMenuVisibility;
       
   166     iOptionsMenuVisibility = &aOptionsMenuVisibility;
       
   167 
       
   168     iIsExecute = EFalse;
       
   169 
       
   170     iContactSet->SetToFirstContact();
       
   171 
       
   172     iActionPriority = KFscActionPriorityNotAvailable;
       
   173 
       
   174     iCanDisplay = KErrNone;
       
   175 
       
   176     if (iActionUid == KFscActionUidSaveAsContact)
       
   177         {
       
   178         // We save only one contact and no groups:
       
   179         iCanDisplay = (aContactSet.GroupCount() == 0
       
   180                 && aContactSet.ContactCount() == 1 ) ? KErrNone : KErrArgument;
       
   181 
       
   182         //Fix for EJKA-7MFDHU
       
   183         // <cmail>
       
   184         if (iCanDisplay == KErrNone
       
   185         		&& IsValidStoreL() )
       
   186         // </cmail>
       
   187             {
       
   188             aActionMenuVisibility.iVisibility
       
   189                     = TFscContactActionVisibility::EFscActionVisible;
       
   190             aOptionsMenuVisibility.iVisibility
       
   191                     = TFscContactActionVisibility::EFscActionVisible;
       
   192 
       
   193             iActionPriority = iParams.iUtils->ActionPriority(
       
   194                     KFscCrUidSaveAsContact, KFscActionPrioritySaveAsContact);
       
   195             if (iActionPriority > 0)
       
   196                 {
       
   197                 // ignore any leave while updating action icons
       
   198                 TRAP_IGNORE( UpdateActionIconL( aActionUid ) );
       
   199                 }
       
   200             }
       
   201         else
       
   202             {
       
   203             iActionPriority = KFscActionPriorityNotAvailable;
       
   204             aActionMenuVisibility.iVisibility
       
   205                     = TFscContactActionVisibility::EFscActionHidden;
       
   206             aActionMenuVisibility.iReasonId = KInvalidReasonId;
       
   207             aOptionsMenuVisibility.iVisibility
       
   208                     = TFscContactActionVisibility::EFscActionHidden;
       
   209             aOptionsMenuVisibility.iReasonId = KInvalidReasonId;
       
   210             }
       
   211         ResetData();
       
   212         aObserver->PriorityForContactSetComplete(iActionPriority);
       
   213         }
       
   214     else
       
   215         {
       
   216         ResetData();
       
   217         aObserver->PriorityForContactSetFailed(KErrArgument);
       
   218         }
       
   219     }
       
   220 // ---------------------------------------------------------------------------
       
   221 // CFscSaveAsContactPluginImpl::CancelPriorityForContactSet 
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CFscSaveAsContactPluginImpl::CancelPriorityForContactSet()
       
   225     {
       
   226     FUNC_LOG;
       
   227     iLastEvent = EActionEventCanceled;
       
   228     ResetData();
       
   229     }
       
   230 // ---------------------------------------------------------------------------
       
   231 // CFscSaveAsContactPluginImpl::ExecuteL 
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CFscSaveAsContactPluginImpl::ExecuteL(
       
   235         TUid aActionUid,
       
   236         MFscContactSet& aContactSet,
       
   237         MFscContactActionPluginObserver* aObserver)
       
   238     {
       
   239     FUNC_LOG;
       
   240     switch (iLastEvent)
       
   241         {
       
   242         case EActionEventIdle:
       
   243             {
       
   244 
       
   245             iLastEvent = EActionEventCanExecuteLaunched;
       
   246 
       
   247             iActionUid = aActionUid;
       
   248             iContactSet = &aContactSet;
       
   249             iPluginObserver = aObserver;
       
   250 
       
   251             iIsExecute = ETrue;
       
   252 
       
   253             iContactSet->SetToFirstContact();
       
   254 
       
   255             CanExecuteL(aActionUid, aContactSet);
       
   256 
       
   257             break;
       
   258             }
       
   259 
       
   260         case EActionEventCanExecuteFinished:
       
   261             {
       
   262 
       
   263             iWaitDialog = new(ELeave)CAknWaitDialog(
       
   264                     (REINTERPRET_CAST(CEikDialog**,&iWaitDialog)), EFalse);
       
   265             iWaitDialog->ExecuteLD(R_FS_WAIT_NOTE);
       
   266             
       
   267             if (iCanDisplay == KErrNone)
       
   268                 {
       
   269                 iLastEvent = EActionEventContactRetrieve;
       
   270                 iPluginObserver = aObserver;
       
   271                 aContactSet.NextContactL(this);
       
   272                 }
       
   273             else
       
   274                 {
       
   275                 ResetData();
       
   276                 iPluginObserver->ExecuteFailed(KErrGeneral);
       
   277                 }
       
   278             break;
       
   279             }            
       
   280         case EActionEventCanceled:
       
   281             {
       
   282             iLastEvent = EActionEventIdle;
       
   283             break;
       
   284             }
       
   285         default:
       
   286             {
       
   287             ResetData();
       
   288             break; // <cmail>
       
   289             }
       
   290         }
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // CFscSaveAsContactPluginImpl::CancelExecute
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CFscSaveAsContactPluginImpl::CancelExecute()
       
   298     {
       
   299     FUNC_LOG;
       
   300     DismissWaitNote();
       
   301     iLastEvent = EActionEventCanceled;
       
   302     ResetData();
       
   303     }
       
   304 // ---------------------------------------------------------------------------
       
   305 // CFscSaveAsContactPluginImpl::GetReasonL
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CFscSaveAsContactPluginImpl::GetReasonL(
       
   309         TUid /* aActionUid */,
       
   310         TInt /* aReasonId */,
       
   311         HBufC*& /* aReason */) const
       
   312     {
       
   313     FUNC_LOG;
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CFscSaveAsContactPluginImpl::NextContactComplete
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CFscSaveAsContactPluginImpl::NextContactComplete(
       
   321         MVPbkStoreContact* aContact)
       
   322     {
       
   323     FUNC_LOG;
       
   324     TInt err( KErrNone );
       
   325     switch (iLastEvent)
       
   326         {
       
   327         case EActionEventContactRetrieve:
       
   328             {
       
   329             iRetrievedStoreContact = aContact;
       
   330             iLastEvent = EActionEventExecuteLaunched;
       
   331             TRAP (err, PrepareStoreL() );
       
   332             break;
       
   333             }
       
   334         case EActionEventCanceled:
       
   335             {
       
   336             iLastEvent = EActionEventIdle;
       
   337             break;
       
   338             }
       
   339         default:
       
   340             {
       
   341             ResetData();
       
   342             break; // <cmail>
       
   343             }
       
   344         }
       
   345     if ( err != KErrNone )
       
   346         {
       
   347         CCoeEnv::Static()->HandleError( err );
       
   348         }
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CFscSaveAsContactPluginImpl::NextContactFailed
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CFscSaveAsContactPluginImpl::NextContactFailed(
       
   356         TInt aError)
       
   357     {
       
   358     FUNC_LOG;
       
   359 
       
   360     ResetData();
       
   361     iPluginObserver->ExecuteFailed(aError);
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // CFscSaveAsContactPluginImpl::NextGroupComplete
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 void CFscSaveAsContactPluginImpl::NextGroupComplete(
       
   369         MVPbkStoreContact* /*aContact*/)
       
   370     {
       
   371     FUNC_LOG;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CFscSaveAsContactPluginImpl::NextGroupFailed
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CFscSaveAsContactPluginImpl::NextGroupFailed(
       
   379         TInt /*aError*/)
       
   380     {
       
   381     FUNC_LOG;
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CFscSaveAsContactPluginImpl::GetGroupContactComplete
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CFscSaveAsContactPluginImpl::GetGroupContactComplete(
       
   389         MVPbkStoreContact* /*aContact*/)
       
   390     {
       
   391     FUNC_LOG;
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CFscSaveAsContactPluginImpl::GetGroupContactFailed
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CFscSaveAsContactPluginImpl::GetGroupContactFailed(
       
   399         TInt /*aError*/)
       
   400     {
       
   401     FUNC_LOG;
       
   402     }
       
   403 
       
   404 // <cmail>
       
   405 // ---------------------------------------------------------------------------
       
   406 // CFscSaveAsContactPluginImpl::IsValidStoreL
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 TBool CFscSaveAsContactPluginImpl::IsValidStoreL()
       
   410 // </cmail>	
       
   411 	{
       
   412     FUNC_LOG;
       
   413 	TBool isValid = EFalse;
       
   414 	
       
   415 	//Currently method is checking if saving store is cntdb
       
   416 	//if saving store is SIM, contact can't be saved
       
   417 	//(SIM store is not supported yet)
       
   418 	
       
   419 	CPbk2StoreConfiguration* storeCnf = CPbk2StoreConfiguration::NewL();
       
   420 	CleanupStack::PushL(storeCnf);
       
   421 	TVPbkContactStoreUriPtr defaultStorePtr = 
       
   422 		storeCnf->DefaultSavingStoreL();
       
   423 	TVPbkContactStoreUriPtr validStorePtr( 
       
   424 			VPbkContactStoreUris::DefaultCntDbUri() 
       
   425 			);
       
   426 	
       
   427 	if ( !defaultStorePtr.Compare( 
       
   428 			validStorePtr.UriDes(), 
       
   429 			TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) 
       
   430 			)
       
   431 		{
       
   432 		isValid = ETrue;
       
   433 		}
       
   434 	
       
   435 	CleanupStack::PopAndDestroy(storeCnf);
       
   436 	return isValid;
       
   437 	}
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // CFscSaveAsContactPluginImpl::PrepareStoreL
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 void CFscSaveAsContactPluginImpl::PrepareStoreL()
       
   444     {
       
   445     FUNC_LOG;
       
   446     CPbk2StoreConfiguration* storeCnf = CPbk2StoreConfiguration::NewL();
       
   447     CleanupStack::PushL(storeCnf);
       
   448     TVPbkContactStoreUriPtr storePtr = storeCnf->DefaultSavingStoreL();
       
   449     CVPbkContactManager& contactManager = iParams.iUtils->ContactManager();
       
   450 	contactManager.LoadContactStoreL( storePtr );            
       
   451 	iTargetStore = contactManager.ContactStoresL().
       
   452 						Find( storePtr );
       
   453 	if ( iTargetStore )
       
   454         {
       
   455 		iTargetStore->OpenL( *this );
       
   456 		}
       
   457 	else //store not found
       
   458 		{
       
   459 		ResetData();
       
   460 		iPluginObserver->ExecuteFailed( KErrNotFound );
       
   461 		}
       
   462 	CleanupStack::PopAndDestroy(storeCnf);
       
   463 	}
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CFscSaveAsContactPluginImpl::SaveToContactDatabaseL
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CFscSaveAsContactPluginImpl::SaveToContactDatabaseL(
       
   470         MVPbkStoreContact* aStoreContact)
       
   471     {
       
   472     FUNC_LOG;
       
   473 
       
   474 	iNewStoreContact = iTargetStore->CreateNewContactLC();
       
   475         CleanupStack::Pop();//iNewStoreContact
       
   476         MVPbkStoreContactFieldCollection& fields = aStoreContact->Fields();
       
   477         TInt i = 0;
       
   478 	TInt a = fields.FieldCount();
       
   479         // Copy fields to the new store contact. No field matching check
       
   480         for (i = 0; i < fields.FieldCount(); i++)
       
   481             {
       
   482             MVPbkStoreContactField& oldField = fields.FieldAt(i);
       
   483             const MVPbkFieldType* fieldType =
       
   484                     oldField.BestMatchingFieldType();
       
   485             if (fieldType != NULL)
       
   486                 {
       
   487                 MVPbkStoreContactField* newField =
       
   488                         iNewStoreContact->CreateFieldLC(*fieldType);
       
   489                 newField->FieldData().CopyL(oldField.FieldData());
       
   490                 iNewStoreContact->AddFieldL(newField);
       
   491                 CleanupStack::Pop();//newField
       
   492                 }
       
   493             }
       
   494         // This is new contact so we don't need to lock it before commiting
       
   495         iNewStoreContact->CommitL( *this);
       
   496  
       
   497 
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CFscSaveAsContactPluginImpl::StoreReady
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CFscSaveAsContactPluginImpl::StoreReady( 
       
   505         MVPbkContactStore& aContactStore )
       
   506     {
       
   507     FUNC_LOG;
       
   508     iTargetStore = &aContactStore;
       
   509     TRAPD( err, SaveToContactDatabaseL( iRetrievedStoreContact ) );
       
   510     if ( err != KErrNone )
       
   511     	{
       
   512 		ResetData();
       
   513         iPluginObserver->ExecuteFailed( err );
       
   514 		}
       
   515     }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // CFscSaveAsContactPluginImpl::StoreUnavailable
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void CFscSaveAsContactPluginImpl::StoreUnavailable( 
       
   522         MVPbkContactStore& /*aContactStore*/, 
       
   523         TInt /*aReason*/ )
       
   524     {
       
   525     FUNC_LOG;
       
   526     ResetData();
       
   527 	iPluginObserver->ExecuteFailed(KErrArgument);
       
   528     }
       
   529         
       
   530 // ---------------------------------------------------------------------------
       
   531 // CFscSaveAsContactPluginImpl::HandleStoreEventL
       
   532 // ---------------------------------------------------------------------------
       
   533 //       
       
   534 void CFscSaveAsContactPluginImpl::HandleStoreEventL(
       
   535         MVPbkContactStore& /*aContactStore*/, 
       
   536         TVPbkContactStoreEvent /*aStoreEvent*/ )
       
   537     {
       
   538     FUNC_LOG;
       
   539     // Do nothing
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // CFscSaveAsContactPluginImpl::CanExecuteL
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CFscSaveAsContactPluginImpl::CanExecuteL(
       
   547         TUid aActionUid,
       
   548         MFscContactSet& aContactSet)
       
   549     {
       
   550     FUNC_LOG;
       
   551 
       
   552     if (aActionUid == KFscActionUidSaveAsContact)
       
   553         {
       
   554         iCanDisplay = (aContactSet.GroupCount() == 0
       
   555                 && aContactSet.ContactCount() == 1 )
       
   556                                                      ? KErrNone
       
   557                                                      : KErrArgument;
       
   558         iLastEvent = EActionEventCanExecuteFinished;
       
   559         ResumeAsync(aActionUid, aContactSet, iIsExecute);
       
   560         }
       
   561     else
       
   562         {
       
   563         //Just in case
       
   564         ResetData();
       
   565         iPluginObserver->ExecuteFailed(KErrArgument);
       
   566         }
       
   567 
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------------------------
       
   571 // CFscSaveAsContactPluginImpl::UpdateActionIconL
       
   572 // ---------------------------------------------------------------------------
       
   573 //
       
   574 void CFscSaveAsContactPluginImpl::UpdateActionIconL(
       
   575         TUid aActionUid)
       
   576     {
       
   577     FUNC_LOG;
       
   578 
       
   579     TFileName dllFileName;
       
   580     Dll::FileName(dllFileName);
       
   581     TParse parse;
       
   582     User::LeaveIfError(parse.Set(
       
   583             KSaveAsContactPluginIconPath, &dllFileName, 
       
   584             NULL) );
       
   585 
       
   586     if (aActionUid == KFscActionUidSaveAsContact)
       
   587 // <cmail>
       
   588         {
       
   589         iContactSaveAsContactAction->SetIcon(iParams.iUtils->SkinIconL(
       
   590                 KAknsIIDQgnFsRclActionSave, parse.FullName(),
       
   591                 EMbmFscsaveascontactpluginQgn_prop_cmail_action_save,
       
   592                 EMbmFscsaveascontactpluginQgn_prop_cmail_action_save_mask) );
       
   593 // </cmail>
       
   594         }
       
   595 
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // CFscSaveAsContactPluginImpl::CFscSaveAsContactPluginImpl
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 CFscSaveAsContactPluginImpl::CFscSaveAsContactPluginImpl(
       
   603         const TFscContactActionPluginParams& aParams) :
       
   604     CFscContactActionPlugin(), iParams(aParams), iResourceHandle( 0),
       
   605             iLastEvent(EActionEventIdle), iCanDisplay(KErrNone),
       
   606             iIsExecute(EFalse)
       
   607     {
       
   608     FUNC_LOG;
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // CFscSaveAsContactPluginImpl::ConstructL
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CFscSaveAsContactPluginImpl::ConstructL()
       
   616     {
       
   617     FUNC_LOG;
       
   618     
       
   619     TFileName dllFileName;
       
   620     Dll::FileName(dllFileName);
       
   621     TParse parse;
       
   622     User::LeaveIfError(parse.Set(
       
   623             KResourceFilePath, &dllFileName, NULL) );
       
   624     TFileName resourceFileName(parse.FullName() );
       
   625     BaflUtils::NearestLanguageFile(
       
   626             CCoeEnv::Static()->FsSession(), resourceFileName);
       
   627 
       
   628     iResourceHandle = ( CCoeEnv::Static() )->AddResourceFileL(resourceFileName);
       
   629 
       
   630     iActionList = new( ELeave )CArrayFixFlat<TUid>( KActionCount );
       
   631     iActionList->AppendL(KFscActionUidSaveAsContact);
       
   632 
       
   633     User::LeaveIfError(parse.Set(
       
   634             KSaveAsContactPluginIconPath, &dllFileName, NULL) );
       
   635 // <cmail>    
       
   636     iContactSaveAsContactAction = iParams.iUtils->CreateActionL(
       
   637             *this, KFscActionUidSaveAsContact, KFscAtManSaveAs, 
       
   638             R_FS_ACTION_SAVE_AS_CONTACT, iParams.iUtils->SkinIconL(
       
   639                     KAknsIIDQgnFsRclActionSave, parse.FullName(),
       
   640                     EMbmFscsaveascontactpluginQgn_prop_cmail_action_save,
       
   641                     EMbmFscsaveascontactpluginQgn_prop_cmail_action_save_mask) );
       
   642 // </cmail>
       
   643     }
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // CFscSaveAsContactPluginImpl::ResetData
       
   647 // ---------------------------------------------------------------------------
       
   648 //
       
   649 void CFscSaveAsContactPluginImpl::ResetData()
       
   650     {
       
   651     FUNC_LOG;
       
   652     if (iContactSet)
       
   653         {
       
   654         iContactSet->SetToFirstContact();
       
   655         iContactSet->SetToFirstGroup();
       
   656         // <cmail>
       
   657         TRAP_IGNORE( iContactSet->CancelNextContactL() );
       
   658         TRAP_IGNORE( iContactSet->CancelNextGroupL() );
       
   659         // </cmail>        
       
   660         iContactSet = NULL;
       
   661         }
       
   662     DismissWaitNote();
       
   663 
       
   664     iLastEvent = EActionEventIdle;
       
   665     iActionMenuVisibility = NULL;
       
   666     iOptionsMenuVisibility = NULL;
       
   667     iCanDisplay = KErrNone;
       
   668     iRetrievedStoreContact = NULL;
       
   669     }
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // CFscSaveAsContactPluginImpl::ResumeAsync
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 void CFscSaveAsContactPluginImpl::ResumeAsync(
       
   676         TUid aActionUid,
       
   677         MFscContactSet& aContactSet,
       
   678         TBool aIsExecute )
       
   679     {
       
   680     FUNC_LOG;
       
   681     TInt err( KErrNone );
       
   682     if ( aIsExecute )
       
   683         {
       
   684         TRAP( err, ExecuteL( aActionUid, aContactSet, iPluginObserver ) );
       
   685         }
       
   686     else
       
   687         {
       
   688         TRAP( err, PriorityForContactSetL(aActionUid, aContactSet, 
       
   689                 *iActionMenuVisibility, *iOptionsMenuVisibility, 
       
   690                 iPluginObserver ) );
       
   691         }
       
   692     
       
   693     if ( err != KErrNone )
       
   694         {
       
   695         ResetData();
       
   696         if ( aIsExecute )
       
   697             {
       
   698             iPluginObserver->ExecuteFailed( err );
       
   699             }
       
   700         else
       
   701             {
       
   702             iPluginObserver->PriorityForContactSetFailed( err );
       
   703             }
       
   704         }
       
   705     
       
   706     }
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // CFscSaveAsContactPluginImpl::ContactOperationCompleted
       
   710 // ---------------------------------------------------------------------------
       
   711 //
       
   712 void CFscSaveAsContactPluginImpl::ContactOperationCompleted(
       
   713         MVPbkContactObserver::TContactOpResult aResult)
       
   714     {
       
   715     FUNC_LOG;
       
   716     TInt err( KErrNone );
       
   717     switch (aResult.iOpCode)
       
   718         {
       
   719         case EContactLock:
       
   720             {
       
   721             TRAP( err, iNewStoreContact->CommitL( *this ) );
       
   722             break;
       
   723             }
       
   724         case EContactCommit:
       
   725             {
       
   726             DismissWaitNote();
       
   727             TRAP( err, iParams.iUtils->ShowCnfNoteL( 
       
   728                     R_FS_ACTION_SAVED_NOTE ) );
       
   729             ResetData();
       
   730             iPluginObserver->ExecuteComplete();
       
   731 
       
   732             if (iNewStoreContact != NULL)
       
   733                 {
       
   734                 delete iNewStoreContact;
       
   735                 iNewStoreContact = NULL;
       
   736                 }
       
   737             break;
       
   738             }
       
   739         case EActionEventCanceled:
       
   740             {
       
   741             iLastEvent = EActionEventIdle;
       
   742             break;
       
   743             }
       
   744         default:
       
   745             {
       
   746             ResetData();
       
   747             break; // <cmail>
       
   748             }            
       
   749         }
       
   750     
       
   751     if ( err != KErrNone )
       
   752         {
       
   753         ResetData();
       
   754         if ( iIsExecute )
       
   755             {
       
   756             iPluginObserver->ExecuteFailed( err );
       
   757             }
       
   758         else
       
   759             {
       
   760             iPluginObserver->PriorityForContactSetFailed( err );
       
   761             }
       
   762         }
       
   763     }
       
   764 
       
   765 // ---------------------------------------------------------------------------
       
   766 // CFscSaveAsContactPluginImpl::ContactOperationFailed
       
   767 // ---------------------------------------------------------------------------
       
   768 //
       
   769 void CFscSaveAsContactPluginImpl::ContactOperationFailed(
       
   770         MVPbkContactObserver::TContactOp /*aOpCode*/,
       
   771         TInt aErrorCode,
       
   772         TBool /*aErrorNotified*/)
       
   773     {
       
   774     FUNC_LOG;
       
   775     iLastEvent = EActionEventIdle;
       
   776     DismissWaitNote();
       
   777     ResetData();
       
   778     iPluginObserver->ExecuteFailed(aErrorCode);
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // CFscSaveAsContactPluginImpl::DismissWaitDialog
       
   783 // ---------------------------------------------------------------------------
       
   784 //
       
   785 void CFscSaveAsContactPluginImpl::DismissWaitNote()
       
   786     {
       
   787     FUNC_LOG;
       
   788     if (iWaitDialog != NULL)
       
   789         {
       
   790         TRAPD( err, iWaitDialog->ProcessFinishedL() );
       
   791         if (err != KErrNone)
       
   792             {
       
   793             delete iWaitDialog;
       
   794             iWaitDialog = NULL;
       
   795             }
       
   796         }
       
   797     }
       
   798 // ======== GLOBAL FUNCTIONS ========
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // ImplementationGroupProxy
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
   805         TInt& aTableCount )
       
   806     {
       
   807     aTableCount =
       
   808     sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   809     return ImplementationTable;
       
   810     }
       
   811