phonebookui/Phonebook2/remotecontactlookup/contactactionservice/sendplugin/src/cfscsendpluginimpl.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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 CFscSendPluginImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <implementationproxy.h>
       
    21 #include <bautils.h>
       
    22 #include <CMessageData.h>
       
    23 #include <sendui.h>
       
    24 #include <sysutil.h>
       
    25 #include <SenduiMtmUids.h>
       
    26 #include <TSendingCapabilities.h>
       
    27 #include <AknQueryDialog.h>
       
    28 #include <AknsConstants.h>
       
    29 #include <RPbkViewResourceFile.h> 
       
    30 #include "mfsccontactset.h"
       
    31 #include "mfscactionutils.h"
       
    32 #include <pbk2rclactionutils.rsg>
       
    33 #include <pbk2rclsendplugin.rsg>
       
    34 #include <pbk2rclsendplugin.mbg>
       
    35 #include "cfsccontactaction.h"
       
    36 #include <StringLoader.h>
       
    37 #include <featmgr.h>
       
    38 #include "fsccontactactionserviceuids.hrh"
       
    39 #include "mfsccontactactionpluginobserver.h"
       
    40 #include <MVPbkStoreContact.h>
       
    41 #include <MVPbkContactStore.h>
       
    42 #include <MVPbkContactGroup.h>
       
    43 #include <MVPbkContactLinkArray.h>
       
    44 #include <CVPbkContactManager.h>
       
    45 #include <CVPbkContactIdConverter.h>
       
    46 
       
    47 #include "fscactionpluginactionuids.h"
       
    48 #include "cfscsendpluginimpl.h"
       
    49 #include "cfscattachmentfile.h"
       
    50 #include "fscactionplugincrkeys.h"
       
    51 
       
    52 // CONSTANTS DECLARATIONS
       
    53 const TInt KMaxContactIdStringLength = 10;
       
    54 const TInt KMsgSpaceEstimationBytes = 10240;
       
    55 const TInt KMaxLenghtOfAddressData = 255;
       
    56 
       
    57 const TUid KCRUidUniEditor = {0x102072E5};
       
    58 const TUint32 KUniEditorMaxRecipientCount = 0x00000002;
       
    59 const TUint32 KUniEditorSoftLimitRecipientCount = 0x00000003;
       
    60 
       
    61 const TInt KDefaultSmsRecipients = 20;
       
    62 const TInt KDefaultMmsRecipients = 100;
       
    63 const TInt KDefaultEmailRecipients = KMaxTInt;
       
    64 
       
    65 const TInt KActionCount = 4;
       
    66 const TInt KInvalidReasonId = 0;
       
    67 //const TInt KContactListGranularity = 2;
       
    68 
       
    69 _LIT( KSendPluginIconPath, "\\resource\\apps\\pbk2rclsendplugin.mif" );
       
    70 _LIT( KResourceFilePath, "\\resource\\apps\\pbk2rclsendplugin.rsc");
       
    71 
       
    72 // typedef declarations
       
    73 typedef TBuf<KMaxLenghtOfAddressData> TAddressData;
       
    74 
       
    75 
       
    76 const TImplementationProxy ImplementationTable[] =
       
    77     {
       
    78     IMPLEMENTATION_PROXY_ENTRY(
       
    79         KFscSendPluginImplImpUid,
       
    80         CFscSendPluginImpl::NewL )
       
    81     };
       
    82 	
       
    83 // ======== MEMBER FUNCTIONS ========
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CFscSendPluginImpl::NewL
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CFscSendPluginImpl* CFscSendPluginImpl::NewL( TAny* aParams )
       
    90     {
       
    91     FUNC_LOG;
       
    92 
       
    93     TFscContactActionPluginParams* params = 
       
    94             reinterpret_cast< TFscContactActionPluginParams* >( aParams );
       
    95             
       
    96     CFscSendPluginImpl* self = new( ELeave ) CFscSendPluginImpl( *params );
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop( self );
       
   100     return self;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CFscSendPluginImpl::~CFscSendPluginImpl
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CFscSendPluginImpl::~CFscSendPluginImpl()
       
   108     {
       
   109     FUNC_LOG;
       
   110     delete iContactMsgAction;
       
   111     delete iContactAudioMsgAction;
       
   112     delete iContactPostcardAction;
       
   113 
       
   114     delete iContactEmailAction;
       
   115     delete iActionList;
       
   116     delete iAttachmentFile;
       
   117     CCoeEnv::Static()->DeleteResourceFile( iResourceHandle );
       
   118     }
       
   119     
       
   120 // ---------------------------------------------------------------------------
       
   121 // CFscSendPluginImpl::Uid
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TUid CFscSendPluginImpl::Uid() const 
       
   125     {
       
   126     FUNC_LOG;
       
   127     TUid uid = { KFscSendPluginImplImpUid };
       
   128     return uid;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CFscSendPluginImpl::ActionList
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 const CArrayFix<TUid>* CFscSendPluginImpl::ActionList() const
       
   136     {
       
   137 	FUNC_LOG;
       
   138     return iActionList;
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------------------------
       
   142 // CFscSendPluginImpl::GetActionL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 const MFscContactAction& CFscSendPluginImpl::GetActionL(
       
   146     TUid aActionUid ) const
       
   147     {
       
   148 	FUNC_LOG;
       
   149     
       
   150     const MFscContactAction* action = NULL;
       
   151 
       
   152     if ( aActionUid == KFscActionUidCreateMsg )
       
   153         {
       
   154         action = iContactMsgAction;
       
   155         }
       
   156     else if ( aActionUid == KFscActionUidCreateAudMsg )
       
   157         {
       
   158         action = iContactAudioMsgAction;
       
   159         }
       
   160     else if ( aActionUid == KFscActionUidPostcard &&
       
   161               iContactPostcardAction != NULL )
       
   162         {
       
   163         action = iContactPostcardAction;
       
   164         }
       
   165     else if ( aActionUid == KFscActionUidEmail )
       
   166         {
       
   167         action = iContactEmailAction;
       
   168         }
       
   169     else
       
   170         {
       
   171         User::Leave( KErrNotFound );
       
   172         }
       
   173         
       
   174     return *action;
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CFscSendPluginImpl::PriorityForContactSetL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CFscSendPluginImpl::PriorityForContactSetL( 
       
   183     TUid aActionUid,
       
   184     MFscContactSet& aContactSet,
       
   185     TFscContactActionVisibility& aActionMenuVisibility,
       
   186     TFscContactActionVisibility& aOptionsMenuVisibility,
       
   187     MFscContactActionPluginObserver* aObserver )
       
   188     {
       
   189     FUNC_LOG;
       
   190 
       
   191     switch(iLastEvent)
       
   192         {
       
   193         case EActionEventIdle:
       
   194             {
       
   195             iActionUid = aActionUid;
       
   196             iContactSet = &aContactSet;
       
   197             iActionMenuVisibility = &aActionMenuVisibility;
       
   198             iOptionsMenuVisibility = &aOptionsMenuVisibility;
       
   199             iPluginObserver = aObserver;
       
   200 
       
   201             iIsExecute = EFalse;
       
   202             iActionPriority = KFscActionPriorityNotAvailable;
       
   203             
       
   204             iContactSet->SetToFirstContact();
       
   205             iContactSet->SetToFirstGroup();
       
   206             
       
   207             iLastEvent = EActionEventCanExecuteLaunched;
       
   208             CanExecuteL( aActionUid, aContactSet );
       
   209             
       
   210             break;
       
   211             }
       
   212         case EActionEventCanExecuteFinished:
       
   213             {
       
   214   
       
   215             if ( iCanDisplay == KErrNone )
       
   216                 {
       
   217                 aActionMenuVisibility.iVisibility = 
       
   218                     TFscContactActionVisibility::EFscActionVisible;
       
   219                 aOptionsMenuVisibility.iVisibility = 
       
   220                     TFscContactActionVisibility::EFscActionVisible;
       
   221         
       
   222                 if ( aActionUid == KFscActionUidCreateMsg )
       
   223                     {
       
   224                     iActionPriority = iParams.iUtils->ActionPriority( 
       
   225                         KFscCrUidCreateMsg,
       
   226                         KFscActionPrioritySendMsg );
       
   227                     }
       
   228                 else if ( aActionUid == KFscActionUidCreateAudMsg )
       
   229                     {
       
   230                     iActionPriority = iParams.iUtils->ActionPriority( 
       
   231                         KFscCrUidCreateAudMsg,
       
   232                         KFscActionPrioritySendAudio );
       
   233                     }
       
   234                 else if ( aActionUid == KFscActionUidPostcard )
       
   235                     {
       
   236                     if ( FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) )
       
   237                         {  
       
   238                         iActionPriority = iParams.iUtils->ActionPriority( 
       
   239                             KFscCrUidPostcard, KFscActionPrioritySendPostcard );
       
   240                         }
       
   241                     }
       
   242                 else if ( aActionUid == KFscActionUidEmail )
       
   243                     {
       
   244                     iActionPriority = iParams.iUtils->ActionPriority( 
       
   245                         KFscCrUidEmail,
       
   246                         KFscActionPrioritySendEmail );
       
   247                     }
       
   248                     // no else. already checked in CanExecuteL()
       
   249                 
       
   250                 CheckPriority( aActionUid );
       
   251                 
       
   252                 }
       
   253             else
       
   254                 {
       
   255                 iLastEvent = EActionEventContactAvailableLaunched;
       
   256                 ContactAvailableL( aContactSet );
       
   257                 }
       
   258             break;
       
   259             }
       
   260         case EActionEventContactAvailableFinished:
       
   261             {
       
   262             // Message is Visible in Options menu even if phone number isn't available
       
   263             if ( aActionUid == KFscActionUidCreateMsg &&
       
   264                     iIsContactAvailable )
       
   265                 {
       
   266                 aOptionsMenuVisibility.iVisibility = 
       
   267                     TFscContactActionVisibility::EFscActionVisible;
       
   268                 aActionMenuVisibility.iVisibility = 
       
   269                     TFscContactActionVisibility::EFscActionHidden;
       
   270                 aActionMenuVisibility.iReasonId = KInvalidReasonId;
       
   271                  
       
   272                 iActionPriority = iParams.iUtils->ActionPriority( 
       
   273                         KFscCrUidCreateMsg,
       
   274                         KFscActionPrioritySendMsg );
       
   275                 }
       
   276             else
       
   277                 {
       
   278                 iActionPriority = KFscActionPriorityNotAvailable;
       
   279                 aActionMenuVisibility.iVisibility = 
       
   280                     TFscContactActionVisibility::EFscActionHidden;
       
   281                 aActionMenuVisibility.iReasonId = KInvalidReasonId;
       
   282                 aOptionsMenuVisibility.iVisibility = 
       
   283                     TFscContactActionVisibility::EFscActionHidden;
       
   284                 aOptionsMenuVisibility.iReasonId = KInvalidReasonId;
       
   285                 }
       
   286              
       
   287             CheckPriority( aActionUid );
       
   288             break;
       
   289             }
       
   290         case EActionEventCanceled:
       
   291             {
       
   292             iLastEvent = EActionEventIdle;
       
   293             break;
       
   294             }
       
   295         default:
       
   296             {
       
   297             ResetData();
       
   298             break; 
       
   299             }
       
   300         }
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CFscSendPluginImpl::ExecuteL 
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CFscSendPluginImpl::ExecuteL( 
       
   308      TUid aActionUid,
       
   309      MFscContactSet& aContactSet,
       
   310      MFscContactActionPluginObserver* aObserver )
       
   311     {
       
   312 	FUNC_LOG;
       
   313 
       
   314     switch ( iLastEvent )
       
   315         {
       
   316         case EActionEventIdle:
       
   317             {
       
   318             
       
   319             iActionUid = aActionUid;
       
   320             iContactSet = &aContactSet;
       
   321             iPluginObserver = aObserver;                      
       
   322                             
       
   323             iIsExecute = ETrue;
       
   324                                             
       
   325             iContactSet->SetToFirstContact();
       
   326             iContactSet->SetToFirstGroup();
       
   327                         
       
   328             iGroupIteratorPosition = 1;
       
   329             iGroupMembersCount = 0;
       
   330             iGroupMemberIndex = 0;
       
   331             
       
   332             iMaxRecipients = MaxMsgRecipientsL();
       
   333             
       
   334             iAddressList = CMessageData::NewL();                
       
   335             
       
   336             if( aContactSet.HasNextContact() )
       
   337                 {
       
   338                 iLastEvent = EActionEventExecuteContactRetrieve;
       
   339                 aContactSet.NextContactL( this );
       
   340                 }
       
   341             else 
       
   342                 {
       
   343                 if ( aContactSet.HasNextGroup() )
       
   344                     {
       
   345                     iLastEvent = EActionEventExecuteGroupRetrieve;
       
   346                     aContactSet.NextGroupL( this );
       
   347                     }
       
   348                 else
       
   349                     {
       
   350                     iLastEvent = EActionEventExecuteFinished;
       
   351                     ExecuteL( aActionUid, aContactSet, aObserver );
       
   352                     }
       
   353                 }
       
   354             
       
   355             break;
       
   356             }
       
   357         case EActionEventExecuteProcessContact:
       
   358             {            
       
   359             
       
   360             MVPbkContactLinkArray* linkArray = 
       
   361                 iRetrievedStoreContact->GroupsJoinedLC();
       
   362             
       
   363             TBool found = EFalse;
       
   364             
       
   365             if ( aContactSet.GroupCount() > 0 
       
   366                     && linkArray->Count() > 0 )
       
   367                 {                                 
       
   368                 
       
   369                 while ( aContactSet.HasNextGroup() 
       
   370                         && !found )
       
   371                     {                    
       
   372                     if ( linkArray->Find( *aContactSet.NextGroupLinkL() ) 
       
   373                             != KErrNotFound )
       
   374                         {
       
   375                         found = ETrue; 
       
   376                         }                    
       
   377                     }
       
   378                 
       
   379                 aContactSet.SetToFirstGroup();  
       
   380                 }
       
   381             
       
   382             CleanupStack::PopAndDestroy(); //linkArray
       
   383             
       
   384             if ( !found ) 
       
   385                 {
       
   386                 if ( aActionUid ==  KFscActionUidPostcard )
       
   387                     {
       
   388                     if ( FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) )
       
   389                         {  
       
   390                         AddPostcardContactL( 
       
   391                             *iAddressList,
       
   392                             *iRetrievedStoreContact );
       
   393                         }
       
   394                     }
       
   395                 else
       
   396                     {
       
   397                     TInt result = AddContactL( 
       
   398                         aActionUid,
       
   399                         *iAddressList,
       
   400                         *iRetrievedStoreContact );
       
   401                                 
       
   402                     if ( result == KErrCancel )
       
   403                         {
       
   404                         // Cancel whole operation                                                
       
   405                         ResetData();
       
   406                         aObserver->ExecuteComplete();
       
   407                         break;
       
   408                         }
       
   409                     else if ( result != KErrNone )
       
   410                         {
       
   411                         ++iMissingCount;
       
   412                         }
       
   413                     }
       
   414                 }
       
   415   
       
   416                 
       
   417             if ( aContactSet.HasNextContact() )
       
   418                 {
       
   419                 iLastEvent = EActionEventExecuteContactRetrieve;
       
   420                 aContactSet.NextContactL( this );
       
   421                 }
       
   422             else if ( aContactSet.HasNextGroup() )
       
   423                 {
       
   424                 iLastEvent = EActionEventExecuteGroupRetrieve;
       
   425                 aContactSet.NextGroupL( this );
       
   426                 }
       
   427             else 
       
   428                 {
       
   429                 iLastEvent = EActionEventExecuteFinished;
       
   430                 ExecuteL( aActionUid, aContactSet, aObserver );
       
   431                 }    
       
   432             
       
   433             break;
       
   434             }
       
   435         case EActionEventExecuteProcessGroup:
       
   436             {
       
   437             iGroupMembersCount = aContactSet.GroupContactCountL( 
       
   438                     *iRetrievedStoreGroup );
       
   439             
       
   440             if ( iGroupMembersCount > 0 )
       
   441                 {
       
   442                 iLastEvent = EActionEventExecuteContactRetrieve;
       
   443                 aContactSet.GetGroupContactL( *iRetrievedStoreGroup, iGroupMemberIndex++, this );
       
   444                 }
       
   445             else
       
   446                 {
       
   447                 if ( aContactSet.HasNextGroup() )
       
   448                     {
       
   449                     iGroupIteratorPosition++;
       
   450                     iLastEvent = EActionEventExecuteGroupRetrieve;
       
   451                     aContactSet.NextGroupL( this );
       
   452                     }
       
   453                 else
       
   454                     {
       
   455                     iLastEvent = EActionEventExecuteFinished;
       
   456                     ExecuteL( aActionUid, aContactSet, aObserver );
       
   457                     }
       
   458                 }            
       
   459             
       
   460             break;
       
   461             }
       
   462         case EActionEventExecuteProcessGroupMember:
       
   463             {
       
   464             
       
   465             if ( !IsAnyGroupMemberL( *iRetrievedGroupMember ) )
       
   466                 {
       
   467                 TInt result = AddContactL( 
       
   468                     aActionUid,
       
   469                     *iAddressList,
       
   470                     *iRetrievedGroupMember );
       
   471                             
       
   472                 if ( result == KErrCancel )
       
   473                     {
       
   474                     // Cancel whole operation                                                
       
   475                     ResetData();
       
   476                     aObserver->ExecuteComplete();
       
   477                     break;
       
   478                     }
       
   479                 else if ( result != KErrNone )
       
   480                     {
       
   481                     ++iMissingCount;
       
   482                     }
       
   483                 }
       
   484             
       
   485             delete iRetrievedGroupMember;
       
   486             iRetrievedGroupMember = NULL;
       
   487 
       
   488             if ( iGroupMemberIndex < iGroupMembersCount )
       
   489                 {
       
   490                 iLastEvent = EActionEventExecuteContactRetrieve;
       
   491                 aContactSet.GetGroupContactL( *iRetrievedStoreGroup, iGroupMemberIndex++, this );
       
   492                 }
       
   493             else if ( aContactSet.HasNextGroup() )
       
   494                 {
       
   495                 iGroupMemberIndex = 0;
       
   496                 iGroupMembersCount = 0;
       
   497                 iGroupIteratorPosition++;
       
   498                 iLastEvent = EActionEventExecuteGroupRetrieve;
       
   499                 aContactSet.NextGroupL( this );
       
   500                 }
       
   501             else
       
   502                 {
       
   503                 iLastEvent = EActionEventExecuteFinished;
       
   504                 ExecuteL( aActionUid, aContactSet, aObserver );
       
   505                 }
       
   506             
       
   507             break;
       
   508             }
       
   509         case EActionEventExecuteFinished:
       
   510             {
       
   511             
       
   512             if ( aContactSet.ContactCount() == 1 
       
   513                      && aContactSet.GroupCount() == 0 
       
   514                      && iMissingCount == 1 )
       
   515                  {
       
   516                  //if only one contact available and without
       
   517                  //proper contact information
       
   518                  HBufC* contactName = iParams.iUtils->GetContactNameL( *iRetrievedStoreContact );                
       
   519                  CleanupStack::PushL(contactName);
       
   520                  
       
   521                  TInt note = R_QTN_FS_NOTE_NO_MSG_TO_NAME;
       
   522                  
       
   523                  iParams.iUtils->ShowInfoNoteL(
       
   524                              note,
       
   525                              contactName );
       
   526                  
       
   527                  CleanupStack::PopAndDestroy( contactName );                
       
   528                  }            
       
   529             else if ( iMissingCount > 0 
       
   530                     && !iParams.iUtils->ShowNumberMissingNoteL(
       
   531                             iMissingCount,
       
   532                             ( iAddressList->ToAddressArray().Count() + iMissingCount ),
       
   533                              R_FS_NOTE_NUMBER_MISSING,
       
   534                              R_FS_NUMBER_MISSING_QUERY_DIALOG ) )
       
   535                 {
       
   536                 //Fix for: EJKA-7KAEVA
       
   537                 ResetData();
       
   538                 aObserver->ExecuteFailed( KErrCancel );
       
   539                 break;
       
   540                 }
       
   541             else
       
   542                 {
       
   543                 if ( iRecipientsCounter <= iMaxRecipients )
       
   544                     {
       
   545                     SendToSelectedMembersL( aActionUid, iAddressList );
       
   546                     }
       
   547                 else if ( iRecipientsCounter == iMaxRecipients + 1 )
       
   548                     {
       
   549                     TInt note = R_QTN_MAX_RECIPIENTS_EXCEEDED_1; 
       
   550                     HBufC *emptyBuf = NULL;
       
   551                     iParams.iUtils->ShowInfoNoteL(
       
   552                                 note,
       
   553                                 emptyBuf );
       
   554                     }
       
   555                 else
       
   556                     {
       
   557                     TInt note = R_QTN_MAX_RECIPIENTS_EXCEEDED_MANY;
       
   558                     iParams.iUtils->ShowInfoNoteL(
       
   559                                 note,
       
   560                                 iRecipientsCounter - iMaxRecipients );
       
   561                     }
       
   562                 }
       
   563             
       
   564             ResetData();
       
   565             aObserver->ExecuteComplete();
       
   566             break;
       
   567             }
       
   568         case EActionEventCanceled:
       
   569             {
       
   570             iLastEvent = EActionEventIdle;
       
   571             break;
       
   572             }
       
   573         default:
       
   574             {
       
   575             ResetData();
       
   576             break; 
       
   577             }
       
   578         }
       
   579 
       
   580     }
       
   581 
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // CFscSendPluginImpl::GetReasonL
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 void CFscSendPluginImpl::GetReasonL(
       
   588     TUid /* aActionUid */,
       
   589     TInt /* aReasonId */,
       
   590     HBufC*& /* aReason */) const
       
   591     {
       
   592 	FUNC_LOG;
       
   593     }
       
   594     
       
   595 // ---------------------------------------------------------------------------
       
   596 // CFscSendPluginImpl::SendToSelectedMembersL
       
   597 // ---------------------------------------------------------------------------
       
   598 //
       
   599 void CFscSendPluginImpl::SendToSelectedMembersL(
       
   600     TUid aActionUid,
       
   601     const CMessageData* aAddressList )
       
   602     {
       
   603 	FUNC_LOG;
       
   604     // Check from sys utils that the flash drive 
       
   605     // is not on critical level before creating a message.
       
   606     TBool flashOnCL =
       
   607         SysUtil::FFSSpaceBelowCriticalLevelL(
       
   608             &CCoeEnv::Static()->FsSession(),
       
   609             KMsgSpaceEstimationBytes );
       
   610     if ( flashOnCL )
       
   611         {
       
   612         User::Leave( KErrNoMemory );
       
   613         }
       
   614 
       
   615     CSendUi* sendUi = CSendUi::NewLC();
       
   616     TUid messageType = KSenduiMtmUniMessageUid;
       
   617     if ( aActionUid == KFscActionUidCreateMsg )
       
   618         {
       
   619         messageType = KSenduiMtmUniMessageUid;
       
   620         }
       
   621     else if ( aActionUid == KFscActionUidCreateAudMsg )
       
   622         {
       
   623         messageType = KSenduiMtmAudioMessageUid;
       
   624         }
       
   625     else if ( aActionUid == KFscActionUidPostcard &&
       
   626               iContactPostcardAction != NULL  )
       
   627         {
       
   628         messageType = KSenduiMtmPostcardUid;
       
   629         }
       
   630     else if ( aActionUid == KFscActionUidEmail )
       
   631         {
       
   632         messageType = KSenduiMtmSmtpUid;
       
   633         }
       
   634     else
       
   635         {
       
   636         User::Leave( KErrArgument );
       
   637         }    
       
   638         
       
   639     sendUi->CreateAndSendMessageL(
       
   640             messageType,
       
   641             aAddressList, KNullUid, EFalse );
       
   642         
       
   643     CleanupStack::PopAndDestroy( sendUi );
       
   644     }
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // CFscSendPluginImpl::ContactAvailableL
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CFscSendPluginImpl::ContactAvailableL( MFscContactSet& aContactSet )
       
   651     {
       
   652 	FUNC_LOG;
       
   653     
       
   654     switch ( iLastEvent )
       
   655         {
       
   656         case EActionEventContactAvailableLaunched:
       
   657             {            
       
   658             if ( aContactSet.ContactCount() > 0 )
       
   659                 {
       
   660                 iIsContactAvailable = ETrue;
       
   661                 iLastEvent = EActionEventContactAvailableFinished;
       
   662                 PriorityForContactSetL( 
       
   663                     iActionUid,
       
   664                     aContactSet,
       
   665                     *iActionMenuVisibility,
       
   666                     *iOptionsMenuVisibility,
       
   667                     iPluginObserver );
       
   668                 }
       
   669             else
       
   670                 {
       
   671                 aContactSet.SetToFirstContact();
       
   672                 aContactSet.SetToFirstGroup();
       
   673                 
       
   674                 if ( aContactSet.HasNextGroup() 
       
   675                         && iIsContactAvailable == EFalse )
       
   676                     {
       
   677                     iLastEvent = EActionEventContactAvailableContactRetrieve;
       
   678                     aContactSet.NextGroupL( this );
       
   679                     }
       
   680                 else
       
   681                     {
       
   682                     iLastEvent = EActionEventContactAvailableFinished;
       
   683                     PriorityForContactSetL( 
       
   684                         iActionUid,
       
   685                         aContactSet,
       
   686                         *iActionMenuVisibility,
       
   687                         *iOptionsMenuVisibility,
       
   688                         iPluginObserver );
       
   689                     }
       
   690                 }
       
   691             break;
       
   692             }
       
   693         case EActionEventContactAvailableProcess:
       
   694             {
       
   695             if ( aContactSet.GroupContactCountL( *iRetrievedStoreGroup ) > 0 )
       
   696                 {
       
   697                 iIsContactAvailable = ETrue;
       
   698                 iLastEvent = EActionEventContactAvailableFinished;
       
   699                 PriorityForContactSetL( 
       
   700                     iActionUid,
       
   701                     aContactSet,
       
   702                     *iActionMenuVisibility,
       
   703                     *iOptionsMenuVisibility,
       
   704                     iPluginObserver );
       
   705                 }
       
   706             else
       
   707                 {
       
   708                 if ( aContactSet.HasNextGroup() 
       
   709                         && iIsContactAvailable == EFalse )
       
   710                     {
       
   711                     iLastEvent = EActionEventContactAvailableContactRetrieve;
       
   712                     aContactSet.NextGroupL( this );
       
   713                     }
       
   714                 else
       
   715                     {
       
   716                     iLastEvent = EActionEventContactAvailableFinished;
       
   717                     PriorityForContactSetL( 
       
   718                         iActionUid,
       
   719                         aContactSet,
       
   720                         *iActionMenuVisibility,
       
   721                         *iOptionsMenuVisibility,
       
   722                         iPluginObserver );
       
   723                     }
       
   724                 }
       
   725             break;
       
   726             }
       
   727         case EActionEventCanceled:
       
   728             {
       
   729             iLastEvent = EActionEventIdle;
       
   730             break;
       
   731             }
       
   732         default:
       
   733             {
       
   734             ResetData();
       
   735             break; 
       
   736             }
       
   737         }
       
   738     }
       
   739 
       
   740 // ---------------------------------------------------------------------------
       
   741 // CFscSendPluginImpl::CanExecuteL
       
   742 // ---------------------------------------------------------------------------
       
   743 //
       
   744 void CFscSendPluginImpl::CanExecuteL(
       
   745     TUid aActionUid,
       
   746     MFscContactSet& aContactSet )
       
   747     {
       
   748 	FUNC_LOG;
       
   749     
       
   750     switch( iLastEvent )
       
   751          {
       
   752          case EActionEventCanExecuteLaunched:
       
   753              {
       
   754     
       
   755              iCanDisplay = KErrArgument;
       
   756              iNumberType = ETypeInvalid;    
       
   757              if ( ( aActionUid == KFscActionUidCreateMsg ) || 
       
   758                      ( aActionUid == KFscActionUidCreateAudMsg ) )
       
   759                  {
       
   760                  iNumberType = ETypeMsgAddress;
       
   761                  }
       
   762              else if ( aActionUid == KFscActionUidPostcard &&
       
   763                      iContactPostcardAction )
       
   764                  {
       
   765                  iNumberType = ETypeInvalid;  
       
   766                  }
       
   767              else if ( aActionUid == KFscActionUidEmail )
       
   768                  {
       
   769                  iNumberType = ETypeEmailAddress;
       
   770                  }
       
   771              else
       
   772                  {
       
   773                  User::Leave( KErrArgument );
       
   774                  }
       
   775 
       
   776              if ( aContactSet.HasNextContact() 
       
   777                      && iCanDisplay != KErrNone )
       
   778                  {
       
   779                  iLastEvent = EActionEventCanExecuteContactRetrieve;
       
   780                  aContactSet.NextContactL( this );
       
   781                  }
       
   782              else
       
   783                  {
       
   784                  if ( aContactSet.HasNextGroup()
       
   785                          && iCanDisplay != KErrNone )
       
   786                      {
       
   787                      iLastEvent = EActionEventCanExecuteGroupRetrieve;
       
   788                      aContactSet.NextGroupL( this );
       
   789                      }
       
   790                  else
       
   791                      {
       
   792                      iLastEvent = EActionEventCanExecuteFinished;
       
   793                      CanExecuteL( aActionUid, aContactSet );
       
   794                      }
       
   795                  }
       
   796                           
       
   797              break;
       
   798              }
       
   799          case EActionEventCanExecuteProcessContact:
       
   800              {
       
   801              if ( aActionUid == KFscActionUidPostcard &&
       
   802                       aContactSet.ContactCount() == 1 &&
       
   803                       aContactSet.GroupCount() == 0 )
       
   804                  {
       
   805                  if ( FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) )
       
   806                      { 
       
   807                      //verify if contact has valid store - needed for attachement
       
   808                      MVPbkContactStore* contactStore = &iRetrievedStoreContact->ContactStore();
       
   809                      if ( contactStore )
       
   810                          {
       
   811                          iLastEvent = EActionEventCanExecuteFinished;
       
   812                          iCanDisplay = KErrNone;
       
   813                          CanExecuteL( aActionUid, aContactSet );
       
   814                          }
       
   815                       }   
       
   816                   }
       
   817              if ( iParams.iUtils->IsContactNumberAvailableL(
       
   818                          *iRetrievedStoreContact, iNumberType ))
       
   819                  {
       
   820                  iLastEvent = EActionEventCanExecuteFinished;
       
   821                  iCanDisplay = KErrNone;
       
   822                  CanExecuteL( aActionUid, aContactSet );
       
   823                  }
       
   824              else if ( aContactSet.HasNextContact() 
       
   825                           && iCanDisplay != KErrNone )
       
   826                  {
       
   827                  iLastEvent = EActionEventCanExecuteContactRetrieve;
       
   828                  aContactSet.NextContactL( this );
       
   829                  }
       
   830              else if (aContactSet.HasNextGroup() )
       
   831                  {
       
   832                  iLastEvent = EActionEventCanExecuteGroupRetrieve;
       
   833                  aContactSet.NextGroupL( this);
       
   834                  }
       
   835              else
       
   836                  {
       
   837                  iLastEvent = EActionEventCanExecuteFinished;
       
   838                  CanExecuteL( aActionUid, aContactSet );
       
   839                  }
       
   840              break;
       
   841              }             
       
   842          case EActionEventCanExecuteProcessGroup:
       
   843              {
       
   844              MVPbkContactGroup* group = iRetrievedStoreGroup->Group();
       
   845              if ( group 
       
   846                      && aContactSet.GroupContactCountL( 
       
   847                              *iRetrievedStoreGroup )>0 )
       
   848                  {
       
   849                  iGroupMembersCount =  
       
   850                      aContactSet.GroupContactCountL( *iRetrievedStoreGroup );
       
   851                  iLastEvent = EActionEventCanExecuteContactRetrieve;
       
   852                  aContactSet.GetGroupContactL( 
       
   853                          *iRetrievedStoreGroup, iGroupMemberIndex++, this );
       
   854                  }
       
   855              else
       
   856                  {
       
   857                  iLastEvent = EActionEventCanExecuteFinished;
       
   858                  CanExecuteL( aActionUid, aContactSet );
       
   859                  }
       
   860              break;
       
   861              }
       
   862          case EActionEventCanExecuteProcessGroupMember:
       
   863              {
       
   864              
       
   865              if ( iParams.iUtils->IsContactNumberAvailableL(
       
   866                           *iRetrievedGroupMember, iNumberType ) 
       
   867                           && aActionUid != KFscActionUidPostcard )
       
   868                   {
       
   869                   iLastEvent = EActionEventCanExecuteFinished;
       
   870                   iCanDisplay = KErrNone; // atleast one number avaialble
       
   871                   delete iRetrievedGroupMember;
       
   872                   iRetrievedGroupMember = NULL;
       
   873                   CanExecuteL( aActionUid, aContactSet );
       
   874                   }
       
   875              else 
       
   876                  {
       
   877                  delete iRetrievedGroupMember;
       
   878                  iRetrievedGroupMember = NULL;
       
   879                  if ( iGroupMemberIndex < iGroupMembersCount )
       
   880                      {
       
   881                      iLastEvent = EActionEventCanExecuteContactRetrieve;
       
   882                      aContactSet.GetGroupContactL( *iRetrievedStoreGroup, 
       
   883                              iGroupMemberIndex++, this );
       
   884                      }
       
   885                  else 
       
   886                      {                     
       
   887                      if ( aContactSet.HasNextGroup()
       
   888                              && iCanDisplay != KErrNone )
       
   889                          {
       
   890                          iGroupMemberIndex = 0;
       
   891                          iGroupMembersCount = 0;
       
   892                          iLastEvent = EActionEventCanExecuteGroupRetrieve;
       
   893                          aContactSet.NextGroupL(this);
       
   894                          }
       
   895                      else
       
   896                          {
       
   897                          iLastEvent = EActionEventCanExecuteFinished;
       
   898                          CanExecuteL( aActionUid, aContactSet );
       
   899                          }
       
   900                      }
       
   901                  }
       
   902              
       
   903              break;
       
   904              }
       
   905          case EActionEventCanExecuteFinished:
       
   906              {
       
   907              PriorityForContactSetL( 
       
   908                  iActionUid,
       
   909                  aContactSet,
       
   910                  *iActionMenuVisibility,
       
   911                  *iOptionsMenuVisibility,
       
   912                  iPluginObserver );
       
   913              break;
       
   914              }
       
   915          case EActionEventCanceled:
       
   916              {
       
   917              iLastEvent = EActionEventIdle;
       
   918              break;
       
   919              }
       
   920          default:
       
   921              {
       
   922              ResetData();
       
   923              break; 
       
   924              }
       
   925          }
       
   926     
       
   927     }    
       
   928     
       
   929 // ---------------------------------------------------------------------------
       
   930 // CFscSendPluginImpl::UpdateActionIconL
       
   931 // ---------------------------------------------------------------------------
       
   932 //
       
   933 void CFscSendPluginImpl::UpdateActionIconL( TUid aActionUid )
       
   934     {
       
   935 	FUNC_LOG;
       
   936 
       
   937     TFileName dllFileName;
       
   938     Dll::FileName( dllFileName );
       
   939     TParse parse;
       
   940     User::LeaveIfError(
       
   941         parse.Set( KSendPluginIconPath, &dllFileName, NULL ) );
       
   942 
       
   943     if ( aActionUid == KFscActionUidCreateMsg )
       
   944         {
       
   945         iContactMsgAction->SetIcon( iParams.iUtils->SkinIconL(
       
   946                 KAknsIIDQgnFsActionMsg,
       
   947                 parse.FullName(),
       
   948                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_msg,
       
   949                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_msg_mask ) );
       
   950         }
       
   951  
       
   952     else if ( aActionUid == KFscActionUidCreateAudMsg )
       
   953         {
       
   954         iContactAudioMsgAction->SetIcon( iParams.iUtils->SkinIconL(
       
   955                 KAknsIIDQgnFsActionAudio,
       
   956                 parse.FullName(),
       
   957                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_audio,
       
   958                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_audio_mask ) );
       
   959         }
       
   960     else if ( aActionUid == KFscActionUidPostcard )
       
   961         {
       
   962         if ( FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) )
       
   963             {  
       
   964             iContactPostcardAction->SetIcon( iParams.iUtils->SkinIconL(
       
   965                    KAknsIIDQgnFsActionPostcard,
       
   966                    parse.FullName(),
       
   967                    EMbmPbk2rclsendpluginQgn_prop_cmail_action_postcard,
       
   968                    EMbmPbk2rclsendpluginQgn_prop_cmail_action_postcard_mask ) );
       
   969             }
       
   970         }
       
   971     else if ( aActionUid == KFscActionUidEmail )
       
   972         {
       
   973         iContactEmailAction->SetIcon( iParams.iUtils->SkinIconL(
       
   974                 KAknsIIDQgnFsActionEmail,
       
   975                 parse.FullName(),
       
   976                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_email,
       
   977                 EMbmPbk2rclsendpluginQgn_prop_cmail_action_email_mask ) );
       
   978         }
       
   979     }
       
   980 
       
   981     
       
   982 // ---------------------------------------------------------------------------
       
   983 // CFscSendPluginImpl::AddContactL
       
   984 // ---------------------------------------------------------------------------
       
   985 //
       
   986 TInt CFscSendPluginImpl::AddContactL( 
       
   987     TUid aActionUid,
       
   988     CMessageData& aAddressList,
       
   989     MVPbkStoreContact& aContact )
       
   990     {
       
   991 	FUNC_LOG;
       
   992     
       
   993     TAddressData addressData;                    
       
   994     TInt ret = KErrNotFound;
       
   995 
       
   996     if ( aActionUid == KFscActionUidEmail )
       
   997         {
       
   998         ret = iParams.iUtils->GetEmailAddressL(
       
   999                 aContact, addressData );
       
  1000         }
       
  1001     else
       
  1002         {
       
  1003         ret = iParams.iUtils->GetMessageAddressL(
       
  1004                 aContact, addressData );
       
  1005         }
       
  1006     
       
  1007     if ( ret == KErrNone && addressData.Length() > 0 ) 
       
  1008         {
       
  1009         // no need to check for duplicate addresses
       
  1010         HBufC* contactName = iParams.iUtils->GetContactNameL(
       
  1011             aContact );
       
  1012         CleanupStack::PushL( contactName );
       
  1013         aAddressList.AppendToAddressL(
       
  1014             addressData, *contactName );
       
  1015         CleanupStack::PopAndDestroy( contactName );   
       
  1016         iRecipientsCounter++;
       
  1017         }
       
  1018     
       
  1019     return ret;
       
  1020     }
       
  1021 
       
  1022 // ---------------------------------------------------------------------------
       
  1023 // CFscSendPluginImpl::AddPostcardContactL
       
  1024 // ---------------------------------------------------------------------------
       
  1025 //
       
  1026 void CFscSendPluginImpl::AddPostcardContactL( 
       
  1027     CMessageData& aMessageData,
       
  1028     const MVPbkStoreContact& aContact )
       
  1029     {
       
  1030 	FUNC_LOG;
       
  1031     MVPbkContactStore* store = &aContact.ContactStore();
       
  1032     if ( store )
       
  1033         {
       
  1034         // Create attachment file object
       
  1035         delete iAttachmentFile;
       
  1036         iAttachmentFile = NULL;
       
  1037         HBufC* attFileName = 
       
  1038             StringLoader::LoadLC( R_FS_POSTCARD_WRITE_ATTACHMENT_TAG );
       
  1039         iAttachmentFile = CFscAttachmentFile::NewL(
       
  1040             *attFileName, 
       
  1041             iParams.iUtils->ContactManager().FsSession(),
       
  1042             EFileWrite | EFileShareAny );
       
  1043         CleanupStack::PopAndDestroy( attFileName );
       
  1044         WritePostcardAttachmentContentL( aContact, *iAttachmentFile );
       
  1045         aMessageData.AppendAttachmentL(
       
  1046             iAttachmentFile->FileName() );
       
  1047         iAttachmentFile->Release(); 
       
  1048         }
       
  1049 
       
  1050     }
       
  1051 
       
  1052 // ---------------------------------------------------------------------------
       
  1053 // CFscSendPluginImpl::WritePostcardAttachmentContentL
       
  1054 // ---------------------------------------------------------------------------
       
  1055 //
       
  1056 void CFscSendPluginImpl::WritePostcardAttachmentContentL( 
       
  1057     const MVPbkStoreContact& aContact, 
       
  1058     CFscAttachmentFile& aAttachmentFile )
       
  1059     {
       
  1060 	FUNC_LOG;
       
  1061     HBufC* contactId = HBufC::NewLC( KMaxContactIdStringLength );
       
  1062     MVPbkContactLink* contactLink = aContact.CreateLinkLC();
       
  1063     
       
  1064     CVPbkContactIdConverter* cntIdCnv = 
       
  1065         CVPbkContactIdConverter::NewL( aContact.ContactStore() );
       
  1066     TContactItemId cntId = cntIdCnv->LinkToIdentifier( *contactLink );
       
  1067     
       
  1068     delete cntIdCnv;
       
  1069     CleanupStack::PopAndDestroy(); //contactLink
       
  1070     
       
  1071     contactId->Des().Num( cntId );
       
  1072     HBufC8* string8 = HBufC8::NewLC( KMaxContactIdStringLength );
       
  1073     string8->Des().Append( *contactId );
       
  1074     aAttachmentFile.File().Write( *string8 );
       
  1075     CleanupStack::PopAndDestroy( 2, contactId );
       
  1076     }    
       
  1077 
       
  1078 // ---------------------------------------------------------------------------
       
  1079 // CFscSendPluginImpl::CFscSendPluginImpl
       
  1080 // ---------------------------------------------------------------------------
       
  1081 //
       
  1082 CFscSendPluginImpl::CFscSendPluginImpl( 
       
  1083     const TFscContactActionPluginParams& aParams )
       
  1084     : CFscContactActionPlugin(),
       
  1085     iParams( aParams ),
       
  1086     iResourceHandle( 0 )
       
  1087     {
       
  1088 	FUNC_LOG;
       
  1089     }
       
  1090 
       
  1091 // ---------------------------------------------------------------------------
       
  1092 // CFscSendPluginImpl::ConstructL
       
  1093 // ---------------------------------------------------------------------------
       
  1094 //
       
  1095 void CFscSendPluginImpl::ConstructL()
       
  1096     {
       
  1097 	FUNC_LOG;
       
  1098     TFileName dllFileName;
       
  1099     Dll::FileName( dllFileName );
       
  1100     TParse parse;
       
  1101     User::LeaveIfError( parse.Set( KResourceFilePath, &dllFileName, NULL ) );
       
  1102     TFileName resourceFileName( parse.FullName() );
       
  1103     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), 
       
  1104         resourceFileName );
       
  1105     
       
  1106     iResourceHandle = 
       
  1107         ( CCoeEnv::Static() )->AddResourceFileL( resourceFileName );
       
  1108 
       
  1109     iActionList = new( ELeave ) CArrayFixFlat<TUid>( KActionCount );
       
  1110     
       
  1111     User::LeaveIfError(
       
  1112         parse.Set( KSendPluginIconPath, &dllFileName, NULL ) );     
       
  1113 
       
  1114     iActionList->AppendL( KFscActionUidCreateMsg );    
       
  1115     iContactMsgAction = iParams.iUtils->CreateActionL(
       
  1116         *this,
       
  1117         KFscActionUidCreateMsg,
       
  1118         KFscAtComSendMsg,
       
  1119         R_FS_ACTION_MESSAGE,
       
  1120         iParams.iUtils->SkinIconL(
       
  1121             KAknsIIDQgnFsActionMsg,
       
  1122             parse.FullName(),
       
  1123             EMbmPbk2rclsendpluginQgn_prop_cmail_action_msg,
       
  1124             EMbmPbk2rclsendpluginQgn_prop_cmail_action_msg_mask ) );
       
  1125 
       
  1126     iActionList->AppendL( KFscActionUidEmail );    
       
  1127     iContactEmailAction = iParams.iUtils->CreateActionL(
       
  1128         *this,
       
  1129         KFscActionUidEmail,
       
  1130         KFscAtComSendEmail,
       
  1131         R_FS_ACTION_EMAIL,
       
  1132         iParams.iUtils->SkinIconL(
       
  1133             KAknsIIDQgnFsActionEmail,
       
  1134             parse.FullName(),
       
  1135             EMbmPbk2rclsendpluginQgn_prop_cmail_action_email,
       
  1136             EMbmPbk2rclsendpluginQgn_prop_cmail_action_email_mask ) );
       
  1137     }
       
  1138 
       
  1139 
       
  1140 // ---------------------------------------------------------------------------
       
  1141 // CFscSendPluginImpl::ResetData
       
  1142 // ---------------------------------------------------------------------------
       
  1143 //
       
  1144 void CFscSendPluginImpl::ResetData()
       
  1145     {
       
  1146 	FUNC_LOG;
       
  1147     if ( iContactSet )
       
  1148         {
       
  1149         TRAP_IGNORE( iContactSet->CancelNextContactL() );
       
  1150         TRAP_IGNORE( iContactSet->CancelNextGroupL() );
       
  1151         iContactSet->SetToFirstContact();
       
  1152         iContactSet->SetToFirstGroup();
       
  1153         iContactSet = NULL;
       
  1154         }
       
  1155     
       
  1156     if ( iAddressList )
       
  1157         {
       
  1158         delete iAddressList;
       
  1159         iAddressList = NULL;
       
  1160         }
       
  1161     
       
  1162     if ( iRetrievedGroupMember )
       
  1163         {
       
  1164         delete iRetrievedGroupMember;
       
  1165         iRetrievedGroupMember = NULL;
       
  1166         }
       
  1167     
       
  1168     iLastEvent = EActionEventIdle;
       
  1169     iActionMenuVisibility = NULL;
       
  1170     iOptionsMenuVisibility = NULL;
       
  1171     iCanDisplay = KErrNone;
       
  1172     iRetrievedStoreContact = NULL;
       
  1173     iRetrievedStoreGroup = NULL;
       
  1174     iNumberType = ETypeInvalid;
       
  1175     iGroupMembersCount = 0;
       
  1176     iGroupMemberIndex = 0;
       
  1177     iIsContactAvailable = EFalse;
       
  1178     iGroupIteratorPosition = 0;
       
  1179     iMissingCount = 0;
       
  1180     iMaxRecipients = 0;
       
  1181     iRecipientsCounter = 0;
       
  1182     }
       
  1183 
       
  1184 // ---------------------------------------------------------------------------
       
  1185 // CFscSendPluginImpl::CheckPriority
       
  1186 // ---------------------------------------------------------------------------
       
  1187 //
       
  1188 void CFscSendPluginImpl::CheckPriority(TUid aActionUid)
       
  1189     {
       
  1190 	FUNC_LOG;
       
  1191     if ( iActionPriority > 0 )
       
  1192         {
       
  1193         // ignore any leave while updating action icons
       
  1194         TRAP_IGNORE( UpdateActionIconL( aActionUid ) );
       
  1195         }
       
  1196     ResetData();
       
  1197     iPluginObserver->PriorityForContactSetComplete(iActionPriority);
       
  1198     }
       
  1199 
       
  1200 // ---------------------------------------------------------------------------
       
  1201 // CFscSendPluginImpl::MoveGroupToIndexL
       
  1202 // ---------------------------------------------------------------------------
       
  1203 //
       
  1204 void CFscSendPluginImpl::MoveGroupToIndexL(MFscContactSet& aContactSet, 
       
  1205         TInt aIndex, TInt& aError)
       
  1206     {
       
  1207 	FUNC_LOG;
       
  1208     aError = KErrNone;
       
  1209     aContactSet.SetToFirstGroup();
       
  1210 
       
  1211     if ( aIndex > aContactSet.GroupCount() )
       
  1212         {
       
  1213         aError = KErrArgument;
       
  1214         }
       
  1215     
       
  1216     //move iterator to specified index
       
  1217     while ( aContactSet.HasNextGroup() 
       
  1218             && aIndex-- > 0 )
       
  1219         {
       
  1220         aContactSet.NextGroupLinkL();
       
  1221         }
       
  1222     
       
  1223     }
       
  1224 
       
  1225 // ---------------------------------------------------------------------------
       
  1226 // CFscSendPluginImpl::IsAnyGroupMember
       
  1227 // ---------------------------------------------------------------------------
       
  1228 //
       
  1229 TBool CFscSendPluginImpl::IsAnyGroupMemberL( MVPbkStoreContact& aContact )
       
  1230     {
       
  1231 	FUNC_LOG;
       
  1232     MVPbkContactLinkArray* linkArray = aContact.GroupsJoinedLC();
       
  1233                 
       
  1234     TBool found = EFalse;
       
  1235     TInt error = KErrNone;
       
  1236     TBool isChanged = EFalse;
       
  1237     
       
  1238     if ( linkArray->Count() > 1
       
  1239             && iContactSet->HasNextGroup() )
       
  1240         {                                 
       
  1241         
       
  1242         while ( iContactSet->HasNextGroup() 
       
  1243                 && !found )
       
  1244             {
       
  1245             isChanged = ETrue;
       
  1246             if ( linkArray->Find( *iContactSet->NextGroupLinkL() ) 
       
  1247                     != KErrNotFound )
       
  1248                 {
       
  1249                 found = ETrue; 
       
  1250                 }                    
       
  1251             }
       
  1252         
       
  1253         if ( isChanged )
       
  1254             {
       
  1255             //if iterator moved
       
  1256             MoveGroupToIndexL( *iContactSet, iGroupIteratorPosition , error );
       
  1257             }        
       
  1258         
       
  1259         User::LeaveIfError( error );            
       
  1260         }
       
  1261     
       
  1262     CleanupStack::PopAndDestroy(); //linkArray    
       
  1263     return found;
       
  1264     }
       
  1265 
       
  1266 // ---------------------------------------------------------------------------
       
  1267 // CFscSendPluginImpl::NextContactComplete
       
  1268 // ---------------------------------------------------------------------------
       
  1269 //
       
  1270 void CFscSendPluginImpl::NextContactComplete( MVPbkStoreContact* aContact )
       
  1271     {
       
  1272 	FUNC_LOG;
       
  1273     TInt err = KErrNone;
       
  1274     
       
  1275     switch( iLastEvent )
       
  1276         {
       
  1277         case EActionEventCanExecuteContactRetrieve:
       
  1278             {
       
  1279             iRetrievedStoreContact = aContact;
       
  1280             iLastEvent = EActionEventCanExecuteProcessContact; 
       
  1281             TRAP( err, CanExecuteL( iActionUid, *iContactSet ) );
       
  1282             break;
       
  1283             }
       
  1284         case EActionEventExecuteContactRetrieve:
       
  1285             {
       
  1286             iRetrievedStoreContact = aContact;
       
  1287             iLastEvent = EActionEventExecuteProcessContact;
       
  1288             TRAP( err, ExecuteL( iActionUid, *iContactSet, iPluginObserver ) );
       
  1289             break;
       
  1290             }
       
  1291         case EActionEventCanceled:
       
  1292             {
       
  1293             iLastEvent = EActionEventIdle;
       
  1294             break;
       
  1295             }
       
  1296         default:
       
  1297             {
       
  1298             ResetData();
       
  1299             break; 
       
  1300             }
       
  1301         }
       
  1302 
       
  1303     if ( err != KErrNone )
       
  1304         {
       
  1305         ResetData();
       
  1306         if ( iIsExecute )
       
  1307             {
       
  1308             iPluginObserver->ExecuteFailed( err );
       
  1309             }
       
  1310         else
       
  1311             {
       
  1312             iPluginObserver->PriorityForContactSetFailed( err );
       
  1313             }
       
  1314         }
       
  1315     }
       
  1316 
       
  1317 // ---------------------------------------------------------------------------
       
  1318 // CFscSendPluginImpl::NextContactFailed
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 void CFscSendPluginImpl::NextContactFailed( TInt aError )
       
  1322     {
       
  1323 	FUNC_LOG;
       
  1324     ResetData();
       
  1325     if (iIsExecute)
       
  1326         {
       
  1327         iPluginObserver->ExecuteFailed(aError);
       
  1328         }
       
  1329     else
       
  1330         {
       
  1331         iPluginObserver->PriorityForContactSetFailed(aError);
       
  1332         }
       
  1333     }
       
  1334 
       
  1335 // ---------------------------------------------------------------------------
       
  1336 // CFscSendPluginImpl::NextGroupComplete
       
  1337 // ---------------------------------------------------------------------------
       
  1338 //
       
  1339 void CFscSendPluginImpl::NextGroupComplete( MVPbkStoreContact* aContact )
       
  1340     {
       
  1341 	FUNC_LOG;
       
  1342     TInt err = KErrNone;
       
  1343     
       
  1344     switch( iLastEvent )
       
  1345         {
       
  1346         case EActionEventCanExecuteGroupRetrieve:
       
  1347             {
       
  1348             iLastEvent = EActionEventCanExecuteProcessGroup;
       
  1349             iRetrievedStoreGroup = aContact;
       
  1350             TRAP( err, CanExecuteL( iActionUid, *iContactSet ) );
       
  1351             break;
       
  1352             }
       
  1353         case EActionEventContactAvailableContactRetrieve:
       
  1354             {
       
  1355             iLastEvent = EActionEventContactAvailableProcess;
       
  1356             iRetrievedStoreGroup = aContact;
       
  1357             TRAP( err, ContactAvailableL( *iContactSet ) );
       
  1358             break;
       
  1359             }
       
  1360         case EActionEventExecuteGroupRetrieve:
       
  1361             {
       
  1362             iLastEvent = EActionEventExecuteProcessGroup;
       
  1363             iRetrievedStoreGroup = aContact;
       
  1364             TRAP( err, ExecuteL( iActionUid, *iContactSet, iPluginObserver ) );
       
  1365             break;
       
  1366             }
       
  1367         case EActionEventCanceled:
       
  1368             {
       
  1369             iLastEvent = EActionEventIdle;
       
  1370             break;
       
  1371             }
       
  1372         default:
       
  1373             {
       
  1374             ResetData();
       
  1375             break; 
       
  1376             }
       
  1377         }
       
  1378     
       
  1379     if ( err != KErrNone )
       
  1380         {
       
  1381         if ( iIsExecute )
       
  1382             {
       
  1383             iPluginObserver->ExecuteFailed( err );
       
  1384             }
       
  1385         else
       
  1386             {
       
  1387             iPluginObserver->PriorityForContactSetFailed( err );
       
  1388             }
       
  1389         }
       
  1390     }
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // CFscSendPluginImpl::NextGroupFailed
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void CFscSendPluginImpl::NextGroupFailed( TInt aError )
       
  1397     {
       
  1398 	FUNC_LOG;
       
  1399     ResetData();
       
  1400     if ( iIsExecute )
       
  1401         {
       
  1402         iPluginObserver->ExecuteFailed(aError);
       
  1403         }
       
  1404     else
       
  1405         {
       
  1406         iPluginObserver->PriorityForContactSetFailed(aError);
       
  1407         }
       
  1408     }
       
  1409 
       
  1410 // ---------------------------------------------------------------------------
       
  1411 // CFscSendPluginImpl::GetGroupContactComplete
       
  1412 // ---------------------------------------------------------------------------
       
  1413 //
       
  1414 void CFscSendPluginImpl::GetGroupContactComplete( MVPbkStoreContact* aContact )
       
  1415     {
       
  1416 	FUNC_LOG;
       
  1417     TInt err = KErrNone;
       
  1418     
       
  1419     switch( iLastEvent )
       
  1420        {
       
  1421        case EActionEventCanExecuteContactRetrieve:
       
  1422            {
       
  1423            iLastEvent = EActionEventCanExecuteProcessGroupMember;
       
  1424            iRetrievedGroupMember = aContact;
       
  1425            TRAP( err, CanExecuteL( iActionUid, *iContactSet ) );
       
  1426            break;
       
  1427            }
       
  1428        case EActionEventExecuteContactRetrieve:
       
  1429            {
       
  1430            iRetrievedGroupMember = aContact;
       
  1431            iLastEvent = EActionEventExecuteProcessGroupMember;
       
  1432            TRAP( err, ExecuteL( iActionUid, *iContactSet, iPluginObserver ) );
       
  1433            break;
       
  1434            }
       
  1435        case EActionEventCanceled:
       
  1436            {
       
  1437            iLastEvent = EActionEventIdle;
       
  1438            break;
       
  1439            }
       
  1440        default:
       
  1441            {
       
  1442            ResetData();
       
  1443            break; 
       
  1444            }
       
  1445        }
       
  1446     
       
  1447     if ( err != KErrNone )
       
  1448         {
       
  1449         if ( iIsExecute )
       
  1450             {
       
  1451             iPluginObserver->ExecuteFailed( err );
       
  1452             }
       
  1453         else
       
  1454             {
       
  1455             iPluginObserver->PriorityForContactSetFailed( err );
       
  1456             }
       
  1457         }
       
  1458     }
       
  1459 
       
  1460 // ---------------------------------------------------------------------------
       
  1461 // CFscSendPluginImpl::GetGroupContactComplete
       
  1462 // ---------------------------------------------------------------------------
       
  1463 //
       
  1464 void CFscSendPluginImpl::GetGroupContactFailed( TInt aError )
       
  1465     {
       
  1466 	FUNC_LOG;
       
  1467     ResetData();
       
  1468     if ( iIsExecute )
       
  1469         {
       
  1470         iPluginObserver->ExecuteFailed(aError);
       
  1471         }
       
  1472     else
       
  1473         {
       
  1474         iPluginObserver->PriorityForContactSetFailed(aError);
       
  1475         }
       
  1476     }
       
  1477 
       
  1478 // ---------------------------------------------------------------------------
       
  1479 // CFscSendPluginImpl::CancelPriorityForContactSet
       
  1480 // ---------------------------------------------------------------------------
       
  1481 //
       
  1482 void CFscSendPluginImpl::CancelPriorityForContactSet()
       
  1483     {
       
  1484 	FUNC_LOG;
       
  1485     iLastEvent = EActionEventCanceled;
       
  1486     ResetData();
       
  1487     }
       
  1488 
       
  1489 // ---------------------------------------------------------------------------
       
  1490 // CFscSendPluginImpl::CancelExecute
       
  1491 // ---------------------------------------------------------------------------
       
  1492 //
       
  1493 void CFscSendPluginImpl::CancelExecute()
       
  1494     {
       
  1495 	FUNC_LOG;
       
  1496     // close popup window for selecting number if opened
       
  1497     TRAPD( err, iParams.iUtils->CloseSelectDialogL() );
       
  1498     
       
  1499     if ( err != KErrNone )
       
  1500         {
       
  1501         CCoeEnv::Static()->HandleError( err );
       
  1502         }
       
  1503     
       
  1504     // set action
       
  1505     iLastEvent = EActionEventCanceled;
       
  1506     ResetData();
       
  1507     }
       
  1508 
       
  1509 // ---------------------------------------------------------------------------
       
  1510 // CFscSendPluginImpl::MaxMsgRecipients
       
  1511 // ---------------------------------------------------------------------------
       
  1512 //
       
  1513 TInt CFscSendPluginImpl::MaxMsgRecipientsL()
       
  1514     {
       
  1515 	FUNC_LOG;
       
  1516     TInt maxRecipients = 0;
       
  1517     TInt smsRecipients = 0;
       
  1518     TInt mmsRecipients = 0;
       
  1519     
       
  1520     if ( iActionUid == KFscActionUidEmail )
       
  1521         {
       
  1522         // There should be no limit for the amount of allowed contacts when sending email
       
  1523         maxRecipients = KDefaultEmailRecipients;
       
  1524         }
       
  1525     else
       
  1526         {
       
  1527         CRepository* repository = CRepository::NewL( KCRUidUniEditor );
       
  1528         CleanupStack::PushL( repository );
       
  1529         
       
  1530         if ( repository->Get( KUniEditorSoftLimitRecipientCount, smsRecipients ) != KErrNone || 
       
  1531                 smsRecipients < 1 )
       
  1532             {
       
  1533             // Unreasonable count, change it back to default value
       
  1534             smsRecipients = KDefaultSmsRecipients;
       
  1535             }
       
  1536             
       
  1537         if ( repository->Get( KUniEditorMaxRecipientCount, mmsRecipients ) != KErrNone || 
       
  1538                 mmsRecipients < 1 )
       
  1539             {
       
  1540             // Unreasonable count, change it back to default value
       
  1541             mmsRecipients = KDefaultMmsRecipients;
       
  1542             }
       
  1543     
       
  1544         CleanupStack::PopAndDestroy( repository );
       
  1545         
       
  1546         if ( smsRecipients > mmsRecipients )
       
  1547             {
       
  1548             maxRecipients = smsRecipients;
       
  1549             }
       
  1550         else
       
  1551             {
       
  1552             maxRecipients = mmsRecipients;
       
  1553             }
       
  1554         }
       
  1555     
       
  1556     return maxRecipients;
       
  1557     }
       
  1558 
       
  1559 
       
  1560 // ======== GLOBAL FUNCTIONS ========
       
  1561 
       
  1562 // ---------------------------------------------------------------------------
       
  1563 // ImplementationGroupProxy
       
  1564 // ---------------------------------------------------------------------------
       
  1565 //
       
  1566 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
  1567     TInt& aTableCount )
       
  1568     {
       
  1569     aTableCount = 
       
  1570         sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
  1571     return ImplementationTable;
       
  1572     }
       
  1573