phonebookui/Phonebook2/CommandsExtension/src/CPbk2SendMessageCmd.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Phonebook 2 send message command.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2SendMessageCmd.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "MPbk2ProcessDecorator.h"
       
    24 #include <MPbk2ContactNameFormatter.h>
       
    25 #include <MPbk2ContactUiControl.h>
       
    26 #include <MPbk2CommandObserver.h>
       
    27 #include <CPbk2FieldPropertyArray.h>
       
    28 #include <CPbk2AppUiBase.h>
       
    29 #include <Pbk2UIControls.rsg>
       
    30 #include <TPbk2AddressSelectParams.h>
       
    31 #include <CPbk2AddressSelect.h>
       
    32 #include <Pbk2Presentation.rsg>
       
    33 #include <Pbk2DataCaging.hrh>
       
    34 #include <RPbk2LocalizedResourceFile.h>
       
    35 #include <CPbk2AttachmentFile.h>
       
    36 #include <Pbk2Commands.rsg>
       
    37 #include <CPbk2PresentationContact.h>
       
    38 #include <CPbk2FieldPropertyArray.h>
       
    39 #include <CPbk2PresentationContactFieldCollection.h>
       
    40 #include <CPbk2DriveSpaceCheck.h>
       
    41 #include <CPbk2ApplicationServices.h>
       
    42 #include <Pbk2CommonUi.rsg>
       
    43 
       
    44 // Virtual Phonebook
       
    45 #include <VPbkFieldType.hrh>
       
    46 #include <CVPbkContactManager.h>
       
    47 #include <MVPbkContactLink.h>
       
    48 #include <MVPbkContactOperationBase.h>
       
    49 #include <MVPbkStoreContact.h>
       
    50 #include <MVPbkContactFieldTextData.h>
       
    51 #include <MVPbkStoreContactFieldCollection.h>
       
    52 #include <RVPbkContactFieldDefaultPriorities.h>
       
    53 #include <MVPbkStreamable.h>
       
    54 #include <CVPbkFieldTypeSelector.h>
       
    55 
       
    56 // System includes
       
    57 #include <StringLoader.h>
       
    58 #include <sendui.h>
       
    59 #include <SenduiMtmUids.h>
       
    60 #include <CMessageData.h>
       
    61 #include <featmgr.h>
       
    62 #include <coemain.h>
       
    63 #include <barsread.h>
       
    64 #include <akntitle.h>
       
    65 
       
    66 // Debugging headers
       
    67 #include <Pbk2Debug.h>
       
    68 
       
    69 /// Unnamed namespace for local definitions
       
    70 namespace {
       
    71 
       
    72 const TInt KDefaultTitleFormat = MPbk2ContactNameFormatter::EUseSeparator;
       
    73 const TInt KGranularity( 4 );
       
    74 
       
    75 #ifdef _DEBUG
       
    76 
       
    77 enum TPanicCode
       
    78     {
       
    79     EPanicUnknownMedia = 1,
       
    80     ERunL_InvalidState,
       
    81     EPanicLogic,
       
    82     EPanicNullPointer
       
    83     };
       
    84 
       
    85 void Panic( TPanicCode aReason )
       
    86     {
       
    87     _LIT( KPanicText, "CPbk2SendMessageCmd" );
       
    88     User::Panic( KPanicText, aReason );
       
    89     }
       
    90 #endif //_DEBUG
       
    91 
       
    92 }  /// namespace
       
    93 
       
    94 
       
    95 // --------------------------------------------------------------------------
       
    96 // CPbk2SendMessageCmd::CPbk2SendMessageCmd
       
    97 // --------------------------------------------------------------------------
       
    98 //
       
    99 CPbk2SendMessageCmd::CPbk2SendMessageCmd(
       
   100         MPbk2ContactUiControl& aUiControl ) :
       
   101     CActive( EPriorityIdle ),
       
   102     iUiControl( &aUiControl ),
       
   103     iRecipientCount( 0 ),
       
   104     iFocusedFieldIndex( aUiControl.FocusedFieldIndex() )
       
   105     {
       
   106     CActiveScheduler::Add( this );
       
   107     }
       
   108 
       
   109 // --------------------------------------------------------------------------
       
   110 // CPbk2SendMessageCmd::~CPbk2SendMessageCmd
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 CPbk2SendMessageCmd::~CPbk2SendMessageCmd()
       
   114     {
       
   115     Cancel();
       
   116     if( iUiControl )
       
   117         {
       
   118         iUiControl->RegisterCommand( NULL );
       
   119         }
       
   120 
       
   121     delete iAttachmentFile;
       
   122     delete iMessageData;
       
   123     delete iSelectedContacts;
       
   124 
       
   125     delete iMtmFilter;
       
   126     delete iRetrieveOperation;
       
   127     delete iStoreContact;
       
   128     delete iSendUi;
       
   129     Release( iAppServices );
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CPbk2SendMessageCmd::NewL
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 CPbk2SendMessageCmd* CPbk2SendMessageCmd::NewL(
       
   137         MPbk2ContactUiControl& aUiControl )
       
   138     {
       
   139     CPbk2SendMessageCmd* self =
       
   140         new ( ELeave ) CPbk2SendMessageCmd( aUiControl );
       
   141     CleanupStack::PushL(self);
       
   142     self->ConstructL();
       
   143     CleanupStack::Pop(self); // self
       
   144     return self;
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CPbk2SendMessageCmd::ConstructL
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 void CPbk2SendMessageCmd::ConstructL()
       
   152     {
       
   153     CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL
       
   154         ( CCoeEnv::Static()->FsSession() );
       
   155     CleanupStack::PushL( driveSpaceCheck );
       
   156     // check FFS situation
       
   157     driveSpaceCheck->DriveSpaceCheckL();
       
   158     CleanupStack::PopAndDestroy( driveSpaceCheck );
       
   159 
       
   160     iSendUi = CSendUi::NewL();
       
   161     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   162 
       
   163     iFieldPropertyArray = &(iAppServices->FieldProperties());
       
   164 
       
   165     iMtmFilter = new ( ELeave ) CArrayFixFlat<TUid>( KGranularity );
       
   166     iSendingCapabilities.iFlags = TSendingCapabilities::ESupportsEditor;
       
   167     iSelectedContacts = iUiControl->SelectedContactsOrFocusedContactL();
       
   168     __ASSERT_DEBUG(iSelectedContacts, Panic(EPanicNullPointer));
       
   169     iMessageData = CMessageData::NewL();
       
   170     iUiControl->RegisterCommand( this );
       
   171     }
       
   172 
       
   173 // --------------------------------------------------------------------------
       
   174 // CPbk2SendMessageCmd::ExecuteLD
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 void CPbk2SendMessageCmd::ExecuteLD()
       
   178     {
       
   179     iCurrentContactLinkIndex = 0;
       
   180     iState = EShowWriteQuery;
       
   181     IssueRequest();
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CPbk2SendMessageCmd::AddObserver
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 void CPbk2SendMessageCmd::AddObserver( MPbk2CommandObserver& aObserver)
       
   189     {
       
   190     iCommandObserver = &aObserver;
       
   191     }
       
   192 
       
   193 // --------------------------------------------------------------------------
       
   194 // CPbk2SendMessageCmd::ResetUiControl
       
   195 // --------------------------------------------------------------------------
       
   196 //
       
   197 void CPbk2SendMessageCmd::ResetUiControl(
       
   198         MPbk2ContactUiControl& aUiControl)
       
   199     {
       
   200     if (iUiControl == &aUiControl)
       
   201         {
       
   202         iUiControl = NULL;
       
   203         }
       
   204     }
       
   205 
       
   206 // --------------------------------------------------------------------------
       
   207 // CPbk2SendMessageCmd::SetMtmUid
       
   208 // --------------------------------------------------------------------------
       
   209 //
       
   210 void CPbk2SendMessageCmd::SetMtmUid( TUid aUid )
       
   211     {
       
   212     iMtmUid = aUid;
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------------
       
   216 // CPbk2SendMessageCmd::RunL
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 void CPbk2SendMessageCmd::RunL()
       
   220     {
       
   221     switch (iState)
       
   222         {
       
   223         case ERetrieving:
       
   224             {
       
   225             if ( iSelectedContacts->Count() == iCurrentContactLinkIndex )
       
   226                 {
       
   227                 iState = EStarting;
       
   228                 IssueRequest();
       
   229                 }
       
   230             else
       
   231                 {
       
   232                 RetrieveContactL( iSelectedContacts->At(
       
   233                     iCurrentContactLinkIndex ) );
       
   234                 iCurrentContactLinkIndex++;
       
   235                 }
       
   236             break;
       
   237             }
       
   238 
       
   239         case EShowWriteQuery:
       
   240             {
       
   241             // No need to query message type if it's already known
       
   242             if( iMtmUid == KNullUid )
       
   243                 {
       
   244                 iMtmUid = ShowWriteQueryL();
       
   245                 }
       
   246 
       
   247             if ( iMtmUid == KNullUid )
       
   248                 {
       
   249                 IssueStopRequest( KErrCancel );
       
   250                 }
       
   251             else
       
   252                 {
       
   253                 iState = ERetrieving;
       
   254                 IssueRequest();
       
   255                 }
       
   256             break;
       
   257             }
       
   258 
       
   259         case EResolveURL:
       
   260             {
       
   261             ResolveUrlL();
       
   262             break;
       
   263             }
       
   264 
       
   265         case EStarting:
       
   266             {
       
   267             DoSendMessageL();
       
   268             break;
       
   269             }
       
   270 
       
   271         case EStopping:
       
   272             {
       
   273             ProcessDismissed( KErrNone );
       
   274             break;
       
   275             }
       
   276 
       
   277         default:
       
   278             {
       
   279             __ASSERT_DEBUG( EFalse, Panic( ERunL_InvalidState ) );
       
   280             break;
       
   281             }
       
   282         }
       
   283     }
       
   284 
       
   285 // --------------------------------------------------------------------------
       
   286 // CPbk2SendMessageCmd::DoCancel
       
   287 // --------------------------------------------------------------------------
       
   288 //
       
   289 void CPbk2SendMessageCmd::DoCancel()
       
   290     {
       
   291     // Do nothing
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CPbk2SendMessageCmd::RunError
       
   296 // --------------------------------------------------------------------------
       
   297 //
       
   298 TInt CPbk2SendMessageCmd::RunError( TInt aError )
       
   299     {
       
   300     return FilterErrors( aError );
       
   301     }
       
   302 
       
   303 // --------------------------------------------------------------------------
       
   304 // CPbk2SendMessageCmd::VPbkSingleContactOperationComplete
       
   305 // --------------------------------------------------------------------------
       
   306 //
       
   307 void CPbk2SendMessageCmd::VPbkSingleContactOperationComplete
       
   308         ( MVPbkContactOperationBase& /*aOperation*/,
       
   309           MVPbkStoreContact* aContact )
       
   310     {
       
   311     delete iRetrieveOperation;
       
   312     iRetrieveOperation = NULL;
       
   313 
       
   314     // We now have a store contact
       
   315     delete iStoreContact;
       
   316     iStoreContact = aContact;
       
   317 
       
   318     iState = EResolveURL;
       
   319     IssueRequest();
       
   320     }
       
   321 
       
   322 // --------------------------------------------------------------------------
       
   323 // CPbk2SendMessageCmd::VPbkSingleContactOperationFailed
       
   324 // --------------------------------------------------------------------------
       
   325 //
       
   326 void CPbk2SendMessageCmd::VPbkSingleContactOperationFailed
       
   327         ( MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   328     {
       
   329     delete iRetrieveOperation;
       
   330     iRetrieveOperation = NULL;
       
   331 
       
   332     // We cannot get the contact, so we have to
       
   333     // fail. We cannot continue, since this operation
       
   334     // was executed only in case of one contact.
       
   335     ProcessDismissed( aError );
       
   336     }
       
   337 
       
   338 // --------------------------------------------------------------------------
       
   339 // CPbk2SendMessageCmd::ShowWriteQueryL
       
   340 // --------------------------------------------------------------------------
       
   341 //
       
   342 TUid CPbk2SendMessageCmd::ShowWriteQueryL()
       
   343     {
       
   344     if ( iSelectedContacts->Count() > 1 )
       
   345         {
       
   346         iMtmFilter->AppendL(KSenduiMtmPostcardUid);  // hide postcard
       
   347         }
       
   348     TUid uid = iSendUi->ShowTypedQueryL( CSendUi::EWriteMenu, NULL,
       
   349         iSendingCapabilities, iMtmFilter );
       
   350     return uid;
       
   351     }
       
   352 
       
   353 // --------------------------------------------------------------------------
       
   354 // CPbk2SendMessageCmd::RetrieveContactL
       
   355 // --------------------------------------------------------------------------
       
   356 //
       
   357 void CPbk2SendMessageCmd::RetrieveContactL
       
   358         ( const MVPbkContactLink& aContactLink )
       
   359     {
       
   360     // Retrieve the actual store contact from the given link
       
   361     iRetrieveOperation = iAppServices->
       
   362         ContactManager().RetrieveContactL( aContactLink, *this );
       
   363     }
       
   364 
       
   365 // --------------------------------------------------------------------------
       
   366 // CPbk2SendMessageCmd::DoSendMessageL
       
   367 // --------------------------------------------------------------------------
       
   368 //
       
   369 void CPbk2SendMessageCmd::DoSendMessageL()
       
   370     {
       
   371     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   372         ("CPbk2SendMessageCmd::DoSendMessageL() start") );
       
   373 
       
   374     iSendUi->CreateAndSendMessageL( iMtmUid, iMessageData );
       
   375 
       
   376     iState = EStopping;
       
   377     IssueRequest();
       
   378     }
       
   379 
       
   380 // --------------------------------------------------------------------------
       
   381 // CPbk2SendMessageCmd::ResolveUrlL
       
   382 // --------------------------------------------------------------------------
       
   383 //
       
   384 void CPbk2SendMessageCmd::ResolveUrlL()
       
   385     {
       
   386     if ( iMtmUid == KSenduiMtmPostcardUid )
       
   387         {
       
   388         // Send post card
       
   389         SendPostCardL();
       
   390         iState = EStarting;
       
   391         IssueRequest();
       
   392         }
       
   393     else
       
   394         {
       
   395         TUid techTypeUid = iSendUi->TechnologyType( iMtmUid );
       
   396 
       
   397         RVPbkContactFieldDefaultPriorities defaults;
       
   398         CleanupClosePushL( defaults );
       
   399 
       
   400         // Prepare address select
       
   401         TInt resourceId = PrepareAddressSelectL( defaults, techTypeUid );
       
   402 
       
   403         if ( resourceId > KErrNotFound )
       
   404             {
       
   405             MVPbkStoreContactField* selectedField =
       
   406                 SelectFieldL( resourceId, defaults );
       
   407 
       
   408             if ( !selectedField )
       
   409                 {
       
   410                 CPbk2AppUiBase<CAknViewAppUi>& appUi = static_cast<CPbk2AppUiBase<CAknViewAppUi>&>
       
   411                     ( *CEikonEnv::Static()->EikAppUi() );
       
   412 
       
   413                 if ( appUi.IsForeground() )
       
   414                     {
       
   415                     if ( iSelectedContacts->Count() == iCurrentContactLinkIndex
       
   416                              && iRecipientCount == 0 )
       
   417                         {
       
   418                         // This is the last contact and there are
       
   419                         // no recipients, stop
       
   420                         IssueStopRequest( KErrNone );
       
   421                         }
       
   422                     else
       
   423                         {
       
   424                         // If this is not the last contact or if there are
       
   425                         // recipients, go on
       
   426                         iState = ERetrieving;
       
   427                         IssueRequest();
       
   428                         }
       
   429                     }
       
   430                 else
       
   431                     {
       
   432                     // If appUi is not in the foreground, 
       
   433                     // It means Phonebook2 has hidden itself in background. 
       
   434                     // All active commands should be stopped so that names list view is to be activated 
       
   435                     // and no other views will be shown when re-entering Phonebook2
       
   436                     IssueStopRequest( KErrNone );
       
   437                     }               	
       
   438                 }
       
   439             else
       
   440                 {
       
   441                 CleanupDeletePushL( selectedField );
       
   442                 SetAddressFromFieldL( *selectedField );
       
   443                 CleanupStack::PopAndDestroy(); // selectedField
       
   444 
       
   445                 iState = ERetrieving;
       
   446                 IssueRequest();
       
   447                 }
       
   448             }
       
   449 
       
   450         CleanupStack::PopAndDestroy(); // defaults
       
   451         }
       
   452     }
       
   453 
       
   454 // --------------------------------------------------------------------------
       
   455 // CPbk2SendMessageCmd::PrepareAddressSelectL
       
   456 // --------------------------------------------------------------------------
       
   457 //
       
   458 inline TInt CPbk2SendMessageCmd::PrepareAddressSelectL
       
   459         ( RVPbkContactFieldDefaultPriorities& aPriorities,
       
   460           TUid aTechType )
       
   461     {
       
   462     // Precondition
       
   463     __ASSERT_DEBUG( iMtmUid != KNullUid, Panic( EPanicUnknownMedia) );
       
   464 
       
   465     TInt resourceId = KErrNotFound;
       
   466 
       
   467     // SMS
       
   468     if ( iMtmUid == KSenduiMtmSmsUid ||
       
   469          aTechType == KSenduiTechnologySmsUid )
       
   470         {
       
   471         if ( FeatureManager::FeatureSupported( KFeatureIdEmailOverSms ) )
       
   472             {
       
   473             resourceId = R_PBK2_EMAIL_OVER_SMS_ADDRESS_SELECT;
       
   474             User::LeaveIfError( aPriorities.Append
       
   475                 ( EVPbkDefaultTypeEmailOverSms ) );
       
   476             }
       
   477         else
       
   478             {
       
   479             resourceId = R_PBK2_PHONE_NUMBER_SELECT;
       
   480             User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeSms ) );
       
   481             }
       
   482         }
       
   483     // MMS & Audio message
       
   484     // Audio Messaging uses same address select as MMS for now
       
   485     else if ( iMtmUid == KSenduiMtmMmsUid ||
       
   486               iMtmUid == KSenduiMtmAudioMessageUid ||
       
   487               aTechType == KSenduiTechnologyMmsUid )
       
   488         {
       
   489         resourceId = R_PBK2_MMS_ADDRESS_SELECT;
       
   490         User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeMms ) );
       
   491         }
       
   492     // E-mail
       
   493     else if ( iMtmUid ==  KSenduiMtmSmtpUid ||
       
   494               aTechType == KSenduiTechnologyMailUid )
       
   495         {
       
   496         resourceId = R_PBK2_EMAIL_ADDRESS_SELECT;
       
   497         User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeEmail ) );
       
   498         }
       
   499     // Unified message
       
   500     else if ( iMtmUid == KSenduiMtmUniMessageUid )
       
   501         {
       
   502         if ( FeatureManager::FeatureSupported( KFeatureIdMMS ) )
       
   503             {
       
   504             if (iAppServices->LocallyVariatedFeatureEnabled(
       
   505                 EVPbkLVShowEmailInSendMsg ))
       
   506                 {
       
   507                 resourceId = R_PBK2_UNIFIED_EDITOR_MMS_ADDRESS_SELECT;
       
   508                 }
       
   509             else
       
   510                 {
       
   511                 resourceId = R_PBK2_UNIFIED_EDITOR_PHONE_NUMBER_SELECT;
       
   512                 }
       
   513             User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeMms ) );
       
   514             }
       
   515 
       
   516         if ( FeatureManager::FeatureSupported
       
   517                 ( KFeatureIdEmailOverSms ) )
       
   518             {
       
   519             if ( resourceId == KErrNotFound )
       
   520                 {
       
   521                 resourceId =
       
   522                     R_PBK2_UNIFIED_EDITOR_EMAIL_OVER_SMS_ADDRESS_SELECT;
       
   523                 }
       
   524             // Include SMS default always in unified message,
       
   525             // in addition unified message has MMS default included
       
   526             // with higher priority
       
   527             User::LeaveIfError( aPriorities.Append
       
   528                 ( EVPbkDefaultTypeEmailOverSms ) );
       
   529             }
       
   530         else
       
   531             {
       
   532             if ( resourceId == KErrNotFound )
       
   533                 {
       
   534                 resourceId = R_PBK2_UNIFIED_EDITOR_PHONE_NUMBER_SELECT;
       
   535                 }
       
   536             // Include SMS default always in unified message,
       
   537             // in addition it has MMS default included with higher priority
       
   538             User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeSms ) );
       
   539             }
       
   540         }
       
   541 
       
   542     // Postcondition
       
   543     __ASSERT_DEBUG( resourceId != KErrNotFound, Panic( EPanicLogic) );
       
   544 
       
   545     return resourceId;
       
   546     }
       
   547 
       
   548 // --------------------------------------------------------------------------
       
   549 // CPbk2SendMessageCmd::SetAddressFromFieldL
       
   550 // --------------------------------------------------------------------------
       
   551 //
       
   552 void CPbk2SendMessageCmd::SetAddressFromFieldL
       
   553         ( MVPbkStoreContactField& aField )
       
   554     {
       
   555     HBufC* address = MVPbkContactFieldTextData::Cast( aField.FieldData()).
       
   556         Text().AllocL();
       
   557     CleanupStack::PushL( address );
       
   558 
       
   559     if ( address && address->Des().Length() > 0 )
       
   560         {
       
   561         HBufC* nameBuffer = iAppServices->NameFormatter().
       
   562             GetContactTitleL(
       
   563                 static_cast<const MVPbkBaseContactFieldCollection&>(
       
   564                     iStoreContact->Fields() ),
       
   565                 KDefaultTitleFormat);
       
   566         CleanupStack::PushL( nameBuffer );
       
   567         const TDesC& unnamed = iAppServices->NameFormatter().UnnamedText();
       
   568         if ( unnamed == ( *nameBuffer ) )
       
   569             {
       
   570             iMessageData->AppendToAddressL( *address );
       
   571             }
       
   572         else
       
   573             {
       
   574             iMessageData->AppendToAddressL( *address, *nameBuffer );
       
   575             }
       
   576         ++iRecipientCount;
       
   577         CleanupStack::PopAndDestroy(); // nameBuffer
       
   578         }
       
   579     CleanupStack::PopAndDestroy( address );
       
   580     }
       
   581 
       
   582 // --------------------------------------------------------------------------
       
   583 // CPbk2SendMessageCmd::ProcessDismissed
       
   584 // --------------------------------------------------------------------------
       
   585 //
       
   586 void CPbk2SendMessageCmd::ProcessDismissed( TInt aCancelCode )
       
   587     {
       
   588     if ( iAttachmentFile )
       
   589         {
       
   590         // No error checking, exiting Phonebook would
       
   591         // be too much for this error
       
   592         CCoeEnv::Static()->FsSession().Delete( iAttachmentFile->FileName() );
       
   593         }
       
   594 
       
   595     if ( aCancelCode != KErrCancel  && iUiControl)
       
   596         {
       
   597         TRAPD( err,
       
   598             iUiControl->ResetFindL();
       
   599             // Keep focus in contact
       
   600             if ( iStoreContact )
       
   601                 {
       
   602                 if ( iFocusedFieldIndex != KErrNotFound )
       
   603                     {
       
   604                     iUiControl->SetFocusedFieldIndex( iFocusedFieldIndex );
       
   605                     }
       
   606                 iUiControl->SetFocusedContactL( *iStoreContact );
       
   607                 }
       
   608                 TUid titlePaneUid;
       
   609                 titlePaneUid.iUid = EEikStatusPaneUidTitle;
       
   610                 CEikStatusPane *statusPane = ((CAknAppUi*)CEikonEnv::Static()->EikAppUi())->StatusPane();
       
   611                 CEikStatusPaneBase::TPaneCapabilities subPane =
       
   612                             statusPane->PaneCapabilities(titlePaneUid);
       
   613 
       
   614                 if (subPane.IsPresent()&&subPane.IsAppOwned())
       
   615                     {
       
   616                     CAknTitlePane* titlePane =
       
   617                                 (CAknTitlePane *)statusPane->ControlL(titlePaneUid);
       
   618                     HBufC* titlePaneText = StringLoader::LoadLC(R_QTN_PHOB_TITLE);
       
   619                     titlePane->SetTextL(*titlePaneText);
       
   620 
       
   621                     CleanupStack::PopAndDestroy(titlePaneText);
       
   622                     }
       
   623             ); // TRAPD
       
   624         iUiControl->UpdateAfterCommandExecution();
       
   625         if (err != KErrNone)
       
   626             {
       
   627             CCoeEnv::Static()->HandleError(err);
       
   628             }
       
   629         }
       
   630 
       
   631     // Notify command owner that the command has finished
       
   632     if (iCommandObserver)
       
   633         {
       
   634         iCommandObserver->CommandFinished( *this );
       
   635         }
       
   636 
       
   637     }
       
   638 
       
   639 // --------------------------------------------------------------------------
       
   640 // CPbk2SendMessageCmd::FilterErrors
       
   641 // --------------------------------------------------------------------------
       
   642 //
       
   643 TInt CPbk2SendMessageCmd::FilterErrors( TInt aErrorCode )
       
   644     {
       
   645     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   646         ( "CPbk2SendMessageCmd::FilterErrors(%d) start" ), aErrorCode );
       
   647 
       
   648     TInt result = aErrorCode;
       
   649     switch (aErrorCode)
       
   650         {
       
   651         case KErrNotFound:  // FALLTHROUGH
       
   652         case KErrInUse:
       
   653             {
       
   654             // Ignore these errors
       
   655             // KErrNotFound means that somebody got the contact first
       
   656             // KErrInUse means that the contact is open
       
   657             result = KErrNone;
       
   658             break;
       
   659             }
       
   660 
       
   661         default:  // Something more serious happened -> give up
       
   662             {
       
   663             Cancel();
       
   664             ProcessDismissed( aErrorCode );
       
   665             break;
       
   666             }
       
   667         }
       
   668 
       
   669     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   670         ( "CPbk2SendMessageCmd::FilterErrors(%d) end" ), result );
       
   671 
       
   672     return result;
       
   673     }
       
   674 
       
   675 // --------------------------------------------------------------------------
       
   676 // CPbk2SendMessageCmd::IssueRequest
       
   677 // --------------------------------------------------------------------------
       
   678 //
       
   679 void CPbk2SendMessageCmd::IssueRequest()
       
   680     {
       
   681     TRequestStatus* status = &iStatus;
       
   682     User::RequestComplete( status, KErrNone );
       
   683     SetActive();
       
   684     }
       
   685 
       
   686 // --------------------------------------------------------------------------
       
   687 // CPbk2SendMessageCmd::IssueStopRequest
       
   688 // --------------------------------------------------------------------------
       
   689 //
       
   690 void CPbk2SendMessageCmd::IssueStopRequest( TInt aErrorCode )
       
   691     {
       
   692     iState = EStopping;
       
   693 
       
   694     if ( aErrorCode != KErrNone )
       
   695         {
       
   696         ProcessDismissed( aErrorCode );
       
   697         }
       
   698 
       
   699     if (!IsActive())
       
   700         {
       
   701         IssueRequest();
       
   702         }
       
   703     }
       
   704 
       
   705 // --------------------------------------------------------------------------
       
   706 // CPbk2SendMessageCmd::ToStoreFieldIndexL
       
   707 // --------------------------------------------------------------------------
       
   708 //
       
   709 TInt CPbk2SendMessageCmd::ToStoreFieldIndexL( TInt aPresIndex )
       
   710     {
       
   711     TInt index( KErrNotFound );
       
   712     CPbk2PresentationContact* presentationContact =
       
   713         CPbk2PresentationContact::NewL(
       
   714             *iStoreContact, iAppServices->FieldProperties() );
       
   715     CleanupStack::PushL( presentationContact );
       
   716 
       
   717     index = presentationContact->PresentationFields().StoreIndexOfField
       
   718         ( aPresIndex );
       
   719 
       
   720     CleanupStack::PopAndDestroy( presentationContact );
       
   721 
       
   722     return index;
       
   723     }
       
   724 
       
   725 // --------------------------------------------------------------------------
       
   726 // CPbk2SendMessageCmd::SelectFieldL
       
   727 // --------------------------------------------------------------------------
       
   728 //
       
   729 MVPbkStoreContactField* CPbk2SendMessageCmd::SelectFieldL(
       
   730         TUint aResourceId,
       
   731         RVPbkContactFieldDefaultPriorities& aPriorities )
       
   732     {
       
   733     TResourceReader resReader;
       
   734     CCoeEnv::Static()->CreateResourceReaderLC( resReader, aResourceId );
       
   735 
       
   736     TPbk2AddressSelectParams params
       
   737         ( *iStoreContact,
       
   738             iAppServices->ContactManager(),
       
   739             iAppServices->NameFormatter(),
       
   740             *iFieldPropertyArray, resReader );
       
   741 
       
   742     // Set focused field if we are in contact info
       
   743     TInt fieldIndex = KErrNotFound;
       
   744     if (iUiControl)
       
   745         {
       
   746         fieldIndex = iUiControl->FocusedFieldIndex();
       
   747         }
       
   748     MVPbkStoreContactField* focusedField = NULL;
       
   749     if ( fieldIndex != KErrNotFound )
       
   750         {
       
   751         focusedField = iStoreContact->Fields().FieldAtLC
       
   752                 ( ToStoreFieldIndexL( fieldIndex ) );
       
   753         }
       
   754     else
       
   755         {
       
   756         // We are in names list and we should use the default value
       
   757         // directly if available
       
   758         params.SetUseDefaultDirectly( ETrue );
       
   759         }
       
   760 
       
   761     params.SetFocusedField( focusedField );
       
   762     params.SetDefaultPriorities( aPriorities );
       
   763 
       
   764     params.iCommMethod = VPbkFieldTypeSelectorFactory::EUniEditorSelector;
       
   765 	CVPbkFieldTypeSelector* actionTypeSelector = 
       
   766         VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL(
       
   767                 VPbkFieldTypeSelectorFactory::EUniEditorSelector,
       
   768                 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager().FieldTypes());
       
   769         
       
   770     CleanupStack::PushL( actionTypeSelector );
       
   771     
       
   772     // Run address select
       
   773     CPbk2AddressSelect* addressSelect = CPbk2AddressSelect::NewL(
       
   774             params,
       
   775             *actionTypeSelector,
       
   776             NULL,
       
   777             NULL );
       
   778     
       
   779     MVPbkStoreContactField* selectedField = addressSelect->ExecuteLD();
       
   780 
       
   781     if ( focusedField )
       
   782         {
       
   783         CleanupStack::PopAndDestroy(); // focusedField
       
   784         }
       
   785     CleanupStack::PopAndDestroy( 2 ); // actionTypeSelector, resReader 
       
   786 
       
   787     return selectedField;
       
   788     }
       
   789 
       
   790 // --------------------------------------------------------------------------
       
   791 // CPbk2SendMessageCmd::SendPostCardL
       
   792 // --------------------------------------------------------------------------
       
   793 //
       
   794 void CPbk2SendMessageCmd::SendPostCardL()
       
   795     {
       
   796     // Create attachment file object
       
   797     delete iAttachmentFile;
       
   798     iAttachmentFile = NULL;
       
   799     HBufC* attFileName = StringLoader::LoadLC
       
   800         ( R_PBK2_POSTCARD_WRITE_ATTACHMENT_TAG );
       
   801     iAttachmentFile = CPbk2AttachmentFile::NewL
       
   802         ( *attFileName, CCoeEnv::Static()->FsSession(),
       
   803           EFileWrite|EFileShareAny );
       
   804     CleanupStack::PopAndDestroy( attFileName );
       
   805 
       
   806     HBufC8* buf = iSelectedContacts->PackLC();
       
   807     iAttachmentFile->File().Write( *buf );
       
   808     CleanupStack::PopAndDestroy( buf );
       
   809 
       
   810     iMessageData->AppendAttachmentL( iAttachmentFile->FileName() );
       
   811     iAttachmentFile->Release();
       
   812     }
       
   813 
       
   814 //  End of File