messagingappbase/mce/src/mceui.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     Defines methods for CMceUi
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <bldvariant.hrh>
       
    24 #include <featmgr.h>
       
    25 #include <mtmuidef.hrh> 
       
    26 
       
    27 #include <messagingvariant.hrh>
       
    28 #include <centralrepository.h>
       
    29 #include <messaginginternalcrkeys.h>
       
    30 #include <CoreApplicationUIsSDKCRKeys.h>
       
    31 
       
    32 // security data caging
       
    33 #include <data_caging_path_literals.hrh>
       
    34 
       
    35 #include <mtudreg.h>        // cmtmuidataregistry
       
    36 #include <MTMStore.h>       // cmtmstore
       
    37 #include <miutset.h>
       
    38 #include <MuiuMsvProgressReporterOperation.h> // cmsvprogressreporteroperation
       
    39 #include <mtmdef.h>         // KUidMtmQueryCanSendMsgValue
       
    40 #include <msvids.h>
       
    41 #include <msvuids.h>
       
    42 #include <mtud.hrh>         // EMtudCommandTransferSend, EMtudCommandTransferSend, EMtudCommandTransferReceive
       
    43 
       
    44 #include <MuiuMsgEmbeddedEditorWatchingOperation.h> // tmsgexitmode
       
    45 #include <MuiuOperationWait.h>  // cmuiuoperationwait
       
    46 #include <muiumsvuiserviceutilitiesinternal.h> // msvuiserviceutilitiesinternal
       
    47 #include <MuiuMsvUiServiceUtilities.h> // msvuiserviceutilities
       
    48 class CGulIcon;
       
    49 #include <MsgFolderSelectionDialog.h>
       
    50 #include <PushMtmCommands.hrh>    // epushmtmcmdcollectgarbage
       
    51 #include <smutcmds.hrh>         // KMtmUiFunctionSmumRemoveSMSC
       
    52 #include <MsgBioUids.h>     // kmsgbiouidpicturemsg
       
    53 #include <mtuireg.h>        // CMtmUiRegistry
       
    54 #include <mmsconst.h>
       
    55 #include <obexclientmtm.h>
       
    56 #include <MuiuOperationWait.h>  // cmuiuoperationwait
       
    57 #include <muiu.mbg>
       
    58 #include <muiu.rsg>
       
    59 #include <MuiuMsvUiServiceUtilities.h>
       
    60 #include <mtmuidef.hrh>
       
    61 
       
    62 #include <SenduiMtmUids.h>      // mtm uids
       
    63 #include <SendUiConsts.h>
       
    64 
       
    65 // MMS.Content.Upload
       
    66 #include <CSendingServiceInfo.h>
       
    67 #include <sendui.h>
       
    68 #include <CMessageData.h>
       
    69 
       
    70 #include <layoutmetadata.cdl.h>//for layout id
       
    71 #include <aknappui.h>
       
    72 #include <StringLoader.h>   // stringloader
       
    73 #include <akntabgrp.h>
       
    74 #include <aknnavide.h>
       
    75 #include <aknclearer.h>
       
    76 #include <aknnotewrappers.h>
       
    77 #include <akninputblock.h> // cakninputblock
       
    78 #include <akntitle.h>
       
    79 #include <ErrorUI.h>        // cerrorui
       
    80 #include <aknnotedialog.h>
       
    81 #include <akninputblock.h> // cakninputblock
       
    82 #include <akncontext.h>
       
    83 
       
    84 #include <gfxtranseffect/gfxtranseffect.h>     // for transition effects
       
    85 #include <akntranseffect.h>                    // for transition effects
       
    86 
       
    87 #include <DocumentHandler.h>
       
    88 
       
    89 
       
    90 #include <RCustomerServiceProfileCache.h>
       
    91 
       
    92 
       
    93 // MMS.Content.Upload
       
    94 #include <muiumsguploadparam.h>
       
    95 #include <CSendingServiceInfo.h>
       
    96 
       
    97 #include <ImumInternalApi.h>                // cimuminternalapi
       
    98 #include <ImumInMailboxServices.h>          // mimuminmailboxservices
       
    99 #include <ImumInSettingsData.h>             // cimuminsettingsdata
       
   100 #include <ImumInSettingsKeys.h>             // timuminsettings
       
   101 #include <UiklafInternalCRKeys.h>
       
   102 
       
   103 #include <MNcnInternalNotification.h>
       
   104 #include <NcnNotificationDefs.h>
       
   105 
       
   106 #include <BTSapDomainPSKeys.h>
       
   107 #include <e32property.h>
       
   108 
       
   109 #include <muiulock.h>
       
   110 
       
   111 #include <messaginginternalpskeys.h>        // kpsuidmuiu, kmuiukeycurrentmsg
       
   112 #include <e32property.h>                    // RProperty
       
   113 
       
   114 #include <CPhCltUssd.h>
       
   115 
       
   116 #include <RPhCltServer.h>
       
   117 
       
   118 #include <hlplch.h>             // For HlpLauncher
       
   119 
       
   120 // For Muiu split
       
   121 #include <muiumsvuiserviceutilitiesinternal.h>
       
   122 
       
   123 #include <ImumInternalApi.h>                // cimuminternalapi
       
   124 
       
   125 #ifdef RD_MULTIPLE_DRIVE
       
   126 #include <driveinfo.h>
       
   127 #endif // RD_MULTIPLE_DRIVE
       
   128 
       
   129 #include <mce.rsg>
       
   130 #include "MceCommands.hrh"
       
   131 #include "mceui.h"
       
   132 #include "MceSessionHolder.h"
       
   133 #include "MceMessageListView.h"
       
   134 //#include "MceMessageListbox.h"
       
   135 #include "MceMainViewListView.h"
       
   136 #include <mcesettingsdialog.h>
       
   137 #include <mcesettingsarrays.h>
       
   138 #include "MceMessageListContainerBase.h"
       
   139 //#include "MceMessageListContainer.h"
       
   140 #include "MceMainViewListContainer.h"
       
   141 #include "MceBitmapResolver.h"
       
   142 #include "MceConnectMailboxTimer.h"
       
   143 #include "MceSendOperation.h"
       
   144 #include "McePanic.h"
       
   145 #include "MceLogEngine.h"
       
   146 #include "MceDeliveryReportView.h"
       
   147 //#include "MceMessageListItemArray.h"
       
   148 #include "MceMainViewListItemArray.h"
       
   149 #include "MceIdleMtmLoader.h"
       
   150 #include "MceNaviPaneFolderIndicator.h"
       
   151 //#include "MceEmailEditorResetTimer.h"
       
   152 #include "MceCancelSendingOperation.h"
       
   153 #include "MceChangeFlagOperation.h"     // cmceremovenewflag
       
   154 #include "MceEmailNotifHandler.h"
       
   155 #include "MceAttachmentAddition.h"
       
   156 #include "mceiaupdateutils.h"
       
   157 
       
   158 
       
   159 #include <miutset.h>
       
   160 #include <mtmuids.h>
       
   161 #include <MessagingDomainCRKeys.h>
       
   162 #include <mcesettingsemailsel.h>
       
   163 #include <mtmuids.h>
       
   164 #include <MessagingDomainCRKeys.h>
       
   165 //CR:422-271
       
   166 #include <mmscodecclient.h>
       
   167 #include "mmsclient.h"
       
   168 #include "mmsconst.h"
       
   169 #include "e32cmn.h"
       
   170 // CONSTANTS
       
   171 
       
   172 const TInt KMceArrayGranularity                     = 4;
       
   173 const TUid KMceCBSApplication                       = {0x101F4CD3};
       
   174 const TInt KMceCBSApplicationStartView              = 2;
       
   175 
       
   176 _LIT( KMceDirAndFile,"muiu.mbm" );
       
   177 // CONSTANTS
       
   178 
       
   179 const TInt KMceAnswerToLifeUniverseAndEverything    = 42;
       
   180 const TInt KMceMaxFolderLength                      = 35;
       
   181 const TInt KMceTextLength                           = 120;
       
   182     // Estimate disk value for move or copy
       
   183 const TInt KMceDiskSpaceForMoveOrCopy = 65536;
       
   184 const TInt KMceMaxDateString(12);  // _mm/dd/yyyy_
       
   185 const TInt KMceOneMMSNotificationFailed                 = 1;
       
   186 
       
   187 _LIT8 ( KMceMMSNotifOne8, "1" ); // 8 bit one
       
   188 
       
   189 #define KMessagingCentreMainViewUid TVwsViewId( \
       
   190     TUid::Uid( KMceApplicationUidValue ), \
       
   191     TUid::Uid( KMceMainViewListViewIdValue ) )
       
   192 
       
   193 #ifdef _DEBUG
       
   194 _LIT( KPanicText, "Mce" );
       
   195 const TInt KCRepositorySettingFailure = 1;
       
   196 #endif
       
   197 
       
   198 const TInt KMceProgressReporterThreshold = 10;
       
   199 
       
   200 const TUid KMailTechnologyTypeUid = { 0x10001671 };
       
   201 
       
   202 //cmail update
       
   203 #define KUidMsgTypeFsMtmVal               0x2001F406
       
   204 //CR:422-271
       
   205 _LIT( KMmsMessageDumpDirectory, "C:\\Private\\1000484b\\mmsvar");
       
   206 _LIT( KRootPath, "C:\\" );
       
   207 const TInt KMmsCodecClientChunkSize = 1024;
       
   208 #define KMtmUiFunctionSimDialog  ( KMtmFirstFreeMtmUiFunctionId + 1 )
       
   209 // LOCAL FUNCTION PROTOTYPES
       
   210 
       
   211 //  ==================== LOCAL FUNCTIONS ====================
       
   212 //
       
   213 
       
   214 GLDEF_C void Panic(TMceUiPanic aPanic)
       
   215     // Panic function
       
   216     {
       
   217     User::Panic(_L("Mce"), aPanic);
       
   218     }
       
   219 
       
   220 
       
   221 // ================= MEMBER FUNCTIONS =======================
       
   222 
       
   223 
       
   224 CMceUi::CMceUi()
       
   225     :CAknViewAppUi(),
       
   226     iMsgTypesWritePopup( KMceArrayGranularity ),
       
   227     iMsgTypesWriteSubmenu( KMceArrayGranularity ),
       
   228     iMsgTypesSettings( KMceArrayGranularity ),
       
   229     iOperations( KMsvSingleOpWatcherArrayGranularity ),
       
   230     iMceIAUpdate( NULL ),
       
   231     iMoveOrCopyMailOperation(-1),
       
   232     iHandleNewMsgToInbox ( EFalse ),
       
   233     iAnchorId( NULL ),
       
   234     iEmailClientIntegration(EFalse),
       
   235     iSelectableEmail(EFalse),
       
   236     iEmailFramework(EFalse),
       
   237     iSimDialogOpen(EFalse)
       
   238     {
       
   239     iMceUiFlags.SetMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
   240     }
       
   241 
       
   242 CMceUi::~CMceUi()
       
   243     {
       
   244     MCELOGGER_ENTERFN("~CMceUi()");
       
   245     iCoeEnv->RemoveForegroundObserver( *this ); // CR : 401-1806
       
   246     delete iBitmapResolver;
       
   247     if(iMtmLoader)
       
   248         {
       
   249         iMtmLoader->Cancel();
       
   250         delete iMtmLoader;
       
   251         }
       
   252 
       
   253 #ifdef _DEBUG
       
   254     MCELOGGER_WRITE_FORMAT("iOperations.Count = %d", iOperations.Count() );
       
   255     const TInt count = iOperations.Count();
       
   256     for ( TInt loop = 0; loop < count; loop++ )
       
   257         {
       
   258         MCELOGGER_WRITE_FORMAT("loop = %d", loop );
       
   259         MCELOGGER_WRITE_FORMAT("operation id = %d", iOperations[loop]->Operation().Id() );
       
   260         }
       
   261 #endif
       
   262     iOperations.ResetAndDestroy();
       
   263     delete iMTMFunctionsArray;
       
   264     delete iUiRegistry;
       
   265     delete iEntry;
       
   266     delete iRootEntry;
       
   267     delete iMtmStore;
       
   268     delete iConnectMailboxTimer;
       
   269     if ( iSessionHolder )
       
   270         {
       
   271         // must not delete sessionholder, it will kill itself...
       
   272         iSessionHolder->RemoveClient();
       
   273         // must not delete iSession, session holder takes care of that
       
   274         }
       
   275     delete iMceLogEngine;
       
   276 
       
   277     delete iFolderIndicator;
       
   278     delete iTabsArray;
       
   279     delete iMMSNotifications;
       
   280     delete iDecoratedTabGroup;
       
   281     delete iMceErrorUi;
       
   282     delete iLocalScreenClearer;
       
   283     // iSession and iMceDeliveryView owned by iSessionHolder
       
   284     // don't delete iMessageTypesDlg, dialog will delete itself.
       
   285     delete iMailAccountItemArray;
       
   286     // MMS.Content.Upload
       
   287     iUploadServices.ResetAndDestroy();
       
   288     delete iEmailApi;
       
   289     delete iEmailNotifHandler;
       
   290     delete iCancelExitFlagOperation;
       
   291     
       
   292     if(iMceIAUpdate)
       
   293 	    {
       
   294 	    delete iMceIAUpdate;
       
   295 	    }
       
   296     
       
   297     if ( iIdArray )
       
   298         {
       
   299         delete iIdArray;
       
   300         iIdArray = NULL;
       
   301         }
       
   302     // close connection monitor
       
   303     if ( iAlwaysOnline )
       
   304         {
       
   305         iConnectionMonitor.Close();
       
   306         }
       
   307 
       
   308     // delete KPSUidMuiu property
       
   309     RProperty::Delete( KPSUidMuiu, KMuiuKeyCurrentMsg );
       
   310     RProperty::Delete( KPSUidMuiu, KMuiuKeyNextMsg );
       
   311     if ( iFeatureMgrEnabled ) // CR : 401-1806
       
   312         {
       
   313     FeatureManager::UnInitializeLib();
       
   314 		    iFeatureMgrEnabled = EFalse ; // CR : 401-1806
       
   315 		    }
       
   316 	if(iEncodeBuffer)
       
   317 	{
       
   318 		delete iEncodeBuffer;
       
   319 	}
       
   320 	iFs.Close();
       
   321 		
       
   322     MCELOGGER_LEAVEFN("~CMceUi()");
       
   323     MCELOGGER_DELETE;
       
   324     }
       
   325 
       
   326 void CMceUi::ConstructL()
       
   327     {
       
   328     MCELOGGER_CREATE
       
   329     MCELOGGER_ENTERFN("ConstructL()");
       
   330     MCELOGGER_WRITE_TIMESTAMP("Time: ");
       
   331 
       
   332     if ( AknLayoutUtils::MSKEnabled() )
       
   333         {
       
   334         BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
   335         }
       
   336     else
       
   337         {
       
   338         BaseConstructL( EAknEnableSkin | EAknSingleClickCompatible );
       
   339         }
       
   340 
       
   341     // SIM access profiles
       
   342     CheckSIMAccessProfileL();
       
   343 
       
   344     // security data caging
       
   345     TParse fp;
       
   346     fp.Set( KMceDirAndFile, &KDC_APP_BITMAP_DIR , NULL );
       
   347     iFilename = fp.FullName();
       
   348 
       
   349     FeatureManager::InitializeLibL();
       
   350     iFeatureMgrEnabled = ETrue ; // CR : 401-1806
       
   351 
       
   352     //check if 'Memory in use' -option is enabled in mce settings
       
   353     iMemoryInUse = MceUtils::MemoryInUseOptionL();
       
   354 
       
   355     iAlwaysOnline = AlwaysOnlineL();
       
   356 
       
   357     iCancelExitFlagOperation = CIdle::NewL( CActive::EPriorityIdle );
       
   358 
       
   359     // Are CSP bits supported
       
   360     iCsp = CspBitsL();
       
   361     iSessionHolder = CMceSessionHolder::NewL( *this );
       
   362     iSession = iSessionHolder->Session();
       
   363 
       
   364     RFs& fs=iEikonEnv->FsSession();
       
   365     TBool storeChanged = EFalse;
       
   366     TBool storeOnPhoneMemory = ETrue;
       
   367 #ifdef RD_MULTIPLE_DRIVE
       
   368     TInt phoneDrive;
       
   369     // At this point, try avoid using any predefined numbers E.G. EDriveC
       
   370     // in order to increase the safety and code flexibility
       
   371     User::LeaveIfError( DriveInfo::GetDefaultDrive( DriveInfo:: EDefaultPhoneMemory, phoneDrive ) );
       
   372     TInt currentDrive = TInt( iSession->CurrentDriveL() );
       
   373     if ( currentDrive != phoneDrive )
       
   374 #else
       
   375     if ( TInt(iSession->CurrentDriveL()) == EDriveE )
       
   376 #endif //RD_MULTIPLE_DRIVE
       
   377         {
       
   378         storeOnPhoneMemory = EFalse;
       
   379         TBool storeMounted = EFalse;
       
   380         TRAPD( error, storeMounted = (*iSession).MessageStoreDrivePresentL( ) );
       
   381         TBool driveContainsStore = EFalse;
       
   382 #ifdef RD_MULTIPLE_DRIVE
       
   383         TRAPD( error2, driveContainsStore = iSession->DriveContainsStoreL( currentDrive ) );        
       
   384 #else
       
   385         TRAPD( error2, driveContainsStore = iSession->DriveContainsStoreL( EDriveE ) );
       
   386 #endif // RD_MULTIPLE_DRIVE
       
   387         if ( error || !storeMounted || error2 || !driveContainsStore )
       
   388             {
       
   389             //change the message store to phone
       
   390             storeChanged = ETrue;
       
   391 
       
   392             //Change message store to phones internal memory(EDriveC)
       
   393             MsvUiServiceUtilitiesInternal::ChangeMessageStoreToPhoneL( *iSession );
       
   394             iMceUiFlags.ClearMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
   395             }
       
   396         }
       
   397 
       
   398     iMTMFunctionsArray=new (ELeave) CMsgFuncArray( KMceArrayGranularity );
       
   399 
       
   400     iBitmapResolver = CMceBitmapResolver::NewL( iSession, *this, ETrue );
       
   401 
       
   402     CMceMainViewListView* mainView = CMceMainViewListView::NewL(
       
   403         iSession,
       
   404         *iSessionHolder,
       
   405         *iBitmapResolver );
       
   406     CleanupStack::PushL( mainView );
       
   407     AddViewL(mainView);     // transfer ownership to CAknAppUi
       
   408     CleanupStack::Pop( mainView );
       
   409     iMceMainView = mainView;
       
   410     SetDefaultViewL( *iMceMainView );
       
   411     SetMceViewActive( EMceMainViewActive );
       
   412 
       
   413     iMceLogEngine = CMceLogEngine::NewL();
       
   414 
       
   415     CEikStatusPane* sp = StatusPane();
       
   416     iNaviPane = (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
       
   417 
       
   418     // iMessageIterator created when opening the message
       
   419 
       
   420     // Create IMAP folder indicator
       
   421 
       
   422     CMceNaviPaneFolderIndicator* folder =
       
   423         CMceNaviPaneFolderIndicator::NewL( storeOnPhoneMemory, 0 );
       
   424 
       
   425     CAknNavigationDecorator* tmp = CAknNavigationDecorator::NewL( 
       
   426         iNaviPane, folder, CAknNavigationDecorator::ENotSpecified );
       
   427 
       
   428     CleanupStack::PushL( tmp );
       
   429     tmp->SetContainerWindowL( *iNaviPane );
       
   430     CleanupStack::Pop( tmp ); 
       
   431     tmp->MakeScrollButtonVisible( EFalse );
       
   432     iFolderIndicator = tmp;
       
   433 
       
   434     iMailAccountItemArray = new(ELeave) CMceMailAccountItemArray(
       
   435         KMceArrayGranularity );
       
   436 
       
   437     iMceIAUpdate = NULL;
       
   438     iIadUpdateVal  = EFalse;
       
   439     if(FeatureManager::FeatureSupported( KFeatureIdIAUpdate ))
       
   440         {
       
   441         iIadUpdateVal = ETrue;
       
   442         }
       
   443         
       
   444     if ( iAlwaysOnline )
       
   445         {
       
   446         iConnectionMonitor.ConnectL();
       
   447         iConnectionMonitor.NotifyEventL( *this );
       
   448         }
       
   449 
       
   450     iMceUiFlags.SetMceFlag( EMceUiFlagsFinishedConstruction );
       
   451 
       
   452     if ( storeChanged )
       
   453         {
       
   454         // message store switching ate EMsvServerReady so do it once again,
       
   455         // when all has been constructed
       
   456         storeChanged = EFalse;
       
   457         HandleSessionEventL( MMsvSessionObserver::EMsvServerReady, NULL, NULL, NULL );
       
   458         }
       
   459 
       
   460     // Contents of uploadservices
       
   461     if ( FeatureManager::FeatureSupported(KFeatureIdSenduiMmsUpload) )
       
   462         {
       
   463         CSendUi* sendui = CSendUi::NewLC( );
       
   464         sendui->AvailableServicesL( iUploadServices, KMmsDirectUpload );
       
   465         sendui->AvailableServicesL( iUploadServices, KMmsIndirectUpload );
       
   466         CleanupStack::PopAndDestroy( sendui );
       
   467         }
       
   468     
       
   469     iAudioMsgEnabled = EFalse ; // CR : 401-1806
       
   470     iPostcardEnabled = EFalse ; // CR : 401-1806
       
   471     if ( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) )
       
   472         {
       
   473         iEmailClientIntegration = ETrue;
       
   474         }
       
   475     if ( FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) )
       
   476         {
       
   477         iSelectableEmail = ETrue;
       
   478         }
       
   479     if ( FeatureManager::FeatureSupported( KFeatureIdFfEmailFramework ) )
       
   480         {
       
   481         iEmailFramework = ETrue;
       
   482         }
       
   483     iMsgDeletedStatus = EFalse;
       
   484     iServerStarted = EFalse ;
       
   485     iEmailNotifHandler = NULL;
       
   486 #ifndef __WINSCW__ 
       
   487     // Handling of NCN reset
       
   488     TRAPD( err, iEmailNotifHandler = CMceEmailNotifHandler::NewL() );
       
   489     MCELOGGER_WRITE_FORMAT("ConstructL iEmailNotifHandler err %d", err);
       
   490     if ( err )
       
   491         {
       
   492         iEmailNotifHandler = NULL;
       
   493         }
       
   494 #endif
       
   495     ZoomLevelChangedL( ReadZoomLevelL() );
       
   496 
       
   497     iEmailApi = CreateEmailApiL( iSession );
       
   498 
       
   499     SetDiskSpaceForMoveOrCopyL();
       
   500     //CR:422-271
       
   501 	//initializing the encodebuffer for MMS templates   
       
   502     iEncodeBuffer = CBufFlat::NewL( 1 );//To remove hardcoding
       
   503     User::LeaveIfError( iFs.Connect() );
       
   504     iFs.SetSessionPath( KRootPath );
       
   505 
       
   506     MCELOGGER_LEAVEFN("ConstructL()");
       
   507     }
       
   508 
       
   509 // ----------------------------------------------------
       
   510 // CMceUi::HandleSessionEventL
       
   511 // ----------------------------------------------------
       
   512 void CMceUi::HandleSessionEventL(
       
   513     TMsvSessionEvent aEvent,
       
   514     TAny* aArg1,
       
   515     TAny* aArg2,
       
   516     TAny* /*aArg3*/ )
       
   517     {
       
   518     MCELOGGER_WRITE_TIMESTAMP("CMceUi::HandleSessionEventL() start");
       
   519     MCELOGGER_WRITE_FORMAT("aEvent=%d", aEvent);
       
   520 
       
   521     if ( !iMceUiFlags.MceFlag( EMceUiFlagsFinishedConstruction ) )
       
   522         {
       
   523         return;
       
   524         }
       
   525 
       
   526     TMsvId folderId = KMsvNullIndexEntryId;
       
   527 
       
   528     // ConstructL must have left as we have returned to the active scheduler
       
   529     // before complete construction
       
   530     TInt err;
       
   531     switch (aEvent)
       
   532         {
       
   533     case EMsvServerReady:
       
   534     case EMsvCorruptedIndexRebuilt:
       
   535         iMceUiFlags.ClearMceFlag( EMceUiFlagsMediaUnavailable );
       
   536         TRAP(err, HandleServerStartupL());
       
   537         if (err!=KErrNone)
       
   538             {
       
   539             // close...
       
   540             MCELOGGER_WRITE_FORMAT("HandleServerStartupL: %d", err);
       
   541             iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
   542             iCoeEnv->HandleError( err );
       
   543             Exit();
       
   544             }
       
   545          // Messaging application is started to background in bootup.
       
   546          // However messaging main view is not activated in background startup.
       
   547          // Because of that startup of messaging application after background startup is not as fast as other startups.
       
   548          // This can be optimized by activating main view same way than when messaging application is hide to background.
       
   549          if ( !IsForeground() )
       
   550             {
       
   551             HideOrExit();
       
   552             }        
       
   553         break;
       
   554     case EMsvMediaChanged:
       
   555     case EMsvMtmGroupInstalled:
       
   556     case EMsvMtmGroupDeInstalled:
       
   557         iMceUiFlags.ClearMceFlag( EMceUiFlagsMediaUnavailable );
       
   558         HandleMTMChangeL();
       
   559         break;
       
   560     case EMsvEntriesCreated:
       
   561     case EMsvEntriesDeleted:
       
   562         iMceUiFlags.ClearMceFlag( EMceUiFlagsMediaUnavailable );
       
   563         folderId = (*(TMsvId*) (aArg2));
       
   564         if ( folderId == KMsvRootIndexEntryId )
       
   565             {
       
   566             if ( IsPresent( KSenduiMtmSyncMLEmailUid ) )
       
   567                 {
       
   568                 // check if syncml item should be added/removed
       
   569                 // in new message dialog
       
   570                 SyncMlNewMessageItemL( (CMsvEntrySelection*) aArg1, aEvent );
       
   571                 }
       
   572             // something changed in root i.e. mailbox created or deleted...
       
   573             RemoveTabsAndUpdateArray();
       
   574             }
       
   575         // fall through 
       
   576     case EMsvEntriesChanged:
       
   577         folderId = (*(TMsvId*) (aArg2));
       
   578         if ( folderId == KMsvRootIndexEntryId && iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ) )
       
   579             {
       
   580             CMsvEntrySelection* selection = (CMsvEntrySelection*) aArg1; // do not take ownership
       
   581             const TInt count = selection->Count();
       
   582             TInt selectedIndex = KErrNotFound;
       
   583             for ( TInt loop = 0; loop < count && selectedIndex == KErrNotFound; loop++ )
       
   584                 {
       
   585                 selectedIndex = iTabsArray->Find( selection->At( loop ) );
       
   586                 }
       
   587 
       
   588             if ( selectedIndex != KErrNotFound )
       
   589                 {
       
   590                 CheckRemoteMailboxTabIconsL();
       
   591                 }
       
   592             }
       
   593         // list update done by active view so do nothing here
       
   594         break;
       
   595     case EMsvServerFailedToStart:
       
   596     case EMsvServerTerminated:
       
   597     case EMsvCloseSession:
       
   598         iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
   599         iAvkonViewAppUi->ProcessCommandL( EAknCmdExit );
       
   600         break;
       
   601     case EMsvGeneralError:
       
   602         {
       
   603         const TInt leave=*STATIC_CAST(TInt*,aArg1);
       
   604         if (iMceUiFlags.MceFlag( EMceUiFlagsWantToExit ) && leave==KLeaveExit)
       
   605             {
       
   606             User::Leave(leave);
       
   607             }
       
   608         break;
       
   609         }
       
   610     case EMsvMediaUnavailable:
       
   611         iMceUiFlags.SetMceFlag( EMceUiFlagsMediaUnavailable );
       
   612         if ( iMceUiFlags.MceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent ) )
       
   613             {
       
   614             MCELOGGER_WRITE("CMceUi::HandleSessionEventL() EMsvMediaUnavailable EXIT");
       
   615             iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
   616             iAvkonViewAppUi->ProcessCommandL( EAknCmdExit );
       
   617             }
       
   618         else
       
   619             {
       
   620             MCELOGGER_WRITE("CMceUi::HandleSessionEventL() EMsvMediaUnavailable Clear flag!");
       
   621             iMceUiFlags.ClearMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
   622             }
       
   623         break;
       
   624     case EMsvMediaAvailable:
       
   625         {
       
   626         iMceUiFlags.ClearMceFlag( EMceUiFlagsMediaUnavailable );
       
   627         iMceUiFlags.SetMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
   628         // update folders tab
       
   629         CMceNaviPaneFolderIndicator* findicator =
       
   630             static_cast<CMceNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
   631         findicator->ChangeRootL( TInt(iSession->CurrentDriveL() == EDriveC) );
       
   632         }
       
   633         // fall through 
       
   634     default:
       
   635         break;
       
   636         }
       
   637     MCELOGGER_WRITE_TIMESTAMP("CMceUi::HandleSessionEventL() end");
       
   638     }
       
   639 
       
   640 // ----------------------------------------------------
       
   641 // CMceUi::HandleServerStartupL
       
   642 // ----------------------------------------------------
       
   643 void CMceUi::HandleServerStartupL()
       
   644     {
       
   645     iServerStarted = EFalse ;
       
   646     LoadContextIconL();
       
   647 
       
   648     if ( iMceUiFlags.MceFlag( EMceUiFlagsServerReady ) )
       
   649         {
       
   650         MCELOGGER_LEAVEFN("HandleServerStartupL(), server ready");
       
   651 
       
   652         if ( iMemoryInUse )
       
   653             {
       
   654             // when iSession->ChangeDriveL is called, also HandleSessionEvent is called
       
   655             // using EMsvServerReady
       
   656 
       
   657             if(iMtmLoader)
       
   658                 {
       
   659                 iMtmLoader->Cancel();
       
   660                 delete iMtmLoader;
       
   661                 iMtmLoader = NULL;
       
   662                 }
       
   663 
       
   664             delete iUiRegistry;
       
   665             iUiRegistry=NULL;
       
   666 
       
   667             delete iEntry;
       
   668             iEntry = NULL;
       
   669             iEntry=iSession->GetEntryL(KMsvRootIndexEntryId);
       
   670 
       
   671             delete iRootEntry;
       
   672             iRootEntry = NULL;
       
   673             iRootEntry=CMsvEntry::NewL(
       
   674                 *iSession,
       
   675             KMsvRootIndexEntryId,
       
   676             TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
       
   677 
       
   678             delete iMtmStore;
       
   679             iMtmStore=NULL;
       
   680 
       
   681             iMtmStore=CMtmStore::NewL(*iSession);
       
   682             iUiRegistry=CMtmUiDataRegistry::NewL(*iSession);
       
   683 
       
   684             iRootEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
   685 
       
   686             // reconstruct main view
       
   687             iMceMainView->ConstructMainViewL();
       
   688 
       
   689             // reconstruct tabs
       
   690             TBool tabsActive = iMceUiFlags.MceFlag( EMceUiFlagsTabsActive );
       
   691             RemoveTabs();
       
   692             delete iDecoratedTabGroup;
       
   693             iDecoratedTabGroup = NULL;
       
   694             delete iTabsArray;
       
   695             iTabsArray = NULL;
       
   696 
       
   697             if ( MceViewActive( EMceMessageViewActive ) 
       
   698                 && tabsActive 
       
   699                 && ( !iMceListView->IsImapFolderOpenL( ) ) )
       
   700                 {
       
   701                 const TMceListItem& tempItem = iMceMainView
       
   702                     ->ListContainer()->CurrentItemListItem();
       
   703                 TMsvId service;
       
   704                 TMsvEntry child;
       
   705                 User::LeaveIfError( iSession->GetEntry( tempItem.iMsvId, service, child ) );
       
   706                 ShowTabsL( child.Id() );
       
   707                 }
       
   708 
       
   709             // update folders tab
       
   710             CMceNaviPaneFolderIndicator* findicator =
       
   711                 static_cast<CMceNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
   712             findicator->ChangeRootL( TInt(iSession->CurrentDriveL()) );
       
   713 
       
   714             iMceMainView->ListContainer()->DrawNow();
       
   715             }
       
   716         iServerStarted = ETrue ;
       
   717         return;
       
   718         }
       
   719 
       
   720     iEntry=iSession->GetEntryL(KMsvRootIndexEntryId);
       
   721     iRootEntry=CMsvEntry::NewL(
       
   722         *iSession,
       
   723         KMsvRootIndexEntryId,
       
   724         TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
       
   725     iMtmStore=CMtmStore::NewL(*iSession);
       
   726 
       
   727     iUiRegistry=CMtmUiDataRegistry::NewL(*iSession);
       
   728 
       
   729    
       
   730     iMceMainView->HandleMsgServerStartupL();
       
   731     
       
   732     CMceDeliveryReportView* view3 = CMceDeliveryReportView::NewL( *iSessionHolder );
       
   733     CleanupStack::PushL( view3 );
       
   734     AddViewL( view3 );      // transfer ownership to CAknAppUi
       
   735     CleanupStack::Pop( view3 );
       
   736 
       
   737     iMceDeliveryView = view3;
       
   738 
       
   739      
       
   740     CMceMessageListView* mceListView = CMceMessageListView::NewL(
       
   741         iSession,
       
   742         KMsvLocalServiceIndexEntryId,
       
   743         *iSessionHolder,
       
   744         *iBitmapResolver,
       
   745         *iMceMainView );
       
   746     CleanupStack::PushL( mceListView );
       
   747     AddViewL( mceListView );      // transfer ownership to CAknAppUi
       
   748     CleanupStack::Pop( mceListView );
       
   749     iMceListView = mceListView;
       
   750 
       
   751 
       
   752 
       
   753 
       
   754     
       
   755     iAudioMsgEnabled = FeatureManager::FeatureSupported( KFeatureIdAudioMessaging ); // CR : 401-1806
       
   756     iPostcardEnabled = FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) ; // CR : 401-1806
       
   757 
       
   758     HandleMTMChangeL();
       
   759 
       
   760 /*    CMceMessageListView* mceListView = CMceMessageListView::NewL(
       
   761         iSession,
       
   762         KMsvLocalServiceIndexEntryId,
       
   763         *iSessionHolder,
       
   764         *iBitmapResolver,
       
   765         *iMceMainView );
       
   766     CleanupStack::PushL( mceListView );
       
   767     AddViewL(mceListView);      // transfer ownership to CAknAppUi
       
   768     CleanupStack::Pop(); // mceListView
       
   769     iMceListView = mceListView;*/
       
   770     iMceListView->HandleMsgServerStartupL();
       
   771 
       
   772 
       
   773 
       
   774     iMceMainView->ListContainer()->ListItems()->SetAlwaysOnline( iAlwaysOnline );
       
   775 
       
   776     if ( iAlwaysOnline )
       
   777         {
       
   778         TRequestStatus status;
       
   779         TInt registrationStatus( 0 );
       
   780 
       
   781         //check network status
       
   782         iConnectionMonitor.GetIntAttribute(
       
   783             EBearerIdGSM, 0, KNetworkRegistration,
       
   784             registrationStatus, status );
       
   785 
       
   786         User::WaitForRequest( status );
       
   787 
       
   788         if ( status.Int() == KErrNone )
       
   789             {
       
   790             iMceMainView->ListContainer()->ListItems()->SetRoaming( 
       
   791                 registrationStatus == ENetworkRegistrationRoaming );
       
   792             }
       
   793         }
       
   794 
       
   795     iMceUiFlags.ClearMceFlag( EMceUiFlagsWantToExit );
       
   796     iMceUiFlags.SetMceFlag( EMceUiFlagsServerReady );
       
   797 
       
   798     ToPhoneMemoryQueryL( iMceUiFlags.MceFlag( EMceUiFlagsMainViewActivated ) );
       
   799 
       
   800     iCoeEnv->AddForegroundObserverL( *this ); // CR : 401-1806
       
   801     //populate MMS templates in inbox which are preloaded KMmsMessageDumpDirectory.
       
   802     //CR:422-271
       
   803     PopulateMMSTemplates();
       
   804     
       
   805     iServerStarted = ETrue ;
       
   806     MCELOGGER_LEAVEFN("HandleServerStartupL()");
       
   807     }
       
   808 
       
   809 // ----------------------------------------------------
       
   810 // CMceUi::Session
       
   811 // ----------------------------------------------------
       
   812 CMsvSession& CMceUi::Session()
       
   813     {
       
   814     return *iSession;
       
   815     }
       
   816 
       
   817 // ----------------------------------------------------
       
   818 // CMceUi::HandleCommandL
       
   819 // ----------------------------------------------------
       
   820 void CMceUi::HandleCommandL( TInt aCommand )
       
   821     {
       
   822     MCELOGGER_WRITE_FORMAT("HandleCommandL: aCommand: %d", aCommand);
       
   823 
       
   824     if ( iMceUiFlags.MceFlag( EMceUiFlagsMediaUnavailable ) 
       
   825         && aCommand != EEikCmdExit 
       
   826         && aCommand != EMceCmdExit 
       
   827         && aCommand != EAknSoftkeyBack)
       
   828         {
       
   829         MCELOGGER_WRITE("HandleCommandL: media unavailable, leave");
       
   830         User::Leave( KMsvIndexBackup );
       
   831         }
       
   832 
       
   833     switch (aCommand)
       
   834         {
       
   835         case EEikCmdExit:
       
   836             iSimDialogOpen = EFalse;
       
   837             Exit();
       
   838             break;
       
   839         case EMceCmdExit:
       
   840             CloseConnectionsBeforeExitL();
       
   841             if ( iMceUiFlags.MceFlag( EMceUiFlagsWantToExit ) )
       
   842                 {
       
   843                 HideOrExit();
       
   844                 }
       
   845             break;
       
   846         case EAknCmdHideInBackground:
       
   847             HideOrExit();
       
   848             break;
       
   849         case EMceCmdNewFolder:
       
   850             CreateNewFolderL( );
       
   851             break;
       
   852         case EMceCmdRenameFolder:
       
   853             RenameFolderL();
       
   854             break;
       
   855         case EMceCmdSettings:
       
   856             SettingsDialogL();
       
   857             break;
       
   858         case EMceCmdDelete:
       
   859             HandleDeleteL();
       
   860             break;
       
   861         case EMceCmdUndelete:
       
   862             HandleUndeleteL();
       
   863             break;
       
   864         case EMceCmdCopy:
       
   865             MoveOrCopyEntriesL( ETrue );
       
   866             break;
       
   867         case EMceCmdMove:
       
   868             MoveOrCopyEntriesL( EFalse );
       
   869             break;
       
   870         case EMceCmdFetchNew:
       
   871             FetchNewL();
       
   872             break;
       
   873         case EMceCmdFetchSelected:
       
   874             FetchSelectedL();
       
   875             break;
       
   876         case EMceCmdFetchAll:
       
   877             FetchAllL();
       
   878             break;
       
   879         case EAknSoftkeyBack:
       
   880             RemoveTabs();
       
   881             ActivateLocalViewL( KMceMainViewListViewId );
       
   882             break;
       
   883         case EMceCmdOutboxStart:
       
   884             SendNowL();
       
   885             break;
       
   886         case EMceCmdOutboxSuspend:
       
   887             CancelSendingL();
       
   888             break;
       
   889         case EMceCmdOutboxMoveToDrafts:
       
   890             {
       
   891             if ( iMceListView->SyncMlOutboxInbox( KMsvGlobalOutBoxIndexEntryId ) )
       
   892                 {
       
   893                 SyncMlMoveFromOutboxToDraftsL();
       
   894                 }
       
   895             else
       
   896                 {
       
   897                 MoveFromOutboxToDraftsL();
       
   898                 }
       
   899             }
       
   900             break;
       
   901         case EMceCmdCBSApplication:
       
   902             LaunchCBSApplicationL();
       
   903             break;
       
   904         case EMceCmdUSSDEditor:
       
   905             LaunchServiceCommandEditorL();
       
   906             break;
       
   907 
       
   908         case EAknCmdHelp:
       
   909             LaunchHelpL();
       
   910             break;
       
   911 
       
   912         case EAknCmdOpen:
       
   913         case EMceCmdConnect:
       
   914         case EMceCmdCloseConnection:
       
   915         case EAknCmdUnmark:
       
   916         case EAknCmdMark:
       
   917         case EAknMarkAll:
       
   918         case EAknUnmarkAll:
       
   919             // these should be handled by view
       
   920             break;
       
   921 
       
   922         case EMceCmdReply:
       
   923             ReplyL(aCommand);
       
   924             break;
       
   925 
       
   926         case EMceCmdMarkAsRead:
       
   927         case EMceCmdMarkAsReadMsg:
       
   928         case EMceCmdMarkAsReadMsgs:
       
   929         case EMceCmdMarkAsReadEmails:
       
   930             MarkAsReadL();
       
   931             break;
       
   932 
       
   933         case EMceCmdMarkAsUnread:
       
   934         case EMceCmdMarkAsUnreadMsg:
       
   935         case EMceCmdMarkAsUnreadMsgs:
       
   936         case EMceCmdMarkAsUnreadEmails:
       
   937             MarkAsReadL( EFalse );
       
   938             break;
       
   939 
       
   940         case EMceCmdMailboxSettings:
       
   941             OpenMailboxSettingsL();
       
   942             break;
       
   943 
       
   944         case EMceCmdForward:
       
   945             ForwardL(aCommand);
       
   946             break;
       
   947 
       
   948         case EMceCmdZoomValueAutomatic:
       
   949         case EMceCmdZoomValueSmall:
       
   950         case EMceCmdZoomValueMedium:
       
   951         case EMceCmdZoomValueLarge:
       
   952             HandleZoomLevelChangeL( aCommand );
       
   953             break;
       
   954         case EMceCmdLanuchUniEditor:
       
   955             LaunchUniEditorL();
       
   956             break;
       
   957             
       
   958         case EMceCmdLaunchEmailEditor:
       
   959             CreateNewMessageL( GetToBeCreatedEmailType () );
       
   960             break;
       
   961 
       
   962         default:
       
   963         if ( aCommand >= EMceCmdFirstMTMFunction && aCommand < EMceCmdFirstMTMContextFunction )
       
   964             {
       
   965             const TMsgFunctionInfo* info=&iMTMFunctionsArray->At(aCommand-EMceCmdFirstMTMFunction);
       
   966             HandleMTMFunctionL(*info);
       
   967             }
       
   968         else if ( aCommand > EMceCmdCreateNewCommands && aCommand < EMceCmdFirstMTMFunction  )
       
   969                 {
       
   970                 const TInt messageIndex =
       
   971                     aCommand - EMceCmdCreateNewCommands - 1;
       
   972                 __ASSERT_ALWAYS( messageIndex < iMsgTypesWriteSubmenu.Count(),
       
   973                     Panic( EMceUiErrCreateNewMessageCommand ) );
       
   974                 CreateNewMessageL( iMsgTypesWriteSubmenu[messageIndex].iUid.iUid );
       
   975                 }
       
   976         break;
       
   977         } // switch
       
   978     MCELOGGER_LEAVEFN("HandleCommandL()");
       
   979     }
       
   980 
       
   981 // ----------------------------------------------------
       
   982 // CMceUi::DynInitMenuPaneL
       
   983 // ----------------------------------------------------
       
   984 void CMceUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   985     {
       
   986     ForceMtmLoaderFinish();
       
   987     TBool cbs = EFalse;
       
   988     if ( FeatureManager::FeatureSupported( KFeatureIdCellBroadcast ) )
       
   989         {
       
   990         cbs = ETrue;
       
   991         if ( iCsp )
       
   992             {
       
   993             cbs = CheckCspBitL();
       
   994             }
       
   995         }
       
   996     switch ( aResourceId )
       
   997         {
       
   998         case R_MCE_MAIN_VIEW_MENU:
       
   999             {
       
  1000             // Run time Cell Broadcast variant.
       
  1001             // Enable/disable CBS
       
  1002             aMenuPane->SetItemDimmed( EMceCmdCBSApplication, !cbs );
       
  1003             // Run time USSD variant.
       
  1004             aMenuPane->SetItemDimmed( EMceCmdUSSDEditor,
       
  1005                 !FeatureManager::FeatureSupported( KFeatureIdUSSD ));
       
  1006 
       
  1007             aMenuPane->SetItemDimmed( EAknCmdHelp,
       
  1008                 !FeatureManager::FeatureSupported( KFeatureIdHelp ) );
       
  1009 
       
  1010             if ( iMsgTypesWriteSubmenu.Count() == 0 )
       
  1011                 {
       
  1012                 aMenuPane->SetItemDimmed( EMceCmdNewMessage, ETrue );
       
  1013                 }
       
  1014             if ( MceViewActive( EMceMainViewActive ) )
       
  1015                 {
       
  1016                 AddMTMFunctionsL(*aMenuPane, EMceCmdCloseConnection);
       
  1017 
       
  1018                 const CMceMainViewListContainer* listContainer =
       
  1019                     iMceMainView->ListContainer();
       
  1020                 const TMceListItem listItem =
       
  1021                     listContainer->CurrentItemListItem();
       
  1022                 if ( listItem.iExtraItem )
       
  1023                     {
       
  1024                     aMenuPane->SetItemDimmed( EMceCmdConnect, ETrue );
       
  1025                     }
       
  1026                 else
       
  1027                     {
       
  1028                     const TUid  connectCapability =
       
  1029                         { KUidMsvMtmUiQueryConnectionOrientedServices };
       
  1030                     TInt rid;
       
  1031 
       
  1032                     iEntry->SetEntryL( listItem.iMsvId );
       
  1033                     TUid uid = iEntry->Entry().iMtm;
       
  1034                     CBaseMtmUiData* uiData = NULL;
       
  1035                     if ( uid != KUidMsvLocalServiceMtm )
       
  1036                         {
       
  1037                         uiData=GetMtmUiDataL( uid );
       
  1038                         }
       
  1039                     if ( uiData && ( uid != KSenduiMtmSyncMLEmailUid ) 
       
  1040                         && uiData->QueryCapability( connectCapability, rid )
       
  1041                         == KErrNone )
       
  1042                         {
       
  1043                         // need to check if connected or not
       
  1044                         if ( iEntry->Entry().Connected() )
       
  1045                             {
       
  1046                             aMenuPane->SetItemDimmed( EMceCmdConnect, ETrue );
       
  1047                             }
       
  1048                         }
       
  1049                     else
       
  1050                         {
       
  1051                         aMenuPane->SetItemDimmed( EMceCmdConnect, ETrue );
       
  1052                         }
       
  1053                     }
       
  1054                 // if we have at least one connection open then do not delete EMceCmdCloseConnection
       
  1055                 CMsvEntrySelection* connectedAccounts = ConnectedServicesLC();
       
  1056                 if ( connectedAccounts->Count() == 0)
       
  1057                     {
       
  1058                     aMenuPane->SetItemDimmed( EMceCmdCloseConnection, ETrue );
       
  1059                     }
       
  1060                 CleanupStack::PopAndDestroy( connectedAccounts );
       
  1061 
       
  1062                 } // if ( MceViewActive( EMceMainViewActive ) )
       
  1063             break;
       
  1064             }
       
  1065         case R_MCE_NEW_MESSAGE_MENU:
       
  1066             {
       
  1067             CEikMenuPaneItem::SData item;
       
  1068             item.iCommandId = EMceCmdCreateNewCommands;
       
  1069             item.iFlags = 0;
       
  1070             item.iCascadeId = 0;
       
  1071             const TInt count = iMsgTypesWriteSubmenu.Count();
       
  1072             for(TInt loop = 0; loop < count; loop++)
       
  1073                 {
       
  1074                 item.iText = iMsgTypesWriteSubmenu[loop].iName;
       
  1075                 item.iCommandId++;
       
  1076                 aMenuPane->AddMenuItemL(item);
       
  1077                 }
       
  1078             break;
       
  1079             }
       
  1080        case R_MCE_FOLDER_MENU:
       
  1081             {
       
  1082             aMenuPane->SetItemDimmed( EAknCmdHelp,
       
  1083                 !FeatureManager::FeatureSupported( KFeatureIdHelp ) );
       
  1084 
       
  1085             AddMTMFunctionsL(*aMenuPane, EAknCmdOpen);
       
  1086             }
       
  1087             break;
       
  1088        case R_MCE_LOCAL_ZOOM_VALUE:
       
  1089             {
       
  1090             HandleZoomSubMenu( aMenuPane );
       
  1091             }
       
  1092             break;
       
  1093         default:
       
  1094             break;
       
  1095         }// end switch
       
  1096     }
       
  1097 
       
  1098 // ----------------------------------------------------
       
  1099 // CMceUi::SendViaL
       
  1100 // ----------------------------------------------------
       
  1101 void CMceUi::SendViaL( TMsvId aId, TUid aMtm )
       
  1102     {
       
  1103     __ASSERT_DEBUG( aMtm == KSenduiMtmIrUid || aMtm == KSenduiMtmBtUid,
       
  1104     Panic(EMceUiErrCanSendViaOnlyBtOrIr) );
       
  1105 
       
  1106     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  1107 
       
  1108     // Get the file name
       
  1109     TFileName fileName;
       
  1110     TInt fileSize;
       
  1111     RFile fileHandle;
       
  1112     MceUtils::GetIrFilePathL( *iSession, aId, fileName, fileHandle, fileSize );
       
  1113     CleanupClosePushL( fileHandle );
       
  1114 
       
  1115     // Required capabilities for message types
       
  1116     TSendingCapabilities capabilities(
       
  1117         0,
       
  1118         0,
       
  1119         TSendingCapabilities::ESupportsAttachments );
       
  1120 
       
  1121     // Create the message
       
  1122     CMessageData* messageData = CMessageData::NewL();
       
  1123     CleanupStack::PushL( messageData );
       
  1124     messageData->AppendAttachmentHandleL( fileHandle );
       
  1125 
       
  1126     // Send the message with SendUI
       
  1127     CSendUi* sendui = CSendUi::NewLC();
       
  1128     sendui->CreateAndSendMessageL( aMtm, messageData, KNullUid, ETrue );
       
  1129 
       
  1130     CleanupStack::PopAndDestroy( 3 ); // sendui, messageData, fileHandle 
       
  1131     }
       
  1132 
       
  1133 // ----------------------------------------------------
       
  1134 // CMceUi::HandleKeyEventL
       
  1135 // ----------------------------------------------------
       
  1136 TKeyResponse CMceUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
  1137     {
       
  1138     if ( iEditorOperation )
       
  1139         {
       
  1140         MCELOGGER_WRITE_FORMAT("HandleKeyEventL: iEditorOperation set 0x%x so don't do anything", iEditorOperation );
       
  1141         return EKeyWasConsumed;
       
  1142         }
       
  1143 
       
  1144     if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ) && aType == EEventKey )
       
  1145         {
       
  1146         CAknTabGroup* tabGroup = NULL;
       
  1147         if ( iDecoratedTabGroup )
       
  1148             {
       
  1149             tabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
       
  1150             }
       
  1151 
       
  1152         if ( !tabGroup )
       
  1153             {
       
  1154             return EKeyWasNotConsumed;
       
  1155             }
       
  1156 
       
  1157         return tabGroup->OfferKeyEventL( aKeyEvent, aType );
       
  1158         }
       
  1159 
       
  1160     return EKeyWasNotConsumed;
       
  1161     }
       
  1162 
       
  1163 // ----------------------------------------------------
       
  1164 // CMceUi::LogEngine
       
  1165 // ----------------------------------------------------
       
  1166 CMceLogEngine* CMceUi::LogEngine()
       
  1167     {
       
  1168     return iMceLogEngine;
       
  1169     }
       
  1170 
       
  1171 // ----------------------------------------------------
       
  1172 // CMceUi::LaunchHelpL
       
  1173 // ----------------------------------------------------
       
  1174 void CMceUi::LaunchHelpL()
       
  1175     {
       
  1176     // activate Help application
       
  1177     CArrayFix<TCoeHelpContext>* helpContext = AppHelpContextL();
       
  1178     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
  1179     }
       
  1180 
       
  1181 // ----------------------------------------------------
       
  1182 // CMceUi::HandleOpenNextPreviousL
       
  1183 // ----------------------------------------------------
       
  1184 void CMceUi::HandleOpenNextPreviousL( TBool /*aOpenNext*/ )
       
  1185     {
       
  1186     MCELOGGER_ENTERFN("HandleOpenNextPreviousL()");
       
  1187      
       
  1188     // Read the next message TMsvId using PS key 
       
  1189     TInt nextEntryId = 0;
       
  1190     TInt r = RProperty::Get( KPSUidMuiu, KMuiuKeyNextMsg, nextEntryId );
       
  1191     if ( r != KErrNone )
       
  1192         {
       
  1193         nextEntryId = 0;
       
  1194         }
       
  1195     
       
  1196     if ( nextEntryId > 0 )
       
  1197         {
       
  1198         // no need of following check because TMsvID is set properly
       
  1199         //set from MsgEditorAppUI.
       
  1200   
       
  1201     
       
  1202         TBool local = iMceListView->ListContainer()->FolderEntry().iServiceId == KMsvLocalServiceIndexEntryId;
       
  1203         if ( local && !iLocalScreenClearer ) 
       
  1204             {
       
  1205             iLocalScreenClearer = CAknLocalScreenClearer::NewL( ETrue );
       
  1206             }
       
  1207 
       
  1208         CMceMessageListContainerBase* container = iMceListView->ListContainer();
       
  1209         
       
  1210         TMsvId currentItemId = nextEntryId;
       
  1211         if ( container )
       
  1212             {
       
  1213             container->SetCurrentItemIdL( currentItemId );
       
  1214             container->DrawNow();
       
  1215             }
       
  1216 
       
  1217         TMsvEntry currentEntry;
       
  1218         TMsvId serviceId; // not used here but needed by GetEntry function
       
  1219         if ( iSession->GetEntry( currentItemId, serviceId, currentEntry ) == KErrNone &&
       
  1220              currentEntry.iType == KUidMsvMessageEntry )
       
  1221             {
       
  1222             TRAPD( err, EditMTMEntryL( currentEntry ) );
       
  1223             if ( err )
       
  1224                 {
       
  1225                 if ( iLocalScreenClearer )
       
  1226                     {
       
  1227                     delete iLocalScreenClearer;
       
  1228                     iLocalScreenClearer = NULL;
       
  1229                     }
       
  1230                 User::Leave( err );
       
  1231                 }
       
  1232             }
       
  1233         } // end  
       
  1234     MCELOGGER_LEAVEFN("HandleOpenNextPreviousL()");
       
  1235     }
       
  1236 
       
  1237 // ----------------------------------------------------
       
  1238 // CMceUi::LaunchCBSApplicationL
       
  1239 // ----------------------------------------------------
       
  1240 void CMceUi::LaunchCBSApplicationL()
       
  1241     {
       
  1242     TVwsViewId id;
       
  1243     id.iAppUid = KMceCBSApplication;
       
  1244     id.iViewUid.iUid = KMceCBSApplicationStartView;
       
  1245     ActivateViewL( id  );
       
  1246     }
       
  1247 
       
  1248 // ----------------------------------------------------
       
  1249 // CMceUi::LaunchServiceCommandEditorL
       
  1250 // ----------------------------------------------------
       
  1251 void CMceUi::LaunchServiceCommandEditorL() const
       
  1252     {
       
  1253     CPhCltUssd* ussdClient = CPhCltUssd::NewL( EFalse );
       
  1254     CleanupStack::PushL( ussdClient );
       
  1255     ussdClient->StartUssdEditor();
       
  1256     CleanupStack::PopAndDestroy( ussdClient );
       
  1257     }
       
  1258 
       
  1259 // ----------------------------------------------------
       
  1260 // CMceUi::HandleResourceChangeL
       
  1261 // ----------------------------------------------------
       
  1262 void CMceUi::HandleResourceChangeL( TInt aType )
       
  1263     {
       
  1264     if ( !iServerStarted )
       
  1265         {
       
  1266     	return ;
       
  1267         }
       
  1268         
       
  1269     CAknViewAppUi::HandleResourceChangeL( aType );
       
  1270 	// this is fix for setting the correct status pane id, if AVKON changes the status pane ids then there will be a problem
       
  1271     TBool landscape( Layout_Meta_Data::IsLandscapeOrientation() );
       
  1272     if(!landscape)
       
  1273     {
       
  1274     CEikStatusPane* statusPane = StatusPane();
       
  1275     if(statusPane->CurrentLayoutResId()== R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT)
       
  1276     {
       
  1277     statusPane->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL_EXT );
       
  1278     }
       
  1279     }
       
  1280     if( aType == KEikDynamicLayoutVariantSwitch )
       
  1281         {
       
  1282         if ( iLocalScreenClearer )
       
  1283 	          {
       
  1284 	          delete iLocalScreenClearer;
       
  1285 	          iLocalScreenClearer = NULL;	
       
  1286 	          iLocalScreenClearer = CAknLocalScreenClearer::NewL( ETrue );
       
  1287 	          }
       
  1288 
       
  1289         if ( MceViewActive( EMceDeliveryReportsViewActive ) )
       
  1290             {
       
  1291             iMceDeliveryView->HandleClientRectChange();
       
  1292             }
       
  1293         iMceMainView->HandleClientRectChange();
       
  1294         
       
  1295         CMceNaviPaneFolderIndicator* findicator =
       
  1296             static_cast<CMceNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
  1297         findicator->HandleResourceChange( aType );
       
  1298         }
       
  1299 
       
  1300     if( aType == KAknsMessageSkinChange )
       
  1301         {
       
  1302         const TInt count = iUiRegistry->NumRegisteredMtmDlls();
       
  1303         for ( TInt i = 0; i < count; i++ )
       
  1304             {
       
  1305             iMtmStore->ReleaseMtmUiData( iUiRegistry->MtmTypeUid(i) );
       
  1306             }
       
  1307 
       
  1308         iBitmapResolver->ChangeBitmapInIconArrayL();
       
  1309         if ( !MceViewActive( EMceMainViewActive ) && iMceMainView )
       
  1310             {
       
  1311             //update the list icons, when delivery reports view is open and skin changes
       
  1312             iMceMainView->ListContainer()->HandleResourceChange( aType );
       
  1313             }
       
  1314         if ( !MceViewActive(EMceMessageViewActive) && iMceListView 
       
  1315             && iMceListView->ListContainer() )
       
  1316             {
       
  1317             iMceListView->ListContainer()->HandleResourceChange( aType );
       
  1318             }
       
  1319 
       
  1320         LoadContextIconL();
       
  1321         TitlePaneL()->DrawDeferred();
       
  1322 
       
  1323         CMceNaviPaneFolderIndicator* findicator =
       
  1324             static_cast<CMceNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
  1325         findicator->HandleResourceChange( aType );
       
  1326 
       
  1327         CAknContextPane* contextPane = (CAknContextPane *)(iEikonEnv->AppUiFactory(*this))
       
  1328             ->StatusPane()->ControlL(TUid::Uid(EEikStatusPaneUidContext));
       
  1329         contextPane->DrawDeferred();
       
  1330         }
       
  1331     if (iDecoratedTabGroup)
       
  1332         {
       
  1333         CAknTabGroup* tab = static_cast<CAknTabGroup*>( iDecoratedTabGroup->DecoratedControl() );
       
  1334         if ( tab )
       
  1335             {
       
  1336             // Inform (possibly off-screen) tab group about the change
       
  1337             tab->HandleResourceChange( aType );
       
  1338             }
       
  1339         }
       
  1340 
       
  1341     iResourceChangeCalled = ETrue;
       
  1342     }
       
  1343 
       
  1344 // ----------------------------------------------------
       
  1345 // CMceUi::CloseEditorApp
       
  1346 // ----------------------------------------------------
       
  1347 void CMceUi::CloseEditorApp()
       
  1348     {
       
  1349     if ( iEditorOperation )
       
  1350         {
       
  1351         TBool foundItem = EFalse;
       
  1352         TMsvOp opId = iEditorOperation->Operation().Id();
       
  1353 
       
  1354         for (TInt cc=iOperations.Count()-1; cc>=0 && !foundItem; cc--)
       
  1355             {
       
  1356             if (iOperations[cc]->Operation().Id()==opId)
       
  1357                 {
       
  1358                 delete iOperations[cc];
       
  1359                 iOperations.Delete(cc);
       
  1360                 foundItem = ETrue;
       
  1361                 }
       
  1362             }
       
  1363         iEditorOperation = NULL;
       
  1364 
       
  1365         delete iLocalScreenClearer;
       
  1366         iLocalScreenClearer = NULL;
       
  1367         }
       
  1368     }
       
  1369 
       
  1370 // ----------------------------------------------------
       
  1371 // CMceUi::LoadContextIconL
       
  1372 // ----------------------------------------------------
       
  1373 void CMceUi::LoadContextIconL( )
       
  1374     {
       
  1375     CEikStatusPane *sp = ( (CAknAppUi*)iEikonEnv->EikAppUi() )->StatusPane();
       
  1376     CAknContextPane* contextPane = (CAknContextPane *)sp->ControlL( 
       
  1377         TUid::Uid(EEikStatusPaneUidContext) );
       
  1378 
       
  1379     RFs& fs=iEikonEnv->FsSession();
       
  1380 
       
  1381     MAknsSkinInstance* skins = AknsUtils::SkinInstance();
       
  1382     CFbsBitmap* bitmap;
       
  1383     CFbsBitmap* bitmapMask;
       
  1384 
       
  1385 #ifdef RD_MULTIPLE_DRIVE
       
  1386     TInt phoneDrive;
       
  1387     // At this point, try avoid using any predefined numbers E.G. EDriveC
       
  1388     // in order to increase the safety and code flexibility
       
  1389     User::LeaveIfError( DriveInfo::GetDefaultDrive( DriveInfo:: EDefaultPhoneMemory, phoneDrive ) );
       
  1390     if ( TInt( iSession->CurrentDriveL() ) != phoneDrive )
       
  1391 #else
       
  1392     if ( TInt( iSession->CurrentDriveL()) == EDriveE )
       
  1393 #endif //RD_MULTIPLE_DRIVE
       
  1394         {
       
  1395 #ifndef __SCALABLE_ICONS
       
  1396         AknsUtils::CreateIconL( skins, KAknsIIDQgnMenuMceMmcCxt, bitmap,
       
  1397            bitmapMask, iFilename, EMbmMuiuQgn_menu_mce_mmc_cxt,
       
  1398            EMbmMuiuQgn_menu_mce_mmc_cxt + 1 );
       
  1399 #else
       
  1400         AknsUtils::CreateIconL( skins, KAknsIIDQgnMenuMceMmcCxt, bitmap,
       
  1401            bitmapMask, iFilename, EMbmMuiuQgn_menu_mce_mmc,
       
  1402            EMbmMuiuQgn_menu_mce_mmc + 1 );
       
  1403 #endif
       
  1404         }
       
  1405     else
       
  1406         {
       
  1407 #ifndef __SCALABLE_ICONS
       
  1408         AknsUtils::CreateIconL( skins, KAknsIIDQgnMenuMceCxt, bitmap,
       
  1409            bitmapMask, iFilename, EMbmMuiuQgn_menu_mce_cxt,
       
  1410            EMbmMuiuQgn_menu_mce_cxt + 1 );
       
  1411 #else
       
  1412         AknsUtils::CreateAppIconLC( skins, KMceApplicationUid, 
       
  1413             EAknsAppIconTypeContext, bitmap, bitmapMask );
       
  1414         CleanupStack::Pop( 2 ); // Both bitmaps are left in the cleanup stack
       
  1415 #endif
       
  1416         }
       
  1417     contextPane->SetPicture( bitmap, bitmapMask );
       
  1418     }
       
  1419 
       
  1420 // ----------------------------------------------------
       
  1421 // CMceUi::ResourceChangeCalled
       
  1422 // ----------------------------------------------------
       
  1423 TBool CMceUi::ResourceChangeCalled()
       
  1424     {
       
  1425     return iResourceChangeCalled;
       
  1426     }
       
  1427 
       
  1428 // ----------------------------------------------------
       
  1429 // CMceUi::ResetResourceChange
       
  1430 // ----------------------------------------------------
       
  1431 void CMceUi::ResetResourceChange()
       
  1432     {
       
  1433     iResourceChangeCalled = EFalse;
       
  1434     }
       
  1435 
       
  1436 // ----------------------------------------------------
       
  1437 // CMceUi::CheckTechnologyTypeFromMtm
       
  1438 // ----------------------------------------------------
       
  1439 TBool CMceUi::CheckTechnologyTypeFromMtm( const TUid aTechnologyType, TUid aMtmType )
       
  1440     {
       
  1441     TBool isMailMtm = EFalse;
       
  1442     if ( aMtmType.iUid != 0 && aMtmType != KUidMsvLocalServiceMtm &&
       
  1443          iUiRegistry->IsPresent( aMtmType ) )
       
  1444     {
       
  1445     // get MTM technology type
       
  1446     TUid technologyType = iUiRegistry->TechnologyTypeUid( aMtmType );
       
  1447         isMailMtm = ( aTechnologyType == technologyType );
       
  1448         }
       
  1449     return isMailMtm;
       
  1450     }
       
  1451 
       
  1452 
       
  1453 
       
  1454 
       
  1455 
       
  1456 // ----------------------------------------------------
       
  1457 // CMceUi::HandleMTMChangeL
       
  1458 // ----------------------------------------------------
       
  1459 void CMceUi::HandleMTMChangeL()
       
  1460     {
       
  1461     MCELOGGER_ENTERFN("HandleMTMChangeL()");
       
  1462     if( !iMtmLoader )
       
  1463         {
       
  1464         iMtmLoader = new(ELeave) CMceIdleMtmLoader(
       
  1465             *iMtmStore,
       
  1466             iMsgTypesWritePopup,
       
  1467             iMsgTypesWriteSubmenu,
       
  1468             iMsgTypesSettings,
       
  1469             *iMTMFunctionsArray,
       
  1470             *iUiRegistry );
       
  1471         }
       
  1472     else
       
  1473         {
       
  1474         iMtmLoader->Cancel();
       
  1475         }
       
  1476 
       
  1477     iMtmLoader->StartL(*iSession, iAudioMsgEnabled, iPostcardEnabled); // CR : 401-1806
       
  1478     MCELOGGER_LEAVEFN("HandleMTMChangeL()");
       
  1479     }
       
  1480 
       
  1481 // ----------------------------------------------------
       
  1482 // CMceUi::GetMtmUiDataL
       
  1483 // will return NULL if no uiData found for entryType
       
  1484 // ----------------------------------------------------
       
  1485 CBaseMtmUiData* CMceUi::GetMtmUiDataL(TUid aMtm)
       
  1486     {
       
  1487     MCELOGGER_ENTERFN("GetMtmUiDataL()");
       
  1488     MCELOGGER_WRITE_FORMAT("GetMtmUiDataL: mtm = 0x%x", aMtm.iUid );
       
  1489 
       
  1490     CBaseMtmUiData* uiData=NULL;
       
  1491     if (iMtmStore)
       
  1492         {
       
  1493         TRAPD(error, ( uiData=&(iMtmStore->MtmUiDataL(aMtm)) ) );
       
  1494         MCELOGGER_WRITE_FORMAT("GetMtmUiDataL: error = %d", error );
       
  1495         if ( iMceUiFlags.MceFlag( EMceUiFlagsServerReady )  && error != KErrNotFound )
       
  1496             {
       
  1497             // KErrNotFound cover case where MTM is not installed but messages exist
       
  1498             User::LeaveIfError( error );
       
  1499             }
       
  1500         }
       
  1501     MCELOGGER_LEAVEFN("GetMtmUiDataL()");
       
  1502     return uiData;
       
  1503     }
       
  1504 
       
  1505 // ----------------------------------------------------
       
  1506 // CMceUi::CanCreateNewAccountL
       
  1507 // ----------------------------------------------------
       
  1508 TBool CMceUi::CanCreateNewAccountL(TUid aMtm)
       
  1509     {
       
  1510     TBool canCreateNewAccount = EFalse;
       
  1511     TMsvEntry serviceEntry;
       
  1512     serviceEntry.iType=KUidMsvServiceEntry;
       
  1513     serviceEntry.iMtm=aMtm;
       
  1514 
       
  1515     TInt rid;
       
  1516     CBaseMtmUiData* uiData=GetMtmUiDataL(aMtm);
       
  1517     if ( uiData && uiData->CanCreateEntryL( iRootEntry->Entry(), serviceEntry, rid ) )
       
  1518         {
       
  1519         canCreateNewAccount = ETrue;
       
  1520         }
       
  1521     return canCreateNewAccount;
       
  1522     }
       
  1523 
       
  1524 // ----------------------------------------------------
       
  1525 // CMceUi::DeleteAccountL
       
  1526 // ----------------------------------------------------
       
  1527 void CMceUi::DeleteAccountL(TMsvId aId)
       
  1528     {
       
  1529     TMsvEntry   entry;
       
  1530     GetEntryL( aId, entry );
       
  1531     const TUid mtm = entry.iMtm;
       
  1532     CBaseMtmUi* ui = &iMtmStore->ClaimMtmUiL( mtm );
       
  1533     if (ui)
       
  1534         {
       
  1535         CMtmStoreMtmReleaser::CleanupReleaseMtmUiLC(*iMtmStore, mtm);
       
  1536         }
       
  1537 
       
  1538     CMsvOperation* op = NULL;
       
  1539     __ASSERT_DEBUG( !iDeleteOperation,
       
  1540         Panic( EMceUiErrAlreadyDeletingAccount ) );
       
  1541 
       
  1542 // Free disk space request for delete to be added
       
  1543 
       
  1544     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  1545     CleanupStack::PushL( singleOpWatcher );
       
  1546 
       
  1547     if (ui)
       
  1548         {
       
  1549         ui->BaseMtm().SetCurrentEntryL(iSession->GetEntryL(KMsvRootIndexEntryId));
       
  1550         CAknInputBlock::NewLC();
       
  1551         op=ui->DeleteServiceL(entry, singleOpWatcher->iStatus);
       
  1552         CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  1553         CleanupStack::PushL(op);
       
  1554         }
       
  1555     else
       
  1556         {
       
  1557         // could not load mtm, so delete as normal local entry
       
  1558         iEntry->SetEntryL( KMsvRootIndexEntryId );
       
  1559 
       
  1560         CMsvProgressReporterOperation* progOp =
       
  1561             CMsvProgressReporterOperation::NewL(
       
  1562             *iSession, singleOpWatcher->iStatus, EMbmAvkonQgn_note_erased);
       
  1563         CleanupStack::PushL( progOp );
       
  1564 
       
  1565         CMsvEntrySelection* selection = new( ELeave ) CMsvEntrySelection();
       
  1566         CleanupStack::PushL( selection );
       
  1567         selection->AppendL( entry.Id() );
       
  1568         CMsvOperation* subOp = iEntry->DeleteL( *selection, progOp->RequestStatus());
       
  1569         CleanupStack::PopAndDestroy( selection );
       
  1570         progOp->SetOperationL( subOp ); // this takes ownership immediately, so no cleanupstack needed.
       
  1571         op = progOp;
       
  1572         }
       
  1573 
       
  1574     iOperations.AppendL( singleOpWatcher );
       
  1575     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  1576     singleOpWatcher->SetOperation( op );
       
  1577     iDeleteOperation = singleOpWatcher;
       
  1578     iMailboxDeleteOperation = op->Id();
       
  1579     MCELOGGER_WRITE_FORMAT("free disk requested, iDeleteOperation set 0x%x", iDeleteOperation );
       
  1580     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  1581 
       
  1582 // Cancel the free disk space request to be added
       
  1583 
       
  1584     if ( ui )
       
  1585         {
       
  1586         CleanupStack::PopAndDestroy();// release mtmUi
       
  1587         }
       
  1588 
       
  1589     }
       
  1590 
       
  1591 // ----------------------------------------------------
       
  1592 // CMceUi::SettingsDialogL
       
  1593 // ----------------------------------------------------
       
  1594 void CMceUi::SettingsDialogL()
       
  1595     {
       
  1596     CMceUidNameArray* tempArray = CMceUidNameArray::NewL();
       
  1597 
       
  1598     if (( iSelectableEmail )&& (!iEmailFramework))
       
  1599         {
       
  1600         CleanupStack::PushL( tempArray );
       
  1601         const TInt count = iMsgTypesSettings.Count();
       
  1602 
       
  1603         // get all email accounts (visible)
       
  1604         CArrayFix<TUid>* listItemUids =
       
  1605             new ( ELeave ) CArrayFixFlat<TUid>( KMceArrayGranularity );
       
  1606         CleanupStack::PushL(listItemUids);
       
  1607         CMsvEntry* entry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
  1608         CleanupStack::PushL( entry );
       
  1609 
       
  1610         TInt canCreateNew;   
       
  1611 
       
  1612         TInt cnt = entry->Count();
       
  1613         if ( cnt != 0 )
       
  1614             {
       
  1615             entry->SetSortTypeL( TMsvSelectionOrdering(
       
  1616                 KMsvGroupByType | KMsvGroupByStandardFolders, EMsvSortByDetailsReverse, ETrue ) );
       
  1617 
       
  1618             // Add default item first
       
  1619             for ( TInt cc = entry->Count(); --cc >= 0; )
       
  1620                 {
       
  1621                 TMsvEntry tentry = (*entry)[cc];                
       
  1622 
       
  1623                 if ( tentry.iType.iUid == KUidMsvServiceEntryValue &&
       
  1624                      tentry.Id() != KMsvLocalServiceIndexEntryIdValue )
       
  1625                     {
       
  1626                     const TBool noRelatedId = tentry.iRelatedId == KMsvNullIndexEntryId || tentry.iRelatedId == tentry.Id();
       
  1627 
       
  1628                     TBool appendEmail = EFalse;
       
  1629 
       
  1630                     if( tentry.Visible() )
       
  1631                         {
       
  1632                         appendEmail = ETrue;
       
  1633                         }
       
  1634                     else
       
  1635                         {
       
  1636                         CMtmUiDataRegistry* uiRegistry = CMtmUiDataRegistry::NewL( *iSession );                
       
  1637                         CleanupStack::PushL(uiRegistry);
       
  1638                         if ( uiRegistry->IsPresent( tentry.iMtm ) &&
       
  1639                              uiRegistry->IsPresent( KUidMsgTypePOP3 ) )
       
  1640                             {            
       
  1641                             TUid mailMTMTechType = uiRegistry->TechnologyTypeUid( KUidMsgTypePOP3 );                                          
       
  1642                             if( uiRegistry->TechnologyTypeUid( tentry.iMtm ) ==
       
  1643                                 mailMTMTechType )
       
  1644                                 {
       
  1645                                 appendEmail = ETrue;                    
       
  1646                                 }
       
  1647                             }
       
  1648                             CleanupStack::PopAndDestroy( uiRegistry );
       
  1649                         } 
       
  1650 
       
  1651                     if ( appendEmail )
       
  1652                         {                         
       
  1653                         TBool append = ETrue; 
       
  1654                         // query capability (new message)
       
  1655                         TUid entryUid;
       
  1656 
       
  1657                         if ( tentry.iMtm == KSenduiMtmPop3Uid ||
       
  1658                              tentry.iMtm == KSenduiMtmImap4Uid)
       
  1659                             {                        
       
  1660                             entryUid = KSenduiMtmSmtpUid;
       
  1661                             }
       
  1662                         else
       
  1663                             {
       
  1664                             entryUid = tentry.iMtm;     
       
  1665                             }
       
  1666 
       
  1667                         CBaseMtmUiData* mtmUiData = NULL;
       
  1668 
       
  1669                         TRAPD( returnVal, mtmUiData =
       
  1670                                &( iMtmStore->MtmUiDataL( entryUid ) ) );
       
  1671 
       
  1672                         if ( returnVal == KErrNone)
       
  1673                             {
       
  1674                             TInt ret = mtmUiData->QueryCapability( KUidMtmQueryCanSendMsg, canCreateNew );                                   
       
  1675 
       
  1676                             if ( ret == KErrNone ) 
       
  1677                                 {
       
  1678                                 append = ETrue;
       
  1679                                 }
       
  1680                             else
       
  1681                                 {
       
  1682                                 append = EFalse;    
       
  1683                                 }                
       
  1684                             }
       
  1685                         else
       
  1686                             {
       
  1687                             append = EFalse;                                
       
  1688                             }                            
       
  1689 
       
  1690                         iMtmStore->ReleaseMtmUiData( entryUid );                  
       
  1691 
       
  1692                         if( append )
       
  1693                             {                     
       
  1694                             listItemUids->AppendL( entryUid );
       
  1695                             }
       
  1696                         }
       
  1697                     }
       
  1698                 }
       
  1699             }
       
  1700         TBool emailIncluded = EFalse;        
       
  1701         TBool syncMLIncluded = EFalse;        
       
  1702         TUid uidMsgValTypeEmailMtmVal = GetFsIntegratedEmailAppMtmPluginId(); 
       
  1703         CDesCArrayFlat* items = new(ELeave)CDesCArrayFlat( KMceArrayGranularity );
       
  1704         CleanupStack::PushL( items );
       
  1705         for ( TInt loop = 0; loop < count ; loop++)
       
  1706             {
       
  1707             if ( FindMtmInVisibleListL( iMsgTypesSettings[loop].iUid, *listItemUids ) )
       
  1708                 {
       
  1709                 if ( !emailIncluded &&
       
  1710                     ( iMsgTypesSettings[loop].iUid == KSenduiMtmSmtpUid ) ) 
       
  1711                     {
       
  1712                     tempArray->AppendL( iMsgTypesSettings[loop] );
       
  1713                     emailIncluded = ETrue;
       
  1714                     }                
       
  1715                 // Following is added because SyncML was missing from the list
       
  1716                 else if ( !syncMLIncluded &&
       
  1717                           ( iMsgTypesSettings[loop].iUid == KSenduiMtmSyncMLEmailUid ) )
       
  1718                     {
       
  1719                     tempArray->AppendL( iMsgTypesSettings[loop] );
       
  1720                     syncMLIncluded = ETrue;					
       
  1721                     }
       
  1722 	        else if(iMsgTypesSettings[loop].iUid!=uidMsgValTypeEmailMtmVal)
       
  1723                     {
       
  1724                     tempArray->AppendL( iMsgTypesSettings[loop] );
       
  1725                     }
       
  1726                 }
       
  1727             else
       
  1728                 {
       
  1729                 tempArray->AppendL( iMsgTypesSettings[loop] );    
       
  1730                 }        
       
  1731             }
       
  1732             CleanupStack::PopAndDestroy( items ); 
       
  1733             CleanupStack::PopAndDestroy( entry );
       
  1734             CleanupStack::PopAndDestroy( listItemUids );
       
  1735         }
       
  1736     else if(iEmailFramework)  //Freestyle Feature is disabled and CMail Feature is enabled 
       
  1737         {
       
  1738         MCELOGGER_WRITE("CMceUi::SettingsDialogL: cmail ");
       
  1739         CleanupStack::PushL( tempArray );
       
  1740         const TInt count = iMsgTypesSettings.Count();
       
  1741         for (TInt loop=0; loop < count; loop++)
       
  1742             {
       
  1743             if ( (iMsgTypesSettings[loop].iUid == KSenduiMtmSmtpUid ) ||
       
  1744                     ( iMsgTypesSettings[loop].iUid == KSenduiMtmSyncMLEmailUid )||
       
  1745                     (iMsgTypesSettings[loop].iUid == KUidMsgTypeFsMtmVal))
       
  1746                 {
       
  1747                 MCELOGGER_WRITE_FORMAT("not Loading %x", iMsgTypesSettings[loop].iUid );
       
  1748                 continue;
       
  1749                 }
       
  1750             else
       
  1751                 {
       
  1752                 MCELOGGER_WRITE_FORMAT(" Loading %x", iMsgTypesSettings[loop].iUid);
       
  1753                 tempArray->AppendL( iMsgTypesSettings[loop] );
       
  1754                 }
       
  1755             }
       
  1756         }
       
  1757     
       
  1758     else    //Freestyle Feature is disabled and CMail Feature is disabled 
       
  1759             
       
  1760        {
       
  1761 
       
  1762     CleanupStack::PushL( tempArray );
       
  1763     const TInt count = iMsgTypesSettings.Count();
       
  1764     for (TInt loop=0; loop < count; loop++)
       
  1765         {
       
  1766         tempArray->AppendL( iMsgTypesSettings[loop] );
       
  1767         }
       
  1768 		}
       
  1769 
       
  1770     TUid uid;
       
  1771     uid.iUid = KMceAnswerToLifeUniverseAndEverything;
       
  1772     // this is not used anywhere, two last items in the list are
       
  1773     // ALWAYS cbs settings and mce general settings
       
  1774 
       
  1775     // Run time Cell Broadcast variant.
       
  1776     TBool cbs = EFalse;
       
  1777     if ( FeatureManager::FeatureSupported( KFeatureIdCellBroadcast ) )
       
  1778         {
       
  1779         cbs = ETrue;
       
  1780         if ( iCsp )
       
  1781             {
       
  1782             cbs = CheckCspBitL();
       
  1783             }
       
  1784         }
       
  1785     if ( cbs )
       
  1786         {
       
  1787         HBufC* text = StringLoader::LoadL( R_MCE_CBS_SETTINGS_TEXT, iEikonEnv );
       
  1788         TUidNameInfo cbsSettings( uid, *text );
       
  1789         delete text;
       
  1790         tempArray->AppendL( cbsSettings );
       
  1791         }
       
  1792 
       
  1793     HBufC* text = StringLoader::LoadL( R_MCE_GENERAL_SETTINGS_TEXT, iEikonEnv );
       
  1794     TUidNameInfo generalSettings( uid, *text );
       
  1795     delete text;
       
  1796     tempArray->AppendL( generalSettings );
       
  1797 
       
  1798     // This is changed to automatic because local zoom should change only listbox zoom value
       
  1799     // so settings dialog zoom value should come from general settings and so we need to change
       
  1800     // local zoom to automatic before launching settings dialog
       
  1801     // Is settings opened from General Settings
       
  1802     CMuiuLock* repositoryLock = CMuiuLock::NewL( KMuiuLockSettings );
       
  1803     CleanupStack::PushL(repositoryLock);
       
  1804     TInt err = repositoryLock->Reserve();
       
  1805 
       
  1806     // Check that settings are not opened from General Settings
       
  1807     if ( !err )
       
  1808         {
       
  1809         TAknUiZoom previous = ZoomLevelChangedL( EAknUiZoomAutomatic );
       
  1810         iMceUiFlags.SetMceFlag( EMceUiFlagsSettingsDialogOpen );
       
  1811         CMceSettingsDialog* dlg = CMceSettingsDialog::NewL( *tempArray, this, iSession);
       
  1812         dlg->ExecuteLD();
       
  1813         iMceUiFlags.ClearMceFlag( EMceUiFlagsSettingsDialogOpen );
       
  1814         ZoomLevelChangedL( previous );
       
  1815         }
       
  1816     else
       
  1817         {
       
  1818         // Show information note: General Settings has opened settings
       
  1819         CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(
       
  1820             CAknNoteDialog::ENoTone, CAknNoteDialog::ELongTimeout);
       
  1821         dlg->ExecuteLD(R_MCE_NOTE_SETTINGS_OPEN_GS);
       
  1822 
       
  1823         }
       
  1824     // Release repository
       
  1825     repositoryLock->Release();
       
  1826     CleanupStack::PopAndDestroy( 2 ); // tempArray, repositoryLock
       
  1827 
       
  1828     }
       
  1829 
       
  1830 // ----------------------------------------------------
       
  1831 // CMceUi::CreateNewMessageL
       
  1832 // Create a new message of the given type, in the given location
       
  1833 // ----------------------------------------------------
       
  1834 void CMceUi::CreateNewMessageL(TInt aMessageType)
       
  1835     {
       
  1836     __ASSERT_DEBUG( aMessageType != KUidMsvLocalServiceMtmValue,
       
  1837         Panic( EMceUiErrLocalMtm ) );
       
  1838     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  1839     TUid messageTypeOrig;
       
  1840     messageTypeOrig.iUid = aMessageType;
       
  1841     TUid msgTypeUid; 
       
  1842     msgTypeUid.iUid = 0;
       
  1843 
       
  1844     TBool tabsToCleanupStack = EFalse;
       
  1845     TMsvId service = KMsvNullIndexEntryId;
       
  1846     if ( MceViewActive( EMceMessageViewActive ) && iMceListView )
       
  1847         {
       
  1848         const TMsvEntry& entry = iMceListView->ListContainer()->FolderEntry();
       
  1849         //cmail change
       
  1850         if ( (iSelectableEmail) && (!iEmailFramework ))
       
  1851             {
       
  1852             if ( entry.iMtm == KSenduiMtmImap4Uid ||
       
  1853                 entry.iMtm == KSenduiMtmPop3Uid )
       
  1854             {
       
  1855             service = entry.iServiceId;
       
  1856             }
       
  1857             }
       
  1858         else
       
  1859             {
       
  1860 	        if ( aMessageType == entry.iMtm.iUid ||
       
  1861 	            ( aMessageType == KSenduiMtmSmtpUidValue
       
  1862 	               && (entry.iMtm == KSenduiMtmImap4Uid
       
  1863 	               || entry.iMtm == KSenduiMtmPop3Uid ) ) )
       
  1864             {
       
  1865             service = entry.iServiceId;
       
  1866             }
       
  1867         }
       
  1868         }
       
  1869 
       
  1870 
       
  1871     if ( service == KMsvNullIndexEntryId )
       
  1872         {
       
  1873         //cmail change
       
  1874         if ( (iSelectableEmail) && (!iEmailFramework ) )
       
  1875             {
       
  1876             if ( GetDefaultServiceL( aMessageType, service, msgTypeUid )
       
  1877         	     == EFalse )        
       
  1878                 {
       
  1879                 return;
       
  1880                 }
       
  1881             }
       
  1882         else
       
  1883             {
       
  1884         GetDefaultServiceL( aMessageType, service );
       
  1885         }
       
  1886         }    
       
  1887 
       
  1888     if ( ((iSelectableEmail) && (!iEmailFramework ))&& ( messageTypeOrig == KSenduiMtmSmtpUid ) )
       
  1889         {	
       
  1890         if( ( msgTypeUid == KSenduiMtmSmtpUid) ||
       
  1891             ( msgTypeUid.iUid == KMsvNullIndexEntryId ) )
       
  1892             {
       
  1893     msgTypeUid.iUid = aMessageType;
       
  1894             }        
       
  1895         }
       
  1896     else
       
  1897         {
       
  1898         msgTypeUid.iUid = aMessageType;            
       
  1899         } 
       
  1900 
       
  1901     if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ) )
       
  1902         {
       
  1903         // must remove tabs because if no mailboxes created then
       
  1904         // mailbox settings dialog is displayed and tabs should not be shown then.
       
  1905         RemoveTabs();
       
  1906         CleanupStack::PushL( TCleanupItem( ShowTabs, this ) );
       
  1907         tabsToCleanupStack = ETrue;
       
  1908         }
       
  1909 
       
  1910     CreateAndEditNewEntryL(
       
  1911         KUidMsvMessageEntryValue,
       
  1912         msgTypeUid,
       
  1913         KMsvDraftEntryId,
       
  1914         service );
       
  1915 
       
  1916     if ( tabsToCleanupStack )
       
  1917         {
       
  1918         CleanupStack::PopAndDestroy(); // TCleanupItem - will show tabs again
       
  1919         }
       
  1920 
       
  1921         // NCN reset does not requied for new email creation
       
  1922     
       
  1923 
       
  1924     }
       
  1925 
       
  1926 // ----------------------------------------------------
       
  1927 // CMceUi::ShowTabs
       
  1928 // Static function.
       
  1929 // Used in CreateNewMessageL as TCleanupItem.
       
  1930 // ----------------------------------------------------
       
  1931 void CMceUi::ShowTabs(TAny* aAny)
       
  1932     {
       
  1933     CMceUi* mceUi = (CMceUi*) aAny;
       
  1934     if ( mceUi && mceUi->MceViewActive( EMceMessageViewActive ) && mceUi->iMceListView )
       
  1935         {
       
  1936         TRAP_IGNORE( mceUi->ShowTabsL( mceUi->iMceListView->ListContainer()->CurrentFolderId() ) );
       
  1937         }
       
  1938     }
       
  1939 
       
  1940 // ----------------------------------------------------
       
  1941 // CMceUi::ResetEditorOperation
       
  1942 // Static function.
       
  1943 // Used in CreateNewMessageL as TCleanupItem.
       
  1944 // ----------------------------------------------------
       
  1945 void CMceUi::ResetEditorOperation(TAny* aAny)
       
  1946     {
       
  1947     CMceUi* mceUi = (CMceUi*) aAny;
       
  1948     MCELOGGER_WRITE_FORMAT("ResetEditorOperation iEditorOperation 0x%x set NULL", mceUi->iEditorOperation );
       
  1949     mceUi->iEditorOperation = NULL;
       
  1950     }
       
  1951 
       
  1952 // ----------------------------------------------------
       
  1953 // CMceUi::CreateAndEditNewEntryL
       
  1954 // ----------------------------------------------------
       
  1955 void CMceUi::CreateAndEditNewEntryL(TMsvId aParentId, TMsvEntry& aNewEntry)
       
  1956     {
       
  1957     MCELOGGER_ENTERFN("CreateAndEditNewEntryL()");
       
  1958 
       
  1959     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  1960 
       
  1961     __ASSERT_DEBUG(aNewEntry.iMtm != KUidMsvLocalServiceMtm,
       
  1962         Panic( EMceUiErrLocalMtm ) );
       
  1963 
       
  1964     aNewEntry.iDate.HomeTime();
       
  1965 
       
  1966     // --- Get the MTM UI relevant to the message type ---
       
  1967     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( aNewEntry.iMtm );
       
  1968     CMsvEntry* centry = iSession->GetEntryL( aParentId );
       
  1969     // this allocates memory so cleanupstack is needed
       
  1970     CleanupStack::PushL( centry );
       
  1971     CAknInputBlock::NewLC();
       
  1972 
       
  1973     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL(*this);
       
  1974     CleanupStack::PushL( singleOpWatcher );
       
  1975 
       
  1976     CleanupStack::PushL( TCleanupItem( ResetEditorOperation, this ) );
       
  1977 
       
  1978     mtmUi.SetPreferences( mtmUi.Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  1979     
       
  1980     CMsvOperation* op = mtmUi.CreateL(
       
  1981         aNewEntry,
       
  1982         *centry,
       
  1983         singleOpWatcher->iStatus );
       
  1984 
       
  1985     MCELOGGER_WRITE_FORMAT("CreateAndEditNewEntryL: iEditorOperation set 0x%x", singleOpWatcher );
       
  1986     iEditorOperation = singleOpWatcher;
       
  1987 
       
  1988     CleanupStack::PushL( op );
       
  1989     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  1990     iOperations.AppendL( singleOpWatcher );
       
  1991     CleanupStack::Pop( op ); // singleOpWatcher, op
       
  1992     CleanupStack::Pop(); // ResetEditorOperation everything ok, don't reset iEditorOperation
       
  1993     CleanupStack::Pop( singleOpWatcher );
       
  1994 
       
  1995     singleOpWatcher->SetOperation( op );
       
  1996 
       
  1997     if ( aNewEntry.iType == KUidMsvMessageEntry &&
       
  1998         iUiRegistry &&
       
  1999         iUiRegistry->IsPresent( op->Mtm() ) )
       
  2000         {
       
  2001         iMtmStore->ClaimMtmUiL( op->Mtm() );            
       
  2002         }
       
  2003 
       
  2004     CleanupStack::PopAndDestroy(3); // CAknInputBlock, centry, release MtmUi
       
  2005 
       
  2006     if ( MceViewActive( EMceMessageViewActive ) )
       
  2007         {
       
  2008         iMceListView->ListContainer()->ClearSelection();
       
  2009         }
       
  2010 
       
  2011     MCELOGGER_LEAVEFN("CreateAndEditNewEntryL()");
       
  2012     }
       
  2013 
       
  2014 // ----------------------------------------------------
       
  2015 // CMceUi::CreateAndEditNewEntryL
       
  2016 // ----------------------------------------------------
       
  2017 void CMceUi::CreateAndEditNewEntryL(
       
  2018     TInt aEntryType,
       
  2019     TUid aMtm,
       
  2020     TMsvId aParentId,
       
  2021     TMsvId aServiceId )
       
  2022     {
       
  2023     __ASSERT_DEBUG(aMtm != KUidMsvLocalServiceMtm,
       
  2024         Panic( EMceUiErrLocalMtm ) );
       
  2025     TMsvEntry nentry;
       
  2026     nentry.iMtm = aMtm;
       
  2027     nentry.iType.iUid = aEntryType;
       
  2028     nentry.iDate.HomeTime();
       
  2029     nentry.iServiceId = aServiceId;
       
  2030     CreateAndEditNewEntryL( aParentId, nentry );
       
  2031     }
       
  2032 
       
  2033 // ----------------------------------------------------
       
  2034 // CMceUi::GetDefaultServiceL
       
  2035 // when MceIntegration runtime flag is on
       
  2036 // ----------------------------------------------------
       
  2037 TBool CMceUi::GetDefaultServiceL( TInt aMtm, TMsvId& aService, TUid& aMtmUid )
       
  2038     {
       
  2039     TBool retVal = ETrue;
       
  2040     TUid mtm = { aMtm };       
       
  2041 
       
  2042     aService = MsvUiServiceUtilities::DefaultServiceForMTML( *iSession,
       
  2043                                                              mtm,
       
  2044                                                              ETrue );
       
  2045 
       
  2046     if ( mtm == KSenduiMtmImap4Uid || mtm == KSenduiMtmPop3Uid
       
  2047             || mtm == KSenduiMtmSmtpUid )
       
  2048         {
       
  2049         retVal = CMceSettingsEmailSel::ShowSelectEmailDlgL( aService,  aMtmUid );
       
  2050         }
       
  2051 
       
  2052     return retVal;
       
  2053     }
       
  2054 
       
  2055 // ----------------------------------------------------
       
  2056 // CMceUi::GetDefaultServiceL
       
  2057 // ----------------------------------------------------
       
  2058 void CMceUi::GetDefaultServiceL(TInt aMtm, TMsvId& aService)
       
  2059     {
       
  2060     TUid mtm = { aMtm };
       
  2061 
       
  2062     aService = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
  2063         *iSession,
       
  2064         mtm,
       
  2065         ETrue );
       
  2066     }
       
  2067 
       
  2068 // ----------------------------------------------------
       
  2069 // CMceUi::OpCompleted
       
  2070 // ----------------------------------------------------
       
  2071 void CMceUi::OpCompleted(
       
  2072     CMsvSingleOpWatcher& aOpWatcher,
       
  2073     TInt aCompletionCode )
       
  2074     {
       
  2075     MCELOGGER_ENTERFN("OpCompleted()");
       
  2076     CMsvOperation* op=&aOpWatcher.Operation();
       
  2077     MCELOGGER_WRITE_FORMAT("operation id=%d completed", op->Id() );
       
  2078 
       
  2079     // Store the command ID
       
  2080     TMsvOp tempOpID = op->Id();
       
  2081     TUid tempOpMtm = op->Mtm();
       
  2082     
       
  2083     if ( &aOpWatcher == iEditorOperation )
       
  2084         {
       
  2085         MCELOGGER_WRITE_FORMAT("iEditorOperation 0x%x set NULL", iEditorOperation );
       
  2086         iEditorOperation = NULL;
       
  2087         if ( iMtmStore && //tempOpMtm != KUidMsvLocalServiceMtm && tempOpMtm != KUidMsvNullEntry &&
       
  2088             iUiRegistry &&
       
  2089             iUiRegistry->IsPresent( tempOpMtm ) )
       
  2090             {
       
  2091             iMtmStore->ReleaseMtmUi( tempOpMtm );                
       
  2092             }
       
  2093         }
       
  2094     
       
  2095 #ifdef _DEBUG
       
  2096     TRAPD(ignore, DoOperationCompletedL(op, aCompletionCode));
       
  2097     MCELOGGER_WRITE_FORMAT("DoOperationCompletedL ignore %d", ignore );
       
  2098 #else
       
  2099     TRAP_IGNORE(DoOperationCompletedL(op, aCompletionCode));
       
  2100 #endif
       
  2101 
       
  2102     ClearDontExitOnNextOperationComplete();
       
  2103     
       
  2104     TBool foundItem = EFalse;
       
  2105     for (TInt cc = iOperations.Count()-1; cc >= 0 && !foundItem; cc--)
       
  2106         {
       
  2107         if (iOperations[cc]->Operation().Id()==op->Id())
       
  2108             {
       
  2109             delete iOperations[cc];
       
  2110             iOperations.Delete(cc);
       
  2111             foundItem = ETrue;
       
  2112             }
       
  2113         }
       
  2114 
       
  2115     if ( &aOpWatcher == iDeleteOperation )
       
  2116         {
       
  2117         MCELOGGER_WRITE_FORMAT("iDeleteOperation 0x%x set NULL", iDeleteOperation );
       
  2118         iDeleteOperation = NULL;
       
  2119 
       
  2120         if ( iMMSNotifications && iMMSNotifications->Count() > 0 )
       
  2121             {
       
  2122             //delete MMS notifications
       
  2123             TBuf8<1> params;
       
  2124             params.Append( KMceMMSNotifOne8 );
       
  2125             TRAPD( error, HandleMMSNotificationsDeleteL( params ) );
       
  2126             if ( error )
       
  2127                 {
       
  2128                 if ( !iMceErrorUi )
       
  2129                     {
       
  2130                     TRAP_IGNORE( iMceErrorUi = CErrorUI::NewL(*iCoeEnv) );
       
  2131                     }
       
  2132                 if ( iMceErrorUi )
       
  2133                     {
       
  2134                     TRAP_IGNORE( iMceErrorUi->ShowGlobalErrorNoteL( error ) );
       
  2135                     }
       
  2136                 // ignore
       
  2137                 }
       
  2138             }
       
  2139 
       
  2140 // Cancel free disk space request to be added
       
  2141 
       
  2142         }
       
  2143 
       
  2144     else if ( iMMSNotifications
       
  2145         && ( tempOpMtm == KUidMsgMMSNotification ) )
       
  2146         {
       
  2147         // check if MMS notification delete failed
       
  2148         TRAP_IGNORE( CheckMMSNotifDelFailedL() );
       
  2149         }
       
  2150     else
       
  2151         {
       
  2152         //nothing special done
       
  2153         }
       
  2154 
       
  2155 
       
  2156     if ( &aOpWatcher == iFetchNewOperation )
       
  2157         {        
       
  2158         iFetchNewOperation = NULL;
       
  2159     // TODO
       
  2160         if ( ( iMceListView->ListContainer()->Count() )
       
  2161             && MceViewActive( EMceMessageViewActive ) )
       
  2162             {        
       
  2163 //            iMceListView->ListContainer()->ListBox()->SetCurrentItemIndex( 0 );
       
  2164 //            iMceListView->ListContainer()->ListBox()->DrawDeferred();
       
  2165             }
       
  2166         }
       
  2167 
       
  2168 // Email messages cannot be copied or moved, show the note
       
  2169     if ( ( iMoveOrCopyMailOperation != -1 ) && ( iMoveOrCopyMailOperation == tempOpID ) )
       
  2170         {
       
  2171         TRAP_IGNORE( InformationNoteCannotMoveCopyEMailL() );
       
  2172         }
       
  2173 
       
  2174     if ( iHandleNewMsgToInbox )
       
  2175         {
       
  2176         TRAP_IGNORE( HandleNewMsgToInboxL( EFalse, NULL ) );
       
  2177         }
       
  2178 
       
  2179     __ASSERT_DEBUG( foundItem, Panic( EMceUiErrOperationNotFound ) );
       
  2180     MCELOGGER_LEAVEFN("OpCompleted()");
       
  2181     }
       
  2182 
       
  2183 // ----------------------------------------------------
       
  2184 // CMceUi::DoOperationCompletedL
       
  2185 // ----------------------------------------------------
       
  2186 void CMceUi::DoOperationCompletedL(
       
  2187     CMsvOperation* aOperation,
       
  2188     TInt aCompletionCode )
       
  2189     {
       
  2190     __ASSERT_DEBUG( aOperation, Panic( EMceUiErrOperationNull ) );
       
  2191     if ( !aOperation )
       
  2192         {
       
  2193         return;
       
  2194         }
       
  2195 
       
  2196     if ( iLocalScreenClearer && 
       
  2197          aCompletionCode != CMsgEmbeddedEditorWatchingOperation::EMsgExitNext &&
       
  2198          aCompletionCode != CMsgEmbeddedEditorWatchingOperation::EMsgExitPrevious )
       
  2199         {
       
  2200         
       
  2201         delete iLocalScreenClearer;
       
  2202         iLocalScreenClearer = NULL;
       
  2203         
       
  2204         }
       
  2205 
       
  2206     MCELOGGER_WRITE_FORMAT("CMceUi::DoOperationCompletedL: aCompletionCode: %d", aCompletionCode );
       
  2207     
       
  2208     if ( aOperation->Id() == iMailboxDeleteOperation )
       
  2209         {
       
  2210         CMceMainViewListItemArray* array = iMceMainView->ListContainer()->ListItems();
       
  2211         if ( array )
       
  2212             {
       
  2213             array->HandleSessionEventL(EMsvEntriesDeleted, NULL, NULL, NULL );
       
  2214             }
       
  2215         }
       
  2216 
       
  2217     if ( ViewUpdateSuppressionFlag() && iBlockingOperation == aOperation )
       
  2218         {
       
  2219         SetViewUpdateSuppressionFlag( EFalse, NULL );
       
  2220         iMceListView->UpdateViewL();
       
  2221         }
       
  2222 
       
  2223     TInt closedEntryId = 0;
       
  2224     // Retrieve value of KMuiuKeyCurrentMsg
       
  2225     TInt r = RProperty::Get( KPSUidMuiu, KMuiuKeyCurrentMsg, closedEntryId );
       
  2226     if ( r != KErrNone )
       
  2227         {
       
  2228         closedEntryId = 0;
       
  2229         }
       
  2230     if ( aCompletionCode == EEikCmdExit &&
       
  2231         !iMceUiFlags.MceFlag( EMceUiFlagsDoNotExitAfterNextOperationComplete ) )
       
  2232         {
       
  2233         MCELOGGER_WRITE("CMceUi::DoOperationCompletedL: EXIT");
       
  2234         iAvkonViewAppUi->ProcessCommandL( EAknCmdHideInBackground );
       
  2235         return;
       
  2236         }
       
  2237     // viewer next/prev
       
  2238     else if ( aCompletionCode == CMsgEmbeddedEditorWatchingOperation::EMsgExitNext ||
       
  2239         aCompletionCode == CMsgEmbeddedEditorWatchingOperation::EMsgExitPrevious )
       
  2240         {
       
  2241         MCELOGGER_WRITE("CMceUi::DoOperationCompletedL: Opening next/previous");
       
  2242         HandleOpenNextPreviousL( aCompletionCode ==
       
  2243             CMsgEmbeddedEditorWatchingOperation::EMsgExitNext );
       
  2244         if ( !IsForeground() )
       
  2245             {
       
  2246              // bring mce application to foreground
       
  2247             iEikonEnv->RootWin().SetOrdinalPosition(0);
       
  2248             }
       
  2249         return;
       
  2250         }
       
  2251     else
       
  2252         {
       
  2253         // Viewer closed
       
  2254         if ( closedEntryId > 0 )
       
  2255             {
       
  2256             CMceMessageListContainerBase* container = iMceListView->ListContainer();
       
  2257             if ( container )
       
  2258                 {
       
  2259                 container->SetCurrentItemIdL( closedEntryId );
       
  2260                 }
       
  2261             }
       
  2262          }
       
  2263 
       
  2264     if ( !iMceErrorUi )
       
  2265         {
       
  2266         iMceErrorUi = CErrorUI::NewL(*iCoeEnv);
       
  2267         }
       
  2268 
       
  2269     if ( aCompletionCode == KMsvIndexRestore )
       
  2270         {
       
  2271         iMceErrorUi->ShowGlobalErrorNoteL( aCompletionCode );
       
  2272         }
       
  2273 
       
  2274     const TDesC8& progress = aOperation->ProgressL();
       
  2275 
       
  2276     if (aOperation->Mtm() != KUidMsvLocalServiceMtm )
       
  2277         {
       
  2278         MCELOGGER_WRITE_FORMAT("CMceUi::DoOperationCompletedL: calling mtm ui 0x%x DisplayProgressSummary", aOperation->Mtm().iUid );
       
  2279         CAknInputBlock::NewLC();
       
  2280         CMtmStore* mtmStore=CMtmStore::NewL(*iSession);
       
  2281         CleanupStack::PushL( mtmStore );
       
  2282         
       
  2283         CBaseMtmUi& ui = mtmStore->GetMtmUiLC( aOperation->Mtm() );
       
  2284         if ( aOperation->Service() > KFirstFreeEntryId
       
  2285             && ( aOperation->Mtm() == KSenduiMtmImap4Uid
       
  2286             || aOperation->Mtm() == KSenduiMtmPop3Uid ) )
       
  2287             {
       
  2288             ui.BaseMtm().SwitchCurrentEntryL( aOperation->Service() );
       
  2289             }
       
  2290         ui.DisplayProgressSummary( progress );
       
  2291         CleanupStack::PopAndDestroy( 3 ); // CAknInputBlock, mtmStore, release mtmUi        
       
  2292         MCELOGGER_WRITE("DisplayProgressSummary done");
       
  2293         return;
       
  2294         }
       
  2295 
       
  2296     if (progress.Length() == 0)
       
  2297         {
       
  2298         return;
       
  2299         }
       
  2300 
       
  2301     TMsvLocalOperationProgress localprogress =
       
  2302         McliUtils::GetLocalProgressL( *aOperation );
       
  2303 
       
  2304     if ( ( aCompletionCode == KErrNone
       
  2305         || aCompletionCode == KErrCancel )
       
  2306         && ( localprogress.iError == KErrNone
       
  2307         || localprogress.iError == KErrCancel ) )
       
  2308         {
       
  2309         return;
       
  2310         }
       
  2311 
       
  2312     MCELOGGER_WRITE_FORMAT("CMceUi::DoOperationCompletedL, localProgress.iType %d", localprogress.iType )
       
  2313     MCELOGGER_WRITE_FORMAT("error %d", localprogress.iError?localprogress.iError:aCompletionCode )
       
  2314 
       
  2315     iMceErrorUi->ShowGlobalErrorNoteL( localprogress.iError?localprogress.iError:aCompletionCode );
       
  2316     }
       
  2317 
       
  2318 // ----------------------------------------------------
       
  2319 // CMceUi::CreateNewFolderL
       
  2320 // ----------------------------------------------------
       
  2321 void CMceUi::CreateNewFolderL()
       
  2322     {
       
  2323     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  2324 
       
  2325     TMsvEntry newFolder;
       
  2326     const TMsvId parentId=iMceListView->ListContainer()->CurrentFolderId();
       
  2327     if ( parentId != KMceDocumentsEntryId )
       
  2328         {
       
  2329 #if defined(_DEBUG)
       
  2330         Panic( EMceUiErrCannotCreateFolder );
       
  2331 #endif
       
  2332         return;
       
  2333         }
       
  2334 
       
  2335     _LIT(KMceFormatFolderName, "%S(%02d)");
       
  2336     TBuf<KMceMaxFolderLength> folderName;
       
  2337     TInt num = 0;
       
  2338     TBuf<KMceTextLength> defaultFolderName;
       
  2339     StringLoader::Load( defaultFolderName, R_MCE_DEFAULT_FOLDER_NAME, iEikonEnv );
       
  2340     folderName.Copy( defaultFolderName );
       
  2341     while( iMceListView->IsFolderNameUsedL( folderName ) )
       
  2342         {
       
  2343         num++;
       
  2344         folderName.Format( KMceFormatFolderName, &defaultFolderName, num );
       
  2345         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( folderName );
       
  2346         }
       
  2347 
       
  2348     if ( FolderNameQueryL( R_MCE_CREATE_FOLDER, folderName ) )
       
  2349         {
       
  2350         CAknInputBlock::NewLC();
       
  2351         CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  2352         CleanupStack::PushL( singleOpWatcher );
       
  2353 
       
  2354         iEntry->SetEntryL( parentId );
       
  2355         newFolder.iDate.HomeTime();
       
  2356         newFolder.iDetails.Set( folderName );
       
  2357         newFolder.iType = KUidMsvFolderEntry;
       
  2358         newFolder.iMtm = iEntry->Entry().iMtm;
       
  2359         newFolder.iServiceId= iEntry->OwningService();
       
  2360 
       
  2361         CMsvOperation* op = iEntry->CreateL( newFolder, singleOpWatcher->iStatus );
       
  2362         CleanupStack::PushL( op );
       
  2363         iOperations.AppendL( singleOpWatcher );
       
  2364         CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  2365         singleOpWatcher->SetOperation( op );
       
  2366         MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  2367         CleanupStack::PopAndDestroy(); //CAknInputBlock
       
  2368         }
       
  2369     }
       
  2370 
       
  2371 // ----------------------------------------------------
       
  2372 // CMceUi::RenameFolderL
       
  2373 // ----------------------------------------------------
       
  2374 void CMceUi::RenameFolderL()
       
  2375     {
       
  2376     const CMceMessageListContainerBase* container = iMceListView->ListContainer();
       
  2377     TMsvId currentId = container->CurrentItemId();
       
  2378 
       
  2379     CMsvEntry* centry=iSession->GetEntryL( currentId );
       
  2380     CleanupStack::PushL( centry );
       
  2381     TMsvEntry entry = centry->Entry();
       
  2382 
       
  2383     __ASSERT_DEBUG(entry.iType == KUidMsvFolderEntry,
       
  2384         Panic(EMceUiErrRenameNotFolder));
       
  2385     __ASSERT_DEBUG(entry.iMtm == KUidMsvLocalServiceMtm,
       
  2386         Panic(EMceUiErrRenameNotLocal));
       
  2387 
       
  2388 
       
  2389     TBuf<KMceMaxFolderLength> buf = entry.iDetails.Left( KMceMaxFolderLength );
       
  2390     if ( FolderNameQueryL( R_MCE_CREATE_FOLDER, buf, entry.Id() ) )
       
  2391         {
       
  2392         CAknInputBlock::NewLC();
       
  2393         CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  2394         CleanupStack::PushL(singleOpWatcher);
       
  2395         iEntry->SetEntryL( entry.Id() );
       
  2396         entry.iDetails.Set( buf );
       
  2397         CMsvOperation* op = iEntry->ChangeL( entry, singleOpWatcher->iStatus );
       
  2398         CleanupStack::PushL( op );
       
  2399         iOperations.AppendL(singleOpWatcher);
       
  2400         CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  2401         singleOpWatcher->SetOperation(op);
       
  2402         MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  2403         CleanupStack::PopAndDestroy(); //CAknInputBlock
       
  2404         }
       
  2405     CleanupStack::PopAndDestroy( centry );
       
  2406     }
       
  2407 
       
  2408 // ----------------------------------------------------
       
  2409 // CMceUi::FolderNameQueryL
       
  2410 // ----------------------------------------------------
       
  2411 TBool CMceUi::FolderNameQueryL(
       
  2412     const TInt aResourceId,
       
  2413     TDes& aFolderName,
       
  2414     const TMsvId aFolderId /*= KMsvNullIndexEntryId */ ) const
       
  2415     {
       
  2416     CAknTextQueryDialog* dlg = NULL;
       
  2417     TInt button = 0;
       
  2418     TBool okToStop = EFalse;
       
  2419     while ( !okToStop )
       
  2420         {
       
  2421         dlg = CAknTextQueryDialog::NewL( aFolderName );
       
  2422         dlg->SetMaxLength( KMceMaxFolderLength );
       
  2423         button = dlg->ExecuteLD( aResourceId );
       
  2424         if ( button )
       
  2425             {
       
  2426             MceUtils::ReplaceCharacters( aFolderName );
       
  2427             if ( iMceListView->IsFolderNameUsedL( aFolderName, aFolderId ) )
       
  2428                 {
       
  2429                 HBufC* errorText = StringLoader::LoadLC(
       
  2430                     R_MCE_DUPLICATE_FOLDER_TEXT, aFolderName, iEikonEnv );
       
  2431                 CAknInformationNote* note = new(ELeave)CAknInformationNote( ETrue );
       
  2432                 note->ExecuteLD(*errorText);
       
  2433                 CleanupStack::PopAndDestroy( errorText );
       
  2434                 }
       
  2435             else
       
  2436                 {
       
  2437                 okToStop = ETrue;
       
  2438                 }
       
  2439             }
       
  2440         else
       
  2441             {
       
  2442             okToStop = ETrue;
       
  2443             }
       
  2444         }
       
  2445     return button;
       
  2446     }
       
  2447 
       
  2448 // ----------------------------------------------------
       
  2449 // CMceUi::CloseConnectionsBeforeExitL
       
  2450 // ----------------------------------------------------
       
  2451 void CMceUi::CloseConnectionsBeforeExitL()
       
  2452     {
       
  2453     CMsvEntrySelection* connectedAccounts = ConnectedServicesLC();
       
  2454     const TInt numberOfConnectedMailboxes = connectedAccounts->Count();
       
  2455     TInt mceConnected = numberOfConnectedMailboxes;
       
  2456 
       
  2457     if ( iAlwaysOnline )
       
  2458         {
       
  2459         TMsvId account;
       
  2460         TMsvEntry entry;
       
  2461         TMsvId service;
       
  2462 
       
  2463         for ( TInt cc = 0; cc < numberOfConnectedMailboxes; cc++ )
       
  2464             {
       
  2465             account = connectedAccounts->At( cc );
       
  2466             User::LeaveIfError( iSession->GetEntry(account,service,entry) );
       
  2467 // Get the allways online mail settings
       
  2468             CImumInSettingsData* settings =
       
  2469                 iEmailApi->MailboxServicesL().LoadMailboxSettingsL( account );
       
  2470             CleanupStack::PushL( settings );
       
  2471 
       
  2472             if ( !ServiceIdFound( account ) && 
       
  2473                 iMceMainView->ListContainer()->ListItems()->
       
  2474                     AlwaysOnlineAccountL( account, *settings ) )
       
  2475                 {
       
  2476                 //this is a real always online account and not connected from mce
       
  2477                 mceConnected--;
       
  2478                 }
       
  2479 
       
  2480             CleanupStack::PopAndDestroy( settings ); // extendedMailSettings
       
  2481             }
       
  2482         }
       
  2483 
       
  2484     if ( mceConnected > 0 )
       
  2485         {
       
  2486         TBool disconnectMailboxes = ETrue;
       
  2487         if( iEmailClientIntegration && iSelectableEmail )
       
  2488             {
       
  2489             //no need to go through the disconnection logic since the FS is enabled
       
  2490             disconnectMailboxes = EFalse;
       
  2491             iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
  2492             }
       
  2493         else
       
  2494         if ( MceViewActive( EMceMainViewActive )
       
  2495             || ( MceViewActive( EMceMessageViewActive )
       
  2496             && iMceListView->IsMSKMailBox() ) )
       
  2497             {
       
  2498         CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
  2499         confDialog->PrepareLC( R_MCE_CONFIRMATION );
       
  2500         HBufC* titleText = NULL;
       
  2501         if ( numberOfConnectedMailboxes == 1 )
       
  2502             {
       
  2503             titleText = StringLoader::LoadLC(
       
  2504                 R_MCE_CONNECTION_ON_TEXT,
       
  2505                 iEikonEnv );
       
  2506             }
       
  2507         else
       
  2508             {
       
  2509             titleText = StringLoader::LoadLC(
       
  2510                 R_MCE_CONNECTION_ON_MANY_TEXT,
       
  2511                 iEikonEnv );
       
  2512             }
       
  2513 
       
  2514         confDialog->SetPromptL( *titleText );
       
  2515         CleanupStack::PopAndDestroy( titleText );
       
  2516 
       
  2517             if ( !confDialog->RunLD() )
       
  2518                 {
       
  2519                 disconnectMailboxes = EFalse;
       
  2520                 }
       
  2521             }
       
  2522         if ( disconnectMailboxes )
       
  2523             {
       
  2524             iMceUiFlags.SetMceFlag( EMceUiFlagsExitAfterDisconnect  );
       
  2525             for ( TInt loop = 0; loop < numberOfConnectedMailboxes; loop++ )
       
  2526                 {
       
  2527                 GoOfflineSynchronouslyL( connectedAccounts->At( loop ) );
       
  2528                 }
       
  2529             if (iMceUiFlags.MceFlag( EMceUiFlagsExitAfterDisconnect ) )
       
  2530                 {
       
  2531                 iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
  2532                 }
       
  2533             }
       
  2534         }
       
  2535     else
       
  2536         {
       
  2537         iMceUiFlags.SetMceFlag( EMceUiFlagsWantToExit );
       
  2538         }
       
  2539     CleanupStack::PopAndDestroy(); // connectedAccounts
       
  2540     }
       
  2541 
       
  2542 // ----------------------------------------------------
       
  2543 // CMceUi::ConnectedServicesLC
       
  2544 // ----------------------------------------------------
       
  2545 CMsvEntrySelection* CMceUi::ConnectedServicesLC()
       
  2546     {
       
  2547     MCELOGGER_ENTERFN("ConnectedServicesLC()");
       
  2548 
       
  2549     CMsvEntrySelection* connectedAccounts = new(ELeave) CMsvEntrySelection();
       
  2550     CleanupStack::PushL(connectedAccounts);
       
  2551 
       
  2552     CMsvEntrySelection* sel = MsvUiServiceUtilities::GetListOfAccountsL(
       
  2553         *iSession );
       
  2554     CleanupStack::PushL( sel );
       
  2555     const TUid  connectCapability={KUidMsvMtmUiQueryConnectionOrientedServices};
       
  2556 
       
  2557     CBaseMtmUiData* uiData=NULL;
       
  2558     TUid uid;
       
  2559     const TInt numAccounts=sel->Count();
       
  2560     for (TInt cc=0; cc<numAccounts; cc++)
       
  2561         {
       
  2562          uid.iUid=sel->At(cc);
       
  2563          const TMsvEntry& tentry=iRootEntry->ChildDataL(uid.iUid);
       
  2564          // if cmail  feature is enabled, no need to add cmail account in connectedAccounts.
       
  2565          if ( !( iEmailFramework && 
       
  2566                ( tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid ||
       
  2567                  tentry.iMtm.iUid == KUidMsgTypeFsMtmVal )))
       
  2568              {
       
  2569               TRAPD(error, ( uiData=GetMtmUiDataL(tentry.iMtm) ) );
       
  2570               if (error==KErrNone && uiData)
       
  2571                  {
       
  2572                   TInt rid;
       
  2573                   if (uiData->QueryCapability(connectCapability, rid)==KErrNone)
       
  2574                      {
       
  2575                       if (tentry.Connected())
       
  2576                          {
       
  2577                           connectedAccounts->AppendL( sel->At(cc) );
       
  2578                          }
       
  2579                      }
       
  2580                  }
       
  2581              }  
       
  2582         }
       
  2583     CleanupStack::PopAndDestroy( sel );
       
  2584     MCELOGGER_LEAVEFN("ConnectedServicesLC()");
       
  2585     return connectedAccounts;
       
  2586     }
       
  2587 
       
  2588 // ----------------------------------------------------
       
  2589 // CMceUi::OpenFolderViewL
       
  2590 // ----------------------------------------------------
       
  2591 void CMceUi::OpenFolderViewL( TMsvId aFolderId )
       
  2592     {
       
  2593     iMceListView->SetFolderL( aFolderId );
       
  2594     ActivateLocalViewL( KMceMessageListViewId );
       
  2595     }
       
  2596 
       
  2597 // ----------------------------------------------------
       
  2598 // CMceUi::OpenRemoteMailboxViewL
       
  2599 // ----------------------------------------------------
       
  2600 void CMceUi::OpenRemoteMailboxViewL( TMsvId aFolderId )
       
  2601     {
       
  2602         // NCN reset, if the mail folder contains unread messages
       
  2603     TBool unreadMessages = EFalse;
       
  2604 #ifndef RD_MSG_NAVIPANE_IMPROVEMENT
       
  2605 	TRAPD(err, ( unreadMessages = iBitmapResolver->HasUnreadMessagesL(aFolderId) ) );
       
  2606 #else   
       
  2607     TInt messageCount = 0;
       
  2608     TInt unreadCount = 0;
       
  2609     TRAPD(err, ( unreadMessages = iBitmapResolver->HasUnreadMessagesL(aFolderId, messageCount, unreadCount) ) );
       
  2610 #endif // RD_MSG_NAVIPANE_IMPROVEMENT     
       
  2611     if (err == KErrNone && unreadMessages )
       
  2612         {
       
  2613         HandleNotif(aFolderId);
       
  2614         }    
       
  2615     OpenFolderViewL( aFolderId );
       
  2616     ShowTabsL( aFolderId );
       
  2617     }
       
  2618 
       
  2619 // ----------------------------------------------------
       
  2620 // CMceUi::CancelMailboxTimer
       
  2621 // ----------------------------------------------------
       
  2622 void CMceUi::CancelMailboxTimer()
       
  2623     {
       
  2624     if ( iConnectMailboxTimer && iConnectMailboxTimer->IsActive() )
       
  2625         {
       
  2626         iConnectMailboxTimer->Cancel();
       
  2627         }
       
  2628     }
       
  2629 
       
  2630 // ----------------------------------------------------
       
  2631 // CMceUi::EditMTMEntryL
       
  2632 // ----------------------------------------------------
       
  2633 void CMceUi::EditMTMEntryL( const TMsvEntry& aEntry /*, TBool aOpen*/)
       
  2634     {
       
  2635     // Define KPSUidMuiu property to be integer type
       
  2636     TInt r = RProperty::Define( KPSUidMuiu, KMuiuKeyCurrentMsg, RProperty::EInt );
       
  2637     if ( r != KErrAlreadyExists )
       
  2638         {
       
  2639         User::LeaveIfError( r );
       
  2640         }
       
  2641     
       
  2642      r = RProperty::Define( KPSUidMuiu, KMuiuKeyNextMsg, RProperty::EInt );
       
  2643      if ( r != KErrAlreadyExists )
       
  2644          {
       
  2645          User::LeaveIfError( r );
       
  2646          }
       
  2647 
       
  2648     // Set entry Id value to property
       
  2649     if ( aEntry.iType == KUidMsvMessageEntry )
       
  2650         {
       
  2651         r = RProperty::Set( KPSUidMuiu, KMuiuKeyCurrentMsg, aEntry.Id() );
       
  2652         r = RProperty::Set( KPSUidMuiu, KMuiuKeyNextMsg, 0 );
       
  2653         }
       
  2654 
       
  2655     TBool tabsToCleanupStack = EFalse;
       
  2656 
       
  2657     CBaseMtmUi& mtmUi=iMtmStore->GetMtmUiAndSetContextLC( aEntry );
       
  2658     mtmUi.SetPreferences( mtmUi.Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  2659 
       
  2660     CMsvOperation* op = NULL;
       
  2661     CAknInputBlock::NewLC();
       
  2662 
       
  2663     CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  2664     CleanupStack::PushL( singleOpWatcher );
       
  2665     if (aEntry.iType == KUidMsvMessageEntry )
       
  2666         {
       
  2667         MCELOGGER_WRITE_FORMAT("EditMTMEntryL: iEditorOperation set 0x%x", singleOpWatcher );
       
  2668         iEditorOperation = singleOpWatcher;
       
  2669         }
       
  2670     CleanupStack::PushL( TCleanupItem( ResetEditorOperation, this ) );
       
  2671     
       
  2672 
       
  2673     if ( aEntry.iType == KUidMsvServiceEntry )
       
  2674         {
       
  2675         if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ) )
       
  2676             {
       
  2677             // must remove tabs because if no mailboxes created then
       
  2678             // mailbox settings dialog is displayed and tabs should not be shown then.
       
  2679             RemoveTabs();
       
  2680             CleanupStack::PushL( TCleanupItem( ShowTabs, this ) );
       
  2681             tabsToCleanupStack = ETrue;
       
  2682             }
       
  2683         TAknUiZoom previous = ZoomLevelChangedL( EAknUiZoomAutomatic );
       
  2684         op=mtmUi.EditL( singleOpWatcher->iStatus );
       
  2685         ZoomLevelChangedL( previous );
       
  2686 
       
  2687         if ( tabsToCleanupStack )
       
  2688             {
       
  2689             CleanupStack::PopAndDestroy(); // TCleanupItem - will show tabs again
       
  2690             }
       
  2691         if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive )  && (!tabsToCleanupStack) )
       
  2692             {
       
  2693             ShowTabsL( iMceListView->ListContainer()->CurrentFolderId() );
       
  2694             }
       
  2695         }
       
  2696     else
       
  2697         {
       
  2698 
       
  2699         ReleaseMtmUiData();
       
  2700 
       
  2701         TRAPD( error, ( op=mtmUi.OpenL(singleOpWatcher->iStatus ) ) );
       
  2702         if ( error )
       
  2703             {
       
  2704             // the returned error ofCBaseMtmUi code is defined in e32err.h instead of DocumentHandler.h
       
  2705             // KMimeNotSupported(-12003) and KErrNotSupported(-5) has same meaning but different value
       
  2706             // Solution: add the corresponding error code from e32err.h : (KErrUnknown, KErrAccessDenied ?)
       
  2707             if ( error == KMimeNotSupported || error == KBadMimeType || error == KExecNotAllowed
       
  2708                 || error == KErrNotSupported || error == KErrUnknown || error == KErrAccessDenied )
       
  2709                 {
       
  2710                 //cannot be opened, mark read
       
  2711                 CMsvEntry* cEntry;
       
  2712                 cEntry = &(mtmUi.BaseMtm().Entry());
       
  2713                 TMsvEntry entry = cEntry->Entry();
       
  2714                 entry.SetUnread( EFalse );
       
  2715                 cEntry->ChangeL( entry );
       
  2716                 }
       
  2717 
       
  2718             // HandleOpenL is Trapped in MceOneRowListContainer to show error note we need to do it by ourselves
       
  2719              delete op; // op should be null if leave occurs but make sure it is not leaked.
       
  2720              HBufC* buf = 0;
       
  2721              HandleErrorL(error, &buf);
       
  2722              delete buf;
       
  2723              CleanupStack::PopAndDestroy( 4 ); 
       
  2724              if (error && iLocalScreenClearer )
       
  2725                  {
       
  2726                  delete iLocalScreenClearer;
       
  2727                  iLocalScreenClearer = NULL;
       
  2728                  }
       
  2729              return;
       
  2730                          
       
  2731             //User::Leave( error );
       
  2732             }
       
  2733             
       
  2734         CMceMessageListContainerBase* listContainer = iMceListView->ListContainer();
       
  2735         if ( listContainer )
       
  2736             {
       
  2737             listContainer->UpdateIconArrayL();
       
  2738             }
       
  2739             
       
  2740     	// the check has been added for email mailbox, need not to clear the screen
       
  2741     	if ( !iLocalScreenClearer &&
       
  2742              !CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, aEntry.iMtm ))       
       
  2743 	        {
       
  2744 	        iLocalScreenClearer = CAknLocalScreenClearer::NewL( ETrue );
       
  2745 	        }            
       
  2746         }
       
  2747 
       
  2748     CleanupStack::PushL( op );
       
  2749     iOperations.AppendL( singleOpWatcher );
       
  2750     CleanupStack::Pop( 3 ); // singleOpWatcher, ResetEditorOperation op
       
  2751     singleOpWatcher->SetOperation( op );
       
  2752     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  2753     if ( aEntry.iType == KUidMsvMessageEntry &&
       
  2754         iUiRegistry &&
       
  2755         iUiRegistry->IsPresent( op->Mtm() ) )
       
  2756         {
       
  2757         iMtmStore->ClaimMtmUiL( aEntry.iMtm );            
       
  2758         }
       
  2759     CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, release mtmUi
       
  2760     }
       
  2761 
       
  2762 // ----------------------------------------------------
       
  2763 // CMceUi::CreateNewAccountL
       
  2764 // ----------------------------------------------------
       
  2765 TBool CMceUi::CreateNewAccountL(
       
  2766     TUid aMessageType,
       
  2767     TMsvId aOldServiceId /* = KMsvNullIndexEntryId */)
       
  2768     {
       
  2769     MCELOGGER_ENTERFN("CreateNewAccountL()");
       
  2770     if ( aMessageType == KSenduiMtmSyncMLEmailUid )
       
  2771     {
       
  2772         aMessageType = KSenduiMtmSmtpUid;
       
  2773     }
       
  2774 
       
  2775     iRootEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
  2776 
       
  2777     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  2778 
       
  2779     TMsvEntry nentry;
       
  2780     nentry.iMtm = aMessageType;
       
  2781     nentry.iType.iUid = KUidMsvServiceEntryValue;
       
  2782     nentry.iDate.HomeTime();
       
  2783     nentry.iServiceId = aOldServiceId;
       
  2784 
       
  2785     // --- Get the MTM UI relevant to the message type ---
       
  2786     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( nentry.iMtm );
       
  2787     CMsvEntry* centry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
  2788     CleanupStack::PushL( centry );
       
  2789     CAknInputBlock::NewLC();
       
  2790 
       
  2791     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL(*this);
       
  2792     CleanupStack::PushL( singleOpWatcher );
       
  2793 
       
  2794     // Mailbox creation is ongoing, syncronic operation
       
  2795     iMailboxCreationOn = ETrue;
       
  2796     CMsvOperation* op = mtmUi.CreateL(
       
  2797         nentry,
       
  2798         *centry,
       
  2799         singleOpWatcher->iStatus );
       
  2800     // Mailbox creation finalized
       
  2801     iMailboxCreationOn = EFalse;
       
  2802 
       
  2803     CleanupStack::PushL( op );
       
  2804     iOperations.AppendL( singleOpWatcher );
       
  2805     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  2806     singleOpWatcher->SetOperation( op );
       
  2807 
       
  2808     TBool accountCreated = (op->iStatus != KErrCancel);
       
  2809     // if not created, imum returns completed operation with KErrCancel
       
  2810     if ( accountCreated )
       
  2811 				{
       
  2812         iMceMainView->ListContainer()->ListItems()->HandleSessionEventL( EMsvEntriesCreated, NULL, NULL, NULL );
       
  2813 				}
       
  2814 
       
  2815     CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  2816     CleanupStack::PopAndDestroy( centry );
       
  2817     CleanupStack::PopAndDestroy(); // mtm ui release
       
  2818     MCELOGGER_LEAVEFN("CreateNewAccountL()");
       
  2819     return accountCreated;
       
  2820     }
       
  2821 
       
  2822 // ----------------------------------------------------
       
  2823 // CMceUi::EditAccountL
       
  2824 // ----------------------------------------------------
       
  2825 void CMceUi::EditAccountL(TMsvId aId)
       
  2826     {
       
  2827 
       
  2828     iRootEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
  2829 
       
  2830     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  2831 
       
  2832     TMsvEntry entry;
       
  2833 
       
  2834     CMsvEntrySelection* rootSel = iRootEntry->ChildrenL();
       
  2835     CleanupStack::PushL( rootSel );
       
  2836     const TInt index = rootSel->Find( aId );
       
  2837     if (index > KErrNotFound)
       
  2838         {
       
  2839         entry = (*iRootEntry)[index];
       
  2840         EditMTMEntryL( entry );
       
  2841         }
       
  2842     CleanupStack::PopAndDestroy( rootSel );
       
  2843     }
       
  2844 
       
  2845 // ----------------------------------------------------
       
  2846 // CMceUi::MtmAccountsL
       
  2847 // ----------------------------------------------------
       
  2848 CUidNameArray* CMceUi::MtmAccountsL( TUid aType )
       
  2849     {
       
  2850 
       
  2851     iRootEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
  2852 
       
  2853     CUidNameArray* accounts = new (ELeave) CUidNameArray(
       
  2854         KMceArrayGranularity );
       
  2855     CleanupStack::PushL( accounts );
       
  2856 
       
  2857     CMsvEntrySelection* sel = NULL;
       
  2858 
       
  2859     if ( aType == KSenduiMtmSmtpUid )
       
  2860         {
       
  2861         sel = MsvUiServiceUtilities::GetListOfAccountsL(
       
  2862             *iSession,
       
  2863             ETrue );
       
  2864         }
       
  2865     else
       
  2866         {
       
  2867         sel = MsvUiServiceUtilities::GetListOfAccountsWithMTML(
       
  2868             *iSession,
       
  2869             aType,
       
  2870             ETrue );
       
  2871         }
       
  2872     CleanupStack::PushL( sel );
       
  2873 
       
  2874     CMsvEntry* rootEntry = CMsvEntry::NewL(
       
  2875         *iSession,
       
  2876         KMsvRootIndexEntryId,
       
  2877         TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
       
  2878     delete iRootEntry;
       
  2879     iRootEntry = rootEntry;
       
  2880 
       
  2881     TUid uid;
       
  2882     TUid techType = iUiRegistry->TechnologyTypeUid( aType );
       
  2883     const TInt numAccounts = sel->Count();
       
  2884     for (TInt cc=0; cc<numAccounts; cc++)
       
  2885         {
       
  2886         uid.iUid = sel->At(cc);
       
  2887         TMsvEntry tentry;
       
  2888         TRAPD( err, ( tentry = iRootEntry->ChildDataL( uid.iUid ) ) );
       
  2889         if ( err == KErrNone &&
       
  2890             iUiRegistry->IsPresent( tentry.iMtm ) && 
       
  2891             iUiRegistry->TechnologyTypeUid( tentry.iMtm ) == techType )
       
  2892             {
       
  2893             const TInt count = accounts->Count();
       
  2894             TBool foundService = EFalse;
       
  2895             //check that related service is not already added to array
       
  2896             for ( TInt loop = 0; loop < count; loop ++ )
       
  2897                 {
       
  2898                 if ( tentry.iRelatedId == (*accounts)[loop].iUid.iUid )
       
  2899                     {
       
  2900                     foundService = ETrue;
       
  2901                     break;
       
  2902                     }
       
  2903                 }
       
  2904             if ( !foundService )
       
  2905                 {
       
  2906                 TUidNameInfo info( uid, tentry.iDetails.Left( KHumanReadableNameLength ) );
       
  2907                 MceUtils::ReplaceCharacters( info.iName );
       
  2908                 accounts->AppendL( info );
       
  2909                 }
       
  2910             }
       
  2911         }
       
  2912     CleanupStack::PopAndDestroy( sel );
       
  2913     CleanupStack::Pop( accounts );
       
  2914     return accounts;
       
  2915     }
       
  2916 
       
  2917 // ----------------------------------------------------
       
  2918 // CMceUi::HandleDeleteL
       
  2919 // ----------------------------------------------------
       
  2920 void CMceUi::HandleDeleteL()
       
  2921     {
       
  2922     MCELOGGER_ENTERFN("HandleDeleteL()");
       
  2923 
       
  2924     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  2925         Panic( EMceUiErrCannotDeleteFromMainView ) );
       
  2926     if ( MceViewActive( EMceMainViewActive ) )
       
  2927         {
       
  2928         return;
       
  2929         }
       
  2930 
       
  2931     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  2932         ->CurrentItemSelectionL();
       
  2933     CleanupStack::PushL( selection );
       
  2934     __ASSERT_DEBUG( selection->Count() > 0,
       
  2935         Panic( EMceUiErrCannotDeleteFromMainView ) );
       
  2936 
       
  2937     if (  selection->Count() <= 0 )
       
  2938         {
       
  2939         CleanupStack::PopAndDestroy( selection );
       
  2940         return;
       
  2941         }
       
  2942 
       
  2943     iMceListView->ListContainer()->SetAnchorItemIdL(
       
  2944         CMceMessageListContainerBase::EMessageListOperationDelete );
       
  2945 
       
  2946     const TMsvId id = selection->At(0);
       
  2947     iEntry->SetEntryL(id);
       
  2948     const TInt type = iEntry->Entry().iType.iUid;
       
  2949 
       
  2950     if ( IsMessageSendingL( id ) )
       
  2951         {
       
  2952         CleanupStack::PopAndDestroy( selection );
       
  2953         return;
       
  2954         }
       
  2955 
       
  2956     __ASSERT_DEBUG( type == KUidMsvMessageEntryValue || type == KUidMsvFolderEntryValue,
       
  2957         Panic(EMceUiErrCannotDeleteServiceFromMainView) );
       
  2958 
       
  2959     TBool local = iEntry->OwningService() == KMsvLocalServiceIndexEntryIdValue;
       
  2960 
       
  2961     if ( iMMSNotifications )
       
  2962         {
       
  2963         delete iMMSNotifications;
       
  2964         iMMSNotifications = NULL;
       
  2965         }
       
  2966 
       
  2967     if ( local )
       
  2968         {
       
  2969         CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
  2970         confDialog->PrepareLC( R_MCE_CONFIRMATION );
       
  2971         // confDialog in CleanupStack now
       
  2972         HBufC* titleText;
       
  2973         if ( type == KUidMsvFolderEntryValue )
       
  2974             {
       
  2975             titleText = StringLoader::LoadLC( R_MCE_QUERY_COMMON_CONF_DELETE_FO,
       
  2976                 iEntry->Entry().iDetails.Left( iBitmapResolver->DescriptionLength() ), iEikonEnv );
       
  2977             }
       
  2978         else
       
  2979             {
       
  2980             if ( selection->Count() == 1 )
       
  2981                 {
       
  2982                 titleText = StringLoader::LoadLC(
       
  2983                     R_MCE_QUERY_COMMON_CONF_DELETE_ME, iEikonEnv );
       
  2984                 }
       
  2985             else
       
  2986                 {
       
  2987                 titleText = StringLoader::LoadLC(
       
  2988                     R_MCE_QUERY_COMMON_CONF_DELETE_MS,
       
  2989                     selection->Count(), iEikonEnv );
       
  2990                 }
       
  2991             }
       
  2992         confDialog->SetPromptL( *titleText );
       
  2993         CleanupStack::PopAndDestroy( titleText );
       
  2994         // RunLD removes confDialog from CleanupStack and deletes itself
       
  2995         if ( !confDialog->RunLD() )
       
  2996             {
       
  2997             CleanupStack::PopAndDestroy( selection ); // selection
       
  2998             return;
       
  2999             }
       
  3000         }
       
  3001     
       
  3002     if ( local && ( ( iEntry->Entry().Parent() == KMsvGlobalInBoxIndexEntryId ) ||
       
  3003         ( iEntry->Entry().Parent() == KMsvGlobalOutBoxIndexEntryId ) ) ) 
       
  3004         {
       
  3005         CheckMMSNotificationsL( selection );
       
  3006         if (  selection->Count() <= 0 )
       
  3007             {
       
  3008             // delete mms notifications, if any
       
  3009             if ( iMMSNotifications->Count() > 0 )
       
  3010                 {
       
  3011                 //delete MMS notifications
       
  3012                 TBuf8<1> params;
       
  3013                 HandleMMSNotificationsDeleteL( params );
       
  3014                 }
       
  3015             CleanupStack::PopAndDestroy( selection );
       
  3016             return;
       
  3017             }
       
  3018         }
       
  3019 
       
  3020    
       
  3021     iEntry->SetEntryL( iEntry->Entry().Parent() );
       
  3022 
       
  3023     CBaseMtmUi* ui = NULL;
       
  3024     TUid mtm=iEntry->Entry().iMtm;
       
  3025     if ( !local )
       
  3026         {
       
  3027         TRAPD(uiErr, (ui = &iMtmStore->ClaimMtmUiL( mtm )));
       
  3028         if ( uiErr == KErrNotFound || uiErr == KErrNotSupported )
       
  3029             {
       
  3030             // MTM not present, so delete as normal local entry
       
  3031             ui = NULL;
       
  3032             }
       
  3033         else
       
  3034             {
       
  3035             User::LeaveIfError(uiErr);
       
  3036             }
       
  3037         }
       
  3038     if (ui)
       
  3039         {
       
  3040         CMtmStoreMtmReleaser::CleanupReleaseMtmUiLC(*iMtmStore, mtm);
       
  3041         }
       
  3042 
       
  3043     CMsvOperation* op;
       
  3044 
       
  3045     if ( local )
       
  3046         {
       
  3047         __ASSERT_DEBUG( !iDeleteOperation,
       
  3048             Panic( EMceUiErrAlreadyDeleting ) );
       
  3049 
       
  3050 // Free disk space request for delete to be added
       
  3051         }
       
  3052 
       
  3053     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  3054     CleanupStack::PushL( singleOpWatcher );
       
  3055 
       
  3056     TBool resetSelection = ETrue;
       
  3057 
       
  3058     if (ui)
       
  3059         {
       
  3060         // reset ncn, if it is unread message
       
  3061         TMsvEntry entry;
       
  3062         TMsvId serviceId;
       
  3063         User::LeaveIfError( iSession->GetEntry(selection->At(0),serviceId,entry) );
       
  3064                 
       
  3065         if ( CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, 
       
  3066                 entry.iMtm )&& entry.Unread() )
       
  3067             {
       
  3068             HandleNotif(iMceListView->ListContainer()->FolderEntry().iServiceId);
       
  3069 
       
  3070             }
       
  3071         
       
  3072         ui->BaseMtm().SetCurrentEntryL(iSession->GetEntryL(
       
  3073             iEntry->Entry().Id()));
       
  3074 
       
  3075         CAknInputBlock::NewLC();
       
  3076         op = ui->DeleteFromL(*selection, singleOpWatcher->iStatus);
       
  3077         SetViewUpdateSuppressionFlag( ETrue, op );
       
  3078         CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  3079         CleanupStack::PushL( op );
       
  3080         // if cancel was pressed then completed operation is returned with
       
  3081         // local service and status KErrCancel
       
  3082         if ( op->Service() == KMsvLocalServiceIndexEntryId &&
       
  3083              op->iStatus == KErrCancel )
       
  3084             {
       
  3085             resetSelection = EFalse;
       
  3086             SetViewUpdateSuppressionFlag( EFalse, NULL );
       
  3087             }
       
  3088         }
       
  3089     else
       
  3090         {
       
  3091         if ( iEntry->EntryId() == KMsvGlobalOutBoxIndexEntryId )
       
  3092             {
       
  3093             CMsvProgressReporterOperation* progOp =
       
  3094                 CMsvProgressReporterOperation::NewL(
       
  3095                 *iSession, singleOpWatcher->iStatus, EMbmAvkonQgn_note_erased );
       
  3096             CleanupStack::PushL( progOp );
       
  3097 
       
  3098             CMsvOperation* subOp = CMceCancelSendingOperation::NewL(
       
  3099                 *iSession,
       
  3100                 progOp->RequestStatus(),
       
  3101                 selection->At(0),
       
  3102                 CMceCancelSendingOperation::ECancelAndDelete,
       
  3103                 *iMtmStore );
       
  3104 
       
  3105             progOp->SetOperationL(subOp); // this takes ownership immediately, so no cleanupstack needed.
       
  3106 
       
  3107             HBufC* text = StringLoader::LoadLC(
       
  3108                 R_MUIU_LOCAL_PROGRESS_DELETING_1,
       
  3109                 iEikonEnv );
       
  3110             progOp->SetTitleL( *text );
       
  3111             CleanupStack::PopAndDestroy( text );
       
  3112             op = progOp;
       
  3113             }
       
  3114         else
       
  3115             {
       
  3116             // SMS and MMS deletion
       
  3117             if ( selection->Count() > KMceProgressReporterThreshold ||
       
  3118                  type == KUidMsvFolderEntryValue )
       
  3119                 {
       
  3120                 // Show the progress note
       
  3121 
       
  3122                 CMsvProgressReporterOperation* progOp =
       
  3123                     CMsvProgressReporterOperation::NewL(
       
  3124                     *iSession, singleOpWatcher->iStatus, EMbmAvkonQgn_note_erased );
       
  3125 
       
  3126                 CleanupStack::PushL( progOp );
       
  3127 
       
  3128                 // deleting folder
       
  3129                 HBufC* text = NULL;
       
  3130                 iEntry->SetEntryL(id);
       
  3131 
       
  3132                 if( type == KUidMsvFolderEntryValue )
       
  3133                     {
       
  3134                     text = StringLoader::LoadLC( R_MCE_WAIT_DELETE_FOLDER,
       
  3135                         iEntry->Entry().iDetails.Left( iBitmapResolver->DescriptionLength() ),
       
  3136                         iEikonEnv );
       
  3137                     }
       
  3138                 else // if message
       
  3139                     {
       
  3140                     text = StringLoader::LoadLC(
       
  3141                         R_MUIU_LOCAL_PROGRESS_DELETING_1,
       
  3142                         iEikonEnv );
       
  3143                     }
       
  3144                 progOp->SetTitleL( *text );
       
  3145                 CleanupStack::PopAndDestroy( text );
       
  3146                 iEntry->SetEntryL( iEntry->Entry().Parent() );
       
  3147 
       
  3148                 CMsvOperation* subOp=iEntry->DeleteL(
       
  3149                     *selection, progOp->RequestStatus() );
       
  3150                 progOp->SetOperationL(subOp); // this takes ownership immediately, so no cleanup stack needed.
       
  3151                 op = progOp;
       
  3152                 }
       
  3153             else
       
  3154                 {
       
  3155                 // Do not show the progress note
       
  3156                 iEntry->SetEntryL(id);
       
  3157                 iEntry->SetEntryL( iEntry->Entry().Parent() );
       
  3158                 op = iEntry->DeleteL( *selection, singleOpWatcher->iStatus );
       
  3159                 CleanupStack::PushL( op );
       
  3160                 }
       
  3161             }
       
  3162         }
       
  3163 
       
  3164     iOperations.AppendL( singleOpWatcher );
       
  3165     CleanupStack::Pop( 2, singleOpWatcher ); // singleOpWatcher, op
       
  3166     singleOpWatcher->SetOperation( op );
       
  3167     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3168 
       
  3169     if ( ui )
       
  3170         {
       
  3171         CleanupStack::PopAndDestroy( );// release mtmUi
       
  3172         }
       
  3173     if ( local )
       
  3174         {
       
  3175         // if deleting from service, then it is mtm's responsibility to free disk...
       
  3176         iDeleteOperation = singleOpWatcher;
       
  3177         MCELOGGER_WRITE_FORMAT("free disk requested, iDeleteOperation set 0x%x", iDeleteOperation );
       
  3178 
       
  3179 // Cancel the free disk space request to be added
       
  3180         }
       
  3181     CleanupStack::PopAndDestroy( selection );
       
  3182     if ( resetSelection )
       
  3183         {
       
  3184         iMceListView->ListContainer()->ClearSelection();
       
  3185         }
       
  3186     iMsgDeletedStatus = ETrue;
       
  3187     MCELOGGER_LEAVEFN("HandleDeleteL()");
       
  3188     }
       
  3189 
       
  3190 // ----------------------------------------------------
       
  3191 // CMceUi::HandleUndeleteL
       
  3192 // ----------------------------------------------------
       
  3193 void CMceUi::HandleUndeleteL()
       
  3194     {
       
  3195     MCELOGGER_ENTERFN("HandleUndeleteL()");
       
  3196 
       
  3197     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  3198         Panic( EMceUiErrCannotUnDeleteFromMainView ) );
       
  3199     if ( MceViewActive( EMceMainViewActive ) )
       
  3200         {
       
  3201         return;
       
  3202         }
       
  3203 
       
  3204     CMsvEntrySelection* selection = iMceListView->ListContainer()
       
  3205         ->CurrentItemSelectionRefreshL();
       
  3206     CleanupStack::PushL( selection );
       
  3207 
       
  3208     const TInt count = selection->Count();
       
  3209     __ASSERT_DEBUG( count != 0, Panic( EMceErrNothingToUnDelete ) );
       
  3210     if ( count == 0 )
       
  3211         {
       
  3212         CleanupStack::PopAndDestroy( selection );
       
  3213         return;
       
  3214         }
       
  3215 
       
  3216     const TMsvId id = selection->At( 0 );
       
  3217     TBool resetSelection = ETrue;
       
  3218 
       
  3219     TMsvEntry tentry;
       
  3220     GetEntryL( id, tentry );
       
  3221     TMsvEntry parentEntry;
       
  3222     GetEntryL( tentry.Parent(), parentEntry );
       
  3223 
       
  3224     CBaseMtmUi& ui = iMtmStore->GetMtmUiAndSetContextLC( parentEntry );
       
  3225 
       
  3226     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  3227     CleanupStack::PushL(singleOpWatcher);
       
  3228 
       
  3229     CAknInputBlock::NewLC();
       
  3230     CMsvOperation* op = ui.UnDeleteFromL(*selection, singleOpWatcher->iStatus);
       
  3231     CleanupStack::PopAndDestroy(); // CAknInputBlock::NewLC()
       
  3232     CleanupStack::PushL( op );
       
  3233     // if cancel was pressed then completed operation is returned with
       
  3234     // local service and status KErrCancel
       
  3235     if ( op->Service() == KMsvLocalServiceIndexEntryId &&
       
  3236          op->iStatus == KErrCancel )
       
  3237         {
       
  3238         resetSelection = EFalse;
       
  3239         }
       
  3240 
       
  3241     iOperations.AppendL( singleOpWatcher );
       
  3242     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  3243     singleOpWatcher->SetOperation( op );
       
  3244     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3245 
       
  3246     CleanupStack::PopAndDestroy( 2 );// release mtmUi, selection
       
  3247     if ( resetSelection )
       
  3248         {
       
  3249         iMceListView->ListContainer()->ClearSelection();
       
  3250         }
       
  3251     MCELOGGER_LEAVEFN("HandleUndeleteL()");
       
  3252     }
       
  3253 
       
  3254 // ----------------------------------------------------
       
  3255 // CMceUi::MoveOrCopyEntriesL
       
  3256 // ----------------------------------------------------
       
  3257 void CMceUi::MoveOrCopyEntriesL( TBool aCopy )
       
  3258     {
       
  3259     TInt count;
       
  3260     TMsvId id;
       
  3261     TMsvId service;
       
  3262     TMsvEntry tEntry;
       
  3263     TBool mailMessage = EFalse;
       
  3264     if ( aCopy )
       
  3265         {
       
  3266         LeaveIfDiskSpaceUnderCriticalLevelL( iDiskSpaceForMoveOrCopy );
       
  3267         }
       
  3268     else
       
  3269         {
       
  3270         LeaveIfDiskSpaceUnderCriticalLevelL();
       
  3271         }
       
  3272 
       
  3273     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  3274         Panic( EMceUiErrCannotMoveFromMainView ) );
       
  3275     if ( MceViewActive( EMceMainViewActive ) )
       
  3276         {
       
  3277         return;
       
  3278         }
       
  3279 
       
  3280     const TMsvId sourceId = iMceListView->ListContainer()->CurrentFolderId();
       
  3281 
       
  3282     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  3283         ->CurrentItemSelectionL();
       
  3284     CleanupStack::PushL( selection );
       
  3285 
       
  3286     if ( !aCopy )
       
  3287         {
       
  3288         count = selection->Count();
       
  3289         // MMS notifications cannot be moved
       
  3290         for ( TInt cc = count; --cc >= 0; )
       
  3291             {
       
  3292             id = selection->At( cc );
       
  3293             if ( iSession->GetEntry( id, service, tEntry ) == KErrNone  )
       
  3294                 {
       
  3295                 if ( tEntry.iMtm == KUidMsgMMSNotification )
       
  3296                     {
       
  3297                     selection->Delete( cc );
       
  3298                     }
       
  3299                 }
       
  3300             }
       
  3301         if ( selection->Count() < count )
       
  3302             {
       
  3303             // MMS notifications have been deleted from selection
       
  3304             CAknQueryDialog* note = CAknQueryDialog::NewL();
       
  3305             HBufC* text = NULL;
       
  3306             text = StringLoader::LoadLC( R_MMS_INFO_CANNOT_MOVE_NOTIF, CCoeEnv::Static() );
       
  3307             note->SetPromptL( *text );
       
  3308             CleanupStack::PopAndDestroy( text );
       
  3309             note->ExecuteLD( R_MCE_MEMC_NOTE );
       
  3310             }
       
  3311         }
       
  3312 
       
  3313     // Email messages cannot be moved
       
  3314     iMoveOrCopyMailOperation = -1;
       
  3315     mailMessage = RemoveEmailMessagesFromSelection( selection );
       
  3316 
       
  3317     if (  selection->Count() <= 0 )
       
  3318         {
       
  3319         CleanupStack::PopAndDestroy( selection );
       
  3320         if ( mailMessage )
       
  3321             {
       
  3322             InformationNoteCannotMoveCopyEMailL();
       
  3323             }
       
  3324         return;
       
  3325         }
       
  3326 // Find an iAnchorId (=itemId) that should be focused after moving some items from the list
       
  3327     iMceListView->ListContainer()->SetAnchorItemIdL(
       
  3328         CMceMessageListContainerBase::EMessageListOperationGeneral );
       
  3329 
       
  3330     TMsvId destinationId = sourceId;
       
  3331     const TInt titleResourceId = aCopy ?
       
  3332         R_MCE_COPY_MESSAGES :
       
  3333         R_MCE_MOVE_MESSAGES;
       
  3334     HBufC* text =  StringLoader::LoadLC( titleResourceId, iEikonEnv );
       
  3335 
       
  3336     const TInt iconId = aCopy ?
       
  3337         EMbmAvkonQgn_note_move :
       
  3338         EMbmAvkonQgn_note_copy;
       
  3339 
       
  3340     if ( CMsgFolderSelectionDialog::SelectFolderL( destinationId, *text ) )
       
  3341         {
       
  3342         // Trap: NCNList cannot seperate New and Unread that comes to Inbox
       
  3343         // So when movning Unread msgs to Inbox, we need to change them to
       
  3344         // read, and then change them back after moving is completed
       
  3345         if ( destinationId == KMsvGlobalInBoxIndexEntryId )
       
  3346             {
       
  3347             HandleNewMsgToInboxL( ETrue, selection );
       
  3348             }
       
  3349 
       
  3350         TMsvEntry srcEntry;
       
  3351         const TBool sourceIsRemote = KMsvLocalServiceIndexEntryId != GetEntryL( sourceId, srcEntry);
       
  3352 
       
  3353         CMsvOperation* op=NULL;
       
  3354 
       
  3355         CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  3356         CleanupStack::PushL( singleOpWatcher );
       
  3357 
       
  3358         CAknInputBlock::NewLC();
       
  3359 
       
  3360         TMsvId service = KMsvLocalServiceIndexEntryId;
       
  3361         TMsvEntry sourceServiceEntry;
       
  3362         User::LeaveIfError( iSession->GetEntry( srcEntry.iServiceId, service, sourceServiceEntry ) );
       
  3363 
       
  3364         if ( ( sourceIsRemote && !( sourceServiceEntry.Connected() ) ) ||
       
  3365             ( sourceServiceEntry.iMtm == KSenduiMtmSyncMLEmailUid ) )
       
  3366             {
       
  3367             CBaseMtmUi& ui=iMtmStore->GetMtmUiAndSetContextLC( srcEntry );
       
  3368             op=ui.CopyFromL( *selection, destinationId, singleOpWatcher->iStatus);
       
  3369             CleanupStack::PopAndDestroy(); // release ui
       
  3370             }
       
  3371         else
       
  3372             {
       
  3373             CMsvProgressReporterOperation* progOp =
       
  3374                 CMsvProgressReporterOperation::NewL( *iSession, singleOpWatcher->iStatus, iconId );
       
  3375             CleanupStack::PushL(progOp);
       
  3376             CMsvOperation* subOp = NULL;
       
  3377             iEntry->SetEntryL( sourceId );
       
  3378 
       
  3379             if ( aCopy )
       
  3380                 {
       
  3381                 subOp = iEntry->CopyL( *selection, destinationId, progOp->RequestStatus());
       
  3382                 }
       
  3383             else
       
  3384                 {
       
  3385                 subOp = iEntry->MoveL( *selection, destinationId, progOp->RequestStatus());
       
  3386                 }
       
  3387 
       
  3388             progOp->SetOperationL( subOp ); // this takes ownership immediately, so no cleanupstack needed.
       
  3389             op = progOp;
       
  3390             CleanupStack::Pop( progOp ); 
       
  3391             }
       
  3392 
       
  3393         CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  3394         CleanupStack::PushL( op );
       
  3395         iOperations.AppendL( singleOpWatcher );
       
  3396         CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  3397         singleOpWatcher->SetOperation( op );
       
  3398         MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3399 
       
  3400         if ( mailMessage )
       
  3401             {
       
  3402             // Mail messages cannot be copied or moved, save the command ID
       
  3403             iMoveOrCopyMailOperation = op->Id();
       
  3404             }
       
  3405 
       
  3406         iMceListView->ListContainer()->ClearSelection();
       
  3407 
       
  3408         } // end if
       
  3409     CleanupStack::PopAndDestroy( 2 ); // text, selection
       
  3410     }
       
  3411 
       
  3412 // ----------------------------------------------------
       
  3413 // CMceUi::ActivateLocalViewL
       
  3414 // ----------------------------------------------------
       
  3415 void CMceUi::ActivateLocalViewL(TUid aViewId)
       
  3416     {
       
  3417     if ( aViewId == KMceMainViewListViewId )
       
  3418         {
       
  3419         iEditorOperation = NULL;
       
  3420         CAknTitlePane* title=TitlePaneL();
       
  3421         HBufC* text = StringLoader::LoadLC( R_MCE_MAIN_VIEW_TITLE, iEikonEnv );
       
  3422         title->SetTextL( *text );
       
  3423         CleanupStack::PopAndDestroy(); // text
       
  3424         }
       
  3425     CAknViewAppUi::ActivateLocalViewL( aViewId );
       
  3426     }
       
  3427 
       
  3428 // ----------------------------------------------------
       
  3429 // CMceUi::CreateTabsL
       
  3430 // ----------------------------------------------------
       
  3431 void CMceUi::CreateTabsL()
       
  3432     {
       
  3433     MCELOGGER_ENTERFN("CreateTabsL()");
       
  3434     __ASSERT_DEBUG( !iTabsArray, Panic( EMceUiErrTabsArrayAlreadyExists ) );
       
  3435 
       
  3436     delete iDecoratedTabGroup;
       
  3437     iDecoratedTabGroup = NULL;
       
  3438     iDecoratedTabGroup = iNaviPane->CreateTabGroupL( this );
       
  3439     iDecoratedTabGroup->SetControlType( CAknNavigationDecorator::ETabGroup );
       
  3440 
       
  3441     CAknTabGroup* tabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
       
  3442 
       
  3443     CMceMainViewListItemArray* array = iMceMainView->ListContainer()->ListItems();
       
  3444     TInt count = array->Count();
       
  3445     CMsvEntrySelection* tabsArray = new( ELeave ) CMsvEntrySelection();
       
  3446     CleanupStack::PushL( tabsArray );
       
  3447     TInt loop = 0;
       
  3448     for ( loop = 0; loop < count; loop++ )
       
  3449         {
       
  3450         const TMceListItem& listItem = (*array)[loop];
       
  3451         if ( !listItem.iExtraItem || listItem.iMsvId == KMceDeliveryReportsListIdValue )
       
  3452             {
       
  3453               if (( iEmailClientIntegration )&&(!iEmailFramework))
       
  3454               {
       
  3455                 TMsvId service;
       
  3456                 TMsvEntry entry;
       
  3457                      
       
  3458                   
       
  3459                 CRepository* repository = NULL;
       
  3460                 TInt mtmPluginID = 0;
       
  3461                 TRAPD( ret, repository = CRepository::NewL(
       
  3462                                          KCRUidSelectableDefaultEmailSettings ) );
       
  3463                 
       
  3464                 if ( ret == KErrNone )
       
  3465                     {
       
  3466                     // Get Email application mtm plugin ID
       
  3467                     repository->Get( KIntegratedEmailAppMtmPluginId, mtmPluginID );
       
  3468                     }
       
  3469                 delete repository;
       
  3470                 if ( iSession->GetEntry(listItem.iMsvId, service, entry) == KErrNone
       
  3471                                                     &&  entry.iMtm.iUid != mtmPluginID)
       
  3472                  {
       
  3473                  tabsArray->AppendL( listItem.iMsvId );
       
  3474                  }
       
  3475 				else if(listItem.iMsvId == KMceDeliveryReportsListIdValue)
       
  3476                  {
       
  3477                  	tabsArray->AppendL( listItem.iMsvId );
       
  3478                  }
       
  3479                }
       
  3480                else
       
  3481                {
       
  3482                  tabsArray->AppendL( listItem.iMsvId );
       
  3483                }
       
  3484             
       
  3485             }
       
  3486         }
       
  3487     CleanupStack::Pop( tabsArray );
       
  3488     iTabsArray = tabsArray;
       
  3489 
       
  3490     CFbsBitmap* bitmap;
       
  3491     CFbsBitmap* bitmapMask;
       
  3492 
       
  3493     TAknsItemID id;
       
  3494     id.iMajor = 0;
       
  3495     id.iMinor = 0;
       
  3496 
       
  3497     MAknsSkinInstance* skins = AknsUtils::SkinInstance();
       
  3498 
       
  3499     count = iTabsArray->Count();
       
  3500     TInt bitmapIndex = EMbmMuiuQgn_prop_mce_inbox_tab4;
       
  3501     for ( loop = 0; loop < count; loop++ )
       
  3502         {
       
  3503         switch ( (*iTabsArray)[loop] )
       
  3504             {
       
  3505             case KMsvGlobalInBoxIndexEntryId:
       
  3506                 bitmapIndex = EMbmMuiuQgn_prop_mce_inbox_tab4;
       
  3507                 id = KAknsIIDQgnPropMceInboxTab4;
       
  3508                 break;
       
  3509             case KMceDocumentsEntryId:
       
  3510                 bitmapIndex = EMbmMuiuQgn_prop_mce_doc_tab4;
       
  3511                 id = KAknsIIDQgnPropMceDocTab4;
       
  3512                 break;
       
  3513             case KMsvDraftEntryId:
       
  3514                 bitmapIndex = EMbmMuiuQgn_prop_mce_drafts_tab4;
       
  3515                 id = KAknsIIDQgnPropMceDraftsTab4;
       
  3516                 break;
       
  3517             case KMsvSentEntryId:
       
  3518                 bitmapIndex = EMbmMuiuQgn_prop_mce_sent_tab4;
       
  3519                 id = KAknsIIDQgnPropMceSentTab4;
       
  3520                 break;
       
  3521             case KMsvGlobalOutBoxIndexEntryId:
       
  3522                 bitmapIndex = EMbmMuiuQgn_prop_mce_outbox_tab4;
       
  3523                 id = KAknsIIDQgnPropMceOutboxTab4;
       
  3524                 break;
       
  3525             case KMceDeliveryReportsListIdValue:
       
  3526                 bitmapIndex = EMbmMuiuQgn_prop_mce_dr_tab4;
       
  3527                 id = KAknsIIDQgnPropMceDrTab4;
       
  3528                 break;
       
  3529             default:
       
  3530                 {
       
  3531                 TMsvId service;
       
  3532                 TMsvEntry entry;
       
  3533                 if ( iSession->GetEntry( (*iTabsArray)[loop], service, entry) == KErrNone
       
  3534                     && ( entry.iMtm == KSenduiMtmImap4Uid || entry.iMtm == KSenduiMtmPop3Uid )
       
  3535                     && entry.Connected() )
       
  3536                     {
       
  3537                     bitmapIndex = EMbmMuiuQgn_prop_mce_remote_on_tab4;
       
  3538                     id = KAknsIIDQgnPropMceRemoteOnTab4;
       
  3539                     }
       
  3540                 else
       
  3541                     {
       
  3542                     bitmapIndex = EMbmMuiuQgn_prop_mce_remote_tab4;
       
  3543                     id = KAknsIIDQgnPropMceRemoteTab4;
       
  3544                     }
       
  3545                 }
       
  3546                 break;
       
  3547             }
       
  3548 
       
  3549         AknsUtils::CreateIconL( skins, id, bitmap,
       
  3550            bitmapMask, iFilename, bitmapIndex,
       
  3551            bitmapIndex + 1 );
       
  3552 
       
  3553         tabGroup->AddTabL(
       
  3554             loop, bitmap, bitmapMask );
       
  3555         }
       
  3556 
       
  3557     tabGroup->SetTabFixedWidthL(KTabWidthWithFourTabs);
       
  3558 
       
  3559     MCELOGGER_LEAVEFN("CreateTabsL()");
       
  3560     }
       
  3561 
       
  3562 // ----------------------------------------------------
       
  3563 // CMceUi::CheckRemoteMailboxTabIconsL
       
  3564 // ----------------------------------------------------
       
  3565 void CMceUi::CheckRemoteMailboxTabIconsL()
       
  3566     {
       
  3567     MCELOGGER_ENTERFN("CheckRemoteMailboxTabIconsL()");
       
  3568     __ASSERT_DEBUG( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ),
       
  3569         Panic( EMceUiErrTabsNotActivated ) );
       
  3570     __ASSERT_DEBUG( iTabsArray, Panic( EMceUiErrTabsArrayDoesNotAlreadyExist ) );
       
  3571     CAknTabGroup* tabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
       
  3572     const TInt count = iTabsArray->Count();
       
  3573     for ( TInt loop = 0; loop < count; loop++ )
       
  3574         {
       
  3575         TMsvId service;
       
  3576         TMsvEntry entry;
       
  3577         if ( iSession->GetEntry( (*iTabsArray)[loop], service, entry) == KErrNone  )
       
  3578             {
       
  3579             TInt bitmapIndex = KErrNotFound;
       
  3580             TAknsItemID id;
       
  3581             id.iMajor = 0;
       
  3582             id.iMinor = 0;
       
  3583             if ( ( entry.iMtm == KSenduiMtmImap4Uid
       
  3584             || entry.iMtm == KSenduiMtmPop3Uid ) )
       
  3585             {
       
  3586                 bitmapIndex = entry.Connected() ?
       
  3587                 EMbmMuiuQgn_prop_mce_remote_on_tab4 : EMbmMuiuQgn_prop_mce_remote_tab4;
       
  3588                 id = entry.Connected() ?
       
  3589                     KAknsIIDQgnPropMceRemoteOnTab4 : KAknsIIDQgnPropMceRemoteTab4;
       
  3590                 }
       
  3591             else if ( entry.iMtm == KSenduiMtmSyncMLEmailUid )
       
  3592                 {
       
  3593                 bitmapIndex = EMbmMuiuQgn_prop_sml_remote_tab4;
       
  3594                 id = KAknsIIDQgnPropSmlRemoteTab4;
       
  3595                 }
       
  3596 
       
  3597             if ( bitmapIndex > KErrNotFound )
       
  3598                 {
       
  3599                 MAknsSkinInstance* skins = AknsUtils::SkinInstance();
       
  3600                 CFbsBitmap* bitmap;
       
  3601                 CFbsBitmap* bitmapMask;
       
  3602 
       
  3603                 AknsUtils::CreateIconL( skins, id, bitmap,
       
  3604                     bitmapMask, iFilename, bitmapIndex, bitmapIndex + 1 );
       
  3605 
       
  3606                 tabGroup->ReplaceTabL(
       
  3607                     loop, bitmap, bitmapMask );
       
  3608                 }
       
  3609             }
       
  3610         }
       
  3611 
       
  3612     MCELOGGER_LEAVEFN("CheckRemoteMailboxTabIconsL()");
       
  3613     }
       
  3614 
       
  3615 // ----------------------------------------------------
       
  3616 // CMceUi::ShowTabsL
       
  3617 // ----------------------------------------------------
       
  3618 void CMceUi::ShowTabsL( TMsvId aOpenedId, TBool aOpeningDeliveryReports /* = EFalse */ )
       
  3619     {
       
  3620     MCELOGGER_ENTERFN("ShowTabsL()");
       
  3621 
       
  3622     if ( !iDecoratedTabGroup )
       
  3623         {
       
  3624         CreateTabsL();
       
  3625         }
       
  3626 
       
  3627     TInt selectedIndex;
       
  3628     if ( aOpeningDeliveryReports )
       
  3629         {
       
  3630         selectedIndex = iTabsArray->Find( KMceDeliveryReportsListIdValue );
       
  3631         }
       
  3632     else
       
  3633         {
       
  3634         selectedIndex = iTabsArray->Find( aOpenedId );
       
  3635         }
       
  3636 
       
  3637     CAknTabGroup* tabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl();
       
  3638     tabGroup->SetActiveTabByIndex( selectedIndex );
       
  3639     iNaviPane->PushL(*iDecoratedTabGroup);
       
  3640     iMceUiFlags.SetMceFlag( EMceUiFlagsTabsActive );
       
  3641     CheckRemoteMailboxTabIconsL();
       
  3642     MCELOGGER_LEAVEFN("ShowTabsL()");
       
  3643     }
       
  3644 
       
  3645 // ----------------------------------------------------
       
  3646 // CMceUi::RemoveTabs
       
  3647 // ----------------------------------------------------
       
  3648 void CMceUi::RemoveTabs()
       
  3649     {
       
  3650     MCELOGGER_ENTERFN("RemoveTabs()");
       
  3651     if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive ) )
       
  3652         {
       
  3653         iNaviPane->Pop();
       
  3654         iMceUiFlags.ClearMceFlag( EMceUiFlagsTabsActive );
       
  3655         }
       
  3656     MCELOGGER_LEAVEFN("RemoveTabs()");
       
  3657     }
       
  3658 
       
  3659 // ----------------------------------------------------
       
  3660 // CMceUi::RemoveTabsAndUpdateArray
       
  3661 // ----------------------------------------------------
       
  3662 void CMceUi::RemoveTabsAndUpdateArray()
       
  3663     {
       
  3664     MCELOGGER_ENTERFN("RemoveTabsAndUpdateArray()");
       
  3665     TBool tabsActive = iMceUiFlags.MceFlag( EMceUiFlagsTabsActive );
       
  3666     RemoveTabs();
       
  3667     delete iDecoratedTabGroup;
       
  3668     iDecoratedTabGroup = NULL;
       
  3669     delete iTabsArray;
       
  3670     iTabsArray = NULL;
       
  3671     
       
  3672     if ( tabsActive && MceViewActive( EMceMessageViewActive ) && iMceListView )
       
  3673         {
       
  3674         TRAP_IGNORE( ShowTabsL( iMceListView->ListContainer()->CurrentFolderId() ) );
       
  3675         }
       
  3676     MCELOGGER_LEAVEFN("RemoveTabsAndUpdateArray()");
       
  3677     }
       
  3678 
       
  3679 // ----------------------------------------------------
       
  3680 // CMceUi::CheckIAUpdate
       
  3681 // ----------------------------------------------------
       
  3682 void CMceUi::CheckIAUpdate()
       
  3683     {
       
  3684     TRAP_IGNORE(iMceIAUpdate->StartL( TUid::Uid( KMceApplicationUidValue ) ));
       
  3685     }
       
  3686 
       
  3687 // ----------------------------------------------------
       
  3688 // CMceUi::GoOnlineWithQueryL
       
  3689 // ----------------------------------------------------
       
  3690 void CMceUi::GoOnlineWithQueryL( TMsvId aAccount )
       
  3691     {
       
  3692     if ( AlwaysOnlineLastConnectionL( aAccount ) )
       
  3693         {
       
  3694         CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
  3695         if ( confDialog->ExecuteLD( R_MCE_GO_ONLINE_CONFIRMATION ) )
       
  3696             {
       
  3697             ChangeServiceConnectionStateL( aAccount, ETrue);
       
  3698             }
       
  3699         }
       
  3700     }
       
  3701 
       
  3702 // ----------------------------------------------------
       
  3703 // CMceUi::GoOnlineL
       
  3704 // ----------------------------------------------------
       
  3705 void CMceUi::GoOnlineL( TMsvId aAccount )
       
  3706     {
       
  3707     MCELOGGER_ENTERFN("GoOnlineL()");
       
  3708     ChangeServiceConnectionStateL( aAccount, ETrue);
       
  3709     MCELOGGER_LEAVEFN("GoOnlineL()");
       
  3710     }
       
  3711 
       
  3712 // ----------------------------------------------------
       
  3713 // CMceUi::CloseConnectionWithListQueryL
       
  3714 // ----------------------------------------------------
       
  3715 void CMceUi::CloseConnectionWithListQueryL()
       
  3716     {
       
  3717     CMsvEntrySelection* connectedAccounts = ConnectedServicesLC();
       
  3718     const TInt numberOfConnectedMailboxes = connectedAccounts->Count();
       
  3719     TInt closeConnection = KErrNotFound;
       
  3720 
       
  3721     if ( numberOfConnectedMailboxes > 0 )
       
  3722         {
       
  3723         if ( numberOfConnectedMailboxes == 1 )
       
  3724             {
       
  3725             closeConnection = 0;
       
  3726             }
       
  3727         else
       
  3728             {
       
  3729             CDesCArrayFlat* items = new(ELeave)CDesCArrayFlat( KMceArrayGranularity );
       
  3730             CleanupStack::PushL( items );
       
  3731             for (TInt loop = 0; loop < numberOfConnectedMailboxes; loop++)
       
  3732                 {
       
  3733                 const TMsvEntry& tentry=iRootEntry->ChildDataL( connectedAccounts->At( loop ) );
       
  3734                 items->AppendL( tentry.iDetails.Left( iBitmapResolver->DescriptionLength() ) );
       
  3735                 }
       
  3736 
       
  3737             CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog(&closeConnection);
       
  3738             dlg->PrepareLC( R_MCE_LIST_QUERY );
       
  3739             dlg->SetItemTextArray( items );
       
  3740             dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  3741             if( !dlg->RunLD() )
       
  3742                 {
       
  3743                 closeConnection = KErrNotFound;
       
  3744                 }
       
  3745             CleanupStack::PopAndDestroy( items );
       
  3746             }
       
  3747 
       
  3748         if ( closeConnection != KErrNotFound )
       
  3749             {
       
  3750             GoOfflineL( connectedAccounts->At( closeConnection ) );
       
  3751             }
       
  3752         }
       
  3753     CleanupStack::PopAndDestroy(); // connectedAccounts
       
  3754 
       
  3755     }
       
  3756 
       
  3757 // ----------------------------------------------------
       
  3758 // CMceUi::GoOfflineL
       
  3759 // ----------------------------------------------------
       
  3760 void CMceUi::GoOfflineL( TMsvId aAccount )
       
  3761     {
       
  3762     MCELOGGER_ENTERFN("GoOfflineL()");
       
  3763     TMsvEntry tentry;
       
  3764     GetEntryL( aAccount, tentry );
       
  3765     if ( tentry.Connected() )
       
  3766         {
       
  3767         ChangeServiceConnectionStateL( aAccount, EFalse );
       
  3768         }
       
  3769     MCELOGGER_LEAVEFN("GoOfflineL()");
       
  3770     }
       
  3771 
       
  3772 // ----------------------------------------------------
       
  3773 // CMceUi::ChangeServiceConnectionStateL
       
  3774 // ----------------------------------------------------
       
  3775 void CMceUi::ChangeServiceConnectionStateL(TMsvId aServiceId, TBool aConnect)
       
  3776     {
       
  3777     MCELOGGER_ENTERFN("ChangeServiceConnectionStateL()");
       
  3778 
       
  3779     if ( aConnect )
       
  3780         {
       
  3781         LeaveIfDiskSpaceUnderCriticalLevelL();
       
  3782         }
       
  3783 
       
  3784     TMsvEntry tentry;
       
  3785     (void)GetEntryL(aServiceId, tentry);
       
  3786     CBaseMtmUi& ui = iMtmStore->GetMtmUiAndSetContextLC(tentry);
       
  3787     CMsvOperation* op;
       
  3788     CAknInputBlock::NewLC();
       
  3789 
       
  3790     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  3791     CleanupStack::PushL( singleOpWatcher );
       
  3792 
       
  3793     if ( aConnect )
       
  3794         {
       
  3795         op = ui.OpenL( singleOpWatcher->iStatus );
       
  3796         if ( tentry.iMtm != KSenduiMtmImap4Uid )
       
  3797             {
       
  3798             SetViewUpdateSuppressionFlag( ETrue, op );
       
  3799             }
       
  3800         if ( iAlwaysOnline && op )
       
  3801             {
       
  3802             AddOperationIdL( op->Id(), aServiceId );
       
  3803             }
       
  3804         }
       
  3805     else
       
  3806         {
       
  3807         op = ui.CloseL( singleOpWatcher->iStatus );
       
  3808         if ( iAlwaysOnline && op )
       
  3809            {
       
  3810            RemoveOperationId( op->Id(), aServiceId );
       
  3811            }
       
  3812         }
       
  3813 
       
  3814     CleanupStack::PushL( op );
       
  3815 
       
  3816     iOperations.AppendL( singleOpWatcher );
       
  3817     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  3818     singleOpWatcher->SetOperation( op );
       
  3819     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3820 
       
  3821     CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, release mtmUi
       
  3822     if ( iMceListView->ListContainer() && 
       
  3823         ( MceViewActive(EMceMessageViewActive ) ) )
       
  3824         {
       
  3825         if ( aConnect )
       
  3826             {
       
  3827             iMceListView->ListContainer()->SetAnchorItemIdL(
       
  3828                 CMceMessageListContainerBase::EMessageListOperationConnect );
       
  3829             }
       
  3830         else
       
  3831             {
       
  3832             iMceListView->ListContainer()->SetAnchorItemIdL(
       
  3833                 CMceMessageListContainerBase::EMessageListOperationGeneral );
       
  3834             }
       
  3835         }
       
  3836 
       
  3837     MCELOGGER_LEAVEFN("ChangeServiceConnectionStateL()");
       
  3838     }
       
  3839 
       
  3840 // ----------------------------------------------------
       
  3841 // CMceUi::GetEntryL
       
  3842 // ----------------------------------------------------
       
  3843 TMsvId CMceUi::GetEntryL(TMsvId aId, TMsvEntry& aEntry) const
       
  3844     {
       
  3845     TMsvId service;
       
  3846     User::LeaveIfError(iSession->GetEntry(aId, service, aEntry));
       
  3847     return service;
       
  3848     }
       
  3849 
       
  3850 // ----------------------------------------------------
       
  3851 // CMceUi::SendSelectionL
       
  3852 // ----------------------------------------------------
       
  3853 void CMceUi::SendSelectionL(CMsvEntrySelection* aSel)
       
  3854     {
       
  3855     CleanupStack::PushL(aSel);
       
  3856     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  3857     CleanupStack::Pop( aSel ); 
       
  3858     CleanupStack::PushL( singleOpWatcher ); // guaranteed not to leave because of previous pop
       
  3859 
       
  3860     CMsvOperation* op = CMceSendOperation::NewL(
       
  3861         *iSession, singleOpWatcher->iStatus, *iMtmStore, aSel );
       
  3862         // aSel will be deleted!
       
  3863 
       
  3864     CleanupStack::PushL( op );
       
  3865     iOperations.AppendL( singleOpWatcher );
       
  3866     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  3867     singleOpWatcher->SetOperation( op );
       
  3868     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3869     }
       
  3870 
       
  3871 // ----------------------------------------------------
       
  3872 // CMceUi::SendNowL
       
  3873 // ----------------------------------------------------
       
  3874 void CMceUi::SendNowL()
       
  3875     {
       
  3876 
       
  3877     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  3878         ->CurrentItemSelectionL();
       
  3879     if ( selection->Count() == 0 )
       
  3880         {
       
  3881         delete selection;
       
  3882         return;
       
  3883         }
       
  3884 
       
  3885     CleanupStack::PushL( selection );
       
  3886 
       
  3887     // if we are sending email just ignore offline checks
       
  3888     iEntry->SetEntryL( (*selection)[0] );
       
  3889     const TMsvEntry& entry = iEntry->Entry();
       
  3890 
       
  3891     if ( entry.iMtm != KSenduiMtmSmtpUid &&
       
  3892         FeatureManager::FeatureSupported( KFeatureIdOfflineMode ))
       
  3893         {
       
  3894         // check if offline mode has been set
       
  3895         TInt offline = 1;
       
  3896 
       
  3897         CRepository* repository = NULL;
       
  3898         TRAPD( ret, repository = CRepository::NewL(KCRUidCoreApplicationUIs) );
       
  3899         CleanupStack::PushL( repository );
       
  3900 
       
  3901         if ( ret == KErrNone )
       
  3902             {
       
  3903             if ( repository->Get(KCoreAppUIsNetworkConnectionAllowed,offline) != KErrNone )
       
  3904                 {
       
  3905                 offline = 1;
       
  3906                 }
       
  3907             }
       
  3908 
       
  3909         CleanupStack::Pop( repository );
       
  3910         delete repository;
       
  3911 
       
  3912         if ( !offline )
       
  3913             {
       
  3914             // offline mode has been set
       
  3915             HBufC* text = StringLoader::LoadLC( R_MCE_OFFLINE_NOT_POSSIBLE, CCoeEnv::Static() );
       
  3916             CAknInformationNote* note = new (ELeave) CAknInformationNote();
       
  3917             note->ExecuteLD(*text);
       
  3918             CleanupStack::PopAndDestroy(2); //text, selection
       
  3919             return;
       
  3920             }
       
  3921 
       
  3922         }
       
  3923 
       
  3924     CleanupStack::Pop( selection ); // this is because SendSelectionL pushes selection immediately
       
  3925     SendSelectionL( selection );
       
  3926     }
       
  3927 
       
  3928 // ----------------------------------------------------
       
  3929 // CMceUi::CancelSendingL
       
  3930 // ----------------------------------------------------
       
  3931 void CMceUi::CancelSendingL()
       
  3932     {
       
  3933     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  3934         ->CurrentItemSelectionL();
       
  3935     CleanupStack::PushL( selection );
       
  3936 
       
  3937     if ( selection->Count() == 0 ||
       
  3938          IsMessageSendingL( selection->At(0) ) )
       
  3939         {
       
  3940         CleanupStack::PopAndDestroy( selection );
       
  3941         return;
       
  3942         }
       
  3943 
       
  3944     CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  3945     CleanupStack::PushL( singleOpWatcher );
       
  3946 
       
  3947     CMsvOperation* op = CMceCancelSendingOperation::NewL(
       
  3948         *iSession,
       
  3949         singleOpWatcher->iStatus,
       
  3950         selection->At( 0 ),
       
  3951         CMceCancelSendingOperation::ECancelOnly,
       
  3952         *iMtmStore );
       
  3953 
       
  3954     CleanupStack::PushL( op );
       
  3955     iOperations.AppendL( singleOpWatcher );
       
  3956     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  3957     singleOpWatcher->SetOperation( op );
       
  3958     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  3959 
       
  3960     CleanupStack::PopAndDestroy( selection );
       
  3961     }
       
  3962 
       
  3963 // ----------------------------------------------------
       
  3964 // CMceUi::FetchNewL
       
  3965 // ----------------------------------------------------
       
  3966 void CMceUi::FetchNewL()
       
  3967     {
       
  3968     DoAsyncFunctionOnCurrentContextL( KMtmUiFunctionFetchNew );
       
  3969     iMceListView->ListContainer()->SetAnchorItemIdL(
       
  3970         CMceMessageListContainerBase::EMessageListOperationFetchNew );
       
  3971     }
       
  3972 
       
  3973 // ----------------------------------------------------
       
  3974 // CMceUi::FetchSelectedL
       
  3975 // ----------------------------------------------------
       
  3976 void CMceUi::FetchSelectedL()
       
  3977     {
       
  3978     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  3979         Panic( EMceUiErrCannotFetchFromMainView ) );
       
  3980     if ( MceViewActive( EMceMainViewActive ) )
       
  3981         {
       
  3982         return;
       
  3983         }
       
  3984 
       
  3985     CMsvEntrySelection* sel = iMceListView->ListContainer()
       
  3986         ->CurrentItemSelectionL();
       
  3987 
       
  3988     if ( sel->Count() == 0 )
       
  3989         {
       
  3990         delete sel;
       
  3991         return;
       
  3992         }
       
  3993 
       
  3994     CleanupStack::PushL( sel );
       
  3995 
       
  3996     iMceListView->ListContainer()->SetAnchorItemIdL(
       
  3997         CMceMessageListContainerBase::EMessageListOperationFetchSelected );
       
  3998     DoAsyncFunctionOnCurrentContextL(KMtmUiFunctionFetchSelected, *sel);
       
  3999     CleanupStack::PopAndDestroy( sel );
       
  4000     }
       
  4001 
       
  4002 // ----------------------------------------------------
       
  4003 // CMceUi::FetchAllL
       
  4004 // ----------------------------------------------------
       
  4005 void CMceUi::FetchAllL()
       
  4006     {
       
  4007     DoAsyncFunctionOnCurrentContextL(KMtmUiFunctionFetchAll);
       
  4008     iMceListView->ListContainer()->SetAnchorItemIdL(
       
  4009         CMceMessageListContainerBase::EMessageListOperationFetchSelected );
       
  4010     }
       
  4011 
       
  4012 // ----------------------------------------------------
       
  4013 // CMceUi::DoAsyncFunctionOnCurrentContextL
       
  4014 // ----------------------------------------------------
       
  4015 void CMceUi::DoAsyncFunctionOnCurrentContextL(TInt aFunctionId)
       
  4016     {
       
  4017     CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
  4018     CleanupStack::PushL( sel );
       
  4019 
       
  4020     DoAsyncFunctionOnCurrentContextL(aFunctionId, *sel);
       
  4021 
       
  4022     CleanupStack::PopAndDestroy( sel );
       
  4023     }
       
  4024 
       
  4025 // ----------------------------------------------------
       
  4026 // CMceUi::DoAsyncFunctionOnCurrentContextL
       
  4027 // ----------------------------------------------------
       
  4028 void CMceUi::DoAsyncFunctionOnCurrentContextL(TInt aFunctionId, CMsvEntrySelection& aSelection)
       
  4029     {
       
  4030     DoAsyncFunctionL(aFunctionId, aSelection, iMceListView->ListContainer()->FolderEntry());
       
  4031     }
       
  4032 
       
  4033 // ----------------------------------------------------
       
  4034 // CMceUi::DoAsyncFunctionL
       
  4035 // ----------------------------------------------------
       
  4036 void CMceUi::DoAsyncFunctionL(TInt aFunctionId, const TMsvEntry& aContext)
       
  4037     {
       
  4038     CMsvEntrySelection* sel= new (ELeave) CMsvEntrySelection();
       
  4039     CleanupStack::PushL( sel );
       
  4040     DoAsyncFunctionL(aFunctionId, *sel, aContext);
       
  4041     CleanupStack::PopAndDestroy( sel );
       
  4042     }
       
  4043 
       
  4044 // ----------------------------------------------------
       
  4045 // CMceUi::DoAsyncFunctionL
       
  4046 // ----------------------------------------------------
       
  4047 void CMceUi::DoAsyncFunctionL( TInt aFunctionId, CMsvEntrySelection& aSelection,
       
  4048     const TMsvEntry& aContext)
       
  4049     {
       
  4050     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  4051 
       
  4052     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiAndSetContextLC( aContext );
       
  4053 
       
  4054     TBuf8<1> blankParams;
       
  4055     CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  4056     CleanupStack::PushL( singleOpWatcher );
       
  4057 
       
  4058     CMsvOperation* op = mtmUi.InvokeAsyncFunctionL( aFunctionId, aSelection,
       
  4059         singleOpWatcher->iStatus, blankParams );
       
  4060 
       
  4061     if ( CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, aContext.iMtm ) &&
       
  4062          (aFunctionId == KMtmUiFunctionFetchNew ||
       
  4063           aFunctionId == KMtmUiFunctionFetchAll 
       
  4064         ))
       
  4065         {
       
  4066         SetViewUpdateSuppressionFlag( ETrue, op );   
       
  4067         }
       
  4068 
       
  4069     if ( iAlwaysOnline && op )
       
  4070         {
       
  4071         TMsvEntry tEntry;
       
  4072         TMsvId serviceId;
       
  4073         User::LeaveIfError( iSession->GetEntry( aContext.iServiceId, serviceId, tEntry ) );
       
  4074         if ( !tEntry.Connected() )
       
  4075             {
       
  4076             AddOperationIdL( op->Id(), serviceId );
       
  4077             }
       
  4078         }
       
  4079 
       
  4080     CleanupStack::PushL( op );
       
  4081     iOperations.AppendL( singleOpWatcher );
       
  4082     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  4083     singleOpWatcher->SetOperation( op );
       
  4084 
       
  4085     if ( aFunctionId == KMtmUiFunctionFetchNew )
       
  4086         {
       
  4087         iFetchNewOperation = singleOpWatcher;
       
  4088         }
       
  4089 
       
  4090     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  4091 
       
  4092     CleanupStack::PopAndDestroy(); // release mtmUI
       
  4093     iMceListView->ListContainer()->ClearSelection();
       
  4094     }
       
  4095 
       
  4096 // ----------------------------------------------------
       
  4097 // CMceUi::AddMTMFunctionsL
       
  4098 // ----------------------------------------------------
       
  4099 void CMceUi::AddMTMFunctionsL(CEikMenuPane& aMenuPane, TInt aMenuCommandId)
       
  4100     {
       
  4101     MCELOGGER_ENTERFN("AddMTMFunctionsL()");
       
  4102     TMsvEntry selectedEntry;
       
  4103     TBool foundSelectedEntry = GetCurrentEntryL( selectedEntry );
       
  4104     TMsvEntry openedEntry;
       
  4105     TBool foundOpenedEntry = GetCurrentEntryL( openedEntry, ETrue );
       
  4106 
       
  4107     CEikMenuPaneItem::SData data;
       
  4108     data.iCascadeId=0;
       
  4109     data.iFlags=0;
       
  4110     TInt cc;
       
  4111     TInt sendCmd = EMceCmdFirstMTMFunction;
       
  4112     const TInt count = iMTMFunctionsArray->Count();
       
  4113     for ( cc = 0; cc < count; cc++ )
       
  4114         {
       
  4115         TMsgFunctionInfo& functionInfo = iMTMFunctionsArray->At(cc);
       
  4116         data.iText = functionInfo.iCaption;
       
  4117         data.iCommandId = sendCmd;
       
  4118         if ( functionInfo.iFlags & EMtudContextSpecific )
       
  4119             {
       
  4120             if ( ( foundSelectedEntry && !CheckCommandAvailableL( sendCmd, selectedEntry ) ) ||
       
  4121                  ( foundOpenedEntry && !CheckCommandAvailableL( sendCmd, openedEntry ) )
       
  4122                 )
       
  4123                 {
       
  4124                 if ( functionInfo.iFuncId == KMtmUiFunctionMessageInfo )
       
  4125                     {
       
  4126 					sendCmd++;
       
  4127 					continue;
       
  4128                     }
       
  4129 
       
  4130                 else if ( functionInfo.iFuncId == KMtmUiFunctionDeliveryStatus )
       
  4131                     {
       
  4132                     data.iFlags |= EEikMenuItemSpecific;               
       
  4133                     aMenuPane.AddMenuItemL( data, EMceCmdUndelete );
       
  4134                     }
       
  4135 
       
  4136                 else if ( functionInfo.iFuncId == KMtmUiFunctionFetchMMS ) //MMS notification
       
  4137                     {
       
  4138                     data.iFlags |= EEikMenuItemSpecific; 
       
  4139                     aMenuPane.AddMenuItemL( data, EAknCmdOpen );
       
  4140                     }
       
  4141 
       
  4142                 else if ( functionInfo.iFuncId == KMtmUiFunctionFetchSyncML ) //SyncML Retrieve
       
  4143                     {
       
  4144                     if ( selectedEntry.iMtm == KSenduiMtmSyncMLEmailUid )
       
  4145                         {
       
  4146                         aMenuPane.AddMenuItemL( data, EAknCmdOpen );
       
  4147                         }
       
  4148                     else
       
  4149                         {
       
  4150                         // nothing is added
       
  4151                         }
       
  4152                     }
       
  4153 
       
  4154                 else if ( functionInfo.iFuncId == KMtmUiFunctionMMBox )
       
  4155                     {
       
  4156                     aMenuPane.AddMenuItemL( data, EAknCmdOpen );
       
  4157                     }
       
  4158 
       
  4159                 else
       
  4160                     {
       
  4161                     // Following comparison added to hide MCE's Mark as read/Unread 
       
  4162                     // as duplicate copy of same options was provided by Visto MTM
       
  4163                     CCoeEnv* ownEikonEnvmak = CEikonEnv::Static();
       
  4164                     HBufC* markasRead = ownEikonEnvmak->AllocReadResourceLC( R_QTN_MCE_MARKAS_READ );
       
  4165                     TBufC<30> bufread(markasRead->Des());
       
  4166                     HBufC* markasUnRead = ownEikonEnvmak->AllocReadResourceLC( R_QTN_MCE_MARKAS_UNREAD );
       
  4167                     TBufC<30> bufUnread(markasUnRead->Des());
       
  4168                     CleanupStack::PopAndDestroy(2); //markasUnRead, markasRead
       
  4169                     if(functionInfo.iFuncId == KMtmUiFunctionMarkAsRead)
       
  4170                         {
       
  4171                         iMceListView->SetMarkReadUnread( ETrue );
       
  4172                         }
       
  4173                     aMenuPane.AddMenuItemL( data, aMenuCommandId );
       
  4174                     }
       
  4175                 }
       
  4176             }
       
  4177         else
       
  4178             {
       
  4179             if ( MceViewActive( EMceMainViewActive ) && !CheckMTMFunctionL( functionInfo, selectedEntry ) )
       
  4180                 {
       
  4181                 aMenuPane.AddMenuItemL( data, aMenuCommandId );
       
  4182                 }
       
  4183             }
       
  4184         sendCmd++;
       
  4185         }
       
  4186     MCELOGGER_LEAVEFN("AddMTMFunctionsL()");
       
  4187     }
       
  4188 
       
  4189 // ----------------------------------------------------
       
  4190 // CMceUi::CheckMTMFunctionL
       
  4191 // ----------------------------------------------------
       
  4192 TInt CMceUi::CheckMTMFunctionL( const TMsgFunctionInfo& aFunction, TMsvEntry& aEntryToCheck )
       
  4193     {
       
  4194     TInt functionAvailable = KErrNotFound;
       
  4195 
       
  4196     CBaseMtmUiData* uiData = NULL;
       
  4197 
       
  4198     if ( MceViewActive( EMceMainViewActive ) )
       
  4199         {
       
  4200         if ( !( aFunction.iFlags & EMtudContextSpecific ) )
       
  4201             {
       
  4202             uiData = GetMtmUiDataL( aFunction.iMtmUid );
       
  4203             if ( uiData )
       
  4204                 {
       
  4205                 functionAvailable = uiData->OperationSupportedL(aFunction.iFuncId, aEntryToCheck);
       
  4206                 }
       
  4207             }
       
  4208         }
       
  4209     else
       
  4210         {
       
  4211         if ( aFunction.iMtmUid == aEntryToCheck.iMtm )
       
  4212             {
       
  4213             uiData = GetMtmUiDataL( aFunction.iMtmUid );
       
  4214             }
       
  4215 
       
  4216         if ( aFunction.iFlags & EMtudContextSpecific )
       
  4217             {
       
  4218             if ( uiData )
       
  4219                 {
       
  4220                 functionAvailable =
       
  4221                     uiData->OperationSupportedL(aFunction.iFuncId, aEntryToCheck);
       
  4222                 }
       
  4223             }
       
  4224         else if ( aFunction.iFlags & EMtudRemoteOnly )
       
  4225             {
       
  4226             if ( uiData &&
       
  4227                  aEntryToCheck.iMtm != KUidMsvLocalServiceMtm )
       
  4228                 {
       
  4229                 functionAvailable =
       
  4230                     uiData->OperationSupportedL(aFunction.iFuncId, aEntryToCheck);
       
  4231                 }
       
  4232             }
       
  4233         }
       
  4234 
       
  4235     return functionAvailable;
       
  4236     }
       
  4237 
       
  4238 // ----------------------------------------------------
       
  4239 // CMceUi::GetCurrentEntryL
       
  4240 // ----------------------------------------------------
       
  4241 TBool CMceUi::GetCurrentEntryL(TMsvEntry& aEntry, TBool aOpenedFolder /*= EFalse*/) const
       
  4242     {
       
  4243     MCELOGGER_ENTERFN("GetCurrentEntryL()");
       
  4244 
       
  4245     TMsvId cursorId = KErrNotFound;
       
  4246 
       
  4247     if ( MceViewActive( EMceMainViewActive ) )
       
  4248         {
       
  4249         cursorId = iMceMainView->ListContainer()->CurrentItemId();
       
  4250         }
       
  4251     else
       
  4252         {
       
  4253         if ( aOpenedFolder )
       
  4254             {
       
  4255             cursorId = iMceListView->ListContainer()->CurrentFolderId();
       
  4256             }
       
  4257         else
       
  4258             {
       
  4259             if ( iMceListView->ListContainer()->CurrentItemSelectionCount() == 1 )
       
  4260                 {
       
  4261                 CMsvEntrySelection* selection =
       
  4262                     iMceListView->ListContainer()->CurrentItemSelectionL();
       
  4263                 cursorId = selection->At(0);
       
  4264                 delete selection;
       
  4265                 }
       
  4266             else
       
  4267                 {
       
  4268                 cursorId = KErrNotFound;
       
  4269                 }
       
  4270             }
       
  4271         }
       
  4272 
       
  4273     if ( cursorId == KErrNotFound )
       
  4274         {
       
  4275         MCELOGGER_LEAVEFN("GetCurrentEntryL() selected entry not found");
       
  4276         return EFalse;
       
  4277         }
       
  4278 
       
  4279     TMsvId service;
       
  4280     const TInt err = iSession->GetEntry(cursorId, service, aEntry);
       
  4281 
       
  4282     if ( err != KErrNone && err != KErrNotFound )
       
  4283         {
       
  4284         User::Leave( err );
       
  4285         }
       
  4286 
       
  4287     MCELOGGER_LEAVEFN("GetCurrentEntryL()");
       
  4288     return ( err == KErrNone );
       
  4289     }
       
  4290 
       
  4291 // ----------------------------------------------------
       
  4292 // CMceUi::CheckCommandAvailableL
       
  4293 // ----------------------------------------------------
       
  4294 TInt CMceUi::CheckCommandAvailableL( TInt aCommand, TMsvEntry& aEntryToCheck )
       
  4295     {
       
  4296     TInt rid = 0; // command is available
       
  4297 
       
  4298     const TBool remoteContext =
       
  4299         aEntryToCheck.iServiceId != KMsvLocalServiceIndexEntryId;
       
  4300 
       
  4301     switch ( aCommand )
       
  4302         {
       
  4303         case EMceCmdUndelete:
       
  4304             if ( remoteContext )
       
  4305                 {
       
  4306                 CBaseMtmUiData* uiData = GetMtmUiDataL( aEntryToCheck.iMtm );
       
  4307                 if ( !uiData || !uiData->CanUnDeleteFromEntryL(aEntryToCheck, rid) && !rid )
       
  4308                     {
       
  4309                     rid = KErrNotSupported;
       
  4310                     }
       
  4311                 }
       
  4312             break;
       
  4313 
       
  4314         case EMceCmdReply:
       
  4315             {
       
  4316             CBaseMtmUiData* uiData = GetMtmUiDataL( aEntryToCheck.iMtm );
       
  4317             if ( !uiData || !uiData->CanReplyToEntryL(aEntryToCheck, rid) )
       
  4318                 {
       
  4319                 rid = KErrNotSupported;
       
  4320                 }
       
  4321             else
       
  4322                 {
       
  4323                 if ( aEntryToCheck.iMtm == KSenduiMtmSmsUid || aEntryToCheck.iMtm == KSenduiMtmBioUid 
       
  4324                      || aEntryToCheck.iMtm == KSenduiMtmMmsUid || aEntryToCheck.iMtm == KSenduiMMSNotificationUid )
       
  4325                     {
       
  4326                     if ( !MceUtils::ValidPhoneNumberL( aEntryToCheck.Id(), *iSession ) )
       
  4327                         {
       
  4328                         rid = KErrNotSupported;
       
  4329                         }
       
  4330                     }
       
  4331                 
       
  4332                 }
       
  4333             }
       
  4334             break;
       
  4335          
       
  4336         case EMceCmdForward:
       
  4337             {
       
  4338             CBaseMtmUiData* uiData = GetMtmUiDataL( aEntryToCheck.iMtm );
       
  4339             if ( !uiData || !uiData->CanForwardEntryL( aEntryToCheck, rid ) )
       
  4340                 {
       
  4341                 rid = KErrNotSupported;
       
  4342                 }
       
  4343             }
       
  4344             break;   
       
  4345             
       
  4346         default:
       
  4347             if (aCommand >= EMceCmdFirstMTMFunction)
       
  4348                 {
       
  4349                 rid = CheckMTMFunctionL(
       
  4350                     iMTMFunctionsArray->At( aCommand-EMceCmdFirstMTMFunction ), aEntryToCheck );
       
  4351                 }
       
  4352             else
       
  4353                 {
       
  4354                 rid = KErrNotSupported;
       
  4355                 }
       
  4356             break;
       
  4357         };
       
  4358 
       
  4359     return rid;
       
  4360     }
       
  4361 
       
  4362 // ----------------------------------------------------
       
  4363 // CMceUi::CheckCommandAvailableL
       
  4364 // ----------------------------------------------------
       
  4365 TInt CMceUi::CheckCommandAvailableL( TInt aCommand, CMsvEntrySelection* aEntriesToCheck )
       
  4366     {
       
  4367     __ASSERT_DEBUG( aEntriesToCheck, Panic( EMceUiErrArrayEmpty ) );
       
  4368     TInt rid = 0; // command is available
       
  4369     if ( !aEntriesToCheck || aEntriesToCheck->Count() == 0 )
       
  4370         {
       
  4371 #if defined(_DEBUG)
       
  4372         Panic(EMceUiErrArrayEmpty);
       
  4373 #endif
       
  4374         return KErrNotSupported;
       
  4375         }
       
  4376 
       
  4377     TMsvEntry entry;
       
  4378     TMsvId serviceId;
       
  4379     TMsvId id = (*aEntriesToCheck)[0];
       
  4380 
       
  4381     if ( iSession->GetEntry( id, serviceId, entry ) != KErrNone )
       
  4382         {
       
  4383         return KErrNotSupported;
       
  4384         }
       
  4385 
       
  4386     if (aCommand >= EMceCmdFirstMTMFunction)
       
  4387         {
       
  4388         rid = KErrNotSupported;
       
  4389         }
       
  4390     else if ( aCommand == EMceCmdUndelete )
       
  4391         {
       
  4392         if ( entry.iServiceId != KMsvLocalServiceIndexEntryId )
       
  4393             {
       
  4394             CBaseMtmUiData* uiData = GetMtmUiDataL( entry.iMtm );
       
  4395             TBool canUndelete = EFalse;
       
  4396             if ( uiData )
       
  4397                 {
       
  4398                 const TInt count = aEntriesToCheck->Count();
       
  4399                 for ( TInt loop = 0; loop < count && !canUndelete; loop++ )
       
  4400                     {
       
  4401                     id = (*aEntriesToCheck)[loop];
       
  4402                     if ( iSession->GetEntry( id, serviceId, entry ) == KErrNone &&
       
  4403                          uiData->CanUnDeleteFromEntryL(entry, rid) )
       
  4404                         {
       
  4405                         canUndelete = ETrue;
       
  4406                         }
       
  4407                     }
       
  4408                 }
       
  4409             rid = canUndelete;
       
  4410             }
       
  4411         else
       
  4412             {
       
  4413             rid = KErrNotSupported;
       
  4414             }
       
  4415         }
       
  4416 
       
  4417     return rid;
       
  4418     }
       
  4419 
       
  4420 
       
  4421 // ----------------------------------------------------
       
  4422 // CMceUi::HandleMTMFunctionL
       
  4423 // ----------------------------------------------------
       
  4424 void CMceUi::HandleMTMFunctionL(const TMsgFunctionInfo& aFunction)
       
  4425     {
       
  4426     MCELOGGER_ENTERFN("HandleMTMFunctionL()");
       
  4427 
       
  4428     CMsvEntrySelection* sel = NULL;
       
  4429     if ( MceViewActive( EMceMainViewActive ) )
       
  4430         {
       
  4431         sel = new ( ELeave ) CMsvEntrySelection();
       
  4432         CleanupStack::PushL( sel );
       
  4433         sel->AppendL( iMceMainView->ListContainer()->CurrentItemId() );
       
  4434         }
       
  4435     else
       
  4436         {
       
  4437         sel = iMceListView->ListContainer()->CurrentItemSelectionRefreshL();
       
  4438         CleanupStack::PushL( sel );
       
  4439         }
       
  4440 
       
  4441 
       
  4442     TMsvId contextId = KMsvNullIndexEntryId;
       
  4443     if ( aFunction.iFlags&EMtudContextSpecific )
       
  4444         {
       
  4445         if ( sel->Count() != 0 )
       
  4446             {
       
  4447             contextId = (*sel)[0];
       
  4448             TMsvId service;
       
  4449             TMsvEntry entry;
       
  4450             if ( iSession->GetEntry( contextId, service, entry) != KErrNone ||
       
  4451                 entry.iMtm != aFunction.iMtmUid )
       
  4452                 {
       
  4453                 contextId = KMsvNullIndexEntryId;
       
  4454                 }
       
  4455             }
       
  4456         if ( contextId == KMsvNullIndexEntryId )
       
  4457             {
       
  4458             CleanupStack::PopAndDestroy( sel );
       
  4459             return;
       
  4460             }
       
  4461         }
       
  4462 
       
  4463     CAknInputBlock::NewLC();
       
  4464 
       
  4465     CBaseMtmUi& mtmUi=iMtmStore->GetMtmUiLC(aFunction.iMtmUid);
       
  4466     CBaseMtm&   mtm=mtmUi.BaseMtm();
       
  4467     if (aFunction.iFlags&EMtudContextSpecific)
       
  4468         {
       
  4469         if (mtm.HasContext())
       
  4470             {
       
  4471             mtm.SwitchCurrentEntryL(contextId);
       
  4472             }
       
  4473         else
       
  4474             {
       
  4475             CMsvEntry* centry=iSession->GetEntryL(contextId);
       
  4476             mtm.SetCurrentEntryL(centry);
       
  4477             }
       
  4478         }
       
  4479 
       
  4480     TBool tabsToCleanupStack = EFalse;
       
  4481 
       
  4482     if ( iMceUiFlags.MceFlag( EMceUiFlagsTabsActive )
       
  4483         && aFunction.iFuncId != KMtmUiFunctionMessageInfo )
       
  4484         {
       
  4485         // must remove tabs because if no mailboxes created then
       
  4486         // mailbox settings dialog is displayed and tabs should not be shown then.
       
  4487         RemoveTabs();
       
  4488         CleanupStack::PushL( TCleanupItem( ShowTabs, this ) );
       
  4489         tabsToCleanupStack = ETrue;
       
  4490         }
       
  4491 
       
  4492     TBuf8<1> buf;
       
  4493     if (!(aFunction.iFlags&EMtudAsynchronous))
       
  4494         {
       
  4495         if(aFunction.iFuncId == KMtmUiFunctionSimDialog)
       
  4496             {
       
  4497             iSimDialogOpen = ETrue;
       
  4498             }
       
  4499         mtmUi.InvokeSyncFunctionL(aFunction.iFuncId, *sel, buf);
       
  4500         }
       
  4501     else
       
  4502         {
       
  4503         CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  4504         CleanupStack::PushL( singleOpWatcher );
       
  4505 
       
  4506         CMsvOperation* op=mtmUi.InvokeAsyncFunctionL( aFunction.iFuncId, *sel,
       
  4507             singleOpWatcher->iStatus, buf );
       
  4508 
       
  4509         if ( op )
       
  4510             {
       
  4511             CleanupStack::PushL( op );
       
  4512             iOperations.AppendL( singleOpWatcher );
       
  4513             CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  4514             singleOpWatcher->SetOperation( op );
       
  4515             MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  4516             }
       
  4517         else
       
  4518             {
       
  4519             CleanupStack::PopAndDestroy( singleOpWatcher );
       
  4520             }
       
  4521         }
       
  4522 
       
  4523     if ( tabsToCleanupStack )
       
  4524         {
       
  4525         CleanupStack::PopAndDestroy(); // TCleanupItem - will show tabs again
       
  4526         }
       
  4527 
       
  4528     CleanupStack::PopAndDestroy(3, sel);// sel, CAknInputBlock, release mtmUi
       
  4529 
       
  4530     MCELOGGER_LEAVEFN("HandleMTMFunctionL()");
       
  4531     }
       
  4532 
       
  4533 // ----------------------------------------------------
       
  4534 // CMceUi::SetMceViewActive
       
  4535 // ----------------------------------------------------
       
  4536 void CMceUi::SetMceViewActive( TUint aActiveView )
       
  4537     {
       
  4538     iMceActiveView = aActiveView;
       
  4539     if ( aActiveView & EMceDeliveryReportsViewActive )
       
  4540         {
       
  4541         iMceMainView->SetDeliveryReportsSelected();
       
  4542         }
       
  4543     }
       
  4544 
       
  4545 // ----------------------------------------------------
       
  4546 // CMceUi::MceViewActive
       
  4547 // ----------------------------------------------------
       
  4548 TBool CMceUi::MceViewActive( TInt aActiveView ) const
       
  4549     {
       
  4550     return iMceActiveView & aActiveView;
       
  4551     }
       
  4552 
       
  4553 // ----------------------------------------------------
       
  4554 // CMceUi::MoveFromOutboxToDraftsL
       
  4555 // ----------------------------------------------------
       
  4556 void CMceUi::MoveFromOutboxToDraftsL()
       
  4557     {
       
  4558     MCELOGGER_ENTERFN("MoveFromOutboxToDraftsL()");
       
  4559     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  4560         Panic( EMceUiErrCannotMoveFromMainView ) );
       
  4561 
       
  4562     LeaveIfDiskSpaceUnderCriticalLevelL();
       
  4563 
       
  4564     CMsvEntrySelection* selection = iMceListView->ListContainer()
       
  4565         ->CurrentItemSelectionL();
       
  4566     CleanupStack::PushL( selection );
       
  4567 
       
  4568 
       
  4569     if ( selection->Count() == 0 ||
       
  4570          IsMessageSendingL( selection->At(0) ) )
       
  4571         {
       
  4572         CleanupStack::PopAndDestroy( selection );
       
  4573         MCELOGGER_LEAVEFN("MoveFromOutboxToDraftsL1()");
       
  4574         return;
       
  4575         }
       
  4576 
       
  4577     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  4578     CleanupStack::PushL( singleOpWatcher );
       
  4579     CAknInputBlock::NewLC();
       
  4580 
       
  4581     CMsvProgressReporterOperation* op =
       
  4582         CMsvProgressReporterOperation::NewL(
       
  4583         *iSession, singleOpWatcher->iStatus, EMbmAvkonQgn_note_move );
       
  4584     CleanupStack::PushL( op );
       
  4585 
       
  4586     CMsvOperation* subOp = CMceCancelSendingOperation::NewL(
       
  4587          *iSession,
       
  4588          op->RequestStatus(),
       
  4589          selection->At(0),
       
  4590          CMceCancelSendingOperation::ECancelAndMoveToDrafts,
       
  4591          *iMtmStore );
       
  4592 
       
  4593     op->SetOperationL(subOp); // this takes ownership immediately, so no cleanupstack needed.
       
  4594 
       
  4595     HBufC* text = StringLoader::LoadLC(
       
  4596         R_MUIU_LOCAL_PROGRESS_MOVING_1,
       
  4597         iEikonEnv );
       
  4598     op->SetTitleL( *text );
       
  4599     CleanupStack::PopAndDestroy( text );
       
  4600     CleanupStack::Pop( op );
       
  4601     singleOpWatcher->SetOperation( op );
       
  4602     CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  4603     CleanupStack::PushL( op );
       
  4604     iOperations.AppendL( singleOpWatcher );
       
  4605     CleanupStack::Pop(2, singleOpWatcher); // singleOpWatcher, op
       
  4606 
       
  4607 
       
  4608     MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", op->Id() );
       
  4609     iMceListView->ListContainer()->ClearSelection();
       
  4610     CleanupStack::PopAndDestroy( selection ); 
       
  4611     MCELOGGER_LEAVEFN("MoveFromOutboxToDraftsL2()");
       
  4612     }
       
  4613 
       
  4614 // ----------------------------------------------------
       
  4615 // CMceUi::ForceMtmLoaderFinish
       
  4616 // ----------------------------------------------------
       
  4617 void CMceUi::ForceMtmLoaderFinish()
       
  4618     {
       
  4619     MCELOGGER_ENTERFN("ForceMtmLoaderFinish()");
       
  4620     if ( iMtmLoader )
       
  4621         {
       
  4622         TRAP_IGNORE(iMtmLoader->FinishL(iAudioMsgEnabled, iPostcardEnabled)); // CR : 401-1806
       
  4623         delete iMtmLoader;
       
  4624         iMtmLoader = NULL;
       
  4625         }
       
  4626     MCELOGGER_LEAVEFN("ForceMtmLoaderFinish()");
       
  4627     }
       
  4628 
       
  4629 // ----------------------------------------------------
       
  4630 // CMceUi::GoOfflineSynchronouslyL
       
  4631 // ----------------------------------------------------
       
  4632 void CMceUi::GoOfflineSynchronouslyL( TMsvId aAccount )
       
  4633     {
       
  4634     MCELOGGER_ENTERFN("GoOfflineSynchronouslyL()");
       
  4635     TMsvEntry tentry;
       
  4636     (void)GetEntryL(aAccount, tentry);
       
  4637 
       
  4638     if (  iAlwaysOnline && ( tentry.iMtm == KSenduiMtmImap4Uid
       
  4639         || tentry.iMtm == KSenduiMtmPop3Uid ) )
       
  4640         {
       
  4641         if ( !ServiceIdFound( tentry.Id()) )
       
  4642             {
       
  4643             // do not close always online connection
       
  4644             return;
       
  4645             }
       
  4646         }
       
  4647 
       
  4648     CBaseMtmUi& ui=iMtmStore->GetMtmUiAndSetContextLC(tentry);
       
  4649     CAknInputBlock::NewLC();
       
  4650 
       
  4651     CMuiuOperationWait* wait =
       
  4652         CMuiuOperationWait::NewLC(EActivePriorityWsEvents+10);
       
  4653     CMsvOperation* op=ui.CloseL(wait->iStatus);
       
  4654     wait->Start();
       
  4655     CleanupStack::PopAndDestroy( wait );
       
  4656     delete op;
       
  4657     CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, release mtmui
       
  4658     MCELOGGER_LEAVEFN("GoOfflineSynchronouslyL()");
       
  4659     }
       
  4660 
       
  4661 // ----------------------------------------------------
       
  4662 // CMceUi::IsEditorOpen
       
  4663 // ----------------------------------------------------
       
  4664 TBool CMceUi::IsEditorOpen( ) const
       
  4665     {
       
  4666     return ( iEditorOperation ? ETrue : EFalse );
       
  4667     }
       
  4668 
       
  4669 // ----------------------------------------------------
       
  4670 // CMceUi::LeaveIfDiskSpaceUnderCriticalLevelL
       
  4671 // Static function.
       
  4672 // Used in CreateNewMessageL as TCleanupItem.
       
  4673 // ----------------------------------------------------
       
  4674 void CMceUi::LeaveIfDiskSpaceUnderCriticalLevelL( TInt aBytesToWrite )
       
  4675     {
       
  4676     MCELOGGER_WRITE_FORMAT("LeaveIfDiskSpaceUnderCriticalLevelL: %d", aBytesToWrite );
       
  4677 
       
  4678 
       
  4679     if ( iMceUiFlags.MceFlag( EMceUiFlagsMediaUnavailable ) )
       
  4680         {
       
  4681         MCELOGGER_WRITE("LeaveIfDiskSpaceUnderCriticalLevelL: media unavailable, leave");
       
  4682         User::Leave( KMsvIndexBackup );
       
  4683         }
       
  4684 
       
  4685     if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL(*iSession, aBytesToWrite) )
       
  4686         {
       
  4687         User::Leave( KErrDiskFull );
       
  4688         }
       
  4689     MCELOGGER_WRITE("LeaveIfDiskSpaceUnderCriticalLevelL: OK to proceed");
       
  4690     }
       
  4691 
       
  4692 // ----------------------------------------------------
       
  4693 // CMceUi::CancelFreeDiskSpaceRequest
       
  4694 // Static function.
       
  4695 // Used in CreateNewMessageL as TCleanupItem.
       
  4696 // ----------------------------------------------------
       
  4697 void CMceUi::CancelFreeDiskSpaceRequest(TAny* /*aAny*/)
       
  4698     {
       
  4699     MCELOGGER_ENTERFN("CancelFreeDiskSpaceRequest()");
       
  4700 
       
  4701 // Cancel the free disk space request to be added
       
  4702 
       
  4703     MCELOGGER_LEAVEFN("CancelFreeDiskSpaceRequest()");
       
  4704     }
       
  4705 
       
  4706 // ----------------------------------------------------
       
  4707 // CMceUi::TitlePaneL
       
  4708 // Returns mce ui's title pane
       
  4709 // ----------------------------------------------------
       
  4710 CAknTitlePane* CMceUi::TitlePaneL() const
       
  4711     {
       
  4712     return (CAknTitlePane *)(iEikonEnv->AppUiFactory(*this))->StatusPane()->ControlL(
       
  4713         TUid::Uid(EEikStatusPaneUidTitle));
       
  4714     }
       
  4715 
       
  4716 // ----------------------------------------------------
       
  4717 // CMceUi::IsMessageSendingL
       
  4718 //
       
  4719 // ----------------------------------------------------
       
  4720 TBool CMceUi::IsMessageSendingL( TMsvId aEntryId ) const
       
  4721     {
       
  4722     MCELOGGER_ENTERFN("IsMessageSendingL()");
       
  4723     MCELOGGER_WRITE_FORMAT( "Check entry 0x%x", aEntryId );
       
  4724 
       
  4725     TBool sending = EFalse;
       
  4726     iEntry->SetEntryL( aEntryId );
       
  4727     const TMsvEntry& entry = iEntry->Entry();
       
  4728     if ( entry.Parent() == KMsvGlobalOutBoxIndexEntryId &&
       
  4729          entry.SendingState() == KMsvSendStateSending &&
       
  4730          ( entry.iMtm == KSenduiMtmSmsUid ||
       
  4731          entry.iMtm == KSenduiMtmMmsUid )
       
  4732        )
       
  4733         {
       
  4734                 sending = ETrue;
       
  4735         }
       
  4736     MCELOGGER_WRITE_FORMAT( "Entry sending: %d", sending);
       
  4737     MCELOGGER_LEAVEFN("IsMessageSendingL()");
       
  4738     return sending;
       
  4739     }
       
  4740 
       
  4741 // ----------------------------------------------------
       
  4742 // CMceUi::ActivateConnectionQueryTimerL
       
  4743 //
       
  4744 // ----------------------------------------------------
       
  4745 void CMceUi::ActivateConnectionQueryTimerL( TMsvId aEntryId )
       
  4746     {
       
  4747     MCELOGGER_ENTERFN("ActivateConnectionQueryTimerL()");
       
  4748     if ( !iConnectMailboxTimer )
       
  4749         {
       
  4750         iConnectMailboxTimer = CMceConnectMailboxTimer::NewL( *this );
       
  4751         }
       
  4752 
       
  4753     TMsvEntry tentry;
       
  4754     TMsvId serviceId = GetEntryL( aEntryId, tentry );
       
  4755     if ( tentry.iMtm != KSenduiMtmImap4Uid &&
       
  4756          tentry.iMtm != KSenduiMtmPop3Uid )
       
  4757         {
       
  4758         // not mailbox, do nothing.
       
  4759         return;
       
  4760         }
       
  4761 
       
  4762     if ( serviceId != aEntryId )
       
  4763         {
       
  4764         // lets find out that service...
       
  4765         GetEntryL( serviceId, tentry );
       
  4766         }
       
  4767     if ( !tentry.Connected() )
       
  4768         {
       
  4769         // this cancels possible old timer
       
  4770         iConnectMailboxTimer->SetTimer( serviceId );
       
  4771         }
       
  4772     MCELOGGER_LEAVEFN("ActivateConnectionQueryTimerL()");
       
  4773     }
       
  4774 
       
  4775 // ----------------------------------------------------
       
  4776 // CMceUi::ReplyL
       
  4777 //
       
  4778 // ----------------------------------------------------
       
  4779 void CMceUi::ReplyL(TInt /*aReplyCommand*/)
       
  4780     {
       
  4781     MCELOGGER_ENTERFN("ReplyL()");
       
  4782     LeaveIfDiskSpaceUnderCriticalLevelL( iDiskSpaceForMoveOrCopy );
       
  4783 
       
  4784     if ( MceViewActive( EMceMainViewActive ) )
       
  4785         {
       
  4786         return;
       
  4787         }
       
  4788 
       
  4789     CMsvEntrySelection * selection = iMceListView->ListContainer()->CurrentItemSelectionL();
       
  4790     CleanupStack::PushL( selection );
       
  4791     if ( selection->Count() <= 0)
       
  4792         {
       
  4793         CleanupStack::PopAndDestroy( selection );
       
  4794         return;
       
  4795         }
       
  4796 
       
  4797     TMsvEntry entry;
       
  4798     TMsvId serviceId;
       
  4799     User::LeaveIfError( iSession->GetEntry(selection->At(0),serviceId,entry) ); // original message?
       
  4800 
       
  4801     // NCN reset, received mail has been replied before opening it
       
  4802     if ( ((entry.iMtm == KSenduiMtmImap4Uid)
       
  4803         || (entry.iMtm == KSenduiMtmPop3Uid)
       
  4804         || (entry.iMtm == KSenduiMtmSyncMLEmailUid)
       
  4805         || CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, entry.iMtm ))
       
  4806         && entry.Unread() )
       
  4807         {
       
  4808         
       
  4809         HandleNotif(iMceListView->ListContainer()->FolderEntry().iServiceId);
       
  4810 
       
  4811         }
       
  4812 
       
  4813     CleanupStack::PopAndDestroy( selection ); 
       
  4814 
       
  4815     TMsvPartList parts=KMsvMessagePartBody|KMsvMessagePartOriginator|KMsvMessagePartDescription;
       
  4816 
       
  4817     // Mark local entry as read before replying, remote entries should be handled by mtm ui
       
  4818     if ( entry.Unread() && entry.iServiceId == KMsvLocalServiceIndexEntryId )
       
  4819         {
       
  4820         iEntry->SetEntryL( entry.Id() );
       
  4821         TMsvEntry entry = iEntry->Entry();
       
  4822         entry.SetUnread( EFalse );
       
  4823         iEntry->ChangeL( entry );
       
  4824         }
       
  4825 
       
  4826     if ( entry.iBioType == KMsgBioUidPictureMsg.iUid)
       
  4827         {
       
  4828         //picture message
       
  4829         TMsvId origMsgId = entry.Id();
       
  4830 
       
  4831         // Change the MTM type of msg temporarily
       
  4832 
       
  4833         CMsvEntry* cEntry = iSession->GetEntryL( origMsgId );
       
  4834         CleanupStack::PushL( cEntry );
       
  4835         TMsvEntry tentry( cEntry->Entry() );
       
  4836         const TUid origMtmUid = tentry.iMtm;
       
  4837         tentry.iMtm = KSenduiMtmSmsUid;
       
  4838 
       
  4839         // Create registry instances
       
  4840         CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *iSession );
       
  4841         CleanupStack::PushL(mtmReg);
       
  4842         CMtmUiRegistry* mtmUiReg = CMtmUiRegistry::NewL( *iSession );
       
  4843         CleanupStack::PushL(mtmUiReg);
       
  4844 
       
  4845         // Create the SMS MTM
       
  4846         CBaseMtm* mtm = mtmReg->NewMtmL( KSenduiMtmSmsUid );
       
  4847         CleanupStack::PushL(mtm);
       
  4848         CBaseMtmUi* mtmUi = mtmUiReg->NewMtmUiL( *mtm );
       
  4849         CleanupStack::PushL(mtmUi);
       
  4850 
       
  4851         // Trap errors, so we can try to restore the original MTM Uid
       
  4852 
       
  4853         TRAPD(err,
       
  4854             {
       
  4855 
       
  4856             cEntry->ChangeL( tentry );
       
  4857 
       
  4858             // Set its context
       
  4859             mtm->SwitchCurrentEntryL( origMsgId );
       
  4860 
       
  4861             mtmUi->SetPreferences( mtmUi->Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  4862             CAknInputBlock::NewLC();
       
  4863 
       
  4864             CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  4865             CleanupStack::PushL( singleOpWatcher );
       
  4866 
       
  4867             CMsvOperation* oper = mtmUi->ReplyL(
       
  4868                 KMsvDraftEntryIdValue, parts, singleOpWatcher->iStatus );
       
  4869             iEditorOperation = singleOpWatcher;
       
  4870 
       
  4871             CleanupStack::PushL( oper );
       
  4872             iOperations.AppendL( singleOpWatcher );
       
  4873             CleanupStack::Pop( 2, singleOpWatcher ); // oper
       
  4874             singleOpWatcher->SetOperation( oper );
       
  4875             CleanupStack::PopAndDestroy(  ); // CAknInputBlock
       
  4876 
       
  4877             });
       
  4878 
       
  4879         // Restore original Mtm Uid
       
  4880         tentry = cEntry->Entry();
       
  4881         tentry.iMtm = origMtmUid;
       
  4882         cEntry->ChangeL(tentry);
       
  4883         mtm->SwitchCurrentEntryL( origMsgId );
       
  4884 
       
  4885         User::LeaveIfError(err);
       
  4886         CleanupStack::PopAndDestroy( 5 ); // mtmUi, mtmReg, mtmUiReg, mtm, cEntry
       
  4887         }
       
  4888 
       
  4889     else
       
  4890         {
       
  4891         CBaseMtmUi& ui = iMtmStore->GetMtmUiAndSetContextLC( entry );
       
  4892         ui.SetPreferences( ui.Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  4893         CAknInputBlock::NewLC();
       
  4894         CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  4895         CleanupStack::PushL( singleOpWatcher );
       
  4896 
       
  4897         CMsvOperation* oper = ui.ReplyL(
       
  4898             KMsvDraftEntryIdValue, parts, singleOpWatcher->iStatus );
       
  4899         iEditorOperation = singleOpWatcher;
       
  4900 
       
  4901         CleanupStack::PushL( oper );
       
  4902         iOperations.AppendL( singleOpWatcher );
       
  4903         CleanupStack::Pop( 2, singleOpWatcher ); // oper
       
  4904         singleOpWatcher->SetOperation( oper );
       
  4905         MCELOGGER_WRITE_FORMAT("iOperations.AppendL(%d)", oper->Id() );
       
  4906         CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, ui
       
  4907         }
       
  4908     MCELOGGER_LEAVEFN("ReplyL()");
       
  4909 
       
  4910     }
       
  4911 
       
  4912 // ----------------------------------------------------
       
  4913 // CMceUi::MarkAsReadL
       
  4914 // ----------------------------------------------------
       
  4915 void CMceUi::MarkAsReadL( TBool aRead )
       
  4916     {
       
  4917     MCELOGGER_ENTERFN("MarkAsReadL()");
       
  4918     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  4919     CleanupStack::PushL(singleOpWatcher);
       
  4920 
       
  4921     CMsvEntrySelection* sel = iMceListView->ListContainer()
       
  4922         ->CurrentItemSelectionL();
       
  4923     CleanupStack::PushL( sel );
       
  4924     TInt selCount = sel->Count();
       
  4925     if ( selCount <= 0 )
       
  4926         {
       
  4927         CleanupStack::PopAndDestroy( 2 ); // singleOpWatcher, sel
       
  4928         return;
       
  4929         }
       
  4930 
       
  4931     TMsvId serviceId;
       
  4932     TMsvEntry entry;
       
  4933     User::LeaveIfError( iSession->GetEntry( sel->At(0), serviceId, entry ) );
       
  4934     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( entry.iMtm );
       
  4935     mtmUi.SetPreferences( mtmUi.Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  4936     CleanupStack::PopAndDestroy( ); // mtmUi
       
  4937 
       
  4938     CMsvProgressReporterOperation* op =
       
  4939         CMsvProgressReporterOperation::NewL(
       
  4940             *iSession, singleOpWatcher->iStatus );
       
  4941     CleanupStack::PushL( op );
       
  4942     HBufC* text = StringLoader::LoadLC( R_MCE_MARK_AS_READ_PROGRESS, iEikonEnv );
       
  4943     op->SetTitleL( *text );
       
  4944     CleanupStack::PopAndDestroy( text );
       
  4945 
       
  4946     // Determine the action for unread flag
       
  4947     TInt type =
       
  4948             aRead ? CMceRemoveNewFlag::EMceRemoveEntryFlagUnread :
       
  4949                     CMceRemoveNewFlag::EMceRemoveEntryFlagNew;
       
  4950     CMceRemoveNewFlag* subOp = CMceRemoveNewFlag::NewL(
       
  4951     type, *iSession, op->RequestStatus(), sel );
       
  4952 
       
  4953     op->SetOperationL( subOp ); // this takes ownership immediately, so no cleanupstack needed.
       
  4954     if ( selCount ==  1 )
       
  4955         {
       
  4956         op->MakeProgressVisibleL(EFalse);
       
  4957         }
       
  4958     op->SetProgressDecoder( *subOp );
       
  4959     CleanupStack::Pop( op );
       
  4960 
       
  4961     iOperations.AppendL( singleOpWatcher );
       
  4962     CleanupStack::Pop( 2, singleOpWatcher ); // singleOpWatcher, sel
       
  4963     singleOpWatcher->SetOperation( op );
       
  4964     iMceListView->ListContainer()->ClearSelection();
       
  4965     if ( CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, entry.iMtm )&& aRead )
       
  4966         {
       
  4967         HandleNotif(iMceListView->ListContainer()->FolderEntry().iServiceId);
       
  4968         }
       
  4969     MCELOGGER_WRITE_FORMAT( "iOperations.AppendL(%d)", op->Id() );
       
  4970     MCELOGGER_LEAVEFN("MarkAsReadL()");
       
  4971     }
       
  4972 
       
  4973 // ----------------------------------------------------
       
  4974 // CMceUi::TabChangedL
       
  4975 //
       
  4976 // ----------------------------------------------------
       
  4977 void CMceUi::TabChangedL(TInt aIndex)
       
  4978     {
       
  4979     TBool bOBoxOrMBox = EFalse ;
       
  4980     if ( !MceViewActive( EMceMessageViewActive )
       
  4981         && !MceViewActive( EMceDeliveryReportsViewActive ) )
       
  4982         {
       
  4983         return;
       
  4984         }
       
  4985     TInt count = iTabsArray->Count();
       
  4986     TMsvId newId = KMsvGlobalInBoxIndexEntryId;
       
  4987     if ( aIndex < count )
       
  4988         {
       
  4989         newId = (*iTabsArray)[aIndex];
       
  4990         }
       
  4991 
       
  4992     CancelMailboxTimer();
       
  4993 
       
  4994     if ( MceViewActive( EMceDeliveryReportsViewActive ) )
       
  4995         {
       
  4996         OpenFolderViewL( newId );
       
  4997         }
       
  4998     else if ( !MceViewActive( EMceDeliveryReportsViewActive )
       
  4999             && newId == KMceDeliveryReportsListIdValue )
       
  5000         {
       
  5001         // activate delivery reports view
       
  5002         ActivateLocalViewL( KMceDeliveryReportViewId );
       
  5003         }
       
  5004     else
       
  5005         {
       
  5006         TBool bIsFromMailbox = EFalse ;
       
  5007         TBool bIsToMailbox = EFalse ;
       
  5008         TUid mtm = iMceListView->ListContainer()->FolderEntry().iMtm ;
       
  5009         bIsFromMailbox = CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, mtm );
       
  5010         
       
  5011         TMsvEntry currentEntry;
       
  5012         TMsvId serviceId; // not used here but needed by GetEntry function
       
  5013         if ( iSession->GetEntry( newId, serviceId, currentEntry )
       
  5014         	== KErrNone )
       
  5015 	        {
       
  5016 	        bIsToMailbox = CheckTechnologyTypeFromMtm( KMailTechnologyTypeUid, currentEntry.iMtm ); 	
       
  5017 	        }
       
  5018         
       
  5019         TMsvId oldId = iMceListView->ListContainer()->FolderEntry().Id();
       
  5020         if (oldId == KMsvGlobalOutBoxIndexEntryId || newId == KMsvGlobalOutBoxIndexEntryId
       
  5021             || bIsFromMailbox || bIsToMailbox)
       
  5022 	        {
       
  5023 		        if (bIsFromMailbox || bIsToMailbox || 
       
  5024 		            oldId == KMsvGlobalOutBoxIndexEntryId || iMceListView->ListContainer()->MceListId() != EMceListTypeTwoRow)
       
  5025 		        {
       
  5026 		        bOBoxOrMBox = ETrue ;
       
  5027 		        iLocalScreenClearer = CAknLocalScreenClearer::NewL( EFalse );	
       
  5028 		        }
       
  5029 	        }
       
  5030         iMceListView->ChangeFolderAndRefreshListboxL( newId );
       
  5031         }
       
  5032      
       
  5033      if (bOBoxOrMBox)
       
  5034 	     {
       
  5035 	     delete iLocalScreenClearer;
       
  5036 	     iLocalScreenClearer = NULL;
       
  5037 	     }
       
  5038     }
       
  5039 
       
  5040 // ----------------------------------------------------
       
  5041 // CMceUi::IsPresent
       
  5042 // ----------------------------------------------------
       
  5043 TBool CMceUi::IsPresent( TUid aMtm ) const
       
  5044     {
       
  5045     return iUiRegistry->IsPresent( aMtm );
       
  5046     }
       
  5047 
       
  5048 // ----------------------------------------------------
       
  5049 // CMceUi::ClearExitAfterDisconnectFlag
       
  5050 //
       
  5051 // ----------------------------------------------------
       
  5052 void CMceUi::ClearExitAfterDisconnectFlag( )
       
  5053     {
       
  5054     iMceUiFlags.ClearMceFlag( EMceUiFlagsExitAfterDisconnect  );
       
  5055     }
       
  5056 
       
  5057 // ----------------------------------------------------
       
  5058 // CMceUi::SetDontExitOnNextOperationComplete
       
  5059 //
       
  5060 // ----------------------------------------------------
       
  5061 void CMceUi::SetDontExitOnNextOperationComplete( )
       
  5062     {
       
  5063     MCELOGGER_WRITE("CMceUi::SetDontExitOnNextOperationComplete");
       
  5064     iMceUiFlags.SetMceFlag( EMceUiFlagsDoNotExitAfterNextOperationComplete );
       
  5065     if ( iCancelExitFlagOperation && !( iCancelExitFlagOperation->IsActive() ) )
       
  5066         {
       
  5067         iCancelExitFlagOperation->Start( 
       
  5068             TCallBack( ClearDontExitOnNextOperationComplete, this ) );
       
  5069         }
       
  5070     }
       
  5071 
       
  5072 // ----------------------------------------------------
       
  5073 // CMceUi::ClearDontExitOnNextOperationComplete
       
  5074 //
       
  5075 // ----------------------------------------------------
       
  5076 void CMceUi::ClearDontExitOnNextOperationComplete( )
       
  5077     {
       
  5078     MCELOGGER_WRITE("CMceUi::ClearDontExitOnNextOperationComplete");
       
  5079     iMceUiFlags.ClearMceFlag( EMceUiFlagsDoNotExitAfterNextOperationComplete );
       
  5080     }
       
  5081 
       
  5082 // ----------------------------------------------------
       
  5083 // CMceUi::ClearDontExitOnNextOperationComplete
       
  5084 //
       
  5085 // ----------------------------------------------------
       
  5086 TInt CMceUi::ClearDontExitOnNextOperationComplete( TAny* aSelf )
       
  5087     {
       
  5088     reinterpret_cast<CMceUi*>(aSelf)->ClearDontExitOnNextOperationComplete();
       
  5089     return KErrNone;
       
  5090     }
       
  5091 
       
  5092 // ----------------------------------------------------
       
  5093 // CMceUi::SyncMlNewMessageItemL
       
  5094 // ----------------------------------------------------
       
  5095 void CMceUi::SyncMlNewMessageItemL( const CMsvEntrySelection* aSelection, TInt aEvent )
       
  5096     {
       
  5097     TMsvId serviceId;
       
  5098     TMsvEntry entry;
       
  5099     if ( aEvent == EMsvEntriesCreated )
       
  5100         {
       
  5101         if ( iSession->GetEntry( aSelection->At(0), serviceId, entry ) == KErrNone )
       
  5102             {
       
  5103             if ( entry.iMtm == KSenduiMtmSyncMLEmailUid )
       
  5104                 {
       
  5105                 HandleMTMChangeL();
       
  5106                 }
       
  5107             }
       
  5108         }
       
  5109     else
       
  5110         {
       
  5111         if ( aEvent == EMsvEntriesDeleted )
       
  5112             {
       
  5113             CMsvEntrySelection* sel=iRootEntry->ChildrenWithTypeL( KUidMsvServiceEntry );
       
  5114             CleanupStack::PushL( sel );
       
  5115             const TMsvEntry* tentry=NULL;
       
  5116             TInt syncMl = 0;
       
  5117             for ( TInt cc=sel->Count(); --cc>=0 && !syncMl; )
       
  5118                 {
       
  5119                 tentry=&(iRootEntry->ChildDataL((*sel)[cc]));
       
  5120                 if ( tentry->iMtm == KSenduiMtmSyncMLEmailUid )
       
  5121                     {
       
  5122                     syncMl++;
       
  5123                     }
       
  5124                 }
       
  5125             if ( !syncMl )
       
  5126                 {
       
  5127                 HandleMTMChangeL();
       
  5128                 }
       
  5129 
       
  5130             CleanupStack::PopAndDestroy( sel );
       
  5131             }
       
  5132         }
       
  5133     }
       
  5134 
       
  5135 // ----------------------------------------------------
       
  5136 // CMceUi::SyncMlMoveFromOutboxToDraftsL
       
  5137 // ----------------------------------------------------
       
  5138 void CMceUi::SyncMlMoveFromOutboxToDraftsL( )
       
  5139     {
       
  5140     LeaveIfDiskSpaceUnderCriticalLevelL( iDiskSpaceForMoveOrCopy );
       
  5141 
       
  5142     __ASSERT_DEBUG( MceViewActive( EMceMessageViewActive ),
       
  5143         Panic( EMceUiErrCannotMoveFromMainView ) );
       
  5144     if ( MceViewActive( EMceMainViewActive ) )
       
  5145         {
       
  5146         return;
       
  5147         }
       
  5148 
       
  5149     const TMsvId sourceId = iMceListView->ListContainer()->CurrentFolderId();
       
  5150     TMsvEntry srcEntry;
       
  5151     GetEntryL( sourceId, srcEntry );
       
  5152 
       
  5153     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  5154         ->CurrentItemSelectionL();
       
  5155     CleanupStack::PushL( selection );
       
  5156 
       
  5157     if (  selection->Count() <= 0 )
       
  5158         {
       
  5159         CleanupStack::PopAndDestroy( selection );
       
  5160         return;
       
  5161         }
       
  5162 
       
  5163     CMsvOperation* op=NULL;
       
  5164 
       
  5165     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  5166     CleanupStack::PushL( singleOpWatcher );
       
  5167 
       
  5168     CAknInputBlock::NewLC();
       
  5169 
       
  5170     CBaseMtmUi& ui=iMtmStore->GetMtmUiAndSetContextLC( srcEntry );
       
  5171     op=ui.MoveFromL( *selection, KMsvDraftEntryId, singleOpWatcher->iStatus );
       
  5172     CleanupStack::PopAndDestroy(); // release ui
       
  5173 
       
  5174     CleanupStack::PopAndDestroy(); // CAknInputBlock::NewLC()
       
  5175     CleanupStack::PushL(op);
       
  5176     iOperations.AppendL( singleOpWatcher );
       
  5177     CleanupStack::Pop( 2 ); // singleOpWatcher, op
       
  5178     singleOpWatcher->SetOperation( op );
       
  5179 
       
  5180     iMceListView->ListContainer()->ClearSelection();
       
  5181     CleanupStack::PopAndDestroy( selection ); 
       
  5182     }
       
  5183 
       
  5184 // ----------------------------------------------------
       
  5185 // CMceUi::MtmName
       
  5186 //
       
  5187 // ----------------------------------------------------
       
  5188 THumanReadableName CMceUi::MtmName( TUid aMtm ) const
       
  5189     {
       
  5190     THumanReadableName data;
       
  5191     const TInt count = iMsgTypesSettings.Count();
       
  5192     for ( TInt cc = 0; cc < count; cc++ )
       
  5193         {
       
  5194         TUidNameInfo info = iMsgTypesSettings.At(cc);
       
  5195         if ( info.iUid == aMtm )
       
  5196             {
       
  5197             data = info.iName;
       
  5198             }
       
  5199         }
       
  5200     return data;
       
  5201     }
       
  5202 
       
  5203 // ----------------------------------------------------
       
  5204 // CMceUi::SetChangeMessageStore
       
  5205 //
       
  5206 // ----------------------------------------------------
       
  5207 void CMceUi::SetChangeMessageStore( TBool aChangeEnded )
       
  5208     {
       
  5209     if ( aChangeEnded )
       
  5210         {
       
  5211         iMceUiFlags.SetMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
  5212         }
       
  5213     else
       
  5214         {
       
  5215         iMceUiFlags.ClearMceFlag( EMceUiFlagsExitOnMsvMediaAvailableEvent );
       
  5216         }
       
  5217     }
       
  5218 
       
  5219 
       
  5220 // ----------------------------------------------------
       
  5221 // CMceUi::IsSyncronizingL
       
  5222 //
       
  5223 // ----------------------------------------------------
       
  5224 TBool CMceUi::IsSyncronizingL( const TMsvEntry& entry )
       
  5225     {
       
  5226     TBool isSyncronizing = EFalse;
       
  5227 
       
  5228     if ( IsPresent( KSenduiMtmSyncMLEmailUid ) &&
       
  5229             entry.iMtm == KSenduiMtmSyncMLEmailUid )
       
  5230         {
       
  5231         CBaseMtmUiData* uiData= GetMtmUiDataL( KSenduiMtmSyncMLEmailUid );
       
  5232         if ( uiData )
       
  5233             {
       
  5234             TInt reason = 0;
       
  5235             TBool syncronizing = uiData->CanOpenEntryL( entry, reason );
       
  5236             if ( !syncronizing )
       
  5237                 {
       
  5238                 //cannot open during syncronizing
       
  5239                 HBufC* text = StringLoader::LoadLC( reason, iEikonEnv );
       
  5240                 CAknInformationNote* note = new (ELeave) CAknInformationNote();
       
  5241                 note->ExecuteLD(*text);
       
  5242                 CleanupStack::PopAndDestroy(); //text
       
  5243                 isSyncronizing = ETrue;
       
  5244                 }
       
  5245             }
       
  5246         }
       
  5247 
       
  5248     return isSyncronizing;
       
  5249     }
       
  5250 
       
  5251 // ----------------------------------------------------
       
  5252 // CMceUi::AlwaysOnlineLastConnectionL
       
  5253 //
       
  5254 // ----------------------------------------------------
       
  5255 TBool CMceUi::AlwaysOnlineLastConnectionL( const TMsvId aAccount )
       
  5256     {
       
  5257     TBool connectionMade = ETrue;
       
  5258 
       
  5259     CImumInSettingsData* settings =
       
  5260         iEmailApi->MailboxServicesL().LoadMailboxSettingsL( aAccount );
       
  5261     CleanupStack::PushL( settings );
       
  5262 
       
  5263     if ( iMceMainView->ListContainer()->ListItems()->
       
  5264         AlwaysOnlineAccountL( aAccount, *settings ) )
       
  5265         {
       
  5266         TInt lastUpdateFailed = 0;
       
  5267         settings->GetAttr(
       
  5268             TImumInSettings::EKeyInfoLastUpdateFailed, lastUpdateFailed );
       
  5269         if ( lastUpdateFailed )
       
  5270             {
       
  5271             TInt64 lastTime = 0;
       
  5272             settings->GetAttr(
       
  5273                 TImumInSettings::EKeyInfoLastSuccessfulUpdate, lastTime );
       
  5274             TTime settingsTime( lastTime );
       
  5275             TBuf<KMceMaxDateString> time;
       
  5276             TBuf<KMceMaxDateString> dateTime;
       
  5277 
       
  5278             HBufC* timeFormat = iCoeEnv->
       
  5279                 AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
  5280             HBufC* dateFormat = iCoeEnv->
       
  5281                 AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
  5282 
       
  5283             TTime currentTime;
       
  5284             currentTime.HomeTime();
       
  5285             TDateTime currentDate( currentTime.DateTime() ); //current date
       
  5286             TDateTime currentDateSettings( settingsTime.DateTime() ); //settings date
       
  5287 
       
  5288             TBool connBeforeToday = EFalse;
       
  5289             if ( currentDate.Year() > currentDateSettings.Year() )
       
  5290                 {
       
  5291                 connBeforeToday = ETrue;
       
  5292                 }
       
  5293             else
       
  5294                 if ( currentDate.Month() > currentDateSettings.Month() )
       
  5295                     {
       
  5296                     connBeforeToday = ETrue;
       
  5297                     }
       
  5298             else
       
  5299                 if ( currentDate.Day() > currentDateSettings.Day() )
       
  5300                     {
       
  5301                     connBeforeToday = ETrue;
       
  5302                     }
       
  5303 
       
  5304             settingsTime.FormatL( time, *timeFormat );
       
  5305             AknTextUtils::LanguageSpecificNumberConversion( time );
       
  5306 
       
  5307             settingsTime.FormatL( dateTime, *dateFormat );
       
  5308             AknTextUtils::LanguageSpecificNumberConversion( dateTime );
       
  5309             CleanupStack::PopAndDestroy( 2, timeFormat ); // timeFormat, dateFormat
       
  5310 
       
  5311             CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
  5312             HBufC* text = NULL;
       
  5313             if ( connBeforeToday ) //last connection failed before today
       
  5314                 {
       
  5315                 CDesCArrayFlat* string=new(ELeave)CDesCArrayFlat( KMceArrayGranularity );
       
  5316                 CleanupStack::PushL( string );
       
  5317                 string->AppendL( dateTime );
       
  5318                 string->AppendL( time );
       
  5319                 text = StringLoader::LoadLC(
       
  5320                     R_MCE_SETTINGS_ALWAYS_LASTTIME2, *string, iEikonEnv );
       
  5321                 }
       
  5322             else
       
  5323                 {
       
  5324                 text = StringLoader::LoadLC(
       
  5325                     R_MCE_SETTINGS_ALWAYS_LASTTIME, time, iEikonEnv );
       
  5326                 }
       
  5327 
       
  5328             confDialog->SetPromptL( *text );
       
  5329             CleanupStack::PopAndDestroy( text );
       
  5330             if ( connBeforeToday ) //last connection failed before today
       
  5331                 {
       
  5332                 CleanupStack::PopAndDestroy(); 
       
  5333                 }
       
  5334 
       
  5335             connectionMade = EFalse;
       
  5336 
       
  5337             if ( confDialog->ExecuteLD( R_MCE_CONFIRMATION ) )
       
  5338                 {
       
  5339                 GoOnlineL( aAccount );
       
  5340                 }
       
  5341 
       
  5342             }
       
  5343         }
       
  5344 
       
  5345     CleanupStack::PopAndDestroy( 1 ); // extendedMailSettings
       
  5346     return connectionMade;
       
  5347     }
       
  5348 
       
  5349 // ----------------------------------------------------
       
  5350 // CMceUi::AddOperationIdL
       
  5351 //
       
  5352 // ----------------------------------------------------
       
  5353 void CMceUi::AddOperationIdL( const TMsvOp& aOp, const TMsvId& aServiceId )
       
  5354     {
       
  5355     if ( !iMailAccountItemArray )
       
  5356         {
       
  5357         return;
       
  5358         }
       
  5359 
       
  5360     TInt count = iMailAccountItemArray->Count();
       
  5361     TInt found = EFalse;
       
  5362     for ( TInt cc = 0; cc < count && !found; cc++ )
       
  5363         {
       
  5364         const TMceMailAccountItem& item = ((*iMailAccountItemArray)[cc]);
       
  5365         if ( item.iServiceId == aServiceId )
       
  5366             {
       
  5367             ((*iMailAccountItemArray)[cc]).iMceConnection = ETrue;
       
  5368             ((*iMailAccountItemArray)[cc]).iOp = aOp;
       
  5369             found = ETrue;
       
  5370             }
       
  5371         }
       
  5372     if ( !found )
       
  5373         {
       
  5374         TMceMailAccountItem item;
       
  5375         item.iServiceId = aServiceId;
       
  5376         item.iMceConnection = ETrue;
       
  5377         item.iOp = aOp;
       
  5378         iMailAccountItemArray->AppendL( item );
       
  5379         }
       
  5380     }
       
  5381 
       
  5382 // ----------------------------------------------------
       
  5383 // CMceUi::RemoveOperationId
       
  5384 //
       
  5385 // ----------------------------------------------------
       
  5386 void CMceUi::RemoveOperationId( const TMsvId& /*aOpId*/, const TMsvId& aServiceId )
       
  5387     {
       
  5388     if ( !iMailAccountItemArray )
       
  5389         {
       
  5390         return;
       
  5391         }
       
  5392 
       
  5393     TInt count = iMailAccountItemArray->Count();
       
  5394 
       
  5395     for ( TInt loop=count-1; loop>=0; loop-- )
       
  5396         {
       
  5397         TMceMailAccountItem item = ((*iMailAccountItemArray)[loop]);
       
  5398         if ( item.iServiceId == aServiceId )
       
  5399             {
       
  5400             iMailAccountItemArray->Delete( loop );
       
  5401             break;
       
  5402             }
       
  5403         }
       
  5404     }
       
  5405 
       
  5406 // ----------------------------------------------------
       
  5407 // CMceUi::ServiceIdFound
       
  5408 //
       
  5409 // ----------------------------------------------------
       
  5410 TBool CMceUi::ServiceIdFound( const TMsvId& aServiceId )
       
  5411     {
       
  5412     TInt found = EFalse;
       
  5413 
       
  5414     TInt count = iMailAccountItemArray->Count();
       
  5415 
       
  5416     for ( TInt cc = 0; cc < count && !found; cc++ )
       
  5417         {
       
  5418         TMceMailAccountItem item = ((*iMailAccountItemArray)[cc]);
       
  5419         if ( item.iServiceId == aServiceId && item.iMceConnection  )
       
  5420             {
       
  5421             found = ETrue;
       
  5422             }
       
  5423         }
       
  5424     return found;
       
  5425     }
       
  5426 
       
  5427 // ----------------------------------------------------
       
  5428 // CMceUi::AlwaysOnline
       
  5429 //
       
  5430 // ----------------------------------------------------
       
  5431 TBool CMceUi::AlwaysOnline( )
       
  5432     {    
       
  5433     return iAlwaysOnline;
       
  5434     }
       
  5435 
       
  5436 // ----------------------------------------------------
       
  5437 // CMceUi::IsMessageSetToBeDeletedFromServer
       
  5438 //
       
  5439 // ----------------------------------------------------
       
  5440 TBool CMceUi::IsMailSetToBeDeletedFromServerL( TMsvId aItemId )
       
  5441     {
       
  5442     TInt rid = 0;
       
  5443     TBool ret = EFalse;
       
  5444     TMsvId serviceId;
       
  5445     TMsvEntry currentEntry;
       
  5446 
       
  5447     iSession->GetEntry( aItemId, serviceId, currentEntry );
       
  5448 
       
  5449     CBaseMtmUiData* mtmUiData = GetMtmUiDataL( currentEntry.iMtm );
       
  5450 
       
  5451     if ( mtmUiData && mtmUiData->CanUnDeleteFromEntryL( currentEntry, rid ) )
       
  5452         {
       
  5453         ret = ETrue;
       
  5454         }
       
  5455 
       
  5456     return ret;
       
  5457     }
       
  5458 
       
  5459 // ----------------------------------------------------
       
  5460 // CMceUi::AnchoredItem
       
  5461 //
       
  5462 // ----------------------------------------------------
       
  5463 //
       
  5464 void CMceUi::DefineAnchorIdL( const CMsvEntrySelection* /*aSelection*/ )
       
  5465     {
       
  5466 #if 0    
       
  5467     if ( IsMailSetToBeDeletedFromServerL() )
       
  5468         {
       
  5469         SetAnchorId( iMceListView->ListContainer()->CurrentItemId() );
       
  5470         return;
       
  5471         }
       
  5472     // TODO
       
  5473     TInt currentItem = iMceListView->ListContainer()->CurrentItemIndex();
       
  5474     CMceMessageListItemArray* items = iMceListView->ListContainer()->ListItems();
       
  5475     iAnchorId = NULL;
       
  5476     
       
  5477 // Do not change the focus if mailbox is offline and currently selected item is set to be deleted from server
       
  5478     if ( IsMailSetToBeDeletedFromServerL() )
       
  5479         {
       
  5480         SetAnchorId( iMceListView->ListContainer()->CurrentItemId() );
       
  5481         return;
       
  5482         }
       
  5483     
       
  5484     for ( TInt i = currentItem; i < items->MdcaCount(); i++ ) // Find forwards
       
  5485         {
       
  5486         if ( aSelection->Find( items->ItemId( i ) ) == KErrNotFound )
       
  5487             {
       
  5488             SetAnchorId( items->ItemId( i ) );
       
  5489             break;
       
  5490             }
       
  5491         }
       
  5492 
       
  5493     if ( !iAnchorId ) // If not found in forward search, find backwards
       
  5494         {
       
  5495         for ( TInt i = currentItem; i >= 0; i-- )
       
  5496             {
       
  5497             if ( aSelection->Find( items->ItemId( i ) ) == KErrNotFound )
       
  5498                 {
       
  5499                 SetAnchorId( items->ItemId( i ) );
       
  5500                 break;
       
  5501                 }
       
  5502             }
       
  5503         }
       
  5504 #endif        
       
  5505     }
       
  5506 
       
  5507 // ----------------------------------------------------
       
  5508 // CMceUi::AnchoredItem
       
  5509 //
       
  5510 // ----------------------------------------------------
       
  5511 TMsvId CMceUi::AnchoredItem()
       
  5512     {
       
  5513     return iAnchorId;
       
  5514     }
       
  5515 
       
  5516 // ----------------------------------------------------
       
  5517 // CMceUi::SetAnchorId
       
  5518 //
       
  5519 // ----------------------------------------------------
       
  5520 void CMceUi::SetAnchorId( TMsvId aAnchorId )
       
  5521     {
       
  5522     iAnchorId = aAnchorId;
       
  5523     }
       
  5524 
       
  5525 // ----------------------------------------------------
       
  5526 // CMceUi::EventL
       
  5527 //
       
  5528 // ----------------------------------------------------
       
  5529 void CMceUi::EventL( const CConnMonEventBase &aConnMonEvent )
       
  5530     {
       
  5531     switch ( aConnMonEvent.EventType() )
       
  5532         {
       
  5533         case EConnMonNetworkRegistrationChange:
       
  5534             {
       
  5535             CConnMonNetworkRegistrationChange* event =
       
  5536                 ( CConnMonNetworkRegistrationChange* ) &aConnMonEvent;                
       
  5537             
       
  5538             if ( iMceMainView->ListContainer() ) // Cannot set roaming if ListContainer is empty
       
  5539                 {
       
  5540                 CMceMainViewListItemArray* array = iMceMainView->ListContainer()->ListItems();
       
  5541                 if ( array && (array->Count() > 0) ) // List item array should not be empty
       
  5542                     {
       
  5543                     // Set roaming status
       
  5544                     array->SetRoaming( event->RegistrationStatus() == ENetworkRegistrationRoaming );
       
  5545                     
       
  5546                     if ( MceViewActive( EMceMainViewActive ) )
       
  5547                         {
       
  5548                         //update icon only if main view is open
       
  5549                         iMceMainView->ListContainer()->DrawDeferred();
       
  5550                         }
       
  5551                     }
       
  5552                 }
       
  5553             }
       
  5554             break;
       
  5555 
       
  5556         default:
       
  5557             break;
       
  5558         }
       
  5559     }
       
  5560 // ----------------------------------------------------
       
  5561 // CMceUi::HandleGainingForeground
       
  5562 //
       
  5563 // ----------------------------------------------------
       
  5564 void CMceUi::HandleGainingForeground() // CR : 401-1806
       
  5565     {
       
  5566    
       
  5567     // This code is added to remove screen clearer when returning from viewer.
       
  5568     if ( iMceListView )
       
  5569         {
       
  5570         CAknLocalScreenClearer** localScreenClearer = NULL; 
       
  5571         iMceListView->GetLocalScreenClearer( localScreenClearer );
       
  5572         delete *localScreenClearer;
       
  5573         *localScreenClearer = NULL;// this will assign null to iLocalScreenClearer in messagelistview.
       
  5574         }
       
  5575     if ( !iFeatureMgrEnabled )
       
  5576         {
       
  5577   	    TRAP_IGNORE( FeatureManager::InitializeLibL() );
       
  5578   	    iFeatureMgrEnabled = ETrue ;
       
  5579         }
       
  5580   	TBool newPostcardVal = EFalse;
       
  5581     TBool newAudioMsgVal = EFalse;
       
  5582     newAudioMsgVal = FeatureManager::FeatureSupported( KFeatureIdAudioMessaging );
       
  5583     newPostcardVal = FeatureManager::FeatureSupported( KFeatureIdMmsPostcard );
       
  5584     
       
  5585     if ( newAudioMsgVal != iAudioMsgEnabled || newPostcardVal != iPostcardEnabled )
       
  5586         {
       
  5587         TRAP_IGNORE( HandleMTMChangeL() );
       
  5588         }
       
  5589     
       
  5590     if ( MceViewActive( EMceMainViewActive ) && iIadUpdateVal)
       
  5591         {      
       
  5592         if(!iMceIAUpdate) // first time messaging view is activated
       
  5593             {
       
  5594             TRAP_IGNORE(iMceIAUpdate = CMceIAUpdateUtils::NewL(*this));     
       
  5595             if(iMceIAUpdate)
       
  5596                 {
       
  5597                 CheckIAUpdate();
       
  5598                 }
       
  5599             }
       
  5600         else
       
  5601             {
       
  5602             if(iMceIAUpdate->IsUpdateRequired())
       
  5603                 {
       
  5604                 CheckIAUpdate();
       
  5605                 }
       
  5606             }
       
  5607         }
       
  5608     }
       
  5609 
       
  5610 // ----------------------------------------------------
       
  5611 // CMceUi::HandleLosingForeground
       
  5612 //
       
  5613 // ----------------------------------------------------
       
  5614 void CMceUi::HandleLosingForeground() // CR : 401-1806
       
  5615     {
       
  5616     iAudioMsgEnabled = FeatureManager::FeatureSupported( KFeatureIdAudioMessaging );
       
  5617     iPostcardEnabled = FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) ;
       
  5618     if ( iFeatureMgrEnabled ) 
       
  5619         {
       
  5620   	    FeatureManager::UnInitializeLib() ;
       
  5621   	    iFeatureMgrEnabled = EFalse ;
       
  5622   	    }
       
  5623   	}
       
  5624     
       
  5625 // ----------------------------------------------------
       
  5626 // CMceUi::ToPhoneMemoryQueryL
       
  5627 //
       
  5628 // ----------------------------------------------------
       
  5629 void CMceUi::ToPhoneMemoryQueryL( TBool aShowQuery )
       
  5630     {
       
  5631 
       
  5632     if ( iPhoneMemoryQuery )
       
  5633         {
       
  5634         // If the dialog for whitching the message store is allready visible,
       
  5635         // dismiss it
       
  5636         delete iPhoneMemoryQuery;
       
  5637         iPhoneMemoryQuery = NULL;
       
  5638         return;
       
  5639         }
       
  5640 
       
  5641     //this method is run when message centre is started
       
  5642     if ( iMemoryInUse && !iMessageStoreExist && aShowQuery )
       
  5643         {
       
  5644         // check, if message store was in MMC but message server has
       
  5645         // automatically changed message store to phone memory
       
  5646         RFs& fs=iEikonEnv->FsSession();
       
  5647         iMessageStoreExist = ETrue;
       
  5648         TInt currentDrive = EDriveC;
       
  5649         currentDrive = TInt(iSession->CurrentDriveL());
       
  5650 
       
  5651         TInt i = EDriveC;
       
  5652 
       
  5653         CRepository* repository = NULL;
       
  5654         TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuSettings) );
       
  5655 
       
  5656         if ( ret == KErrNone )
       
  5657             {
       
  5658             CleanupStack::PushL( repository );
       
  5659             if ( repository->Get(KMuiuMemoryInUse,i) != KErrNone )
       
  5660                 {
       
  5661                 i = EDriveC;
       
  5662                 }
       
  5663             if ( i != EDriveC && currentDrive == EDriveC )
       
  5664                 {
       
  5665                 // message server has changed the store automatically
       
  5666                 iMessageStoreExist = EFalse;
       
  5667                 }
       
  5668             }
       
  5669 
       
  5670         if ( !iMessageStoreExist )
       
  5671             {
       
  5672             // message store was in MMC, but now there is no MMC
       
  5673             iPhoneMemoryQuery = CAknQueryDialog::NewL();
       
  5674             iPhoneMemoryQuery->ExecuteLD( R_MCE_MEMC_NOTE );
       
  5675             iPhoneMemoryQuery = NULL; // ExecuteLD deletes the object
       
  5676             }
       
  5677         iMessageStoreExist = ETrue;
       
  5678 
       
  5679         if ( ret == KErrNone )
       
  5680             {
       
  5681             ret = repository->Set( KMuiuMemoryInUse, currentDrive );
       
  5682             __ASSERT_DEBUG( !ret, User::Panic(KPanicText,KCRepositorySettingFailure) );
       
  5683             CleanupStack::PopAndDestroy( repository );
       
  5684             }
       
  5685 
       
  5686         }
       
  5687     }
       
  5688 
       
  5689 // ----------------------------------------------------
       
  5690 // CMceUi::SetMainViewActivatedFlag
       
  5691 //
       
  5692 // ----------------------------------------------------
       
  5693 void CMceUi::SetMainViewActivatedFlag( )
       
  5694     {
       
  5695     iMceUiFlags.SetMceFlag( EMceUiFlagsMainViewActivated );
       
  5696     }
       
  5697 
       
  5698 // ---------------------------------------------------------
       
  5699 // CMceUi::AlwaysOnlineL
       
  5700 // This is static function
       
  5701 // Returns ETrue if always online is supported
       
  5702 // ---------------------------------------------------------
       
  5703 TBool CMceUi::AlwaysOnlineL( )
       
  5704     {
       
  5705     TBool alwaysOnline = EFalse;
       
  5706      if ( FeatureManager::FeatureSupported( KFeatureIdAlwaysOnLine )
       
  5707         && FeatureManager::FeatureSupported( KFeatureIdAlwaysOnLineEmail ) )
       
  5708         {
       
  5709         TInt featureBitmask = 0;
       
  5710 
       
  5711         CRepository* repository = NULL;
       
  5712         TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuVariation) );
       
  5713         CleanupStack::PushL( repository );
       
  5714 
       
  5715         if ( ret == KErrNone )
       
  5716             {
       
  5717             if ( repository->Get(KMuiuEmailConfigFlags,featureBitmask) != KErrNone )
       
  5718                 {
       
  5719                 alwaysOnline = EFalse;
       
  5720                 }
       
  5721             else
       
  5722                 {
       
  5723                 alwaysOnline = featureBitmask & KEmailFeatureIdAlwaysOnline;
       
  5724                 }
       
  5725             }
       
  5726 
       
  5727         CleanupStack::Pop( repository );
       
  5728         delete repository;
       
  5729 
       
  5730         }
       
  5731 
       
  5732     return alwaysOnline;
       
  5733     }
       
  5734 
       
  5735 // ----------------------------------------------------
       
  5736 // CMceUi::RemoveFolderTabs
       
  5737 // ----------------------------------------------------
       
  5738 void CMceUi::RemoveFolderTabs()
       
  5739     {
       
  5740     MCELOGGER_ENTERFN("RemoveFolderTabs()");
       
  5741 
       
  5742     iNaviPane->Pop( iFolderIndicator );
       
  5743 
       
  5744     MCELOGGER_LEAVEFN("RemoveFolderTabs()");
       
  5745     }
       
  5746 
       
  5747 // ----------------------------------------------------
       
  5748 // CMceUi::ShowFolderTabsL
       
  5749 // ----------------------------------------------------
       
  5750 void CMceUi::ShowFolderTabsL( const TInt aDepth )
       
  5751     {
       
  5752     MCELOGGER_ENTERFN("ShowFolderTabsL()");
       
  5753 
       
  5754     CMceNaviPaneFolderIndicator* findicator =
       
  5755         static_cast<CMceNaviPaneFolderIndicator*>( iFolderIndicator->DecoratedControl() );
       
  5756 
       
  5757     findicator->SetFolderDepth( aDepth );
       
  5758     iNaviPane->PushL( *iFolderIndicator );
       
  5759 
       
  5760     MCELOGGER_LEAVEFN("ShowFolderTabsL()");
       
  5761     }
       
  5762 
       
  5763 // ----------------------------------------------------
       
  5764 // CMceUi::HandleMMSNotificationsDeleteL
       
  5765 //
       
  5766 // ----------------------------------------------------
       
  5767 void CMceUi::HandleMMSNotificationsDeleteL( TDes8& aParameter )
       
  5768     {
       
  5769     CBaseMtmUiData* uiData = NULL;
       
  5770     uiData = GetMtmUiDataL( KUidMsgMMSNotification );
       
  5771 
       
  5772     TMsvId selId = iMMSNotifications->At(0);
       
  5773     TMsvId mmsService;
       
  5774     TMsvEntry mmsEntry;
       
  5775     if ( uiData && iSession->GetEntry( selId, mmsService, mmsEntry ) == KErrNone  )
       
  5776         {
       
  5777         CBaseMtmUi& mtmUi=iMtmStore->GetMtmUiAndSetContextLC( mmsEntry );
       
  5778         CMsvSingleOpWatcher* tempSingleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  5779         CleanupStack::PushL( tempSingleOpWatcher );
       
  5780 
       
  5781         CMsvOperation* tempOp=mtmUi.InvokeAsyncFunctionL( KMtmUiFunctionDeleteMessage, *iMMSNotifications,
       
  5782             tempSingleOpWatcher->iStatus, aParameter );
       
  5783 
       
  5784         if ( tempOp )
       
  5785             {
       
  5786             CleanupStack::PushL( tempOp );
       
  5787             iOperations.AppendL( tempSingleOpWatcher );
       
  5788             CleanupStack::Pop(2); // tempSingleOpWatcher, tempOp
       
  5789             tempSingleOpWatcher->SetOperation( tempOp );
       
  5790             }
       
  5791         else
       
  5792             {
       
  5793             // User answered 'No' to the confirmation query and
       
  5794             // NULL operation was returned
       
  5795             CleanupStack::PopAndDestroy( tempSingleOpWatcher );
       
  5796             if( iMMSNotifications )
       
  5797                 {
       
  5798                 delete iMMSNotifications;
       
  5799                 iMMSNotifications = NULL;
       
  5800                 }
       
  5801             }
       
  5802         CleanupStack::PopAndDestroy( ); // mtmUi
       
  5803         }
       
  5804 
       
  5805     }
       
  5806 
       
  5807 // ----------------------------------------------------
       
  5808 // CMceUi::CheckMMSNotificationsL
       
  5809 //
       
  5810 // ----------------------------------------------------
       
  5811 void CMceUi::CheckMMSNotificationsL( CMsvEntrySelection* aSelection )
       
  5812     {
       
  5813     TMsvId id;
       
  5814     TMsvId service;
       
  5815     TMsvEntry tEntry;
       
  5816     CBaseMtmUiData* uiData = NULL;
       
  5817     uiData = GetMtmUiDataL( KUidMsgMMSNotification );
       
  5818 
       
  5819     if ( iMMSNotifications )
       
  5820         {
       
  5821         delete iMMSNotifications;
       
  5822         iMMSNotifications = NULL;
       
  5823         }
       
  5824     iMMSNotifications = new( ELeave ) CMsvEntrySelection();
       
  5825 
       
  5826     for ( TInt cc=aSelection->Count(); --cc>=0; )
       
  5827         {
       
  5828         id = aSelection->At(cc);
       
  5829         if ( iSession->GetEntry( id, service, tEntry ) == KErrNone  )
       
  5830             {
       
  5831             if ( tEntry.iMtm == KUidMsgMMSNotification )
       
  5832                 {
       
  5833                 if ( uiData && !uiData->OperationSupportedL( KMtmUiFunctionDeleteMessage, tEntry ) )
       
  5834                     {
       
  5835                     iMMSNotifications->AppendL( tEntry.Id() );
       
  5836                     aSelection->Delete( cc );
       
  5837                     }
       
  5838                 else
       
  5839                     {
       
  5840                     aSelection->Delete( cc );
       
  5841                     }
       
  5842                 }
       
  5843             }
       
  5844         }
       
  5845 
       
  5846     }
       
  5847 
       
  5848 // ----------------------------------------------------
       
  5849 // CMceUi::OpenMailboxSettingsL
       
  5850 // ----------------------------------------------------
       
  5851 void CMceUi::OpenMailboxSettingsL()
       
  5852     {
       
  5853     MCELOGGER_ENTERFN("OpenMailboxSettingsL()");
       
  5854 
       
  5855     if ( MceViewActive( EMceMainViewActive ) )
       
  5856         {
       
  5857         return;
       
  5858         }
       
  5859 
       
  5860     // Is settings opened from General Settings
       
  5861     CMuiuLock* repositoryLock = CMuiuLock::NewL( KMuiuLockSettings );
       
  5862     CleanupStack::PushL(repositoryLock);
       
  5863     TInt err = repositoryLock->Reserve();
       
  5864     // Check that settings are not opened from General Settings
       
  5865     if ( !err )
       
  5866         {
       
  5867         iMceListView->OpenMailboxSettingsL();
       
  5868         }
       
  5869     else
       
  5870         {
       
  5871         // Show information note: General Settings has opened settings
       
  5872         CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(
       
  5873             CAknNoteDialog::ENoTone, CAknNoteDialog::ELongTimeout);
       
  5874         dlg->ExecuteLD(R_MCE_NOTE_SETTINGS_OPEN_GS);
       
  5875         }
       
  5876     repositoryLock->Release();
       
  5877     CleanupStack::PopAndDestroy( repositoryLock );
       
  5878 
       
  5879     MCELOGGER_LEAVEFN("OpenMailboxSettingsL");
       
  5880     }
       
  5881 
       
  5882 // ----------------------------------------------------
       
  5883 // CMceUi::SyncMlMarkAsReadL
       
  5884 // ----------------------------------------------------
       
  5885 void CMceUi::SyncMlMarkAsReadL( )
       
  5886     {
       
  5887     if ( MceViewActive( EMceMainViewActive ) )
       
  5888         {
       
  5889         return;
       
  5890         }
       
  5891 
       
  5892     CMsvEntrySelection * selection = iMceListView->ListContainer()
       
  5893         ->CurrentItemSelectionL();
       
  5894     CleanupStack::PushL( selection );
       
  5895 
       
  5896     if (  selection->Count() <= 0 )
       
  5897         {
       
  5898         CleanupStack::PopAndDestroy( selection );
       
  5899         return;
       
  5900         }
       
  5901 
       
  5902     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( KSenduiMtmSyncMLEmailUid );
       
  5903 
       
  5904     CMsvSingleOpWatcher* tempSingleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  5905     CleanupStack::PushL( tempSingleOpWatcher );
       
  5906     TBuf8<1> blankParams;
       
  5907 
       
  5908     CMsvOperation* tempOp = mtmUi.InvokeAsyncFunctionL( KMtmUiFunctionMarkAsRead, *selection,
       
  5909         tempSingleOpWatcher->iStatus, blankParams );
       
  5910 
       
  5911     CleanupStack::PushL( tempOp );
       
  5912     iOperations.AppendL( tempSingleOpWatcher );
       
  5913     CleanupStack::Pop( 2 ); // tempSingleOpWatcher, tempOp
       
  5914     tempSingleOpWatcher->SetOperation( tempOp );
       
  5915     CleanupStack::PopAndDestroy( 2 ); // mtmUi, selection
       
  5916     }
       
  5917 
       
  5918 // ----------------------------------------------------
       
  5919 // CMceUi::CheckMMSNotifDelFailedL
       
  5920 // ----------------------------------------------------
       
  5921 void CMceUi::CheckMMSNotifDelFailedL()
       
  5922     {
       
  5923     MCELOGGER_ENTERFN("CheckMMSNotifDelFailedL()");
       
  5924 
       
  5925     CBaseMtmUiData* data = GetMtmUiDataL( KUidMsgMMSNotification );
       
  5926     if ( data )
       
  5927         {
       
  5928         TInt count = iMMSNotifications->Count();
       
  5929         TInt failed = 0;
       
  5930         TMsvId serviceId;
       
  5931         for(TInt loop = 0; loop < count; loop++)
       
  5932             {
       
  5933             TMsvEntry entry;
       
  5934             if ( iSession->GetEntry(iMMSNotifications->At(loop),serviceId,entry) == KErrNone )
       
  5935             	{
       
  5936             	if ( !( entry.iMtmData2 & KMmsNewOperationForbidden ) &&
       
  5937                 	!( entry.iMtmData2 & KMmsOperationOngoing ) &&
       
  5938                 	( entry.iMtmData2 & KMmsOperationFinished ) &&
       
  5939                 	( entry.iMtmData2 & KMmsOperationResult ) )
       
  5940                 	{
       
  5941                 	failed++;               
       
  5942                 	}
       
  5943             	}
       
  5944             } // end loop
       
  5945 
       
  5946 
       
  5947         if ( failed > 0 )
       
  5948             {
       
  5949             CAknQueryDialog* note = CAknQueryDialog::NewL();
       
  5950             HBufC* text = NULL;
       
  5951             if ( failed == KMceOneMMSNotificationFailed )
       
  5952                 {
       
  5953                 text = StringLoader::LoadLC(
       
  5954                     R_MMS_INFO_REMOTE_DEL_FAILED, iEikonEnv );
       
  5955                 note->SetPromptL( *text );
       
  5956                 note->ExecuteLD( R_MCE_MEMC_NOTE );
       
  5957                 CleanupStack::PopAndDestroy(  ); // text
       
  5958                 }
       
  5959             else
       
  5960                 {
       
  5961                 CArrayFix<TInt>* indexArray =
       
  5962                      new( ELeave ) CArrayFixFlat<TInt>( KMceArrayGranularity );
       
  5963                 CleanupStack::PushL( indexArray );
       
  5964                 indexArray->AppendL( failed );
       
  5965                 indexArray->AppendL( count );
       
  5966                 text = StringLoader::LoadLC(
       
  5967                     R_MMS_INFO_REMOTE_DEL_FAILED_MANY, *indexArray, iEikonEnv );
       
  5968 
       
  5969                 note->SetPromptL( *text );
       
  5970                 note->ExecuteLD( R_MCE_MEMC_NOTE );
       
  5971                 CleanupStack::PopAndDestroy( 2 ); // text, indexArray
       
  5972                 }
       
  5973            }
       
  5974 
       
  5975        delete iMMSNotifications;
       
  5976        iMMSNotifications = NULL;
       
  5977        }
       
  5978 
       
  5979     MCELOGGER_LEAVEFN("CheckMMSNotifDelFailedL");
       
  5980     }
       
  5981 
       
  5982 // ----------------------------------------------------
       
  5983 // CMceUi::AddMultiselectionMTMFunctionsL
       
  5984 // ----------------------------------------------------
       
  5985 void CMceUi::AddMultiselectionMTMFunctionsL(CEikMenuPane& aMenuPane, TInt /*aMenuCommandId*/)
       
  5986     {
       
  5987     MCELOGGER_ENTERFN("AddMultiselectionMTMFunctionsL()");
       
  5988     
       
  5989     CEikMenuPaneItem::SData data;
       
  5990     data.iCascadeId = 0;
       
  5991     data.iFlags = 0;
       
  5992     TInt cc;
       
  5993     TInt sendCmd = EMceCmdFirstMTMFunction;
       
  5994     const TInt count = iMTMFunctionsArray->Count();
       
  5995 
       
  5996     for ( cc = 0; cc < count; cc++ )
       
  5997         {
       
  5998         TMsgFunctionInfo& functionInfo = iMTMFunctionsArray->At(cc);
       
  5999         data.iText = functionInfo.iCaption;
       
  6000         data.iCommandId = sendCmd;
       
  6001 
       
  6002         if ( ( functionInfo.iFuncId == KMtmUiFunctionMMBox ) &&
       
  6003             ( MceViewActive( EMceMessageViewActive ) && 
       
  6004             iMceListView->ListContainer()->CurrentFolderId() 
       
  6005             == KMsvGlobalInBoxIndexEntryId ) ) //MMS notification
       
  6006             {
       
  6007             TInt pos;
       
  6008             if ( !aMenuPane.MenuItemExists ( sendCmd, pos ) )
       
  6009                 {
       
  6010                 aMenuPane.AddMenuItemL( data, EAknCmdOpen );
       
  6011                 }
       
  6012             }
       
  6013 
       
  6014         sendCmd++;
       
  6015         }
       
  6016     MCELOGGER_LEAVEFN("AddMultiselectionMTMFunctionsL()");
       
  6017     }
       
  6018 
       
  6019 // ----------------------------------------------------
       
  6020 // CMceUi::CheckCspBitL
       
  6021 // ----------------------------------------------------
       
  6022 TBool CMceUi::CheckCspBitL( ) const
       
  6023     {
       
  6024     MCELOGGER_ENTERFN("CheckCspBitL()");
       
  6025     RCustomerServiceProfileCache csp;
       
  6026     TInt error = csp.Open();
       
  6027     if ( error )
       
  6028         {
       
  6029         return ETrue;
       
  6030         }
       
  6031 
       
  6032     RMobilePhone::TCspTeleservices params;
       
  6033     TInt retVal = csp.CspTeleServices( params );
       
  6034     csp.Close();
       
  6035 
       
  6036     if ( retVal == KErrNone )
       
  6037         {
       
  6038         if ( ( params&RMobilePhone::KCspSMCB ) != 0 )
       
  6039             {
       
  6040             MCELOGGER_LEAVEFN("CheckCspBitL()");
       
  6041             // Cell Broadcast CSP bit is on
       
  6042             return ETrue;
       
  6043             }
       
  6044         else
       
  6045             {
       
  6046             MCELOGGER_LEAVEFN("CheckCspBitL()");
       
  6047             // Cell Broadcast CSP bit is off
       
  6048             return EFalse;
       
  6049             }
       
  6050         }
       
  6051     else
       
  6052         {
       
  6053         MCELOGGER_LEAVEFN("CheckCspBitL()");
       
  6054         // Error: By default show the CBS service
       
  6055         return ETrue;
       
  6056         }
       
  6057     }
       
  6058 
       
  6059 // ---------------------------------------------------------
       
  6060 // CMceUi::CspBitsL
       
  6061 // Returns ETrue if csp bits is supported
       
  6062 // ---------------------------------------------------------
       
  6063 //
       
  6064 TBool CMceUi::CspBitsL( )
       
  6065     {
       
  6066     TBool csp = EFalse;
       
  6067     TInt featureBitmask = 0;
       
  6068 
       
  6069     CRepository* repository = NULL;
       
  6070     TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuVariation) );
       
  6071     CleanupStack::PushL( repository );
       
  6072 
       
  6073     if ( ret == KErrNone )
       
  6074         {
       
  6075         if ( repository->Get(KMuiuMceFeatures,featureBitmask) != KErrNone )
       
  6076             {
       
  6077             csp = EFalse;
       
  6078             }
       
  6079         else
       
  6080             {
       
  6081             csp = featureBitmask & KMceFeatureIdCSPSupport;
       
  6082             }
       
  6083         }
       
  6084 
       
  6085     CleanupStack::Pop( repository );
       
  6086     delete repository;
       
  6087 
       
  6088     return csp;
       
  6089     }
       
  6090 
       
  6091 // ---------------------------------------------------------
       
  6092 // CMmsViewerAppUi::DoUploadL
       
  6093 // ---------------------------------------------------------
       
  6094 void CMceUi::DoUploadL( TInt aIndex )
       
  6095     {
       
  6096     TInt i = aIndex;
       
  6097     CSendingServiceInfo* info = iUploadServices[ i ];
       
  6098     TMsgUploadParameters uploadParams;
       
  6099     uploadParams.iDirect = ( info->ServiceProviderId() == KMmsDirectUpload );
       
  6100     uploadParams.iRealAddress = info->ServiceAddress();
       
  6101     uploadParams.iAlias = info->ServiceName();
       
  6102 
       
  6103     // Pack upload parameters
       
  6104     TPckgBuf<TMsgUploadParameters> param( uploadParams );
       
  6105 
       
  6106     // Current selection
       
  6107     CMsvEntrySelection* selection = iMceListView->ListContainer()->CurrentItemSelectionL();
       
  6108     CleanupStack::PushL( selection );
       
  6109 
       
  6110     CAknInputBlock::NewLC();
       
  6111     CMuiuOperationWait* wait =
       
  6112         CMuiuOperationWait::NewLC( EActivePriorityWsEvents + 10 );
       
  6113 
       
  6114 // Get a handle of the MMS MTM
       
  6115     CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiLC( KSenduiMtmMmsUid );
       
  6116 
       
  6117     CMsvOperation* oper = mtmUi.InvokeAsyncFunctionL(
       
  6118         KMtmUiFunctionUpload,
       
  6119         *selection,
       
  6120         wait->iStatus,
       
  6121         param );
       
  6122     CleanupStack::PushL( oper );
       
  6123 
       
  6124     wait->Start();
       
  6125 
       
  6126     CleanupStack::PopAndDestroy( 5, selection ); // selection, CAknInputBlock, wait, oper
       
  6127     }
       
  6128 
       
  6129 // ---------------------------------------------------------
       
  6130 // CMceUi::ShowUploadQueryL
       
  6131 // ---------------------------------------------------------
       
  6132 void CMceUi::ShowUploadQueryL()
       
  6133     {
       
  6134     TInt count = iUploadServices.Count();
       
  6135 
       
  6136     TInt selectedIndex = 0;
       
  6137     CAknListQueryDialog* dlg = new ( ELeave )
       
  6138         CAknListQueryDialog( &selectedIndex );
       
  6139     dlg->PrepareLC( R_MCE_UPLOAD_LIST_QUERY );
       
  6140 
       
  6141     // Populate list query array
       
  6142     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 4 );
       
  6143     CleanupStack::PushL( array );
       
  6144     for ( TInt i = 0; i < count; i++ )
       
  6145         {
       
  6146         array->AppendL( iUploadServices[ i ]->ServiceMenuName() );
       
  6147         }
       
  6148     dlg->SetItemTextArray( array );
       
  6149     CleanupStack::Pop( array );
       
  6150 
       
  6151     if ( dlg->RunLD() )
       
  6152         {
       
  6153         DoUploadL( selectedIndex );
       
  6154         }
       
  6155 
       
  6156     }
       
  6157 
       
  6158 // MMS.Content.Upload
       
  6159 // ---------------------------------------------------------
       
  6160 // CMceUi::NumUploadServices
       
  6161 // ---------------------------------------------------------
       
  6162 TInt CMceUi::NumUploadServices()
       
  6163     {
       
  6164     return iUploadServices.Count();
       
  6165     }
       
  6166 
       
  6167 // ---------------------------------------------------------
       
  6168 // CMceUi::HandleNotifL
       
  6169 // ---------------------------------------------------------
       
  6170 void CMceUi::HandleNotif()
       
  6171     {
       
  6172     if ( !iEmailNotifHandler )
       
  6173         {
       
  6174         // Handling of NCN reset
       
  6175         TRAPD( err, iEmailNotifHandler = CMceEmailNotifHandler::NewL() );
       
  6176         MCELOGGER_WRITE_FORMAT("ConstructL iEmailNotifHandler err %d", err);
       
  6177         if ( err )
       
  6178             {
       
  6179             iEmailNotifHandler = NULL;
       
  6180             }
       
  6181         }
       
  6182     if (iEmailNotifHandler)
       
  6183         iEmailNotifHandler->HandleNotif();
       
  6184     }
       
  6185 
       
  6186 // ---------------------------------------------------------
       
  6187 // CMceUi::HandleNotifL
       
  6188 // ---------------------------------------------------------
       
  6189 void CMceUi::HandleNotif(const TMsvId& aMailbox)
       
  6190     {
       
  6191     if ( !iEmailNotifHandler )
       
  6192         {
       
  6193         // Handling of NCN reset
       
  6194         TRAPD( err, iEmailNotifHandler = CMceEmailNotifHandler::NewL() );
       
  6195         if ( err )
       
  6196             {
       
  6197             iEmailNotifHandler = NULL;
       
  6198             }
       
  6199         }
       
  6200     if ( iEmailNotifHandler )
       
  6201         {
       
  6202         iEmailNotifHandler->HandleNotif(aMailbox);
       
  6203         }
       
  6204     }
       
  6205 
       
  6206 // ---------------------------------------------------------
       
  6207 // CMceUi::CheckSIMAccessProfileL
       
  6208 // ---------------------------------------------------------
       
  6209 void CMceUi::CheckSIMAccessProfileL()
       
  6210     {
       
  6211     // P&S key of the SIM access profile
       
  6212     RProperty property;
       
  6213     TInt sapState( 0 );
       
  6214     User::LeaveIfError( property.Attach( KPSUidBluetoothSapConnectionState, KBTSapConnectionState ) );
       
  6215     CleanupClosePushL( property );
       
  6216     
       
  6217     property.Get( sapState );
       
  6218 
       
  6219     if ( (sapState==EBTSapConnecting) || (sapState==EBTSapConnected) )
       
  6220         {
       
  6221         // SIM access profile is connecting/connected, MCE is not started
       
  6222         HBufC* text = StringLoader::LoadLC( R_QTN_OFFLINE_NOT_POSSIBLE_SAP, iEikonEnv );
       
  6223         // ETrue waiting/non-waiting dialoog
       
  6224         CAknInformationNote* note = new(ELeave) CAknInformationNote( ETrue );
       
  6225         note->SetTimeout( CAknNoteDialog::ELongTimeout ); // ELongTimeout
       
  6226         note->ExecuteLD( *text );
       
  6227         CleanupStack::PopAndDestroy( text );
       
  6228         // Exit the application
       
  6229         CleanupStack::PopAndDestroy( &property );
       
  6230         Exit();
       
  6231         }
       
  6232     else
       
  6233         {
       
  6234         CleanupStack::PopAndDestroy( &property );       
       
  6235         }
       
  6236     }
       
  6237 
       
  6238 // ---------------------------------------------------------
       
  6239 // CMceUi::SetViewUpdateSuppressionFlag
       
  6240 // ---------------------------------------------------------
       
  6241 void CMceUi::SetViewUpdateSuppressionFlag( TBool aValue, CMsvOperation* aOp )
       
  6242     {
       
  6243     if ( aValue )
       
  6244         {
       
  6245         iMceUiFlags.SetMceFlag( EMceUiFlagsSupressViewUpdate );
       
  6246         iBlockingOperation = aOp;
       
  6247         }
       
  6248     else
       
  6249         {
       
  6250         iMceUiFlags.ClearMceFlag( EMceUiFlagsSupressViewUpdate );
       
  6251         iBlockingOperation = NULL;
       
  6252         }
       
  6253 
       
  6254     }
       
  6255 
       
  6256 // ---------------------------------------------------------
       
  6257 // CMceUi::ViewUpdateSuppressionFlag
       
  6258 // ---------------------------------------------------------
       
  6259 TBool CMceUi::ViewUpdateSuppressionFlag()
       
  6260     {
       
  6261     return iMceUiFlags.MceFlag( EMceUiFlagsSupressViewUpdate );
       
  6262     }
       
  6263 
       
  6264 // ---------------------------------------------------------
       
  6265 // CMceUi::ReleaseMtmUiData
       
  6266 // ---------------------------------------------------------
       
  6267 void CMceUi::ReleaseMtmUiData()
       
  6268     {
       
  6269     MCELOGGER_ENTERFN("ReleaseMtmUiData()");
       
  6270     const TInt count = iUiRegistry->NumRegisteredMtmDlls();
       
  6271     MCELOGGER_WRITE_FORMAT("Mtm cound %d", count);
       
  6272 
       
  6273     for ( TInt i = 0; i < count; i++ )
       
  6274         {
       
  6275         TUid uid = iUiRegistry->MtmTypeUid(i);
       
  6276         if ( !MceUtils::IsMtmBuiltIn(uid) )
       
  6277             {
       
  6278             iMtmStore->ReleaseMtmUiData( uid );
       
  6279             }
       
  6280         }
       
  6281     MCELOGGER_LEAVEFN("ReleaseMtmUiData()");
       
  6282     }
       
  6283 
       
  6284 // ---------------------------------------------------------
       
  6285 // CMceUi::InformationNoteCannotMoveCopyEMailL
       
  6286 // ---------------------------------------------------------
       
  6287 void CMceUi::InformationNoteCannotMoveCopyEMailL()
       
  6288     {
       
  6289     HBufC* errorText = StringLoader::LoadL( R_MCE_INFO_CANNOT_MOVE, iEikonEnv );
       
  6290     CleanupStack::PushL( errorText );
       
  6291     CAknInformationNote* note = new(ELeave)CAknInformationNote( ETrue );
       
  6292     note->ExecuteLD(*errorText);
       
  6293     CleanupStack::PopAndDestroy( errorText );
       
  6294     }
       
  6295 
       
  6296 // ---------------------------------------------------------
       
  6297 // CMceUi::RemoveEmailMessagesFromSelection
       
  6298 // ---------------------------------------------------------
       
  6299 TBool CMceUi::RemoveEmailMessagesFromSelection( CMsvEntrySelection *aSelection )
       
  6300     {
       
  6301     TBool mailMessage = EFalse;
       
  6302     TInt count = aSelection->Count();
       
  6303     TMsvId service;
       
  6304     TMsvEntry tEntry;
       
  6305 
       
  6306     for ( TInt cc=count; --cc>=0; )
       
  6307         {
       
  6308         TMsvId id = aSelection->At(cc);
       
  6309         if ( iSession->GetEntry( id, service, tEntry ) == KErrNone  )
       
  6310             {
       
  6311             if ( tEntry.iMtm==KSenduiMtmImap4Uid || tEntry.iMtm==KSenduiMtmPop3Uid ||
       
  6312                  tEntry.iMtm==KSenduiMtmSmtpUid )
       
  6313                 {
       
  6314                 aSelection->Delete( cc );
       
  6315                 mailMessage = ETrue;
       
  6316                 }
       
  6317             }
       
  6318         }
       
  6319 
       
  6320     return mailMessage;
       
  6321     }
       
  6322 
       
  6323 // ---------------------------------------------------------
       
  6324 // CMceUi::MailboxCreationOn
       
  6325 // ---------------------------------------------------------
       
  6326 TBool CMceUi::MailboxCreationOn()
       
  6327     {
       
  6328     return iMailboxCreationOn;
       
  6329     }
       
  6330 
       
  6331 // ---------------------------------------------------------
       
  6332 // CMceUi::ZoomLevelChangedL
       
  6333 // ---------------------------------------------------------
       
  6334 TAknUiZoom CMceUi::ZoomLevelChangedL( TAknUiZoom aZoomLevel )
       
  6335     {
       
  6336     TAknUiZoom previous = LocalUiZoom();
       
  6337     if ( aZoomLevel != previous &&
       
  6338         !iMceUiFlags.MceFlag( EMceUiFlagsSettingsDialogOpen ) )
       
  6339         {
       
  6340         SetLocalUiZoom( aZoomLevel );
       
  6341         ApplyLayoutChangeL( ETrue );
       
  6342         }
       
  6343     return previous;
       
  6344     }
       
  6345 
       
  6346 // ---------------------------------------------------------
       
  6347 // CMceUi::ReadZoomLevelL
       
  6348 // ---------------------------------------------------------
       
  6349 TAknUiZoom CMceUi::ReadZoomLevelL()
       
  6350     {
       
  6351     TInt zoomValue = EAknUiZoomAutomatic;
       
  6352     CRepository* repository = NULL;
       
  6353     TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuSettings) );
       
  6354     if ( ret == KErrNone )
       
  6355         {
       
  6356         CleanupStack::PushL( repository );
       
  6357         if ( repository->Get(KMuiuZoomValue, zoomValue) != KErrNone )
       
  6358             {
       
  6359             zoomValue = EAknUiZoomAutomatic;
       
  6360             }
       
  6361         CleanupStack::PopAndDestroy( repository );
       
  6362         }
       
  6363     return (TAknUiZoom) zoomValue;
       
  6364     }
       
  6365 
       
  6366 // ---------------------------------------------------------
       
  6367 // CMceUi::WriteZoomLevelL
       
  6368 // ---------------------------------------------------------
       
  6369 void CMceUi::WriteZoomLevelL( TAknUiZoom aZoomLevel )
       
  6370     {
       
  6371     CRepository* repository = NULL;
       
  6372     TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuSettings) );
       
  6373     if ( ret == KErrNone )
       
  6374         {
       
  6375         CleanupStack::PushL( repository );
       
  6376         if ( repository->Set(KMuiuZoomValue, aZoomLevel) != KErrNone )
       
  6377             {
       
  6378             // hmm, just ignore?
       
  6379             }
       
  6380         CleanupStack::PopAndDestroy( repository );
       
  6381         }
       
  6382     }
       
  6383 
       
  6384 // ---------------------------------------------------------
       
  6385 // CMceUi::HandleZoomLevelChangeL
       
  6386 // ---------------------------------------------------------
       
  6387 void CMceUi::HandleZoomLevelChangeL( TInt aCommand )
       
  6388     {
       
  6389     TAknUiZoom uiZoom;
       
  6390     switch ( aCommand )
       
  6391         {
       
  6392         default:
       
  6393         case EMceCmdZoomValueAutomatic:
       
  6394            uiZoom = EAknUiZoomAutomatic;
       
  6395            break;
       
  6396         case EMceCmdZoomValueLarge:
       
  6397            uiZoom = EAknUiZoomLarge;
       
  6398            break;
       
  6399         case EMceCmdZoomValueMedium:
       
  6400            uiZoom = EAknUiZoomNormal;
       
  6401            break;
       
  6402         case EMceCmdZoomValueSmall:
       
  6403            uiZoom = EAknUiZoomSmall;
       
  6404            break;
       
  6405         }
       
  6406 
       
  6407     TAknUiZoom previousZoom = ZoomLevelChangedL( uiZoom );
       
  6408     if ( previousZoom != uiZoom )
       
  6409         {
       
  6410         WriteZoomLevelL( uiZoom );
       
  6411         }
       
  6412     }
       
  6413 
       
  6414 // ---------------------------------------------------------
       
  6415 // CMceUi::HandleZoomSubMenu
       
  6416 // ---------------------------------------------------------
       
  6417 void CMceUi::HandleZoomSubMenu( CEikMenuPane* aMenuPane )
       
  6418     {
       
  6419     TAknUiZoom currentLevel = LocalUiZoom();
       
  6420     TInt buttonId = EMceCmdZoomValueAutomatic;
       
  6421     switch ( currentLevel )
       
  6422         {
       
  6423         default:
       
  6424         case EAknUiZoomAutomatic:
       
  6425             buttonId = EMceCmdZoomValueAutomatic;
       
  6426             break;
       
  6427         case EAknUiZoomLarge:
       
  6428             buttonId = EMceCmdZoomValueLarge;
       
  6429             break;
       
  6430         case EAknUiZoomNormal:
       
  6431             buttonId = EMceCmdZoomValueMedium;
       
  6432             break;
       
  6433         case EAknUiZoomSmall:
       
  6434             buttonId = EMceCmdZoomValueSmall;
       
  6435             break;
       
  6436         }
       
  6437     aMenuPane->SetItemButtonState( buttonId, EEikMenuItemSymbolOn );
       
  6438     }
       
  6439 
       
  6440 // ----------------------------------------------------
       
  6441 // CMceUi::ForwardL
       
  6442 //
       
  6443 // ----------------------------------------------------
       
  6444 void CMceUi::ForwardL(TInt /*aForwardCommand*/)
       
  6445     {
       
  6446     MCELOGGER_ENTERFN( "MceUi::ForwardL()----Start>>>>" );
       
  6447 
       
  6448     LeaveIfDiskSpaceUnderCriticalLevelL( iDiskSpaceForMoveOrCopy );
       
  6449 
       
  6450     if ( MceViewActive( EMceMainViewActive ) )
       
  6451         {
       
  6452         return;
       
  6453         }
       
  6454 
       
  6455     CMsvEntrySelection * selection = iMceListView->ListContainer()->CurrentItemSelectionL();
       
  6456     CleanupStack::PushL( selection );
       
  6457     if ( selection->Count() <= 0)
       
  6458         {
       
  6459         CleanupStack::PopAndDestroy( selection );
       
  6460         return;
       
  6461         }
       
  6462 
       
  6463     TMsvEntry entry;
       
  6464     TMsvId serviceId;
       
  6465     User::LeaveIfError( iSession->GetEntry(selection->At(0),serviceId,entry) );
       
  6466     CleanupStack::PopAndDestroy( selection );
       
  6467 
       
  6468     TMsvPartList parts = KMsvMessagePartBody | KMsvMessagePartOriginator | KMsvMessagePartDescription | KMsvMessagePartAttachments;
       
  6469 
       
  6470     CBaseMtmUi& ui=iMtmStore->GetMtmUiAndSetContextLC( entry );
       
  6471     ui.SetPreferences( ui.Preferences() | EMtmUiFlagEditorPreferEmbedded );
       
  6472     CAknInputBlock::NewLC();
       
  6473     CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL( *this );
       
  6474     CleanupStack::PushL( singleOpWatcher );
       
  6475 
       
  6476     CMsvOperation* oper = ui.ForwardL(
       
  6477         KMsvDraftEntryIdValue, parts, singleOpWatcher->iStatus );
       
  6478     iEditorOperation = singleOpWatcher;
       
  6479 
       
  6480     CleanupStack::PushL( oper );
       
  6481     iOperations.AppendL( singleOpWatcher );
       
  6482     CleanupStack::Pop( 2, singleOpWatcher ); // oper
       
  6483     singleOpWatcher->SetOperation( oper );
       
  6484     MCELOGGER_WRITE_FORMAT( "iOperations.AppendL(%d)", oper->Id() );
       
  6485     CleanupStack::PopAndDestroy( 2 ); // CAknInputBlock, ui
       
  6486 
       
  6487     MCELOGGER_LEAVEFN( "MceUi::ForwardL()----End<<<<" );
       
  6488 
       
  6489     }
       
  6490 
       
  6491 // ----------------------------------------------------
       
  6492 // CMceUi::HandleNewMsgToInboxL
       
  6493 // Remove New Flag from selected message(s) if there is any
       
  6494 // From 5.0
       
  6495 // ----------------------------------------------------
       
  6496 void CMceUi::HandleNewMsgToInboxL( TBool removeNewFlag, CMsvEntrySelection* aSelection )
       
  6497     {
       
  6498     TMsvEntry aEntry;
       
  6499 
       
  6500     if ( !removeNewFlag && ( !iIdArray ) )
       
  6501         {
       
  6502         return;
       
  6503         }
       
  6504     else if( removeNewFlag )
       
  6505         {
       
  6506         if ( iIdArray )
       
  6507             {
       
  6508             delete iIdArray;
       
  6509             iIdArray = NULL;
       
  6510             }
       
  6511         iIdArray = new ( ELeave ) CMsvEntrySelection;
       
  6512         for (TInt i = 0; i < aSelection->Count(); ++i )
       
  6513             {
       
  6514             TMsvId selectedId = aSelection->At(i);
       
  6515             iEntry->SetEntryL( selectedId );
       
  6516             aEntry = iEntry->Entry();
       
  6517             if ( aEntry.Unread() )
       
  6518                 {
       
  6519                 iIdArray->AppendL( selectedId );
       
  6520                 aEntry.SetUnread( EFalse );
       
  6521                 iEntry->ChangeL( aEntry );
       
  6522                 }
       
  6523             }
       
  6524         if ( iIdArray->Count() )
       
  6525             {
       
  6526             iHandleNewMsgToInbox = ETrue;
       
  6527             }
       
  6528         }
       
  6529     else
       
  6530         {
       
  6531         for ( TInt i = 0; i < iIdArray->Count(); ++i )
       
  6532             {
       
  6533             iEntry->SetEntryL( iIdArray->At(i) );
       
  6534             aEntry = iEntry->Entry();
       
  6535             aEntry.SetUnread( ETrue );
       
  6536             iEntry->ChangeL( aEntry );
       
  6537             }
       
  6538         delete iIdArray;
       
  6539         iIdArray = NULL;
       
  6540         iHandleNewMsgToInbox = EFalse;
       
  6541         }
       
  6542     }
       
  6543 
       
  6544 
       
  6545 // ----------------------------------------------------
       
  6546 // TBool CMceUi::HasNewEmailL
       
  6547 // Check if there is new email the the folder
       
  6548 // public
       
  6549 // ----------------------------------------------------
       
  6550 TBool CMceUi::HasNewEmailL( TMsvId aFolderId )
       
  6551     {
       
  6552     CMsvEntry* entry = iSession->GetEntryL( aFolderId );
       
  6553     CleanupStack::PushL( entry );
       
  6554 
       
  6555     TBool newEmail = EFalse;
       
  6556     const TInt count = entry->Count();
       
  6557     for ( TInt loop = 0; loop < count ; loop++ )
       
  6558         {
       
  6559         if ( (*entry)[loop].iType.iUid != KUidMsvFolderEntryValue )
       
  6560             {
       
  6561             if ( (*entry)[loop].New() )
       
  6562                 {
       
  6563                 newEmail = ETrue;
       
  6564                 break;
       
  6565                 }
       
  6566             }
       
  6567         }
       
  6568     CleanupStack::PopAndDestroy( entry );
       
  6569     return newEmail;
       
  6570     }
       
  6571 
       
  6572 // ----------------------------------------------------
       
  6573 // void CMceUi::SetDiskSpaceForMoveOrCopyL
       
  6574 // Reads critical and warning levels from cenrep
       
  6575 // ----------------------------------------------------
       
  6576 void CMceUi::SetDiskSpaceForMoveOrCopyL( )
       
  6577     {
       
  6578     // If can't open cenrep use default value
       
  6579     iDiskSpaceForMoveOrCopy = KMceDiskSpaceForMoveOrCopy;
       
  6580     TInt diskWarningThreshold = 0;
       
  6581     TInt diskCriticalThreshold = 0;
       
  6582     
       
  6583     CRepository* repository = NULL;
       
  6584     TRAPD( ret, repository = CRepository::NewL( KCRUidUiklaf ) );
       
  6585 
       
  6586     if ( ret == KErrNone )
       
  6587         {
       
  6588         CleanupStack::PushL( repository );
       
  6589         if ( repository->Get( KUikOODDiskWarningThreshold, 
       
  6590              diskWarningThreshold ) == KErrNone && 
       
  6591              repository->Get( KUikOODDiskCriticalThreshold,
       
  6592              diskCriticalThreshold ) == KErrNone )
       
  6593             {
       
  6594             iDiskSpaceForMoveOrCopy = diskWarningThreshold 
       
  6595             - diskCriticalThreshold;        
       
  6596             }
       
  6597         CleanupStack::PopAndDestroy( repository );
       
  6598         }
       
  6599 
       
  6600     }
       
  6601 // ----------------------------------------------------
       
  6602 // CMceUi::LaunchUniEditorL
       
  6603 // ----------------------------------------------------
       
  6604 //    
       
  6605 void CMceUi::LaunchUniEditorL()
       
  6606     {
       
  6607     //KUidUniMtm 0x102072D6
       
  6608     CreateNewMessageL( KSenduiMtmUniMessageUidValue ); 
       
  6609     }    
       
  6610     
       
  6611 // ----------------------------------------------------
       
  6612 // CMceUi::GetToBeCreatedEmailType
       
  6613 // ----------------------------------------------------
       
  6614 //
       
  6615  TInt CMceUi::GetToBeCreatedEmailType ()
       
  6616     {
       
  6617     // not sure if it's save
       
  6618     TInt messageType = KErrNone;
       
  6619     if ( MceViewActive( EMceMessageViewActive ) && iMceListView )
       
  6620         {
       
  6621         const TMsvEntry& entry = iMceListView->ListContainer()->FolderEntry();
       
  6622         if ( entry.iMtm == KSenduiMtmImap4Uid
       
  6623             || entry.iMtm == KSenduiMtmPop3Uid ) 
       
  6624             {
       
  6625             messageType = KSenduiMtmSmtpUidValue;
       
  6626             }
       
  6627         else
       
  6628             {
       
  6629              messageType = entry.iMtm.iUid;
       
  6630             }
       
  6631         }
       
  6632     return messageType;
       
  6633     }
       
  6634     
       
  6635 // ----------------------------------------------------
       
  6636 // CMceUi::HideOrExit
       
  6637 // ----------------------------------------------------
       
  6638 void CMceUi::HideOrExit()
       
  6639     {
       
  6640     SetDontExitOnNextOperationComplete();
       
  6641     iMceUiFlags.ClearMceFlag( EMceUiFlagsWantToExit );
       
  6642     if (ExitHidesInBackground())
       
  6643         {
       
  6644         // Always use exit effect even if this is actually application switch
       
  6645 		// Note: Not allowed to call GfxTransEffect::EndFullScreen() as AVKON takes care of that when
       
  6646 		// EApplicationExit context is used!  
       
  6647 		// Set effect begin point
       
  6648 		GfxTransEffect::BeginFullScreen( AknTransEffect::EApplicationExit, TRect(), 
       
  6649 			AknTransEffect::EParameterType, AknTransEffect::GfxTransParam(TUid::Uid( KMceApplicationUidValue )) );       
       
  6650 
       
  6651         ResetAndHide();
       
  6652         }
       
  6653     else
       
  6654         {
       
  6655         CAknEnv::RunAppShutter();
       
  6656         }
       
  6657     }
       
  6658 
       
  6659 // ----------------------------------------------------
       
  6660 // CMceUi::ResetAndHide
       
  6661 // ----------------------------------------------------
       
  6662 void CMceUi::ResetAndHide()
       
  6663     {
       
  6664     // To close embedded MsgEditor
       
  6665     if ( IsEditorOpen() )
       
  6666         {
       
  6667         CloseEditorApp();
       
  6668         }
       
  6669     // Messaging was not exiting properly when "exit" is pressed from settings dialog.
       
  6670     // iMceUiFlags.MceFlag( EMceUiFlagsSettingsDialogOpen ) will be true 
       
  6671     // when we exit from any of the settings Dialog. 
       
  6672     // Closing of Settings dialogs will be taken care by AVKON. 
       
  6673 	if (!(MceViewActive( EMceMainViewActive) && IsForeground()) || 
       
  6674 	      iMceUiFlags.MceFlag( EMceUiFlagsSettingsDialogOpen ) || iSimDialogOpen )
       
  6675         {
       
  6676         SetCustomControl(1);    // Disable bring-to-foreground on view activation
       
  6677         TRAP_IGNORE( CAknViewAppUi::CreateActivateViewEventL( \
       
  6678             KMessagingCentreMainViewUid, \
       
  6679             TUid::Uid(KMceHideInBackground), \
       
  6680             KNullDesC8 ) ) ;
       
  6681         iSimDialogOpen = EFalse;
       
  6682         }
       
  6683     else
       
  6684         {
       
  6685         SetCustomControl(0); // Enable bring-to-foreground on view activation
       
  6686         }
       
  6687     HideInBackground();
       
  6688     }
       
  6689 
       
  6690 // ----------------------------------------------------
       
  6691 // CMceUi::OpenMtmMailboxViewL
       
  6692 // ----------------------------------------------------
       
  6693 void CMceUi::OpenMtmMailboxViewL( const TMsvEntry& aEntry )
       
  6694 	{
       
  6695     CBaseMtmUi& mtmUi=iMtmStore->GetMtmUiAndSetContextLC( aEntry );
       
  6696 
       
  6697     CMsvSingleOpWatcher* singleOpWatcher=CMsvSingleOpWatcher::NewL( *this );
       
  6698     CleanupStack::PushL( singleOpWatcher );
       
  6699 
       
  6700     CMsvOperation* op = NULL;
       
  6701     TRAP_IGNORE(  op=mtmUi.OpenL(singleOpWatcher->iStatus )  );
       
  6702     
       
  6703     CleanupStack::PushL( op );
       
  6704     iOperations.AppendL( singleOpWatcher );
       
  6705     CleanupStack::Pop( op );
       
  6706     CleanupStack::Pop( singleOpWatcher );
       
  6707     
       
  6708     singleOpWatcher->SetOperation( op );
       
  6709     
       
  6710     // Destroys mtmUi object insted of PopAndDestroy
       
  6711     iMtmStore->ReleaseMtmUi( mtmUi.Type() );
       
  6712 	}
       
  6713 
       
  6714 // ----------------------------------------------------
       
  6715 // CMceUi::FindMtmInVisibleListL
       
  6716 // ----------------------------------------------------
       
  6717 TBool CMceUi::FindMtmInVisibleListL( TUid aMtm, CArrayFix<TUid>& aListItemUids )
       
  6718     {
       
  6719     for ( TInt i = 0 ; i < aListItemUids.Count() ; i++)
       
  6720         {
       
  6721         if( aMtm == aListItemUids[i] )
       
  6722             {
       
  6723             return ETrue;
       
  6724             }
       
  6725         }
       
  6726     return EFalse;
       
  6727     }
       
  6728 // ----------------------------------------------------
       
  6729 // CMceUi::GetMsgDeletedStatus
       
  6730 // ----------------------------------------------------    
       
  6731 TInt CMceUi::GetMsgDeletedStatus()
       
  6732     {
       
  6733     return iMsgDeletedStatus;	
       
  6734     }
       
  6735 // ----------------------------------------------------
       
  6736 // CMceUi::SetMsgDeletedStatus
       
  6737 // ----------------------------------------------------
       
  6738 void CMceUi::SetMsgDeletedStatus(TBool aStatus)
       
  6739     {
       
  6740     iMsgDeletedStatus = aStatus;	
       
  6741     }
       
  6742 
       
  6743 // ----------------------------------------------------
       
  6744 // CMceUi::GetFsIntegratedEmailAppMtmPluginId
       
  6745 // ----------------------------------------------------
       
  6746 TUid CMceUi::GetFsIntegratedEmailAppMtmPluginId()
       
  6747     {
       
  6748     TUid uidMsgValTypeEmailMtmVal = TUid::Uid(0);
       
  6749      if ( (iEmailClientIntegration )&& (!iEmailFramework))
       
  6750         {
       
  6751         CRepository* repository = NULL;
       
  6752         TInt mtmPluginID = 0;
       
  6753         TRAPD( ret, repository = CRepository::NewL(
       
  6754                                  KCRUidSelectableDefaultEmailSettings ) );
       
  6755         
       
  6756         if ( ret == KErrNone )
       
  6757             {
       
  6758             // Get Email application mtm plugin ID
       
  6759             repository->Get( KIntegratedEmailAppMtmPluginId, mtmPluginID );
       
  6760             }
       
  6761         delete repository;
       
  6762         uidMsgValTypeEmailMtmVal = TUid::Uid( mtmPluginID );       
       
  6763         }
       
  6764      return uidMsgValTypeEmailMtmVal;
       
  6765     }
       
  6766 //CR:422-271
       
  6767 // ----------------------------------------------------
       
  6768 // CMceUi::PopulateMMSTemplates
       
  6769 // ----------------------------------------------------
       
  6770 TInt CMceUi::PopulateMMSTemplates()
       
  6771     {
       
  6772 
       
  6773     TInt error = KErrNone;
       
  6774     TInt numErrors = 0;
       
  6775     TInt errorIncrement = 0;
       
  6776     
       
  6777     //first try if the directory of mms dump exists or not
       
  6778     _LIT(KTopDir,"C:\\Private\\1000484b\\");
       
  6779       
       
  6780     _LIT( KWild, "mmsvar" );
       
  6781 
       
  6782     TFindFile finder( iFs );
       
  6783     error = finder.FindByDir(KWild,KTopDir);
       
  6784 
       
  6785     if ( error !=KErrNone )
       
  6786         {
       
  6787         return -1;
       
  6788         }
       
  6789     // Reset inactivity timer to keep viewServer from crashing  
       
  6790     User::ResetInactivityTime();
       
  6791     
       
  6792     TFileName CurrentPath;
       
  6793     CurrentPath.Copy( KMmsMessageDumpDirectory );
       
  6794     
       
  6795     TRAP( error, errorIncrement = DecodeAllMMSFromDirectoryL( CurrentPath,KMsvGlobalInBoxIndexEntryId) );
       
  6796     numErrors += errorIncrement;
       
  6797     if ( error != KErrNone )
       
  6798         {
       
  6799       //"left with error "
       
  6800         	numErrors++;
       
  6801         	error = KErrNone;
       
  6802         }
       
  6803     if ( errorIncrement > 0 )
       
  6804         {
       
  6805         //("- returned errors")
       
  6806         }
       
  6807 	User::ResetInactivityTime();
       
  6808 	return numErrors;
       
  6809 }
       
  6810 // ----------------------------------------------------
       
  6811 // CMceUi::DecodeAllMMSFromDirectoryL
       
  6812 // ----------------------------------------------------
       
  6813 TInt CMceUi::DecodeAllMMSFromDirectoryL( TFileName& aFilePath, TMsvId aBoxid /*= KMsvGlobalInBoxIndexEntryId*/ )
       
  6814     {
       
  6815     TInt numErrors = 0;
       
  6816     TInt error = KErrNone;
       
  6817     _LIT( KWild, "*" );
       
  6818 
       
  6819     CDir* fileList = NULL;
       
  6820     TInt i = 0;  // general counter
       
  6821     TFileName Filename;
       
  6822     TFileName CurrentPath = aFilePath;
       
  6823     if ( CurrentPath[CurrentPath.Length()-1] != '\\' )
       
  6824     CurrentPath.Append( '\\' );
       
  6825     iFs.SetSessionPath( CurrentPath );
       
  6826 
       
  6827     TFindFile finder( iFs );
       
  6828     error = finder.FindWildByPath( KWild, NULL, fileList );
       
  6829     CleanupStack::PushL( fileList );
       
  6830     TInt fileCounter = 0;
       
  6831 
       
  6832     if ( error == KErrNone )
       
  6833         {
       
  6834         fileCounter = fileList->Count();
       
  6835         }
       
  6836     TEntry entry;
       
  6837 
       
  6838     if ( error == KErrNone )
       
  6839         {
       
  6840         for ( i = 0; i < fileCounter; i++ )
       
  6841             {
       
  6842             // Reset inactivity timer to keep viewServer from crashing  
       
  6843             User::ResetInactivityTime();
       
  6844             entry = (*fileList)[i]; // name is entry.iName
       
  6845             Filename.Copy( entry.iName );
       
  6846             if (!entry.IsDir())
       
  6847                 {
       
  6848                 TRAP( error, DecodeMMSFromFileL( Filename, aBoxid ));
       
  6849                 if ( error != KErrNone )
       
  6850                     {
       
  6851                         //There are errors in decoding the files
       
  6852                     }
       
  6853                 iFs.Delete(entry.iName);
       
  6854                 }
       
  6855 
       
  6856              }
       
  6857             
       
  6858         }
       
  6859 
       
  6860     CleanupStack::PopAndDestroy(); // fileList
       
  6861     fileList = NULL;
       
  6862 
       
  6863     return numErrors;
       
  6864     }
       
  6865 // ----------------------------------------------------
       
  6866 // CMceUi::DecodeFromFileL
       
  6867 // ----------------------------------------------------
       
  6868 TInt CMceUi::DecodeMMSFromFileL( TFileName& aFilePath, TMsvId aBoxId /* KMsvGlobalInBoxIndexEntryId*/, TUint32 aFlags /*= 0*/ )
       
  6869     {
       
  6870     TInt numErrors = 0;
       
  6871     TInt error = KErrNone;
       
  6872     TMsvId id;
       
  6873         
       
  6874     FillBufferFromFileL( aFilePath, iFs, iEncodeBuffer );
       
  6875         
       
  6876     CMmsCodecClient* codecClient = CMmsCodecClient::NewL( *iSession );
       
  6877     CleanupStack::PushL( codecClient );
       
  6878     
       
  6879     TBool unread = EFalse;
       
  6880     
       
  6881     TRAP( error, codecClient->InitializeChunkedAddingL( aBoxId, id, aFlags, unread ) ); 
       
  6882     if ( error != KErrNone )
       
  6883         {
       
  6884         numErrors++;
       
  6885         }
       
  6886     
       
  6887     if ( error == KErrNone )
       
  6888         {
       
  6889         error = FeedDataInChunks( codecClient );
       
  6890         }
       
  6891         
       
  6892     if ( error != KErrNone )
       
  6893         {
       
  6894         numErrors++;
       
  6895         }
       
  6896     
       
  6897     // Not needed can be cleaned up
       
  6898     CMsvEntry* cEntry = iSession->GetEntryL( id );
       
  6899     TMsvEntry entry = cEntry->Entry();
       
  6900 
       
  6901     entry.SetReadOnly(ETrue);
       
  6902     entry.iServiceId = KMsvLocalServiceIndexEntryId;
       
  6903     entry.iMtmData1 = KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated;
       
  6904     entry.SetUnread(EFalse);
       
  6905     
       
  6906     
       
  6907     cEntry->ChangeL(entry); 
       
  6908     CleanupStack::PopAndDestroy( codecClient );
       
  6909        
       
  6910     return numErrors;
       
  6911     }
       
  6912 // ----------------------------------------------------
       
  6913 // CMceUi::FeedDataInChunks
       
  6914 // ----------------------------------------------------
       
  6915 TInt CMceUi::FeedDataInChunks( CMmsCodecClient* aCodecClient )
       
  6916     {
       
  6917     
       
  6918     TInt error = KErrNone;
       
  6919     TInt chunkSize = KMmsCodecClientChunkSize;
       
  6920     TInt size = iEncodeBuffer->Size();
       
  6921     
       
  6922     // Number of full chunks
       
  6923     TInt chunkNumber = size / chunkSize;
       
  6924     TInt remainder = size % chunkSize;
       
  6925     
       
  6926     TInt pos = 0;    
       
  6927     TPtrC8 messagePtr( iEncodeBuffer->Ptr( 0 ) );
       
  6928     
       
  6929     TBool lastChunk = EFalse;
       
  6930     TInt i = 0;
       
  6931     for ( i = 0; i < chunkNumber && error == KErrNone; i++ )
       
  6932         {
       
  6933         pos = i * chunkSize;
       
  6934         TPtrC8 ptr( iEncodeBuffer->Ptr( 0 ).Mid( pos, chunkSize ) );
       
  6935         error = aCodecClient->NextDataPart( ptr, lastChunk );
       
  6936         }
       
  6937         
       
  6938     // last chunk
       
  6939     if ( remainder > 0 && error == KErrNone )
       
  6940         {
       
  6941         TPtrC8 ptr2( iEncodeBuffer->Ptr( size - remainder ) );
       
  6942         if ( ptr2.Length() > 0 )
       
  6943             {
       
  6944             error = aCodecClient->NextDataPart( ptr2, lastChunk );
       
  6945             }
       
  6946         }
       
  6947         
       
  6948     lastChunk = ETrue;
       
  6949     TPtrC8 ptr3;
       
  6950     if ( error == KErrNone )
       
  6951         {
       
  6952         aCodecClient->NextDataPart( ptr3, lastChunk );
       
  6953         }
       
  6954     return error;    
       
  6955     
       
  6956     }
       
  6957 // ----------------------------------------------------
       
  6958 // CMceUi::FillBufferFromFileL
       
  6959 // ----------------------------------------------------
       
  6960 void CMceUi::FillBufferFromFileL(
       
  6961     const TDesC& aFilePath,
       
  6962     RFs& aFs,
       
  6963     CBufFlat* aEncodeBuffer )
       
  6964     {
       
  6965     TInt error = KErrNone;
       
  6966     TEntry orgEntry;
       
  6967     error = aFs.Entry( aFilePath, orgEntry );
       
  6968     TInt size = orgEntry.iSize;
       
  6969     RFile inFile;
       
  6970     if ( aEncodeBuffer == NULL )
       
  6971         {
       
  6972         aEncodeBuffer = CBufFlat::NewL( size );
       
  6973         }
       
  6974     else
       
  6975         {
       
  6976         aEncodeBuffer->ResizeL( 0 );
       
  6977         aEncodeBuffer->ResizeL( size );
       
  6978         }
       
  6979 
       
  6980     error = inFile.Open( aFs, aFilePath, EFileShareReadersOnly );
       
  6981     
       
  6982     TPtr8 ptr = aEncodeBuffer->Ptr( 0 );
       
  6983     if ( error == KErrNone )
       
  6984         {
       
  6985         error = inFile.Read( ptr, size );
       
  6986         inFile.Close();
       
  6987         }
       
  6988     else
       
  6989         {
       
  6990         //"*** - can't read file"
       
  6991         }
       
  6992     User::LeaveIfError( error );    
       
  6993     
       
  6994     }
       
  6995 //CR:422-271
       
  6996 // end of file
       
  6997 
       
  6998 // end of file