ipsservices/ipssossettings/src/ipssetui.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 *  Description: This file implements class CIpsSetUi.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <eikfrlb.h>                // CEikFormattedCellListBox
       
    21 #include <aknappui.h>               // CAknAppUi
       
    22 #include <AknsDrawUtils.h>
       
    23 #include <akntitle.h>               // CAknTitlePane
       
    24 #include <hlplch.h>                 // HlpLauncher
       
    25 #include <eikrted.h>                // CEikRichTextEditor
       
    26 #include <ipssossettings.rsg>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <AlwaysOnlineManagerClient.h>
       
    29 
       
    30 #include "ipssetui.h"
       
    31 #include "ipssetuidialog.h"
       
    32 #include "ipssetutilsdisconnectlogic.h"
       
    33 
       
    34 // becuase of RD_IPS_AO_PLUGIN flag, can be removed
       
    35 // when flag is removed
       
    36 #include "ipsplgsosbaseplugin.hrh"
       
    37 
       
    38 const TInt KIpsSetOptionsMenuItemCount = 4;
       
    39 // Resource file name and path, drive letter need to be parsed run time
       
    40 _LIT( KIpsSetUiResourceFile, "\\resource\\IpsSosSettings.rsc" );
       
    41 
       
    42 // ============================ LOCAL FUNCTIONS ===============================
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CIpsSetUi::CIpsSetUi
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CIpsSetUi::CIpsSetUi( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail>
       
    51     :
       
    52     iFlags( 0x00 ),
       
    53     iListBox( NULL ),
       
    54     iSettings( NULL ),
       
    55     iResourceLoader( *iCoeEnv ),
       
    56     iMailboxId( aMailboxId )
       
    57     , iShowFolderSettings(aFolderSettingView), iIgnoreOneBackKey(ETrue) //<cmail>
       
    58     {
       
    59     FUNC_LOG;
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CIpsSetUi::NewL()
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CIpsSetUi* CIpsSetUi::NewL( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail>
       
    67     {
       
    68     FUNC_LOG;
       
    69     CIpsSetUi* self = NewLC( aMailboxId, aFolderSettingView ); //<cmail>
       
    70     CleanupStack::Pop( self );
       
    71 
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // CIpsSetUi::NewLC()
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CIpsSetUi* CIpsSetUi::NewLC( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail>
       
    80     {
       
    81     FUNC_LOG;
       
    82     CIpsSetUi* self = new ( ELeave ) CIpsSetUi( aMailboxId, aFolderSettingView ); //<cmail>
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85 
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CIpsSetUi::~CIpsSetUi()
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CIpsSetUi::~CIpsSetUi()
       
    94     {
       
    95     FUNC_LOG;
       
    96     iResourceLoader.Close();
       
    97     delete iSession;
       
    98     delete iSettings;
       
    99     iSettings = NULL;
       
   100     iListBox = NULL;
       
   101     iTextEditor = NULL;
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CIpsSetUi::ConstructL()
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CIpsSetUi::ConstructL()
       
   109     {
       
   110     FUNC_LOG;
       
   111     iResourceMenuBar = R_IPS_SET_MENUBAR;
       
   112 
       
   113     // Call the base ConstructL
       
   114     CAknDialog::ConstructL( iResourceMenuBar );
       
   115     LoadResourceL();
       
   116     iSession = CMsvSession::OpenSyncL( *this );
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // CIpsSetUi::OkToExitL
       
   121 // ----------------------------------------------------------------------------
       
   122 //
       
   123 TBool CIpsSetUi::OkToExitL( TInt aButtonId )
       
   124     {
       
   125     FUNC_LOG;
       
   126     TBool allowQuit = EFalse;
       
   127 
       
   128     // Exit not issued, forward the call to command processor
       
   129     if ( !( iFlags & EIpsSetUiShouldExit ) &&
       
   130          !( iFlags & EIpsSetUiShouldClose ) )
       
   131         {
       
   132         iSettings->ProcessCommandL( aButtonId );
       
   133         }
       
   134     else
       
   135         {
       
   136         // Should quit
       
   137         allowQuit = iSettings->OkToExitL( aButtonId );
       
   138 
       
   139         // Clear the flag after usage
       
   140         iFlags &= ~EIpsSetUiQueryClose;
       
   141 
       
   142         // If quit is allowed, store the settings, otherwise clear the flag
       
   143         if ( allowQuit && iFlags & EIpsSetUiAllowSave )
       
   144             {
       
   145             iFlags &= ~EIpsSetUiAllowSave;
       
   146             
       
   147             DisconnectIfOnlineL( EFalse );
       
   148             // Failing to store the settings should cause panic, to prevent
       
   149             // the settings to stop into unwanted errors
       
   150             TRAP_IGNORE( iSettings->StoreSettingsToAccountL() );
       
   151 
       
   152             // switch ao back on
       
   153 // <cmail> RD_IPS_AO_PLUGIN flag removed
       
   154             RAlwaysOnlineClientSession aosession; 
       
   155             TInt err = aosession.Connect();
       
   156             if ( err == KErrNone )
       
   157                 {
       
   158                 TPckgBuf<TMsvId> mboxBuf( iMailboxId );
       
   159                 TRAP( err, aosession.RelayCommandL( 
       
   160                         EServerAPIEmailTurnOn, 
       
   161                        mboxBuf ) );
       
   162                 }
       
   163             aosession.Close();
       
   164 // </cmail>
       
   165             }
       
   166         else
       
   167             {
       
   168             // Clear the flags
       
   169             iFlags &= ~EIpsSetUiShouldExit;
       
   170             iFlags &= ~EIpsSetUiShouldClose;
       
   171             }
       
   172 
       
   173         // Exit, now
       
   174         if ( allowQuit )
       
   175             {
       
   176             allowQuit = CAknDialog::OkToExitL( EAknSoftkeyCancel );
       
   177             }
       
   178         }
       
   179 
       
   180     return allowQuit;
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // CIpsSetUi::HandleResourceChange
       
   185 // ----------------------------------------------------------------------------
       
   186 //
       
   187 void CIpsSetUi::HandleResourceChange( TInt aType )
       
   188     {
       
   189     FUNC_LOG;
       
   190     CAknDialog::HandleResourceChange( aType );
       
   191 
       
   192     if ( iTextEditor && aType == KEikDynamicLayoutVariantSwitch )
       
   193         {
       
   194         TRect rect = Rect();
       
   195         iTextEditor->SetRect( rect );
       
   196         iTextEditor->HandleResourceChange( aType );
       
   197         iListBox->SetRect( rect );
       
   198         iListBox->HandleResourceChange( aType );
       
   199         }
       
   200     if ( aType == KAknsMessageSkinChange )
       
   201         {
       
   202         SetFontAndSkin();
       
   203         }
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CIpsSetUi::SetFontAndSkin
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CIpsSetUi::SetFontAndSkin()
       
   211     {
       
   212     FUNC_LOG;
       
   213     if ( iTextEditor )
       
   214         {
       
   215         MAknsControlContext* context =
       
   216             AknsDrawUtils::ControlContext( iListBox );
       
   217         TRAP_IGNORE(
       
   218             iTextEditor->SetSkinBackgroundControlContextL( context ) );
       
   219 
       
   220         const CFont* font = ControlEnv()->NormalFont();
       
   221         TFontSpec fontSpec = font->FontSpecInTwips();
       
   222 
       
   223         TCharFormat charFormat;
       
   224         TCharFormatMask formatMask;
       
   225         charFormat.iFontSpec = fontSpec;
       
   226 
       
   227         formatMask.SetAttrib( EAttFontTypeface );
       
   228         formatMask.SetAttrib( EAttFontHeight );
       
   229         formatMask.SetAttrib( EAttFontPosture );
       
   230         formatMask.SetAttrib( EAttFontStrokeWeight );
       
   231 
       
   232         TRgb textColor;
       
   233         TInt error = AknsUtils::GetCachedColor(
       
   234     	    AknsUtils::SkinInstance(),
       
   235             textColor,
       
   236             KAknsIIDQsnTextColors,
       
   237             EAknsCIQsnTextColorsCG7 );
       
   238 
       
   239         if ( error != KErrNone )
       
   240     	    {
       
   241     	    textColor = AKN_LAF_COLOR_STATIC( 215 );
       
   242     	    }
       
   243 
       
   244         charFormat.iFontPresentation.iTextColor = textColor;
       
   245         formatMask.SetAttrib( EAttColor );
       
   246 
       
   247         CCharFormatLayer* charFormatLayer = NULL;
       
   248 
       
   249         TRAP( error,
       
   250             charFormatLayer = CCharFormatLayer::NewL( charFormat, formatMask )
       
   251         );
       
   252 
       
   253         if ( error )
       
   254             {
       
   255             delete charFormatLayer;
       
   256             }
       
   257         else
       
   258             {
       
   259             iTextEditor->SetCharFormatLayer( charFormatLayer );
       
   260             }
       
   261         }
       
   262 
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CIpsSetUi::PreLayoutDynInitL
       
   267 // ----------------------------------------------------------------------------
       
   268 //
       
   269 void CIpsSetUi::PreLayoutDynInitL()
       
   270     {
       
   271     FUNC_LOG;
       
   272     // Get the pointer to titlepane
       
   273     CEikStatusPane* sp =
       
   274         static_cast<CAknAppUi*>(
       
   275             iEikonEnv->EikAppUi() )->StatusPane();
       
   276     CAknTitlePane* title = static_cast<CAknTitlePane*>(
       
   277         sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   278 
       
   279     CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   280 
       
   281     // check connect state before entering settings
       
   282     DisconnectIfOnlineL();
       
   283     
       
   284 // <cmail> RD_IPS_AO_PLUGIN flag removed
       
   285     // prevent ao operations during settings edit
       
   286     RAlwaysOnlineClientSession aosession;
       
   287     TInt err = aosession.Connect();
       
   288     if ( err == KErrNone )
       
   289         {
       
   290         TPckgBuf<TMsvId> mboxBuf( iMailboxId );
       
   291         TRAP_IGNORE( aosession.RelayCommandL( 
       
   292                 EServerAPIEmailTurnOff, 
       
   293                 mboxBuf ) );
       
   294         }
       
   295     aosession.Close();
       
   296 // </cmail>
       
   297     
       
   298     // Prepare the listbox
       
   299     iListBox = static_cast<CEikFormattedCellListBox*>(
       
   300         Control( EIpsSetUiIdListBox ) );
       
   301 
       
   302     iSettings = CIpsSetUiDialogCtrl::NewL(
       
   303         *this, *iListBox, *title, cba, *iSession, iFlags );
       
   304     
       
   305     //<cmail>
       
   306     //When settings are launched from folderlist view, we need to go directly to 'what to sync' view
       
   307     if(iShowFolderSettings)
       
   308         {
       
   309         if(iSettings->CountInListBox() > 1)
       
   310             {
       
   311             iListBox->SetCurrentItemIndex(1);
       
   312             iSettings->ProcessCommandL( EAknSoftkeySelect );
       
   313             if(iSettings->CountInListBox() > 2)
       
   314                 {
       
   315                 iListBox->SetCurrentItemIndex(2);
       
   316                 }
       
   317             }
       
   318         }
       
   319     //</cmail>
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CIpsSetUi::ProcessCommandL
       
   324 // ----------------------------------------------------------------------------
       
   325 //
       
   326 void CIpsSetUi::ProcessCommandL( TInt aCommandId )
       
   327     {
       
   328     FUNC_LOG;
       
   329     // Forward the commands
       
   330     CAknDialog::ProcessCommandL( aCommandId );
       
   331 
       
   332     // Forward command either to wizard or setting dialog
       
   333     iSettings->ProcessCommandL( aCommandId );
       
   334     }
       
   335 
       
   336 void CIpsSetUi::LaunchMenuL()
       
   337 	{
       
   338 	if ( iFlags & EIpsSetUiOpenOptionsMenu )
       
   339 		{
       
   340 		iFlags &= ~EIpsSetUiOpenOptionsMenu;
       
   341 		TIpsSetUiSettingsType type = iSettings->CurrentItem()->iItemType;
       
   342 		//sub-menu
       
   343 		if ( type == EIpsSetUiMenuArray )
       
   344 			{
       
   345 			iFlags |= EIpsSetUiPositionSubMenu;
       
   346 			iFlags &= ~EIpsSetUiSettingsMenuItem;
       
   347 			}
       
   348 		//settings item
       
   349 		else if( type == EIpsSetUiRadioButtonArray || 
       
   350 				 type == EIpsSetUiItemText ||
       
   351 				 type == EIpsSetUiUndefined || 
       
   352 				 type == EIpsSetUiCheckBoxArray )
       
   353 			{
       
   354 			iFlags |= EIpsSetUiSettingsMenuItem;
       
   355 			iFlags &= ~EIpsSetUiPositionSubMenu;
       
   356 			}
       
   357 		else
       
   358 			{
       
   359 			iFlags &= ~EIpsSetUiPositionSubMenu;
       
   360 			iFlags &= ~EIpsSetUiSettingsMenuItem;
       
   361 			}
       
   362 		DisplayMenuL();
       
   363 		}
       
   364 	}
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // CIpsSetUi::OfferKeyEventL
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 TKeyResponse CIpsSetUi::OfferKeyEventL(
       
   371     const TKeyEvent& aKeyEvent,
       
   372     TEventCode aType )
       
   373     {
       
   374     FUNC_LOG;
       
   375 
       
   376     //<cmail>
       
   377     // When settings are launched from folder list view, we need to show directly 'what to sync' view
       
   378     // this logic is used when coming back from that view
       
   379     if( (aType == EEventKeyUp) && (aKeyEvent.iScanCode == EStdKeyDevice1) 
       
   380             && (iShowFolderSettings) && iIgnoreOneBackKey)
       
   381         {
       
   382         iFlags |= EIpsSetUiShouldClose;
       
   383         }
       
   384     iIgnoreOneBackKey = ETrue;
       
   385     //</cmail>
       
   386         
       
   387     // Offer the key event to existing mailbox setting handler
       
   388     TKeyResponse ret = iSettings->OfferKeyEventL( aKeyEvent, aType );
       
   389 
       
   390     // Improve menu handling here!!!
       
   391 
       
   392     // Show the menu, if asked
       
   393     LaunchMenuL();
       
   394     
       
   395     // Check if exit has been issued
       
   396     if ( iFlags & EIpsSetUiShouldExit ||
       
   397          iFlags & EIpsSetUiShouldClose )
       
   398         {
       
   399         DoQuitL();
       
   400         
       
   401         // Quit attempted, so consume the key
       
   402         ret = EKeyWasConsumed;
       
   403         }
       
   404 
       
   405     if ( ret != EKeyWasConsumed )
       
   406         {
       
   407         ret = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   408         }
       
   409 
       
   410     return ret;
       
   411     }
       
   412 
       
   413 // ----------------------------------------------------------------------------
       
   414 // CIpsSetUi::DynInitMenuPaneL()
       
   415 // ----------------------------------------------------------------------------
       
   416 //
       
   417 void CIpsSetUi::DynInitMenuPaneL(
       
   418     TInt /* aResourceId */,
       
   419     CEikMenuPane* aMenuPane )
       
   420     {
       
   421     FUNC_LOG;
       
   422     if ( aMenuPane->NumberOfItemsInPane() == KIpsSetOptionsMenuItemCount )
       
   423         {
       
   424         aMenuPane->SetItemDimmed(
       
   425             EAknSoftkeyOpen, iFlags & EIpsSetUiSettingsMenuItem );
       
   426         aMenuPane->SetItemDimmed(
       
   427             EAknSoftkeySelect, iFlags & EIpsSetUiPositionSubMenu );
       
   428         }
       
   429     }
       
   430 
       
   431 // ----------------------------------------------------------------------------
       
   432 // CIpsSetUi::DoQuitL()
       
   433 // ----------------------------------------------------------------------------
       
   434 //
       
   435 void CIpsSetUi::DoQuitL()
       
   436     {
       
   437     FUNC_LOG;
       
   438     // Start the exit process, the query is shown during TryExitL call
       
   439     if ( iFlags & EIpsSetUiShouldExit )
       
   440         {
       
   441         TryExitL( EAknSoftkeyExit );
       
   442         }
       
   443     else
       
   444         {
       
   445         TryExitL( EAknSoftkeyCancel );
       
   446         }
       
   447     }
       
   448 
       
   449 
       
   450 // ----------------------------------------------------------------------------
       
   451 // CIpsSetUi::GetHelpContext()
       
   452 // ----------------------------------------------------------------------------
       
   453 //
       
   454 void CIpsSetUi::GetHelpContext( TCoeHelpContext& aContext ) const
       
   455     {
       
   456     FUNC_LOG;
       
   457     iSettings->GetHelpContext( aContext );
       
   458     }
       
   459 
       
   460 // ----------------------------------------------------------------------------
       
   461 // CIpsSetUi::LaunchHelpL()
       
   462 // ----------------------------------------------------------------------------
       
   463 //
       
   464 void CIpsSetUi::LaunchHelpL()
       
   465     {
       
   466     FUNC_LOG;
       
   467     CCoeAppUi* appUi = static_cast<CCoeAppUi*>( ControlEnv()->AppUi() );
       
   468     CArrayFix<TCoeHelpContext>* helpContext = appUi->AppHelpContextL();
       
   469     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
   470     }
       
   471 
       
   472 void CIpsSetUi::HandleSessionEventL(
       
   473         TMsvSessionEvent /*aEvent*/, 
       
   474         TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   475     {
       
   476     FUNC_LOG;
       
   477     // handle general server events if needed
       
   478     // EMsvCloseSession
       
   479     // EMsvServerReady
       
   480     // EMsvServerFailedToStart
       
   481     // EMsvCorruptedIndexRebuilt
       
   482     // EMsvServerTerminated
       
   483     }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CIpsSetUi::LoadResourceL()
       
   487 // ---------------------------------------------------------------------------
       
   488 //
       
   489 void CIpsSetUi::LoadResourceL()
       
   490     {
       
   491     FUNC_LOG;
       
   492 
       
   493     // Load resource file from the same drive where this dll is loaded from
       
   494     TFileName dllFileName;
       
   495     Dll::FileName( dllFileName );
       
   496 
       
   497     TParse parse;
       
   498     parse.Set( KIpsSetUiResourceFile, &dllFileName, NULL );
       
   499     TFileName fileName( parse.FullName() );
       
   500     
       
   501     // Attempt to load the resource
       
   502     iResourceLoader.OpenL( fileName );
       
   503     }
       
   504     
       
   505 void CIpsSetUi::DisconnectIfOnlineL( TBool aDoShowQuery )
       
   506     {
       
   507     FUNC_LOG;
       
   508     CIpsSetUtilsDisconnectLogic* dLogic = CIpsSetUtilsDisconnectLogic::NewL( 
       
   509             *iSession, iMailboxId );
       
   510     CleanupStack::PushL( dLogic );
       
   511     // check if mailbox is online and disconnect
       
   512     TInt result = KErrNone;
       
   513     // <cmail>
       
   514     TInt error = KErrNone;
       
   515     TRAP( error, result = dLogic->RunDisconnectLogicL( aDoShowQuery ) );
       
   516     __ASSERT_DEBUG( error == KErrNone, 
       
   517             User::Panic( KIpsSetGenPanicLit, error ));
       
   518     // </cmail>
       
   519 
       
   520     if ( result == KErrCancel )
       
   521         {
       
   522         User::Leave( KErrCancel );
       
   523         }
       
   524     CleanupStack::PopAndDestroy( dLogic );
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CIpsSetUi::MailboxId()
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 TMsvId CIpsSetUi::MailboxId()
       
   532     {
       
   533     FUNC_LOG;
       
   534     return iMailboxId;
       
   535     }
       
   536 
       
   537 //<cmail>
       
   538 // ---------------------------------------------------------------------------
       
   539 // CIpsSetUi::SetIgnoreOneBackKey()
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 void CIpsSetUi::SetIgnoreOneBackKey(TBool aIgnoreBackKey)
       
   543     {
       
   544     iIgnoreOneBackKey = aIgnoreBackKey;
       
   545     }
       
   546 //</cmail>
       
   547 
       
   548     
       
   549 
       
   550 //  End of File
       
   551 
       
   552 
       
   553