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