calendarui/settings/settingsui/src/calensettingsuicontainer.cpp
branchRCL_3
changeset 30 bd7edf625bdd
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
       
     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:   Calendar settings container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //debug
       
    20 #include "calendarui_debug.h"
       
    21 
       
    22 // INCLUDES
       
    23 #include "calensettingsuicontainer.h"
       
    24 
       
    25 #include "CalenFileListSettingItem.h"
       
    26 #include "calenglobaldata.h"
       
    27 #include "CalenInterimUtils2.h"
       
    28 #include "CalenSliderSettingItem.h"
       
    29 #include "CalenUid.h"
       
    30 #include "RImplInfoPtrArrayOwn.inl"
       
    31 #include "CleanupResetAndDestroy.h"
       
    32 #include "calencheckboxsettingitem.h"
       
    33 #include "calennestedsettingitem.h"
       
    34 #include "calenbooleansettingitem.h"
       
    35 #include "calenviewinfo.h"
       
    36 
       
    37 #include <Calendar.rsg>
       
    38 #include <csxhelp/cale.hlp.hrh>
       
    39 #include "calencustomisationmanager.h"
       
    40 //#include <CalenUiPluginInterface.h>
       
    41 
       
    42 #include <utf.h>
       
    43 #include <aknlists.h>               // for CAknSettingStyleListBox
       
    44 #include <eikclbd.h>                // CColumnListBoxData
       
    45 #include <StringLoader.h>
       
    46 #include <bacntf.h>                 // CEnvironmentChangeNotifier
       
    47 #include <centralrepository.h>      // CRepository
       
    48 #include <CalendarInternalCRKeys.h> // KCRUidCalendar
       
    49 
       
    50 
       
    51 #ifdef RD_CALEN_EXTERNAL_CAL
       
    52 #include <aiwservicehandler.h>
       
    53 
       
    54 // MIME types
       
    55 _LIT8(KContentTypeCalendar, "text/calendar");
       
    56 
       
    57 #endif //RD_CALEN_EXTERNAL_CAL
       
    58 
       
    59 
       
    60 #include <AknUtils.h>
       
    61 
       
    62 
       
    63 
       
    64 const TInt KDisablePluginEnablement = 2;
       
    65 
       
    66 void ListMailboxesL( 
       
    67 		CMRMailboxUtils& aMbUtils,
       
    68 		RArray<CMRMailboxUtils::TMailboxInfo>& aMailBoxes )
       
    69 	{
       
    70 	aMbUtils.ListMailBoxesL( aMailBoxes );
       
    71 	
       
    72     // Get MR Viewer implementations
       
    73 	RImplInfoPtrArrayOwn implArray;
       
    74     CleanupClosePushL( implArray );
       
    75     const TUid mrViewersIface = {KMRViewersInterfaceUID};
       
    76     REComSession::ListImplementationsL( mrViewersIface, implArray );
       
    77     TBuf16<KMaxUidName> mbName;
       
    78     
       
    79     TInt index(0);
       
    80     while (index < aMailBoxes.Count() )
       
    81     	{
       
    82     	TBool matchingMRViewerFound( EFalse );
       
    83     	TInt mrviewerImplCount( implArray.Count() );
       
    84         for( TInt j=0; j < mrviewerImplCount && !matchingMRViewerFound; ++j )
       
    85             {
       
    86             CnvUtfConverter::ConvertToUnicodeFromUtf8( mbName, implArray[j]->DataType() );
       
    87             if( aMailBoxes[index].iMtmUid.Name().CompareF(mbName) == 0 )
       
    88                 {
       
    89                 // Found a match. This mailbox would have been shown in the settings list.
       
    90                 matchingMRViewerFound = ETrue;
       
    91                 }
       
    92             }
       
    93         
       
    94         if ( !matchingMRViewerFound )
       
    95         	{
       
    96         	aMailBoxes.Remove( index );        	
       
    97         	}
       
    98         else
       
    99         	{
       
   100         	++index;
       
   101         	}
       
   102     	}
       
   103     CleanupStack::PopAndDestroy(); // implArray
       
   104 	}
       
   105 
       
   106 // ========================= MEMBER FUNCTIONS ================================
       
   107 
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CCalenSettingsUiContainer::NewL
       
   111 // Symbian two-phased constructor.
       
   112 // Two-phased constructor. Does NOT take ownership of aParentControl or aListBox.
       
   113 // (other items were commented in a header).
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C CCalenSettingsUiContainer* CCalenSettingsUiContainer::NewL(
       
   117                                                 CCoeControl* aParentControl,
       
   118                                                 CAknSettingStyleListBox& aListBox,
       
   119                                                 CCalenGlobalData& aGlobalData,
       
   120                                                 CCalenCustomisationManager& aCustomisationManager )
       
   121     {
       
   122     TRACE_ENTRY_POINT;
       
   123 
       
   124     CCalenSettingsUiContainer* self = new(ELeave) CCalenSettingsUiContainer( aParentControl,
       
   125                                                                              aListBox,
       
   126                                                                              aGlobalData,
       
   127                                                                              aCustomisationManager );
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL();
       
   130     CleanupStack::Pop( self );
       
   131 
       
   132     TRACE_EXIT_POINT;
       
   133     return self;
       
   134     }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // CCalenSettingsUiContainer::ConstructL
       
   138 // Symbian OS default constructor
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 void CCalenSettingsUiContainer::ConstructL()
       
   142     {
       
   143     TRACE_ENTRY_POINT;
       
   144 
       
   145     iSetting = CCalenSetting::InstanceL();
       
   146 
       
   147     // Initialize TLocale watcher
       
   148     TCallBack callback( LocaleCallbackL, this );
       
   149     iLocaleChangeNotifier =
       
   150         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, callback );
       
   151 
       
   152     // Initialize Central Repository watcher
       
   153     iRepository = CRepository::NewL( KCRUidCalendar );
       
   154     iCenRepNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository );
       
   155     
       
   156     iSettingItemArray = new( ELeave )CAknSettingItemArray( 2, 0, 0 );
       
   157 
       
   158     if( iGlobalData.InterimUtilsL().MRViewersEnabledL() )
       
   159         {
       
   160         LoadMailboxSettingsL();
       
   161         }
       
   162 
       
   163     iLocaleChangeNotifier->Start();
       
   164     iCenRepNotifyHandler->StartListeningL();
       
   165 
       
   166     iPageStatus = EFalse;
       
   167     TRACE_EXIT_POINT;
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // CCalenSettingsUiContainer::~CCalenSettingsUiContainer
       
   172 // Destructor
       
   173 // ----------------------------------------------------------------------------
       
   174 //
       
   175 CCalenSettingsUiContainer::~CCalenSettingsUiContainer()
       
   176     {
       
   177     TRACE_ENTRY_POINT;
       
   178 
       
   179     delete iLocaleChangeNotifier;
       
   180     if( iCenRepNotifyHandler )
       
   181         {
       
   182         iCenRepNotifyHandler->StopListening();
       
   183         delete iCenRepNotifyHandler;
       
   184         }
       
   185 
       
   186     delete iRepository;
       
   187 
       
   188     iMailBoxes.Close();
       
   189     if( iSettingItemArray )
       
   190         {
       
   191         iSettingItemArray->ResetAndDestroy();
       
   192         delete iSettingItemArray;
       
   193         }
       
   194 
       
   195     if ( iSetting )
       
   196         {
       
   197         iSetting->Release();
       
   198         }
       
   199 
       
   200 #ifdef RD_CALEN_EXTERNAL_CAL
       
   201     delete iServiceHandler;
       
   202 #endif //RD_CALEN_EXTERNAL_CAL
       
   203 
       
   204     TRACE_EXIT_POINT;
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // CCalenSettingsUiContainer::CCalenSettingsUiContainer
       
   209 // Default constructor
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 CCalenSettingsUiContainer::CCalenSettingsUiContainer( CCoeControl* aParentControl,
       
   213                                                       CAknSettingStyleListBox& aListBox,
       
   214                                                       CCalenGlobalData& aGlobalData,
       
   215                                                       CCalenCustomisationManager& aCustomisationManager )
       
   216     : iGlobalData( aGlobalData ),
       
   217       iParentControl( aParentControl ),
       
   218       iListBox( aListBox ),
       
   219       iCustomisationManager( aCustomisationManager ),
       
   220       iIgnoreNextSettingsNotification( EFalse ),
       
   221       iIgnoreFirstLocaleChange( ETrue )
       
   222     {
       
   223     TRACE_ENTRY_POINT;
       
   224     TRACE_EXIT_POINT;
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CCalenSettingsUiContainer::AddCustomSettingsWithLinkL
       
   229 // Adds all settings from customisations. This will get a link from the front
       
   230 // settings page. Removes items from the array when ownership transferred
       
   231 // away from the array.
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 void CCalenSettingsUiContainer::AddCustomSettingsWithLinkL( RPointerArray<CAknSettingItem>& aSettings,
       
   235                                                             const TDesC& aName,
       
   236                                                             TInt aOrdinal )
       
   237     {
       
   238     TRACE_ENTRY_POINT;
       
   239 
       
   240     // CCalenNestedSettingItem will take items out of aSettings array and
       
   241     // take ownership of removed items.
       
   242     CCalenNestedSettingItem* item = new( ELeave )CCalenNestedSettingItem( 0,
       
   243                                                                           aSettings,
       
   244                                                                           aName );
       
   245     CleanupStack::PushL( item );
       
   246 
       
   247     // The followng text should never actually be displayed on screen
       
   248     item->SetEmptyItemTextL( KNullDesC );
       
   249 
       
   250     // Construct setting item with parametrized values
       
   251     item->ConstructL( EFalse, aOrdinal, aName, NULL,
       
   252                       R_CALEN_EMPTY_SETTING_PAGE, EAknSetListBox,
       
   253                       NULL, R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
       
   254 
       
   255     iSettingItemArray->InsertL( aOrdinal, item );
       
   256 
       
   257     CleanupStack::Pop( item );
       
   258 
       
   259     TRACE_EXIT_POINT;
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------------------------------
       
   263 // CCalenSettingsUiContainer::AddSingleCustomSettingL
       
   264 // Adds a setting from customisations. This will go directly into the front
       
   265 // settings page. Takes ownership of aSetting when the function completes.
       
   266 // ----------------------------------------------------------------------------
       
   267 //
       
   268 void CCalenSettingsUiContainer::AddSingleCustomSettingL( CAknSettingItem* aSetting,
       
   269                                                          TInt aOrdinal )
       
   270     {
       
   271     TRACE_ENTRY_POINT;
       
   272 
       
   273     iSettingItemArray->InsertL( aOrdinal, aSetting ); // Takes ownership of aSetting.
       
   274 
       
   275     TRACE_EXIT_POINT;
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CCalenSettingsUiContainer::AddCustomSettingsItemsL
       
   280 // Adds all settings from customisations.
       
   281 // ----------------------------------------------------------------------------
       
   282 //
       
   283 void CCalenSettingsUiContainer::AddCustomSettingsItemsL( TInt& aOrdinal )
       
   284     {
       
   285     TRACE_ENTRY_POINT;
       
   286 
       
   287     const RArray<TUid>& plugins = iCustomisationManager.ActivePlugins();
       
   288 
       
   289     RPointerArray<CAknSettingItem> settings;
       
   290     CleanupResetAndDestroyPushL( settings );
       
   291 
       
   292     for ( TInt i( 0 ); i<plugins.Count(); ++i )
       
   293         {
       
   294         iCustomisationManager.GetPluginSettingsL( plugins[i],
       
   295                                                   settings );
       
   296         // We have ownership of settings items now.
       
   297 
       
   298         // If there is more than one setting per plugin, it gets a link in the main
       
   299         // setting page. If there is only one, it goes directly into the main page.
       
   300         if ( settings.Count() > 1 )
       
   301             {
       
   302             const RImplInfoPtrArray& pluginInfo = iCustomisationManager.PluginInfoArray();
       
   303             TInt pluginIndex = KErrNotFound;
       
   304 
       
   305             for ( TInt j( 0 ); j<pluginInfo.Count(); ++j )
       
   306                 {
       
   307                 if ( pluginInfo[j]->ImplementationUid() == plugins[i] )
       
   308                     {
       
   309                     pluginIndex = j;
       
   310                     break;
       
   311                     }
       
   312                 }
       
   313 
       
   314             ASSERT( pluginIndex != KErrNotFound );
       
   315             const TDesC& pluginName = pluginInfo[pluginIndex]->DisplayName();
       
   316 
       
   317             AddCustomSettingsWithLinkL( settings, pluginName, aOrdinal++ );
       
   318             }
       
   319         else if ( settings.Count() == 1 )
       
   320             {
       
   321             // This function takes ownership of the setting item we pass it,
       
   322             // when the function completes.
       
   323             AddSingleCustomSettingL( settings[0], aOrdinal++ );
       
   324             settings.Remove( 0 );
       
   325             }
       
   326 
       
   327         ASSERT( settings.Count() == 0 );
       
   328         }
       
   329 
       
   330     CleanupStack::PopAndDestroy( &settings );
       
   331 
       
   332     TRACE_EXIT_POINT;
       
   333     }
       
   334 
       
   335 // ----------------------------------------------------------------------------
       
   336 // CCalenSettingsUiContainer::AddPluginSettingItemL
       
   337 // Adds a settings item allowing the user to enable/disable plugins and
       
   338 // change their priority.
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 void CCalenSettingsUiContainer::AddPluginSettingItemL( TInt& aOrdinal )
       
   342     {
       
   343     TRACE_ENTRY_POINT;
       
   344 
       
   345     const RImplInfoPtrArray& plugins = iCustomisationManager.PluginInfoArray();
       
   346     TInt pluginCount = plugins.Count();
       
   347     
       
   348     if ( pluginCount > 0 )
       
   349         {
       
   350         // Check to see if any of the plugins are able to be be enable or 
       
   351         // disabled
       
   352         TBool pluginFound( EFalse );
       
   353         TBuf<100> displayName;
       
   354         for ( TInt index(0); index < pluginCount && !pluginFound; ++index )
       
   355             {
       
   356             // if the display name is empty and the plugin is in ROM the
       
   357             // plugin can  not be disabled
       
   358             TInt version = plugins[index]->Version();
       
   359             TBool romBased = plugins[index]->RomBased();
       
   360             displayName = plugins[index]->DisplayName();
       
   361            
       
   362             if ( ( version != KDisablePluginEnablement ) || !romBased )
       
   363                 {
       
   364                 pluginFound = ETrue;
       
   365                 }
       
   366             } 
       
   367         
       
   368         
       
   369         
       
   370         if ( pluginFound )
       
   371             {
       
   372             //There will not be any sort of settings item for plugins which are not part of settings 
       
   373             TInt countOfAvailability =  iSetting->PluginAvailability().Count();
       
   374             
       
   375             if(countOfAvailability)
       
   376                 {
       
   377                 //If available plugins(which has settings) count is > 1 its check box or toggle button.  
       
   378                 if(countOfAvailability > 1 )
       
   379                     {
       
   380                     CCalenCheckboxSettingItem* settingItem
       
   381                         = new( ELeave )CCalenCheckboxSettingItem( ECalenPluginListItemId,
       
   382                                                                   iCustomisationManager );
       
   383         
       
   384                     CleanupStack::PushL( settingItem );
       
   385         
       
   386                     // The followng text should never actually be displayed on screen
       
   387                     settingItem->SetEmptyItemTextL( KNullDesC );
       
   388                     
       
   389         
       
   390                     // Construct setting item with parametrized values
       
   391                     HBufC* itemTitle = StringLoader::LoadLC( R_CALEN_SETTING_PLUGINLIST_TITLE );
       
   392                     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   393                                              R_CALEN_SETTING_PLUGINLIST, EAknSetListBox,
       
   394                                              NULL, R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
       
   395                     
       
   396                     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   397         
       
   398                     CleanupStack::PopAndDestroy( itemTitle );
       
   399                     CleanupStack::Pop( settingItem );
       
   400                     aOrdinal++;
       
   401                     }
       
   402                 else
       
   403                     {
       
   404                     CCalenBooleanSettingItem* settingItem =
       
   405                             CCalenBooleanSettingItem::NewLC(ECalenPluginListItemId,aOrdinal,iCustomisationManager);
       
   406                     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   407                     CleanupStack::Pop( settingItem );
       
   408                     aOrdinal++;
       
   409                     }
       
   410                 }
       
   411             }
       
   412         }
       
   413 
       
   414     TRACE_EXIT_POINT;
       
   415     }
       
   416 
       
   417 // ----------------------------------------------------------------------------
       
   418 // CCalenSettingsUiContainer::AddDefaultViewItemL
       
   419 // Adds a setting item to allow selection of the default view. Includes custom
       
   420 // views in the view cycle array.
       
   421 // (other items were commented in a header).
       
   422 // ----------------------------------------------------------------------------
       
   423 //
       
   424 void CCalenSettingsUiContainer::AddDefaultViewItemL( TInt& aBuffer,
       
   425                                                      TInt aId,
       
   426                                                      TInt aTitleResource,
       
   427                                                      TInt aSettingPageResource,
       
   428                                                      TInt aOrdinal )
       
   429     {
       
   430     TRACE_ENTRY_POINT;
       
   431 
       
   432     // Create new setting item
       
   433     CAknEnumeratedTextPopupSettingItem* settingItem =
       
   434         new( ELeave )CAknEnumeratedTextPopupSettingItem( aId, aBuffer );
       
   435     CleanupStack::PushL( settingItem );
       
   436 
       
   437     // The followng text should never actually be displayed on screen
       
   438     _LIT( KNone, "None" );
       
   439     settingItem->SetEmptyItemTextL( KNone );
       
   440 
       
   441     // Construct setting item with parametrized values
       
   442     HBufC* itemTitle = StringLoader::LoadLC( aTitleResource );
       
   443     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   444                              aSettingPageResource, EAknCtPopupSettingList,
       
   445                              NULL, R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
       
   446 
       
   447     CArrayPtr<CAknEnumeratedText>* items = settingItem->EnumeratedTextArray();
       
   448 
       
   449     const RPointerArray<CCalenViewInfo>& views = iCustomisationManager.Views();
       
   450     const RArray<TUid>& activePlugins = iCustomisationManager.ActivePlugins();
       
   451 
       
   452     TBool isDefViewValid( EFalse );
       
   453 
       
   454     TInt numViews = views.Count();
       
   455     for ( TInt i( 0 ); i<numViews; ++i )
       
   456         {
       
   457         CCalenViewInfo* view = views[i];
       
   458         TUid pluginUid = view->PluginUid();
       
   459 	    TInt position = activePlugins.Find( pluginUid );
       
   460 	    
       
   461 		// If the view is from plugin or native view with cycle position,
       
   462         // then add it to the default view list
       
   463         if((position != KErrNotFound) ||
       
   464         	( view->CyclePosition() != CCalenView::ENoCyclePosition ))
       
   465             {
       
   466             TInt viewUidInt = view->ViewUid().iUid;
       
   467 
       
   468             if ( viewUidInt == iDefView )
       
   469                 {
       
   470                 isDefViewValid = ETrue;
       
   471                 }
       
   472 
       
   473             CAknEnumeratedText* item = new( ELeave )CAknEnumeratedText( viewUidInt,
       
   474                                                                         view->SettingsName().AllocL() );
       
   475             items->AppendL( item );
       
   476             }
       
   477         }
       
   478 
       
   479     if ( !isDefViewValid )
       
   480         {
       
   481         // Default view is no longer valid (could be first ever load, or could be
       
   482         // a 3rd party plugin's view used to be the default but is not removed).
       
   483         // Set default to the first in the view cycle array. 
       
   484         TInt defViewIndex( 0 );
       
   485         while ( views[defViewIndex]->CyclePosition() == CCalenView::ENoCyclePosition )
       
   486             {
       
   487             defViewIndex++;
       
   488             }
       
   489             
       
   490         iDefView = views[defViewIndex]->ViewUid().iUid;
       
   491         iSetting->SetDefaultView( TUid::Uid( iDefView ) );
       
   492         }
       
   493 
       
   494     settingItem->HandleTextArrayUpdateL();
       
   495 
       
   496     // Append item to settingitem-array
       
   497     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   498 
       
   499     CleanupStack::PopAndDestroy( itemTitle );
       
   500     CleanupStack::Pop( settingItem );
       
   501 
       
   502     TRACE_EXIT_POINT;
       
   503     }
       
   504 
       
   505 // ----------------------------------------------------------------------------
       
   506 // CCalenSettingsUiContainer::AddSnoozeTimeItemL
       
   507 // Adds an alarm snooze time item
       
   508 // (other items were commented in a header).
       
   509 // ----------------------------------------------------------------------------
       
   510 //
       
   511 void CCalenSettingsUiContainer::AddSnoozeTimeItemL( TInt aOrdinal,
       
   512                                                     CArrayPtr<CGulIcon>* aIconArray,
       
   513                                                     TInt& aSnoozeTime)
       
   514     {
       
   515     TRACE_ENTRY_POINT;
       
   516 
       
   517     CCalenSliderSettingItem* settingItem =
       
   518                 new( ELeave )CCalenSliderSettingItem( ECalenSnoozeTimeItemId,
       
   519                                                       aSnoozeTime,
       
   520                                                       R_SNOOZE_TIME_SLIDER );
       
   521     CleanupStack::PushL( settingItem );
       
   522 
       
   523     HBufC* itemTitle = StringLoader::LoadLC( R_QTN_CALE_SET_SNOOZE_TIME );
       
   524 
       
   525     settingItem->ConstructL( EFalse,
       
   526                              aOrdinal,
       
   527                              *itemTitle,
       
   528                              aIconArray,
       
   529                              R_SNOOZE_TIME_SETTING_PAGE,
       
   530                              EAknCtSlider );
       
   531 
       
   532     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   533 
       
   534     CleanupStack::PopAndDestroy( itemTitle );
       
   535     CleanupStack::Pop( settingItem );
       
   536 
       
   537     TRACE_EXIT_POINT;
       
   538     }
       
   539 
       
   540 // ----------------------------------------------------------------------------
       
   541 // AddEnumerationItemL()
       
   542 // Add integer type of settings item
       
   543 // Integer type item can have multiple choices shown as radiobutton list.
       
   544 // (other items were commented in a header).
       
   545 // ----------------------------------------------------------------------------
       
   546 //
       
   547 void CCalenSettingsUiContainer::AddEnumerationItemL( TInt& aBuffer,
       
   548                                                      TInt aId,
       
   549                                                      TInt aTitleResource,
       
   550                                                      TInt aSettingPageResource,
       
   551                                                      TInt aAssociatedResource,
       
   552                                                      TInt aOrdinal )
       
   553     {
       
   554     TRACE_ENTRY_POINT;
       
   555 
       
   556     // Create new setting item
       
   557     CAknSettingItem* settingItem =
       
   558         new ( ELeave ) CAknEnumeratedTextPopupSettingItem( aId, aBuffer );
       
   559     CleanupStack::PushL( settingItem );
       
   560 
       
   561     // Construct setting item with parametrized values
       
   562     HBufC* itemTitle = StringLoader::LoadLC( aTitleResource );
       
   563     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   564                              aSettingPageResource, EAknCtPopupSettingList,
       
   565                              NULL, aAssociatedResource );
       
   566 
       
   567     // Append item to settingitem-array
       
   568     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   569 
       
   570     CleanupStack::PopAndDestroy( itemTitle );
       
   571     CleanupStack::Pop( settingItem );
       
   572 
       
   573     TRACE_EXIT_POINT;
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CCalenSettingsUiContainer::AddBinaryItemL()
       
   578 // Add binary type (true/false) settings item
       
   579 // (other items were commented in a header).
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void CCalenSettingsUiContainer::AddBinaryItemL( TBool& aBuffer,
       
   583                                                 TInt aId,
       
   584                                                 TInt aTitleResource,
       
   585                                                 TInt aSettingPageResource,
       
   586                                                 TInt aAssociatedResource,
       
   587                                                 TInt aOrdinal )
       
   588     {
       
   589     TRACE_ENTRY_POINT;
       
   590 
       
   591     // Create new setting item
       
   592     CAknSettingItem* settingItem =
       
   593         new ( ELeave ) CAknBinaryPopupSettingItem( aId,  aBuffer );
       
   594     CleanupStack::PushL( settingItem );
       
   595 
       
   596     // Construct setting item with parametrized values
       
   597     HBufC* itemTitle = StringLoader::LoadLC( aTitleResource );
       
   598     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   599                              aSettingPageResource, EAknCtPopupSettingList,
       
   600                              NULL, aAssociatedResource );
       
   601 
       
   602     // Append item to settingitem-array
       
   603     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   604 
       
   605     CleanupStack::PopAndDestroy( itemTitle );
       
   606     CleanupStack::Pop( settingItem );
       
   607 
       
   608     TRACE_EXIT_POINT;
       
   609     }
       
   610 
       
   611 // ----------------------------------------------------------------------------
       
   612 // CCalenSettingsUiContainer::AddAlarmToneItemL
       
   613 // Adds an item to the settings page which contains information about
       
   614 // which tone should be played when an alarm expires.
       
   615 // (other items were commented in a header).
       
   616 // ----------------------------------------------------------------------------
       
   617 //
       
   618 void CCalenSettingsUiContainer::AddAlarmToneItemL( TInt aOrdinal )
       
   619     {
       
   620     TRACE_ENTRY_POINT;
       
   621 
       
   622     CCalenFileListSettingItem* settingItem =
       
   623         new ( ELeave ) CCalenFileListSettingItem( ECalenAlarmToneItemId );
       
   624     CleanupStack::PushL( settingItem );
       
   625 
       
   626     // Construct setting item with parametrized values
       
   627     HBufC* itemTitle = StringLoader::LoadLC( R_CALEN_SETTING_ALARMTONE_TITLE );
       
   628     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   629                              NULL, NULL, NULL, NULL );
       
   630 
       
   631     // Append item to settingitem-array
       
   632     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   633 
       
   634     CleanupStack::PopAndDestroy( itemTitle );
       
   635     CleanupStack::Pop( settingItem );
       
   636 
       
   637     TRACE_EXIT_POINT;
       
   638     }
       
   639 
       
   640 // ----------------------------------------------------------------------------
       
   641 // CCalenSettingsUiContainer::CreateMailboxSettingsItemL
       
   642 // Creates the settings item for selection of the default meeting request
       
   643 // mailbox. This should only be called when MR viewers are enabled.
       
   644 // (other items were commented in a header).
       
   645 // ----------------------------------------------------------------------------
       
   646 //
       
   647 void CCalenSettingsUiContainer::CreateMailboxSettingsItemL( TInt aOrdinal )
       
   648     {
       
   649     TRACE_ENTRY_POINT;
       
   650 
       
   651     // Mailbox settings are shown when we have a MR viewers implementation.
       
   652     ASSERT( iGlobalData.InterimUtilsL().MRViewersEnabledL() );
       
   653     CMRMailboxUtils& mailboxUtils = iGlobalData.MRMailboxUtilsL();
       
   654     CAknEnumeratedTextPopupSettingItem* settingItem =
       
   655         new ( ELeave ) CAknEnumeratedTextPopupSettingItem( ECalenDefaultMailboxId,
       
   656                                                            iDefMailbox );
       
   657     CleanupStack::PushL( settingItem );
       
   658 
       
   659     // Construct setting item with parametrized values
       
   660     HBufC* itemTitle = StringLoader::LoadLC( R_CALEN_SETTING_DEFAULTMAILBOX_TITLE );
       
   661     // The resources loaded up here are empty as the items need to be dynamically updated.
       
   662     
       
   663     settingItem->SetEmptyItemTextL( KNullDesC );
       
   664     
       
   665     settingItem->ConstructL( EFalse, aOrdinal, *itemTitle, NULL,
       
   666                              R_CALEN_SETTING_DEFAULTMAILBOX, EAknCtPopupSettingList,
       
   667                              NULL, R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
       
   668 
       
   669     CArrayPtr<CAknEnumeratedText>* items = settingItem->EnumeratedTextArray();
       
   670 
       
   671     RImplInfoPtrArrayOwn implArray;
       
   672     CleanupClosePushL( implArray );
       
   673     //Get all MRViewers Implementation
       
   674     CMRMailboxUtils::TMailboxInfo defaultMailbox;
       
   675     const TUid mrViewersIface = {KMRViewersInterfaceUID};
       
   676     REComSession::ListImplementationsL( mrViewersIface, implArray );
       
   677 
       
   678     TBuf16<KMaxUidName> mbName;
       
   679     TInt enumerationCounter = 0;
       
   680 
       
   681     for( TInt i=0; i < iMailBoxes.Count(); ++i )
       
   682         {
       
   683         for( TInt j=0; j < implArray.Count(); ++j )
       
   684             {
       
   685             CnvUtfConverter::ConvertToUnicodeFromUtf8( mbName, implArray[j]->DataType() );
       
   686             if( iMailBoxes[i].iMtmUid.Name().CompareF(mbName) == 0 )
       
   687                 {
       
   688                  // Found a match
       
   689                 CAknEnumeratedText* item = new(ELeave) CAknEnumeratedText( enumerationCounter,
       
   690                                                                            iMailBoxes[i].iName.AllocL() );
       
   691                 items->AppendL( item );
       
   692                 ++enumerationCounter;
       
   693                 }
       
   694             }
       
   695         }
       
   696 
       
   697     CleanupStack::PopAndDestroy();    //implArray
       
   698 
       
   699     settingItem->HandleTextArrayUpdateL();
       
   700 
       
   701     // Append item to settingitem-array
       
   702     iSettingItemArray->InsertL( aOrdinal, settingItem );
       
   703 
       
   704     CleanupStack::PopAndDestroy( itemTitle );
       
   705     CleanupStack::Pop( settingItem );
       
   706 
       
   707     TRACE_EXIT_POINT;
       
   708     }
       
   709 
       
   710 // ----------------------------------------------------------------------------
       
   711 // CCalenSettingsUiContainer::UpdateListBoxL
       
   712 // Update listbox item
       
   713 // ----------------------------------------------------------------------------
       
   714 //
       
   715 EXPORT_C void CCalenSettingsUiContainer::UpdateListBoxL()
       
   716     {
       
   717     TRACE_ENTRY_POINT;
       
   718 
       
   719     iListBox.HandleItemAdditionL();
       
   720 
       
   721     TRACE_EXIT_POINT;
       
   722     }
       
   723 
       
   724 // ----------------------------------------------------------------------------
       
   725 // CCalenSettingsUiContainer::ConstructListBoxL
       
   726 // Update listbox item
       
   727 // Items are added manually, instead of loading them from resources
       
   728 // ----------------------------------------------------------------------------
       
   729 //
       
   730 EXPORT_C void CCalenSettingsUiContainer::ConstructListBoxL()
       
   731     {
       
   732     TRACE_ENTRY_POINT;
       
   733 
       
   734     iListBox.ConstructL( iParentControl, EAknListBoxSelectionList );
       
   735 
       
   736     LoadCurrentValuesL();
       
   737 
       
   738     // Create items to array
       
   739     CreateListBoxItemsL();
       
   740 
       
   741     // Set array to listbox
       
   742     CTextListBoxModel* model = iListBox.Model();
       
   743     model->SetItemTextArray( iSettingItemArray );
       
   744     // Ownership retained by us
       
   745     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   746 
       
   747     iSettingItemArray->RecalculateVisibleIndicesL();
       
   748     iListBox.CreateScrollBarFrameL();
       
   749     iListBox.ScrollBarFrame()->SetScrollBarVisibilityL(
       
   750                         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   751 
       
   752     TRACE_EXIT_POINT;
       
   753     }
       
   754 
       
   755 // ----------------------------------------------------------------------------
       
   756 // CCalenSettingsUiContainer::CreateListBoxItemsL
       
   757 // Update listbox item
       
   758 // ----------------------------------------------------------------------------
       
   759 //
       
   760 void CCalenSettingsUiContainer::CreateListBoxItemsL()
       
   761     {
       
   762     TRACE_ENTRY_POINT;
       
   763 
       
   764     TInt ordinal = 0;
       
   765 
       
   766     AddAlarmToneItemL( ordinal++ );
       
   767 
       
   768     CArrayPtr<CGulIcon>* iconArray = iListBox.ItemDrawer()->ColumnData()->IconArray();
       
   769 
       
   770     if( !iconArray )
       
   771         {
       
   772         iconArray = new( ELeave )CArrayPtrFlat<CGulIcon>( 1 );
       
   773         iListBox.ItemDrawer()->ColumnData()->SetIconArrayL( iconArray ); // ownership transfered
       
   774         }
       
   775 
       
   776     AddSnoozeTimeItemL( ordinal++, iconArray, iSnoozeTime );
       
   777 
       
   778     AddDefaultViewItemL( iDefView,
       
   779                          ECalenDefaultViewItemId,
       
   780                          R_CALEN_SETTING_DEFAULTVIEW_TITLE,
       
   781                          R_CALEN_SETTING_DEFAULTVIEW,
       
   782                          ordinal++ );
       
   783 
       
   784     AddEnumerationItemL( iWeekFormat,
       
   785                          ECalenWeekFormatItemId,
       
   786                          R_CALEN_SETTING_WEEKFORMAT_TITLE,
       
   787                          R_CALEN_SETTING_WEEKFORMAT,
       
   788                          R_CALEN_WEEKFORMAT_TEXTS,
       
   789                          ordinal++ );
       
   790 
       
   791     AddEnumerationItemL( iWeekNumberEnable,
       
   792                          ECalenWeekNumberItemId,
       
   793                          R_CALEN_SETTING_WEEKNUMBER_TITLE,
       
   794                          R_CALEN_SETTING_WEEKNUMBER,
       
   795                          R_CALEN_WEEKNUMBER_TEXTS,
       
   796                          ordinal++ );
       
   797 
       
   798     // Always add this in. We will set it hidden when it's not needed (i.e. when the
       
   799     // week start is set to anything other than "Monday") at the bottom of this function.
       
   800     AddEnumerationItemL( iWeekTitle,
       
   801                          ECalenWeekTitleItemId,
       
   802                          R_CALEN_SETTING_WEEKTITLE_TITLE,
       
   803                          R_CALEN_SETTING_WEEKTITLE,
       
   804                          R_CALEN_WEEKTITLE_TEXTS,
       
   805                          ordinal++ );
       
   806     
       
   807 
       
   808 #ifdef RD_CALEN_EXTERNAL_CAL
       
   809     // add external calendar support if available.
       
   810     TBool isExt=ExtCalendarAvailableL();
       
   811     if (isExt)
       
   812         {
       
   813         AddEnumerationItemL( iExtCalendar,
       
   814                              ECalenExtCalendarItemId,
       
   815                              R_CALEN_SETTING_EXT_CALENDAR_TITLE,
       
   816                              R_CALEN_EXT_CALENDAR_SETTING_PAGE,
       
   817                              R_CALEN_EXT_CALENDAR_SETTING_TEXTS,
       
   818                              ordinal++ );
       
   819         }
       
   820 
       
   821 #endif //RD_CALEN_EXTERNAL_CAL
       
   822 
       
   823     // Only add the mailbox choice when the Meeting Request functionality is there.
       
   824     if( iGlobalData.InterimUtilsL().MRViewersEnabledL() )
       
   825         {
       
   826         CreateMailboxSettingsItemL( ordinal++ ); // increments ordinal
       
   827         }
       
   828 
       
   829 #ifdef RD_SCALABLE_UI_V2_NO_TOOLBAR_SETTING
       
   830     if( AknLayoutUtils::PenEnabled() )
       
   831         {
       
   832         AddBinaryItemL( iToolbar,
       
   833                         ECalenToolbarItemId,
       
   834                         R_CALEN_SETTING_TOOLBAR_TITLE,
       
   835                         R_CALEN_SETTING_TOOLBAR,
       
   836                         R_CALEN_TOOLBAR_TEXTS,
       
   837                         ordinal++ );
       
   838         }
       
   839 #endif // RD_SCALABLE_UI_V2_NO_TOOLBAR_SETTING
       
   840 
       
   841     AddPluginSettingItemL( ordinal );
       
   842 
       
   843     AddCustomSettingsItemsL( ordinal );
       
   844     ++ordinal;
       
   845 
       
   846     // Hide the week title setting if the week start is anything other than Monday.
       
   847     Item( ECalenWeekTitleItemId )->SetHidden( !ShouldShowWeekTitleItem() );
       
   848     Item( ECalenWeekNumberItemId )->SetHidden( !ShouldShowWeekTitleItem() );
       
   849 
       
   850     TRACE_EXIT_POINT;
       
   851     }
       
   852 
       
   853 // ----------------------------------------------------------------------------
       
   854 // CCalenSettingsUiContainer::CurrentFeatureId
       
   855 // Get the currently selected feature
       
   856 // ----------------------------------------------------------------------------
       
   857 //
       
   858 EXPORT_C TInt CCalenSettingsUiContainer::CurrentFeatureId() const
       
   859     {
       
   860     TRACE_ENTRY_POINT;
       
   861 
       
   862     if ( iSettingItemArray )
       
   863         {
       
   864         TRACE_EXIT_POINT;
       
   865         return iSettingItemArray->MdcaCount();
       
   866         }
       
   867     else
       
   868         {
       
   869         TRACE_EXIT_POINT;
       
   870         return 0;
       
   871         }
       
   872     }
       
   873 
       
   874 // ----------------------------------------------------------------------------
       
   875 // CCalenSettingsUiContainer::GetHelpContext
       
   876 // Get help for this view
       
   877 // ----------------------------------------------------------------------------
       
   878 //
       
   879 void CCalenSettingsUiContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   880     {
       
   881     TRACE_ENTRY_POINT;
       
   882 
       
   883     aContext.iMajor = KUidCalendar;
       
   884     // This is specified in HRH file.
       
   885     aContext.iContext = KCALE_HLP_SETTINGS;
       
   886 
       
   887     TRACE_EXIT_POINT;
       
   888     }
       
   889 
       
   890 // ----------------------------------------------------------------------------
       
   891 // CCalenSettingsUiContainer::ShouldShowWeekTitleItem
       
   892 // Returns ETrue if the start of the week is set to Monday.
       
   893 // (other items were commented in a header).
       
   894 // ----------------------------------------------------------------------------
       
   895 //
       
   896 TBool CCalenSettingsUiContainer::ShouldShowWeekTitleItem() const
       
   897     {
       
   898     TRACE_ENTRY_POINT;
       
   899     TDay day = static_cast<TDay>( iWeekFormat );
       
   900     TRACE_EXIT_POINT;
       
   901     return ( day == EMonday );
       
   902     }
       
   903 
       
   904 // ----------------------------------------------------------------------------
       
   905 // CCalenSettingsUiContainer::Item
       
   906 // Returns the settings item associated with the given setting list item id.
       
   907 // (other items were commented in a header).
       
   908 // ----------------------------------------------------------------------------
       
   909 //
       
   910 CAknSettingItem* CCalenSettingsUiContainer::Item( TSettingListItemId aId )
       
   911     {
       
   912     TRACE_ENTRY_POINT;
       
   913     for( TInt i = 0; i < iSettingItemArray->Count(); ++i )
       
   914         {
       
   915         if( iSettingItemArray->At(i)->Identifier() == aId )
       
   916             {
       
   917             TRACE_EXIT_POINT;
       
   918             return iSettingItemArray->At( i );
       
   919             }
       
   920         }
       
   921     ASSERT( EFalse );
       
   922     TRACE_EXIT_POINT;
       
   923     return NULL;
       
   924     }
       
   925 
       
   926 // ----------------------------------------------------------------------------
       
   927 // CCalenSettingsUiContainer::ValidateWeekTitleItemL
       
   928 // Hides or shows the week title item based on whether the beginning of the
       
   929 // week is set to Monday or not. This should only be called on the week format item.
       
   930 // (other items were commented in a header).
       
   931 // ----------------------------------------------------------------------------
       
   932 //
       
   933 void CCalenSettingsUiContainer::ValidateWeekTitleItemL( CAknSettingItem *aItem )
       
   934     {
       
   935     TRACE_ENTRY_POINT;
       
   936 
       
   937     ASSERT( aItem->Identifier() == ECalenWeekFormatItemId );
       
   938     TBool wasShown = ShouldShowWeekTitleItem();
       
   939     aItem->StoreL(); // Updates iWeekFormat variable
       
   940     TBool doShow = ShouldShowWeekTitleItem();
       
   941 
       
   942     if ( wasShown != doShow )
       
   943         {
       
   944         Item( ECalenWeekTitleItemId )->SetHidden( !doShow );
       
   945         Item( ECalenWeekNumberItemId )->SetHidden( !doShow );
       
   946 
       
   947         if ( !doShow )
       
   948             {
       
   949             Item( ECalenWeekTitleItemId )->LoadL();
       
   950             Item( ECalenWeekNumberItemId )->LoadL();            
       
   951             }
       
   952 
       
   953         iSettingItemArray->RecalculateVisibleIndicesL();
       
   954         iListBox.HandleItemAdditionL();
       
   955         iListBox.UpdateScrollBarsL();
       
   956         }
       
   957     TRACE_EXIT_POINT;
       
   958     }
       
   959 
       
   960 // ----------------------------------------------------------------------------
       
   961 // CCalenSettingsUiContainer::ShowOrHideWeekTitleL
       
   962 // Shows or hides the week title setting as appropriate.
       
   963 // (other items were commented in a header).
       
   964 // ----------------------------------------------------------------------------
       
   965 //
       
   966 void CCalenSettingsUiContainer::ShowOrHideWeekTitleL()
       
   967     {
       
   968     TRACE_ENTRY_POINT;
       
   969 
       
   970     CAknSettingItem* wkTitle = Item( ECalenWeekTitleItemId );
       
   971     const TInt currentIndex( iListBox.CurrentItemIndex() );
       
   972     
       
   973     const TBool wasLookingAtWeekTitle( currentIndex == wkTitle->VisibleIndex() );
       
   974     const TBool doShow( ShouldShowWeekTitleItem() );
       
   975 
       
   976     wkTitle->SetHidden( !doShow );
       
   977 
       
   978     // Make sure we're still looking at a setting item after one was removed.
       
   979     if ( !doShow && wasLookingAtWeekTitle )
       
   980         {
       
   981         iListBox.SetCurrentItemIndex( Item( ECalenWeekFormatItemId )->VisibleIndex() );
       
   982         }
       
   983 
       
   984     iSettingItemArray->RecalculateVisibleIndicesL();
       
   985     iListBox.HandleItemAdditionL();
       
   986     iListBox.UpdateScrollBarsL();
       
   987 
       
   988     TRACE_EXIT_POINT;
       
   989     }
       
   990 
       
   991 // ----------------------------------------------------------------------------
       
   992 // CCalenSettingsUiContainer::HandleListBoxSelectionL
       
   993 // Handles list box selection events.
       
   994 // (other items were commented in a header).
       
   995 // ----------------------------------------------------------------------------
       
   996 //
       
   997 EXPORT_C void CCalenSettingsUiContainer::HandleListBoxSelectionL( TInt aCommand ,TBool& aPageStatus)
       
   998     {
       
   999     TRACE_ENTRY_POINT;
       
  1000 
       
  1001     TInt index( iListBox.CurrentItemIndex() );
       
  1002 
       
  1003     if ( index >= 0 )   // index is -1 if there are no items in the list
       
  1004         {
       
  1005         CAknSettingItem* item;
       
  1006         TDay day = static_cast<TDay>( iWeekFormat );
       
  1007 
       
  1008         // If the starting day of a week is other than Monday, "Title of week view" setting item 
       
  1009         // is  not displayed. For the item below "Week Format", the index in iSettingItemArray
       
  1010         // is one more than CurrentItemIndex().
       
  1011         if( ( day != EMonday && index >= 4 ) )
       
  1012             {
       
  1013             item = iSettingItemArray->At( index + 1);
       
  1014             }
       
  1015         else
       
  1016             {
       
  1017             item = iSettingItemArray->At( index );          
       
  1018             }
       
  1019          // Open edit dialog if EAknCmdOpen, invert the value otherwise
       
  1020         aPageStatus = ETrue;
       
  1021         iPageStatus = aPageStatus;
       
  1022         // for week title only two options available
       
  1023         // so let's toggle instead of opening setting page
       
  1024         if( (item->Identifier() != ECalenWeekTitleItemId) && (item->Identifier() != ECalenWeekNumberItemId))
       
  1025             {
       
  1026             item->EditItemL( aCommand == EAknCmdOpen );
       
  1027             }
       
  1028         aPageStatus = EFalse;
       
  1029         iPageStatus = aPageStatus;
       
  1030         TBool isNativeSettingChange = ETrue;
       
  1031         
       
  1032        if(item->Identifier() > 0 )
       
  1033             {
       
  1034              // Save the settings change, so if we have two settings windows open
       
  1035             // the background one can be updated.
       
  1036             switch( item->Identifier() )
       
  1037                 {
       
  1038                 case ECalenWeekFormatItemId:
       
  1039                     // item->StoreL() gets called in ValidateWeekTitleItemL
       
  1040                     ValidateWeekTitleItemL( item );
       
  1041                     iSetting->SetWeekFormat( static_cast<TDay>( iWeekFormat ) );
       
  1042                     break;
       
  1043                 case ECalenAlarmToneItemId:
       
  1044                     item->StoreL();
       
  1045                     // CCalenFileListSettingItem::StoreL saves the filename to cenrep.
       
  1046                     break;
       
  1047                 case ECalenSnoozeTimeItemId:
       
  1048                     item->StoreL();
       
  1049                     iSetting->SetSnoozeTime( iSnoozeTime );
       
  1050                     break;
       
  1051                 case ECalenDefaultViewItemId:
       
  1052                     item->StoreL();
       
  1053                     iSetting->SetDefaultView( TUid::Uid( iDefView ) );
       
  1054                     break;
       
  1055                 case ECalenWeekTitleItemId:
       
  1056 					//item->StoreL();
       
  1057                     // toggling option done here
       
  1058                     iSetting->SetWeekTitle( static_cast<TCalenWeekTitle>( iWeekTitle ) == EWeekTitleNumber ?
       
  1059                             EWeekTitleDuration  : EWeekTitleNumber );
       
  1060                     iWeekTitle = iSetting->WeekTitle();
       
  1061                     item->LoadL();
       
  1062                     item->UpdateListBoxTextL();
       
  1063                     break;
       
  1064                 case ECalenWeekNumberItemId:
       
  1065                     // toggling option done here
       
  1066                     iSetting->SetWeekNumber( static_cast<TCalenWeekNumber>( iWeekNumberEnable ) == EWeekNumberOn ?
       
  1067                         EWeekNumberOff : EWeekNumberOn );
       
  1068                     iWeekNumberEnable = iSetting->WeekNumberEnable();
       
  1069                     item->LoadL();
       
  1070                     item->UpdateListBoxTextL();
       
  1071                     break;
       
  1072                 case ECalenDefaultMailboxId:
       
  1073                     item->StoreL();
       
  1074                     StoreMailboxSettingsL();
       
  1075                     break;
       
  1076     #ifdef RD_CALEN_EXTERNAL_CAL
       
  1077                 case ECalenExtCalendarItemId:
       
  1078                     item->StoreL();
       
  1079                     iSetting->SetExtCalendar( iExtCalendar);
       
  1080                     break;
       
  1081     #endif // RD_CALEN_EXTERNAL_CAL
       
  1082     #ifdef RD_SCALABLE_UI_V2_NO_TOOLBAR_SETTING
       
  1083                 case ECalenToolbarItemId:
       
  1084                     item->StoreL();
       
  1085                     iSetting->SetToolbar( iToolbar );
       
  1086                     break;
       
  1087     #endif // RD_SCALABLE_UI_V2_NO_TOOLBAR_SETTING
       
  1088                 case ECalenPluginListItemId:
       
  1089                     // No item to store, CCalenCheckboxSettingItem updated
       
  1090                     // the customisation manager and CCalenSetting. Need to
       
  1091                     // redraw the listboc
       
  1092                     item->StoreL();
       
  1093                     PluginListChangedL();
       
  1094                     
       
  1095                     break;
       
  1096                 default:  // Custom setting.
       
  1097                     item->StoreL();
       
  1098                     // Custom settings won't generate a repository change, so keep listening.
       
  1099                     isNativeSettingChange = EFalse;
       
  1100                     break;
       
  1101                 }
       
  1102     
       
  1103             if ( isNativeSettingChange )
       
  1104                 
       
  1105                 {
       
  1106                 // Don't listen for changes to cenrep/TLocale for this settings change.
       
  1107                 iIgnoreNextSettingsNotification = ETrue;
       
  1108                 iSetting->SaveL();
       
  1109                 }
       
  1110             
       
  1111           
       
  1112             iListBox.DrawItem( index );
       
  1113             }
       
  1114         }
       
  1115 		TRACE_EXIT_POINT;
       
  1116     }
       
  1117     
       
  1118 // ----------------------------------------------------------------------------
       
  1119 // CCalenSettingsUiContainer::PluginListChangedL()
       
  1120 // Cenrep watcher callback
       
  1121 // ----------------------------------------------------------------------------
       
  1122 //
       
  1123 void CCalenSettingsUiContainer::PluginListChangedL()
       
  1124     {
       
  1125     iSettingItemArray->ResetAndDestroy();
       
  1126 
       
  1127     // Update the default view as it would have changed after enabling/disabling plugins
       
  1128     iDefView = iSetting->DefaultView().iUid;
       
  1129     iWeekFormat = iSetting->WeekFormat();
       
  1130     iWeekTitle = iSetting->WeekTitle();
       
  1131     iSnoozeTime = iSetting->SnoozeTime();
       
  1132     CreateListBoxItemsL();
       
  1133     
       
  1134     iSettingItemArray->RecalculateVisibleIndicesL();
       
  1135     iListBox.HandleItemAdditionL();
       
  1136     iListBox.UpdateScrollBarsL();
       
  1137     }
       
  1138 
       
  1139 // ----------------------------------------------------------------------------
       
  1140 // CCalenSettingsUiContainer::HandleNotifyGeneric
       
  1141 // Cenrep watcher callback
       
  1142 // ----------------------------------------------------------------------------
       
  1143 //
       
  1144 void CCalenSettingsUiContainer::HandleNotifyGeneric( TUint32 aId )
       
  1145     {
       
  1146     TRACE_ENTRY_POINT;
       
  1147 
       
  1148     // Make sure it wasn't this object that generated the settings change.    
       
  1149     if ( iIgnoreNextSettingsNotification )
       
  1150         {
       
  1151         iIgnoreNextSettingsNotification = EFalse;        
       
  1152         }
       
  1153     else
       
  1154         {
       
  1155         PIM_TRAPD_HANDLE( HandleExternalSettingsChangedL(aId));
       
  1156         }
       
  1157 
       
  1158     // Use another trap to make sure we start listening again, regardless
       
  1159     // of whether the previous function left or not.
       
  1160     PIM_TRAPD_HANDLE( iCenRepNotifyHandler->StartListeningL() );
       
  1161 
       
  1162     TRACE_EXIT_POINT
       
  1163     }
       
  1164 
       
  1165 // ----------------------------------------------------------------------------
       
  1166 // CCalenSettingsUiContainer::HandleNotifyError
       
  1167 // Cenrep watcher error callback
       
  1168 // ----------------------------------------------------------------------------
       
  1169 //
       
  1170 void CCalenSettingsUiContainer::HandleNotifyError( TUint32 /*aId*/,
       
  1171                                                    TInt /*aError*/,
       
  1172                                                    CCenRepNotifyHandler* /*aHandler*/ )
       
  1173     {
       
  1174     TRACE_ENTRY_POINT;
       
  1175 
       
  1176     PIM_TRAPD_HANDLE( iCenRepNotifyHandler->StartListeningL() );
       
  1177 
       
  1178     TRACE_EXIT_POINT;
       
  1179     }
       
  1180 
       
  1181 // ----------------------------------------------------------------------------
       
  1182 // CCalenSettingsUiContainer::LocaleCallbackL
       
  1183 // Locale watcher callback
       
  1184 // ----------------------------------------------------------------------------
       
  1185 //
       
  1186 TInt CCalenSettingsUiContainer::LocaleCallbackL( TAny* aThisPtr )
       
  1187     {
       
  1188     TRACE_ENTRY_POINT;
       
  1189     
       
  1190     CCalenSettingsUiContainer* ptr = static_cast<CCalenSettingsUiContainer*>( aThisPtr );
       
  1191     ptr->DoLocaleCallbackL();
       
  1192     
       
  1193     TRACE_EXIT_POINT;
       
  1194     return FALSE;
       
  1195     }
       
  1196 
       
  1197 // ----------------------------------------------------------------------------
       
  1198 // CCalenSettingsUiContainer::DoLocaleCallbackL
       
  1199 // Implementation of locale watcher callback
       
  1200 // ----------------------------------------------------------------------------
       
  1201 //
       
  1202 void CCalenSettingsUiContainer::DoLocaleCallbackL()
       
  1203     {
       
  1204     TRACE_ENTRY_POINT;
       
  1205 
       
  1206     if ( iLocaleChangeNotifier->Change() & EChangesLocale )
       
  1207         {
       
  1208         if( iIgnoreFirstLocaleChange )
       
  1209             {
       
  1210             // When initialising the locale change observer, we get a notification
       
  1211             // when observing starts. We ignore this as we don't need to act on it.
       
  1212             iIgnoreFirstLocaleChange = EFalse;
       
  1213             }
       
  1214         else
       
  1215             {
       
  1216             // Make sure it wasn't this object that generated the settings change.
       
  1217             if ( iIgnoreNextSettingsNotification )
       
  1218                 {
       
  1219                 iIgnoreNextSettingsNotification = EFalse;
       
  1220                 }
       
  1221             else
       
  1222                 {
       
  1223                 HandleExternalSettingsChangedL();
       
  1224                 ShowOrHideWeekTitleL();
       
  1225 //                ValidateWeekTitleItemL( Item( ECalenWeekFormatItemId ) );
       
  1226                 }
       
  1227             }
       
  1228         }
       
  1229 
       
  1230     TRACE_EXIT_POINT;
       
  1231     }
       
  1232 
       
  1233 // ----------------------------------------------------------------------------
       
  1234 // CCalenSettingsUiContainer::HandleExternalSettingsChangedL
       
  1235 // Called when something else changed our settings
       
  1236 // ----------------------------------------------------------------------------
       
  1237 //
       
  1238 void CCalenSettingsUiContainer::HandleExternalSettingsChangedL(TUint32 aId)
       
  1239     {
       
  1240     TRACE_ENTRY_POINT;
       
  1241     // Load from cenrep to member data.
       
  1242     LoadCurrentValuesL();
       
  1243     
       
  1244     switch(aId)
       
  1245         {
       
  1246         case KCalendarPluginAvailability:
       
  1247            {
       
  1248            HandlePluginChange(); 
       
  1249            if(!iPageStatus)
       
  1250                {
       
  1251                PluginListChangedL();
       
  1252                }
       
  1253           }    
       
  1254         break;
       
  1255         
       
  1256         default:
       
  1257             {
       
  1258             // If the starting day of a week is Monday, "Title of week view" setting item 
       
  1259             // is also displayed. so the number of default items will be 5.
       
  1260             TInt maxDefaultSettingItems = ShouldShowWeekTitleItem()?5:4;
       
  1261             
       
  1262             for( TInt i=0; i<maxDefaultSettingItems; ++i )
       
  1263               {
       
  1264               iSettingItemArray->At( i )->LoadL();
       
  1265               iSettingItemArray->At( i )->UpdateListBoxTextL();
       
  1266               }
       
  1267             }
       
  1268         }
       
  1269     iListBox.HandleItemAdditionL();    
       
  1270 
       
  1271     TRACE_EXIT_POINT;
       
  1272     }
       
  1273 
       
  1274 // ----------------------------------------------------------------------------
       
  1275 // CCalenSettingsUiContainer::LoadCurrentValuesL
       
  1276 // Loads current values from cenrep.
       
  1277 // ----------------------------------------------------------------------------
       
  1278 //
       
  1279 void CCalenSettingsUiContainer::LoadCurrentValuesL()
       
  1280     {
       
  1281     TRACE_ENTRY_POINT;
       
  1282     iSetting->LoadL();
       
  1283     
       
  1284     iDefView = iSetting->DefaultView().iUid;
       
  1285     iWeekFormat = iSetting->WeekFormat();
       
  1286     iWeekTitle = iSetting->WeekTitle();
       
  1287     iWeekNumberEnable = iSetting->WeekNumberEnable();
       
  1288     iSnoozeTime = iSetting->SnoozeTime();
       
  1289 #ifdef RD_SCALABLE_UI_V2_NO_TOOLBAR_SETTING
       
  1290     iToolbar = iSetting->Toolbar();
       
  1291 #endif
       
  1292 
       
  1293 #ifdef RD_CALEN_EXTERNAL_CAL
       
  1294     iExtCalendar = iSetting->ExtCalendar();
       
  1295 #endif
       
  1296 
       
  1297     TRACE_EXIT_POINT;
       
  1298     }
       
  1299 
       
  1300 // ----------------------------------------------------------------------------
       
  1301 // CCalenSettingsUiContainer::StoreMailboxSettingsL
       
  1302 // Stores the mailbox settings.
       
  1303 // ----------------------------------------------------------------------------
       
  1304 //
       
  1305 void CCalenSettingsUiContainer::StoreMailboxSettingsL()
       
  1306     {
       
  1307     TRACE_ENTRY_POINT;
       
  1308 
       
  1309     if( iGlobalData.InterimUtilsL().MRViewersEnabledL() )
       
  1310         {
       
  1311          // iHasSelectedMailbox will be EFalse if we didn't select a MR MB previously.
       
  1312          // However, they might have selected one this time.
       
  1313         if( !iHasSelectedMailbox && iDefMailbox != 0 )
       
  1314             {
       
  1315             iHasSelectedMailbox = ETrue;
       
  1316             --iDefMailbox; // This gets decremented as the first menu item was a blank, unselected choice.
       
  1317             }
       
  1318 
       
  1319         if( iHasSelectedMailbox )
       
  1320             {
       
  1321             CMRMailboxUtils& mbUtils = iGlobalData.MRMailboxUtilsL();
       
  1322 
       
  1323             ListMailboxesL( mbUtils, iMailBoxes );
       
  1324 
       
  1325             RImplInfoPtrArrayOwn implArray;
       
  1326             CleanupClosePushL( implArray );
       
  1327             const TUid mrViewersIface = {KMRViewersInterfaceUID};
       
  1328             REComSession::ListImplementationsL( mrViewersIface, implArray );
       
  1329             TBuf16<KMaxUidName> mbName;
       
  1330 
       
  1331             TInt enumValue = 0; // How many mailboxes we have been through so far that are visible to the user.
       
  1332             // Convert from the enumeration to the default mailbox id.
       
  1333             for( TInt i=0; i < iMailBoxes.Count(); ++i )
       
  1334                 {
       
  1335                 for( TInt j=0; j<implArray.Count(); ++j )
       
  1336                     {
       
  1337                     CnvUtfConverter::ConvertToUnicodeFromUtf8( mbName, implArray[j]->DataType() );
       
  1338                     if( iMailBoxes[i].iMtmUid.Name().CompareF(mbName) == 0 )
       
  1339                         {
       
  1340                         // Found a match. This mailbox would have been shown in the settings list.
       
  1341                         if( enumValue == iDefMailbox )
       
  1342                             {
       
  1343                             User::LeaveIfError( mbUtils.SetDefaultMRMailBoxL( iMailBoxes[iDefMailbox].iEntryId ) );
       
  1344                             break;
       
  1345                             }
       
  1346                         ++enumValue;
       
  1347                         }
       
  1348                     }
       
  1349                 }
       
  1350             CleanupStack::PopAndDestroy(); // implArray
       
  1351             }
       
  1352         }
       
  1353 
       
  1354     TRACE_EXIT_POINT;
       
  1355     }
       
  1356 
       
  1357 // ----------------------------------------------------------------------------
       
  1358 // CCalenSettingsUiContainer::LoadMailboxSettingsL
       
  1359 // Loads the MR mailbox settings, if MR functionality is enabled.
       
  1360 // ----------------------------------------------------------------------------
       
  1361 //
       
  1362 void CCalenSettingsUiContainer::LoadMailboxSettingsL()
       
  1363     {
       
  1364     TRACE_ENTRY_POINT;
       
  1365 
       
  1366     if( iGlobalData.InterimUtilsL().MRViewersEnabledL() )
       
  1367         {
       
  1368         iHasSelectedMailbox = EFalse;
       
  1369         CMRMailboxUtils::TMailboxInfo defaultMailbox;
       
  1370         CMRMailboxUtils& mbUtils = iGlobalData.MRMailboxUtilsL();
       
  1371 				
       
  1372         ListMailboxesL( mbUtils, iMailBoxes );
       
  1373 
       
  1374         TInt res = KErrNone;
       
  1375         TRAPD( err, res = mbUtils.GetDefaultMRMailBoxL( defaultMailbox ) );
       
  1376         if( res == KErrNone && err == KErrNone )
       
  1377             {
       
  1378             // Convert from the default mailbox to an enumeration.
       
  1379             for( TInt i=0; i<iMailBoxes.Count(); ++i )
       
  1380                 {
       
  1381                 if( iMailBoxes[i].iEntryId == defaultMailbox.iEntryId )
       
  1382                     {
       
  1383                     iDefMailbox = i;
       
  1384                     iHasSelectedMailbox = ETrue;
       
  1385                     break;
       
  1386                     }
       
  1387                 }
       
  1388             }
       
  1389         else if ( err != KErrNotFound || err != KErrGeneral )
       
  1390             {
       
  1391             // KErrNotFound and KErrGeneral are thrown when no mailbox is selected.
       
  1392             // This is OK as iHasSelectedMailbox is EFalse, so we will show the blank option
       
  1393             // and allow the user to choose. Any other error needs to leave.
       
  1394             User::LeaveIfError( err );
       
  1395             }
       
  1396         }
       
  1397 
       
  1398     TRACE_EXIT_POINT;
       
  1399     }
       
  1400 
       
  1401 #ifdef RD_CALEN_EXTERNAL_CAL
       
  1402 // ----------------------------------------------------------------------------
       
  1403 // CCalenSettingViewDlg::ExtCalendarAvailableL()
       
  1404 // Return ETrue if we have service handler
       
  1405 // (other items were commented in a header).
       
  1406 // ----------------------------------------------------------------------------
       
  1407 //
       
  1408 TBool CCalenSettingsUiContainer::ExtCalendarAvailableL()
       
  1409     {
       
  1410     TRACE_ENTRY_POINT;
       
  1411 
       
  1412     // Create service handler instance.
       
  1413     if ( !iServiceHandler )
       
  1414         {
       
  1415         iServiceHandler = CAiwServiceHandler::NewL();
       
  1416         }
       
  1417 
       
  1418     // create criteria item, this is used to specify which provider we are interested in.
       
  1419     CAiwCriteriaItem* crit = CAiwCriteriaItem::NewLC( ECalenExtAiwCommandId,
       
  1420                                                       KAiwCmdView,
       
  1421                                                       KContentTypeCalendar );
       
  1422 
       
  1423     // we have a base service just for finding out if there is our provider available
       
  1424     // this should be fixed by AIW framework in the future so that we don't need extra service.
       
  1425     crit->SetServiceClass( TUid::Uid( KAiwClassBase ) );
       
  1426     crit->SetMaxProviders( 1 );
       
  1427     //crit->SetId(0x10282e42);
       
  1428     RCriteriaArray array;
       
  1429     array.Append( crit );
       
  1430     // attach to the service provider if available, owenership of array is not transferred.
       
  1431     iServiceHandler->AttachL( array );
       
  1432 
       
  1433     // if there is a provider here is count of suitable ones, if not it is zero
       
  1434     TInt num=iServiceHandler->NbrOfProviders( crit );
       
  1435 
       
  1436     // if we detach, dll is unloaded, we don't want that as it is likely that we need it again.
       
  1437     //    iServiceHandler->DetachL( array );
       
  1438     array.ResetAndDestroy();
       
  1439     CleanupStack::Pop( crit );
       
  1440 
       
  1441     TBool res = EFalse;
       
  1442 
       
  1443     if ( num > 0 )
       
  1444         {
       
  1445         res = ETrue;
       
  1446         }
       
  1447 
       
  1448     TRACE_EXIT_POINT;
       
  1449     return res;
       
  1450     }
       
  1451 
       
  1452 #endif //RD_CALEN_EXTERNAL_CAL
       
  1453 
       
  1454 // ----------------------------------------------------------------------------
       
  1455 // CCalenSettingsUiContainer::PluginUidFinder
       
  1456 // Matches a uid and a plugin uid. Used by when finding a uid to match the
       
  1457 // setting's array against the customisation manager's array.
       
  1458 // (other items were commented in a header).
       
  1459 // ----------------------------------------------------------------------------
       
  1460 //
       
  1461 TBool CCalenSettingsUiContainer::PluginUidFinder( const TUid* aUid,
       
  1462                                                   const CImplementationInformation& aArrayItem )
       
  1463     {
       
  1464     TRACE_ENTRY_POINT;
       
  1465     TRACE_EXIT_POINT;
       
  1466     return ( *aUid == aArrayItem.ImplementationUid() );
       
  1467     }
       
  1468 
       
  1469 void CCalenSettingsUiContainer::HandlePluginChange()
       
  1470     {
       
  1471     TRACE_ENTRY_POINT;
       
  1472     
       
  1473     pluginAvail& pluginAvailablity = iSetting->PluginAvailability();
       
  1474     for(TInt index = 0;index < pluginAvailablity.Count(); index++)
       
  1475         {
       
  1476         TRAP_IGNORE(iCustomisationManager.SetPluginAvailabilityL(pluginAvailablity[index].iUid, 
       
  1477                                                 pluginAvailablity[index].iEnabled));
       
  1478         }
       
  1479     TRACE_EXIT_POINT;
       
  1480     }
       
  1481 
       
  1482 // End of file
       
  1483