messagingappbase/mcesettings/src/MceSettingsMtmServicesDialog.cpp
changeset 0 72b543305e3a
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 *     Dialog for handling services of certain mtm (if possible to create services).
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <msvids.h>
       
    24 #include <MsgArrays.h>      // CUidNameArray
       
    25 #include <eikmenup.h>       // CEikMenuPane, CEikMenuPaneItem
       
    26 #include <StringLoader.h>   // StringLoader
       
    27 #include <aknViewAppUi.h>
       
    28 
       
    29 #include <aknlists.h>       // CAknPopupSingle1StyleListBox
       
    30 #include <MceSettings.rsg>
       
    31 #include "MceSettingsMtmServicesDialog.h"
       
    32 #include "MceSettingsIds.hrh"
       
    33 #include "MceSettingsAccountManager.h"
       
    34 #include "MceSettingsArrays.h"
       
    35 
       
    36 #include "MceSettingsMultipleServicesDialog.h"
       
    37 
       
    38 #include <featmgr.h>
       
    39 #include <hlplch.h>             // For HlpLauncher
       
    40 #include <csxhelp/mbxs.hlp.hrh>
       
    41 
       
    42 #include <bldvariant.hrh>
       
    43 #include <SenduiMtmUids.h>
       
    44 
       
    45 #include <ImumInternalApi.h>
       
    46 #include <ImumInHealthServices.h>
       
    47 #include <ImumInMailboxUtilities.h>
       
    48 
       
    49 #include "MceSettingsUtils.h"
       
    50 #include <muiuflags.h>
       
    51 
       
    52 // CONSTANTS
       
    53 
       
    54 #define KMceApplicationUidValue         0x100058C5
       
    55 const TUid KMceApplicationUid       = {KMceApplicationUidValue};
       
    56 
       
    57 
       
    58 const TInt KMceVisibleTextLength = KHumanReadableNameLength;
       
    59 
       
    60 // The position of the middle soft key
       
    61 const TInt KMSKPosition = 3;
       
    62 
       
    63 
       
    64 // ================= MEMBER FUNCTIONS =======================
       
    65 
       
    66 // C++ default constructor can NOT contain any code that
       
    67 // might leave.
       
    68 //
       
    69 // ----------------------------------------------------
       
    70 // CMceSettingsMtmServicesDialog::Constructor
       
    71 // ----------------------------------------------------
       
    72 CMceSettingsMtmServicesDialog::CMceSettingsMtmServicesDialog(
       
    73     TUid                aMtmType,
       
    74     MMceSettingsAccountManager& aManager,
       
    75     CMsvSession*        aSession,
       
    76     CMceSettingsMultipleServicesDialog& aParent )
       
    77     :
       
    78     CMceSettingsTitlePaneHandlerDialog(),
       
    79     iMtmType( aMtmType ),    
       
    80     iAccountManager( aManager ),
       
    81     iSession( aSession ),
       
    82     iParentDialog( aParent ),
       
    83     iCurrentMailAccountId( KErrNotFound )
       
    84     {
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------
       
    88 // CMceSettingsMtmServicesDialog::Destructor
       
    89 // ----------------------------------------------------
       
    90 CMceSettingsMtmServicesDialog::~CMceSettingsMtmServicesDialog()
       
    91     {
       
    92     if ( iSessionObserverAdded )
       
    93         {
       
    94         iAccountManager.Session().RemoveObserver( *this );
       
    95         }
       
    96     delete iAccountArray;
       
    97     delete iEmailApi;
       
    98     iEmailApi = NULL;   
       
    99     iMailboxArray.Reset();
       
   100     }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------
       
   104 // CMceSettingsMtmServicesDialog::OkToExitL
       
   105 // ----------------------------------------------------
       
   106 TBool CMceSettingsMtmServicesDialog::OkToExitL( TInt aButtonId )
       
   107     {
       
   108     TBool okToExit = CAknDialog::OkToExitL( aButtonId );
       
   109     if ( aButtonId == EMceSettingsCmdSettingsDialogOpen ||
       
   110          aButtonId == EMceSettingsCmdSettingsDialogCreateNewEmpty )
       
   111         {
       
   112         ProcessCommandL( aButtonId );
       
   113         okToExit = EFalse;  // Cannot exit, since MSK was pressed
       
   114         }
       
   115     else if ( aButtonId != EEikBidCancel && okToExit )
       
   116         {
       
   117         RestoreTitleTextL();
       
   118         }
       
   119         
       
   120     if ( okToExit && aButtonId == EEikBidCancel )
       
   121         {
       
   122         // Let's inform parent that we are closed
       
   123         iParentDialog.SubdialogClosed();
       
   124         }
       
   125 
       
   126     return okToExit;
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------
       
   130 // CMceSettingsMtmServicesDialog::HandleListBoxEventL
       
   131 // ----------------------------------------------------
       
   132 void CMceSettingsMtmServicesDialog::HandleListBoxEventL(
       
   133     CEikListBox* /*aListBox*/,
       
   134     TListBoxEvent aEventType )
       
   135     {
       
   136     switch(aEventType)
       
   137         {
       
   138         case EEventEnterKeyPressed:
       
   139         case EEventItemSingleClicked:
       
   140             ProcessCommandL( EMceSettingsCmdSettingsDialogOpen );
       
   141             break;
       
   142         default:
       
   143             break;
       
   144         }
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------
       
   148 // CMceSettingsMtmServicesDialog::ProcessCommandL
       
   149 // ----------------------------------------------------
       
   150 void CMceSettingsMtmServicesDialog::ProcessCommandL( TInt aCommandId )
       
   151     {
       
   152     CAknDialog::ProcessCommandL( aCommandId ); // hides menu
       
   153     if ( aCommandId == EMceSettingsCmdSettingsDialogExit )
       
   154         {
       
   155         if (iAvkonViewAppUi->ExitHidesInBackground()) 
       
   156             { 
       
   157             iAvkonViewAppUi->ProcessCommandL( EAknCmdHideInBackground );
       
   158             }
       
   159         else
       
   160             {
       
   161             iAvkonViewAppUi->ProcessCommandL( EAknCmdExit );
       
   162             }
       
   163         return;
       
   164         }
       
   165 
       
   166     
       
   167     CEikTextListBox* list=STATIC_CAST( CEikTextListBox*, 
       
   168         Control( EMceSettingsMtmServicesDialogChoiceList ) );
       
   169     const TInt choice = list->CurrentItemIndex();
       
   170     TInt count = iAccountArray->Count();
       
   171 
       
   172     switch ( aCommandId )
       
   173         {
       
   174         case EMceSettingsCmdSettingsDialogOpen:
       
   175             if ( choice >= 0 && choice < count )
       
   176                 {
       
   177                 iCurrentMailAccountId = (*iAccountArray)[choice].iUid.iUid;
       
   178                 iAccountManager.EditAccountL( iCurrentMailAccountId );
       
   179                 }
       
   180             break;
       
   181 
       
   182         case EMceSettingsCmdSettingsDialogCreateNewEmpty:
       
   183             iMailboxCreationOn = ETrue;
       
   184             iAccountManager.CreateNewAccountL( iMtmType, KMsvNullIndexEntryId );
       
   185             iMailboxCreationOn = EFalse;
       
   186             break;
       
   187 
       
   188         case EMceSettingsCmdSettingsDialogDelete:
       
   189             if ( choice >= 0 && choice < count )
       
   190                 {
       
   191                 iAccountManager.DeleteAccountL( (*iAccountArray)[choice].iUid.iUid );
       
   192                 }
       
   193             break;
       
   194        
       
   195         case EAknCmdHelp:
       
   196             {
       
   197             LaunchHelpL();                
       
   198             }
       
   199             break;            
       
   200 
       
   201         default :
       
   202             break;
       
   203         }
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------
       
   207 // CMceSettingsMtmServicesDialog::DynInitMenuPaneL
       
   208 // ----------------------------------------------------
       
   209 void CMceSettingsMtmServicesDialog::DynInitMenuPaneL( TInt aResourceId, 
       
   210                                                        CEikMenuPane* aMenuPane )
       
   211     {
       
   212     if ( aResourceId == R_MCE_SETTINGS_MTM_SERVICES_DIALOG_MENUPANE )
       
   213         {
       
   214         aMenuPane->SetItemDimmed( EMceSettingsCmdSettingsDialogHelp,
       
   215             !FeatureManager::FeatureSupported( KFeatureIdHelp ) );  
       
   216 
       
   217         if ( iAccountArray->Count() == 0 )
       
   218             {
       
   219             aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogOpen );
       
   220             aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogDelete );
       
   221             if ( iSelectionKeyPressedToOpenOptionMenu )
       
   222                 {
       
   223                 aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogExit );
       
   224                 aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   225                 iSelectionKeyPressedToOpenOptionMenu = EFalse;
       
   226                 }
       
   227             }
       
   228         if ( iNumberOfMailboxes >= KMceMaxNumberOfMailboxes )
       
   229             {
       
   230             aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogCreateNewEmpty );
       
   231             }
       
   232         else
       
   233             {
       
   234             // no action
       
   235             }
       
   236 
       
   237         }
       
   238     }
       
   239   
       
   240 // ---------------------------------------------------------------------------
       
   241 // CMceSettingsMtmServicesDialog::UpdateMailboxDataL()
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CMceSettingsMtmServicesDialog::UpdateMailboxDataL()
       
   245     {
       
   246     const MImumInHealthServices* healthApi = &iEmailApi->HealthServicesL();
       
   247     
       
   248     // Get the array of the mailboxes for the current view
       
   249     MceSettingsUtils::GetHealthyMailboxListL( 
       
   250         *healthApi,
       
   251         iMailboxArray,
       
   252         iMtmType != KSenduiMtmSyncMLEmailUid,
       
   253         iMtmType != KSenduiMtmSyncMLEmailUid,
       
   254         iMtmType == KSenduiMtmSyncMLEmailUid,
       
   255         EFalse );
       
   256     iNumberOfMailboxes = iMailboxArray.Count();
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------
       
   260 // CMceSettingsMtmServicesDialog::UpdateForArrayChangeL
       
   261 // ----------------------------------------------------
       
   262 void CMceSettingsMtmServicesDialog::UpdateServicesArrayL()
       
   263     {        
       
   264     CEikTextListBox* list=STATIC_CAST( CEikTextListBox*, 
       
   265         Control( EMceSettingsMtmServicesDialogChoiceList ) );
       
   266     TInt selectedIndex = list->CurrentItemIndex();
       
   267     const TInt count = iAccountArray->Count();
       
   268 
       
   269     iAccountArray->Reset();
       
   270 
       
   271     UpdateMailboxDataL();
       
   272     for ( TInt loop=0; loop<iMailboxArray.Count(); loop++ )
       
   273         {
       
   274         TMsvEntry tentry = iEmailApi->MailboxUtilitiesL().GetMailboxEntryL( 
       
   275             iMailboxArray[loop],
       
   276             MImumInMailboxUtilities::ERequestSending );
       
   277 
       
   278         TUid tmpUid = {iMailboxArray[loop]};
       
   279         TUidNameInfo info(
       
   280             tmpUid,
       
   281             tentry.iDetails.Left( KMceVisibleTextLength ) );
       
   282         iAccountArray->AppendL( info );                
       
   283         if ( iCurrentMailAccountId == tmpUid.iUid )
       
   284             {
       
   285             selectedIndex = loop;
       
   286             iCurrentMailAccountId = KErrNotFound;
       
   287             }
       
   288         }
       
   289 
       
   290     TInt newCount = iAccountArray->Count();
       
   291     if ( newCount > count )
       
   292         {
       
   293         list->HandleItemAdditionL();
       
   294         }
       
   295     else if ( newCount < count )
       
   296         {
       
   297         list->HandleItemRemovalL();
       
   298         }
       
   299     else
       
   300         {
       
   301         // no action
       
   302         }
       
   303 
       
   304     if ( newCount > 0 )
       
   305         {
       
   306         if ( selectedIndex >= 0 && selectedIndex < newCount )
       
   307             {
       
   308             list->SetCurrentItemIndex( selectedIndex );
       
   309             }
       
   310         else if ( selectedIndex >= newCount )
       
   311             {
       
   312             list->SetCurrentItemIndex( newCount - 1 );
       
   313             }
       
   314         else
       
   315             {
       
   316             list->SetCurrentItemIndex( 0 );
       
   317             }
       
   318         }
       
   319     if ( newCount == 0 )
       
   320         {
       
   321         SetSpecialMSKButtonL(R_MCE_MSK_BUTTON_CREATE_NEW_EMPTY);
       
   322         }
       
   323     else
       
   324     	{
       
   325     	SetSpecialMSKButtonL( R_MCE_MSK_BUTTON_OPEN );
       
   326     	}        
       
   327     list->DrawNow();
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------
       
   331 // CMceSettingsMtmServicesDialog::PreLayoutDynInitL
       
   332 // ----------------------------------------------------
       
   333 void CMceSettingsMtmServicesDialog::PreLayoutDynInitL()
       
   334     {    
       
   335     CEikTextListBox* list=STATIC_CAST( CEikTextListBox*, 
       
   336         Control( EMceSettingsMtmServicesDialogChoiceList ) );
       
   337 
       
   338     // Setting scrollbar-indicators on
       
   339     list->CreateScrollBarFrameL( ETrue );
       
   340     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   341         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   342 
       
   343     if ( !iAccountArray )
       
   344         {
       
   345         iAccountArray = CMceUidNameArray::NewL( CMceUidNameArray::EServicesList );
       
   346         }
       
   347 
       
   348     if ( !iEmailApi )
       
   349         {
       
   350         iEmailApi = CreateEmailApiL( iSession );
       
   351         }       
       
   352 
       
   353     CTextListBoxModel* model= list->Model();
       
   354     model->SetItemTextArray( iAccountArray );
       
   355     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   356     list->SetListBoxObserver(this);    
       
   357 
       
   358     THumanReadableName mtmName = iAccountManager.MtmName( iMtmType );    
       
   359     if ( iMtmType == KSenduiMtmSmtpUid )
       
   360         {
       
   361         // email
       
   362         HBufC* text = StringLoader::LoadL( R_MCE_SETTINGS_NO_MAILBOXES, iEikonEnv );
       
   363         CleanupStack::PushL( text );
       
   364         list->View()->SetListEmptyTextL( *text );
       
   365         CleanupStack::PopAndDestroy( text ); // text
       
   366         HBufC* title = StringLoader::LoadLC( R_MCE_SETTINGS_MTM_SERVICES_DIALOG_TITLE, 
       
   367                                                                   iEikonEnv );
       
   368         StoreTitleTextAndSetNewL( *title );
       
   369         CleanupStack::PopAndDestroy( title ); // title
       
   370         }
       
   371     else if ( iMtmType == KSenduiMtmSyncMLEmailUid )
       
   372         {
       
   373         // syncML
       
   374         HBufC* text = StringLoader::LoadL( R_MCE_SETTINGS_NO_SYNCBOX, iEikonEnv );
       
   375         CleanupStack::PushL( text );
       
   376         list->View()->SetListEmptyTextL( *text );
       
   377         CleanupStack::PopAndDestroy( text ); // text
       
   378         HBufC* title = StringLoader::LoadLC( R_MCE_SETTINGS_SYNCMAIL_TITLE, iEikonEnv );
       
   379         StoreTitleTextAndSetNewL( *title );
       
   380         CleanupStack::PopAndDestroy( title ); // title
       
   381         }
       
   382     else
       
   383         {
       
   384         // not email/syncML
       
   385         HBufC* text = StringLoader::LoadLC( 
       
   386         R_MCE_MTM_NOT_DEFINED, mtmName, iEikonEnv );
       
   387         list->View()->SetListEmptyTextL( *text );
       
   388         CleanupStack::PopAndDestroy( text ); // text
       
   389         StoreTitleTextAndSetNewL( mtmName );
       
   390         }
       
   391 
       
   392     iAccountManager.Session().AddObserverL( *this );
       
   393     iSessionObserverAdded = ETrue;
       
   394 
       
   395     UpdateServicesArrayL();
       
   396     }
       
   397 
       
   398 // ----------------------------------------------------
       
   399 // CMceSettingsMtmServicesDialog::OfferKeyEventL
       
   400 // ----------------------------------------------------
       
   401 TKeyResponse CMceSettingsMtmServicesDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   402                                                           TEventCode aType)
       
   403     {
       
   404     if ( aType == EEventKey && aKeyEvent.iCode == EKeyBackspace )
       
   405         {
       
   406         if( !iEmailApi->IsEmailFeatureSupportedL( 
       
   407             CImumInternalApi::EMailLockedSettings ) ) 
       
   408             {
       
   409             ProcessCommandL( EMceSettingsCmdSettingsDialogDelete );                    
       
   410             }
       
   411         return EKeyWasConsumed;
       
   412         }
       
   413     return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   414     }
       
   415 
       
   416 // ----------------------------------------------------
       
   417 // CMceSettingsMtmServicesDialog::HandleSessionEventL
       
   418 // ----------------------------------------------------
       
   419 void CMceSettingsMtmServicesDialog::HandleSessionEventL(
       
   420     TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   421     {
       
   422     switch ( aEvent )
       
   423         {
       
   424         case EMsvEntriesCreated:
       
   425         case EMsvEntriesChanged:
       
   426         case EMsvEntriesDeleted:
       
   427             if ( !iMailboxCreationOn )
       
   428                 {
       
   429                 UpdateServicesArrayL();                    
       
   430                 }
       
   431             break;        
       
   432         default:
       
   433             // just ignore
       
   434             break;
       
   435         }
       
   436     }
       
   437 
       
   438 // ----------------------------------------------------
       
   439 // CMceSettingsMtmServicesDialog::GetHelpContext
       
   440 // returns helpcontext as aContext
       
   441 //
       
   442 // ----------------------------------------------------
       
   443 void CMceSettingsMtmServicesDialog::GetHelpContext
       
   444         (TCoeHelpContext& aContext) const
       
   445     {
       
   446     aContext.iMajor = KMceApplicationUid;
       
   447     if ( iMtmType != KSenduiMtmSyncMLEmailUid )
       
   448         { 
       
   449         /*aContext.iContext = KMCE_HLP_SETT_SMAILBLIST;
       
   450         }
       
   451         else
       
   452         {*/
       
   453         aContext.iContext = KMCE_HLP_SETT_MAILBLIST;
       
   454         }
       
   455     }
       
   456 
       
   457 // ----------------------------------------------------
       
   458 // CMceSettingsMtmServicesDialog::LaunchHelpL
       
   459 // Launch help using context
       
   460 // 
       
   461 // ----------------------------------------------------
       
   462 void CMceSettingsMtmServicesDialog::LaunchHelpL() const
       
   463     { 
       
   464     CCoeAppUi* appUi = STATIC_CAST(CCoeAppUi*, ControlEnv()->AppUi());       
       
   465     CArrayFix<TCoeHelpContext>* helpContext = appUi->AppHelpContextL();   
       
   466     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
   467     }
       
   468 
       
   469 // ----------------------------------------------------
       
   470 // CMceSettingsMtmServicesDialog::SetSpecialMSKButtonL
       
   471 // ----------------------------------------------------
       
   472 void CMceSettingsMtmServicesDialog::SetSpecialMSKButtonL( TInt aResourceId )
       
   473     { 
       
   474     CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
   475     cba.SetCommandL( KMSKPosition, aResourceId );
       
   476     cba.DrawNow();
       
   477     }
       
   478 
       
   479 //  End of File