messagingappbase/mcesettings/mcesettingsgsplugin/src/MceSettingsGSPluginContainer.cpp
changeset 0 72b543305e3a
child 25 fa1df4b99609
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Messaging Settings sub-menu in General Settings.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 
       
    23 
       
    24 #include <MuiuMsvUiServiceUtilities.h> //MsvUiServiceUtilities
       
    25 #include <MtmExtendedCapabilities.hrh>  // KUidMtmQueryCanCreateNewMsgValue
       
    26 
       
    27 #include <mtudreg.h>        // CMtmUiDataRegistry
       
    28 #include <MTMStore.h>       // CMtmStore
       
    29 #include <msvids.h>       // KMsvRootIndexEntryId, KMsvNullIndexEntryId
       
    30 
       
    31 #include <MceSettingsArrays.h>                 // CMceUidNameArray
       
    32 #include <MceSettingsSessionObserver.h>        // CMceSettingsSessionObserver
       
    33 #include <MceSettingsGeneralSettingsDialog.h>  // CMceGeneralSettingsDialog
       
    34 #include <MceSettingsMultipleServicesDialog.h> // CMceSettingsMultipleServicesDialog
       
    35 #include <aknlists.h>                          // CAknSettingStyleListBox
       
    36 #include <MceSettingsGSPluginRsc.rsg>          // Resources
       
    37 #include <RCustomerServiceProfileCache.h>      // RCustomerServiceProfileCache
       
    38 #include <SenduiMtmUids.h>                     // KSenduiMtmSmtpUid, KSenduiMtmSmsUid,
       
    39                                                // KSenduiMtmMmsUid
       
    40 #include <csxhelp/mce.hlp.hrh>                 // Help file
       
    41 #include "MceSettingsGSPluginContainer.h"      // own header
       
    42 
       
    43 #include <featmgr.h>  // CR : 401-1806
       
    44 
       
    45 
       
    46 // CONSTANTS
       
    47 const TUid KCBSApplicationId                = {0x101F4CD3};
       
    48 const TUid KCBSApplicationSettingsViewId    = {6};
       
    49 const TInt KMceSettingsExtraItems           = 2;
       
    50 const TInt KMceSettingsCBS                  = 2;
       
    51 const TInt KMceSettingsCBSUid               = 42;
       
    52 const TUid KMceApplicationId                = { 0x100058C5 };
       
    53 
       
    54 //CMAIL Update
       
    55 #define KUidMsgTypeFsMtmVal               0x2001F406
       
    56 
       
    57 // ========================= MEMBER FUNCTIONS ================================
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CMceSettingsGSPluginContainer::CMceSettingsGSPluginContainer()
       
    61 // Default constructor.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CMceSettingsGSPluginContainer::CMceSettingsGSPluginContainer()
       
    65     {
       
    66     iDialogOpen = EFalse;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CMceSettingsGSPluginContainer::ConstructL(const TRect& aRect)
       
    72 // Symbian OS phase 2 constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CMceSettingsGSPluginContainer::ConstructL( const TRect& aRect )
       
    76     {
       
    77     // Construct iListBox
       
    78     iListBox = new ( ELeave ) CAknSettingStyleListBox;
       
    79     iMsvSession = CMsvSession::OpenSyncL(*this);
       
    80     iAccountManager = CMceSettingsSessionObserver::NewL( iMsvSession );
       
    81     iEmailFramework = EFalse;
       
    82     
       
    83     FeatureManager::InitializeLibL();
       
    84     
       
    85     if ( FeatureManager::FeatureSupported( KFeatureIdFfEmailFramework ) )
       
    86      {
       
    87             iEmailFramework = ETrue;
       
    88      }
       
    89     
       
    90     FeatureManager::UnInitializeLib();
       
    91    
       
    92     
       
    93     BaseConstructL( aRect, R_MCEUI_MAINVIEW_TITLE, 0 );// last parameter 0, since dynamic listbox
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CMceSettingsGSPluginContainer::~CMceSettingsGSPluginContainer()
       
    99 // Destructor
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CMceSettingsGSPluginContainer::~CMceSettingsGSPluginContainer()
       
   103     {
       
   104     delete iAccountManager;
       
   105     delete iMsgTypesSettings;
       
   106     delete iMsvSession;
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CMceSettingsGSPluginContainer::ConstructListBoxL()
       
   112 // See header for details.
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CMceSettingsGSPluginContainer::ConstructListBoxL( TInt /*aResLbxId*/ )
       
   116     {
       
   117     // listbox creation and initialization
       
   118     iListBox->SetContainerWindowL( *this );
       
   119     iListBox->ConstructL( this, EAknListBoxLoopScrolling );
       
   120     iListBox->CreateScrollBarFrameL( ETrue );
       
   121     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   122         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   123 
       
   124     UpdateSettingItemsL();
       
   125     CTextListBoxModel* model = iListBox->Model();
       
   126     model->SetItemTextArray( iMsgTypesSettings );
       
   127     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CMceSettingsGSPluginContainer::OfferKeyEventL()
       
   133 // See header for details.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 TKeyResponse CMceSettingsGSPluginContainer::OfferKeyEventL(
       
   137     const TKeyEvent& aKeyEvent,
       
   138     TEventCode aType )
       
   139     {
       
   140     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMceSettingsGSPluginContainer::GetHelpContext()
       
   146 // See header for details.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CMceSettingsGSPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   150     {
       
   151     aContext.iMajor = KMceApplicationId;
       
   152     aContext.iContext = KMCE_HLP_SETTINGS;
       
   153     }
       
   154     
       
   155     
       
   156 // -----------------------------------------------------------------------------
       
   157 // CMceSettingsGSPluginContainer::UpdateSettingItemsL()
       
   158 // See header for details.
       
   159 // -----------------------------------------------------------------------------
       
   160 //    
       
   161 void CMceSettingsGSPluginContainer::UpdateSettingItemsL()
       
   162     {
       
   163     if ( !iMsgTypesSettings )
       
   164         {
       
   165         iMsgTypesSettings = CMceUidNameArray::NewL();
       
   166         }
       
   167     else
       
   168         {
       
   169         iMsgTypesSettings->Reset();
       
   170         }
       
   171 
       
   172     CMtmUiDataRegistry* uiRegistry = iAccountManager->UiRegistry();
       
   173     CMtmStore* mtmStore = iAccountManager->MtmStore();
       
   174     const TInt count = uiRegistry->NumRegisteredMtmDlls();
       
   175     TInt loop = 0;
       
   176     for ( loop = 0; loop < count; loop++ )
       
   177         {
       
   178         LoadMtmL( uiRegistry->MtmTypeUid( loop ), *mtmStore );
       
   179         }
       
   180 
       
   181     // this is not used anywhere, two last items in the list are
       
   182     // ALWAYS cbs settings and mce general settings
       
   183 
       
   184     // Sort settings groups
       
   185     SortAndChangeSmsMmsEmailFirstL();
       
   186 
       
   187     // Check Cell Broadcast Csp bit
       
   188     iCbs = CheckCspBitL();
       
   189 
       
   190 
       
   191     TUid uid;
       
   192     uid.iUid = KMceSettingsCBSUid;
       
   193 
       
   194     HBufC* text = StringLoader::LoadL( R_MCEUI_CBS_SETTINGS_TEXT, iEikonEnv );
       
   195     TUidNameInfo cbsSettings( uid, *text );
       
   196     delete text;
       
   197     iMsgTypesSettings->AppendL( cbsSettings );
       
   198 
       
   199     text = StringLoader::LoadL( R_MCEUI_GENERAL_SETTINGS_TEXT, iEikonEnv );
       
   200     TUidNameInfo generalSettings( uid, *text );
       
   201     delete text;
       
   202     iMsgTypesSettings->AppendL( generalSettings );
       
   203     }
       
   204 
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CMceSettingsGSPluginContainer::LoadMtmL
       
   208 //
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CMceSettingsGSPluginContainer::LoadMtmL(
       
   212     const TUid aMtmType,
       
   213     CMtmStore& aMtmStore )
       
   214     {
       
   215     
       
   216     TUid   mtmUid = TUid::Uid(aMtmType.iUid);
       
   217     
       
   218     TBool notSelectableMtm = ( (mtmUid == KSenduiMtmSmtpUid)  
       
   219             || (mtmUid == KSenduiMtmSyncMLEmailUid) 
       
   220             || (aMtmType.iUid == KUidMsgTypeFsMtmVal) ) ;
       
   221     
       
   222     // Cmail changes - EMail, Sync EMail, Freestyle Settings will not be populated in the Messaging settings 
       
   223     
       
   224     if( !( (iEmailFramework) && (notSelectableMtm) ) )
       
   225     {
       
   226       
       
   227     CBaseMtmUiData* uiData = NULL;
       
   228     TRAPD( err, ( uiData = &(aMtmStore.MtmUiDataL(aMtmType)) ) );
       
   229     if( err != KErrNone )
       
   230         {
       
   231         return;
       
   232         }
       
   233     TBool foundSettings = EFalse;
       
   234     const CArrayFix<CBaseMtmUiData::TMtmUiFunction>& funcs =
       
   235         uiData->MtmSpecificFunctions();
       
   236     const TInt numFuncs = funcs.Count();
       
   237     for (TInt funcIndex = 0; funcIndex < numFuncs && !foundSettings; funcIndex++ )
       
   238         {
       
   239         CBaseMtmUiData::TMtmUiFunction func = funcs.At( funcIndex );
       
   240         if ( func.iFunctionId == KMtmUiMceSettings )
       
   241             {
       
   242             iMsgTypesSettings->AppendL( TUidNameInfo(
       
   243                 aMtmType,
       
   244                 func.iCaption ) );
       
   245             foundSettings = ETrue;
       
   246             }
       
   247         } // end for  
       
   248     }//end if
       
   249         
       
   250     }
       
   251 
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CMceUi::HandleSessionEventL
       
   255 //
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CMceSettingsGSPluginContainer::HandleSessionEventL(
       
   259     TMsvSessionEvent aEvent,
       
   260     TAny* /*aArg1*/,
       
   261     TAny* aArg2,
       
   262     TAny* /*aArg3*/ )
       
   263     {
       
   264     TMsvId folderId = KMsvNullIndexEntryId;
       
   265 
       
   266     // ConstructL must have left as we have returned to the active scheduler
       
   267     // before complete construction
       
   268     switch (aEvent)
       
   269         {
       
   270     case EMsvServerReady:
       
   271     case EMsvCorruptedIndexRebuilt:
       
   272         break;
       
   273     case EMsvMtmGroupInstalled:
       
   274     case EMsvMtmGroupDeInstalled:
       
   275         UpdateSettingItemsL();
       
   276         break;
       
   277     case EMsvEntriesCreated:
       
   278     case EMsvEntriesDeleted:
       
   279     case EMsvEntriesChanged:
       
   280         folderId = (*(TMsvId*) (aArg2));
       
   281         if ( folderId == KMsvRootIndexEntryId )
       
   282             {
       
   283             UpdateSettingItemsL();
       
   284             }
       
   285         break;
       
   286 
       
   287     case EMsvServerFailedToStart:
       
   288     case EMsvServerTerminated:
       
   289     case EMsvCloseSession:
       
   290     case EMsvGeneralError:
       
   291     case EMsvMediaUnavailable:
       
   292     case EMsvMediaAvailable:
       
   293     default:
       
   294         break;
       
   295         }
       
   296     }
       
   297     
       
   298     
       
   299 // -----------------------------------------------------------------------------
       
   300 // CMceSettingsGSPluginContainer::EditSubSettingsL()
       
   301 //
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CMceSettingsGSPluginContainer::EditSubSettingsL()
       
   305     {
       
   306     const TInt numberOfItems = iListBox->Model()->NumberOfItems();
       
   307     TInt choice = iListBox->CurrentItemIndex();
       
   308     // Run time Cell Broadcast variant.
       
   309     TInt removedSettingItems = 0;
       
   310 
       
   311     if ( !iCbs )
       
   312     {
       
   313         removedSettingItems++;
       
   314     }
       
   315 
       
   316     if ( choice < ( numberOfItems - KMceSettingsExtraItems ) + removedSettingItems )
       
   317         {
       
   318 
       
   319         TBool  canCreateNewAccount = iAccountManager->CanCreateNewAccountL(
       
   320             (*iMsgTypesSettings)[choice].iUid );
       
   321 
       
   322         if ( canCreateNewAccount )
       
   323             {
       
   324             if( iDialogOpen )
       
   325             	{
       
   326 				return;            	
       
   327             	}
       
   328             iDialogOpen = ETrue;
       
   329             // if mtm supports account creation then open new dialog to handle many accounts
       
   330             TInt value = CMceSettingsMultipleServicesDialog::CreateAndExecuteL(
       
   331                 *iAccountManager,  (*iMsgTypesSettings)[choice].iUid, iMsvSession );
       
   332             iDialogOpen = EFalse;
       
   333             }
       
   334         else
       
   335             {
       
   336             // mtm cannot create new accounts, edit only FIRST service if exists
       
   337             CMsvEntrySelection* sel =
       
   338                 MsvUiServiceUtilities::GetListOfAccountsWithMTML( *iMsvSession, (*iMsgTypesSettings)[choice].iUid );
       
   339 
       
   340             CleanupStack::PushL( sel );
       
   341 
       
   342             if ( sel->Count() > 0 )
       
   343                 {
       
   344                 iAccountManager->EditAccountL( (*sel)[0] );
       
   345                 }
       
   346             else
       
   347                 { // service disappeared?
       
   348 
       
   349                 }
       
   350             CleanupStack::PopAndDestroy( sel );
       
   351             }
       
   352         } // end if ( choice < numberOfItems )
       
   353     else if ( /*iCbs &&*/ choice == numberOfItems - KMceSettingsCBS )
       
   354         {
       
   355         // CBS settings are second from the end of the list
       
   356         TVwsViewId viewId( KCBSApplicationId, KCBSApplicationSettingsViewId );
       
   357         STATIC_CAST( CCoeAppUi*, ControlEnv()->AppUi())->ActivateViewL( viewId );
       
   358         }
       
   359     else
       
   360         {
       
   361         // general settings are list item in the list
       
   362         TInt value = CMceGeneralSettingsDialog::CreateAndExecuteL(
       
   363             iMsvSession,
       
   364             *this );
       
   365         }
       
   366     }
       
   367 
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CMceSettingsGSPluginContainer::SortAndChangeSmsMmsEmailFirstL
       
   371 // ---------------------------------------------------------
       
   372 //
       
   373 void CMceSettingsGSPluginContainer::SortAndChangeSmsMmsEmailFirstL()
       
   374     {
       
   375     iMsgTypesSettings->Sort(ECmpFolded);    
       
   376 
       
   377     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmPostcardUid );
       
   378     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmSyncMLEmailUid );
       
   379     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmSmtpUid );
       
   380     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmAudioMessageUid );
       
   381     // SMS & MMS still have own settings although the editor is common.
       
   382     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmMmsUid );
       
   383     ChangeMsgTypeTopL( *iMsgTypesSettings, KSenduiMtmSmsUid );
       
   384     }
       
   385 
       
   386 
       
   387 // ---------------------------------------------------------
       
   388 // CMceSettingsGSPluginContainer::ChangeMsgTypeTopL
       
   389 // ---------------------------------------------------------
       
   390 //
       
   391 void CMceSettingsGSPluginContainer::ChangeMsgTypeTopL( 
       
   392     CUidNameArray& aArray, 
       
   393     TUid aMsgType ) const
       
   394     {
       
   395     TInt loop = 0;
       
   396     // first change email to the top
       
   397     for (loop=1; loop < aArray.Count(); loop++)
       
   398         {
       
   399         if (aArray[loop].iUid == aMsgType)
       
   400             {
       
   401             TUidNameInfo info = aArray[loop];
       
   402             aArray.InsertL( 0, info );
       
   403             aArray.Delete( loop+1 );
       
   404             break;
       
   405             }
       
   406         }
       
   407     }
       
   408 
       
   409 
       
   410 // ----------------------------------------------------
       
   411 // CMceSettingsGSPluginContainer::CheckCspBitL
       
   412 // returns ETrue if Cell Broadcast csp bit is on
       
   413 //
       
   414 // ----------------------------------------------------
       
   415 TBool CMceSettingsGSPluginContainer::CheckCspBitL( ) const
       
   416     {
       
   417     RCustomerServiceProfileCache csp;
       
   418 
       
   419     TInt error = csp.Open();
       
   420     if ( error )
       
   421         {        
       
   422         return ETrue;  
       
   423         }
       
   424     
       
   425     RMobilePhone::TCspTeleservices params;
       
   426     TInt retVal = csp.CspTeleServices( params );
       
   427     csp.Close();
       
   428 
       
   429     if ( retVal == KErrNone )
       
   430         {
       
   431         if ( ( params&RMobilePhone::KCspSMCB ) != 0 )
       
   432             {
       
   433             // Cell Broadcast CSP bit is on
       
   434             return ETrue;
       
   435             }
       
   436         else
       
   437             {
       
   438             // Cell Broadcast CSP bit is off
       
   439             return EFalse;
       
   440             }
       
   441         }
       
   442     else
       
   443         {
       
   444         // Error: By default show CBS service
       
   445         return ETrue;
       
   446         }
       
   447 
       
   448     }
       
   449 
       
   450 
       
   451 // End of File