calendarui/settings/settingsui/src/calenbooleansettingitem.cpp
branchRCL_3
changeset 66 bd7edf625bdd
parent 0 f979ecb2b13e
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 2008 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 checkbox setting item
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //debug
       
    20 #include "calendarui_debug.h"
       
    21 
       
    22 //User include
       
    23 #include "calenbooleansettingitem.h"
       
    24 #include "calencustomisationmanager.h"
       
    25 #include "calensetting.h"
       
    26 
       
    27 //System include
       
    28 #include <akncheckboxsettingpage.h>
       
    29 #include <bautils.h>
       
    30 #include <StringLoader.h>
       
    31 #include <eikenv.h>
       
    32 #include <data_caging_path_literals.hrh>
       
    33 #include <Calendar.rsg>
       
    34 
       
    35 
       
    36 
       
    37 
       
    38 // ========================= MEMBER FUNCTIONS ================================
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CCalenBooleanSettingItem::CCalenBooleanSettingItem
       
    42 // Constructor.Phase One
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CCalenBooleanSettingItem::CCalenBooleanSettingItem(TInt aId,CCalenCustomisationManager& aCustMan)
       
    46     : CAknBinaryPopupSettingItem( aId , iInternalValue),
       
    47       iCustMan( aCustMan )
       
    48     
       
    49     {
       
    50     TRACE_ENTRY_POINT;
       
    51     TRACE_EXIT_POINT;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CCalenBooleanSettingItem::NewLC
       
    56 // Constructor.
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CCalenBooleanSettingItem* CCalenBooleanSettingItem::NewLC(TInt aId,
       
    60                                                               TInt aOridinal,
       
    61                                                               CCalenCustomisationManager& aCustMan)
       
    62     {
       
    63     TRACE_ENTRY_POINT
       
    64     CCalenBooleanSettingItem* self = new(ELeave) CCalenBooleanSettingItem(aId,aCustMan);
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL(aOridinal);
       
    67     TRACE_EXIT_POINT
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CCalenBooleanSettingItem::ConstructL
       
    73 // Constructor.Phase Two
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 void CCalenBooleanSettingItem::ConstructL(TInt aOrdinal)
       
    77     {
       
    78     TRACE_ENTRY_POINT
       
    79     CCalenSetting* setting = CCalenSetting::InstanceL();
       
    80     CleanupReleasePushL( *setting );
       
    81         
       
    82         
       
    83     // Assuming settings list is up to date (it should be).
       
    84     const CCalenCustomisationManager::CCalenPluginStatusArray& knownPlugins 
       
    85                                                        = setting->PluginAvailability();
       
    86     const RImplInfoPtrArray& allPlugins = iCustMan.PluginInfoArray();
       
    87     
       
    88     for ( TInt i( 0 ); i < knownPlugins.Count(); ++i )
       
    89         {
       
    90         const TUid pluginUid = knownPlugins[i].iUid;
       
    91 
       
    92         // Settings doesn't keep plugin names; they need to be retrieved from
       
    93         // the customisation manager.
       
    94         TInt implIndex = allPlugins.Find( pluginUid, PluginUidFinder );
       
    95         if(implIndex != KErrNotFound)
       
    96             {
       
    97             HBufC* displayName = allPlugins[implIndex]->DisplayName().AllocLC();
       
    98         
       
    99             //Construct the boolean setting item
       
   100             //R_CALEN_REGIONAL_SETTING_TEXTS -> On/Off array
       
   101             CAknSettingItem::ConstructL(EFalse, aOrdinal, *displayName, NULL, 
       
   102                                                    R_CALEN_LUNAR_SETTING_PAGE, EAknCtPopupSettingList, 
       
   103                                                    NULL, R_CALEN_REGIONAL_SETTING_TEXTS);
       
   104             
       
   105             
       
   106             CleanupStack::PopAndDestroy( displayName );
       
   107             }
       
   108         }
       
   109     
       
   110     CleanupStack::PopAndDestroy( setting );
       
   111     TRACE_EXIT_POINT
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CCalenBooleanSettingItem::~CCalenBooleanSettingItem
       
   116 // Destructor
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 CCalenBooleanSettingItem::~CCalenBooleanSettingItem()
       
   120     {
       
   121     TRACE_ENTRY_POINT;
       
   122     TRACE_EXIT_POINT;
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CCalenCheckboxSettingItem::EditItemL
       
   127 // Edits the item
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 void CCalenBooleanSettingItem::EditItemL( TBool aCalledFromMenu)
       
   131     {
       
   132     TRACE_ENTRY_POINT;
       
   133     
       
   134     CCalenSetting* setting = CCalenSetting::InstanceL();
       
   135     CleanupReleasePushL( *setting );
       
   136     
       
   137     
       
   138     // Assuming settings list is up to date (it should be).
       
   139     const CCalenCustomisationManager::CCalenPluginStatusArray& knownPlugins
       
   140                                                = setting->PluginAvailability();
       
   141 
       
   142     const RImplInfoPtrArray& allPlugins = iCustMan.PluginInfoArray();
       
   143 
       
   144     RArray<TUid> canBeEnabled;
       
   145     CleanupClosePushL( canBeEnabled );
       
   146     
       
   147     for ( TInt i( 0 ); i < knownPlugins.Count(); ++i )
       
   148         {
       
   149         const TUid pluginUid = knownPlugins[i].iUid;
       
   150 
       
   151         // Settings doesn't keep plugin names; they need to be retrieved from
       
   152         // the customisation manager.
       
   153         TInt implIndex = allPlugins.Find( pluginUid, PluginUidFinder );
       
   154         ASSERT( implIndex != KErrNotFound );
       
   155         canBeEnabled.AppendL( pluginUid );
       
   156         }
       
   157     
       
   158     //Pass to base class to toggle the item
       
   159     CAknBinaryPopupSettingItem::EditItemL(aCalledFromMenu);
       
   160     
       
   161     //Get the toggle item On/Off status to set the plugin status
       
   162     TBool internalValue = InternalValue();
       
   163     
       
   164     iCustMan.SetPluginAvailabilityL( canBeEnabled[0], internalValue );
       
   165     setting->SetPluginStatusL( canBeEnabled[0], internalValue );
       
   166     
       
   167  
       
   168     CleanupStack::PopAndDestroy(); // canBeEnabled
       
   169     CleanupStack::PopAndDestroy( setting );
       
   170     
       
   171     TRACE_EXIT_POINT;
       
   172     }
       
   173 
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CCalenCheckboxSettingItem::PluginUidFinder
       
   177 // Matches a uid and a plugin uid. Used by when finding a uid to match the
       
   178 // setting's array against the customisation manager's array.
       
   179 // (other items were commented in a header).
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 TBool CCalenBooleanSettingItem::PluginUidFinder( const TUid* aUid,
       
   183                                                   const CImplementationInformation& aArrayItem )
       
   184     {
       
   185     TRACE_ENTRY_POINT;
       
   186     TRACE_EXIT_POINT;
       
   187     return ( *aUid == aArrayItem.ImplementationUid() );
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------------------------------
       
   191 // CCalenBooleanSettingItem::StoreL
       
   192 // ----------------------------------------------------------------------------
       
   193 //
       
   194 void CCalenBooleanSettingItem::StoreL()
       
   195     {
       
   196     TRACE_ENTRY_POINT;
       
   197     CAknBinaryPopupSettingItem::StoreL();
       
   198     TRACE_EXIT_POINT;
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // CCalenBooleanSettingItem::LoadL
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 void CCalenBooleanSettingItem::LoadL()
       
   206     {
       
   207     TRACE_ENTRY_POINT;
       
   208     
       
   209     CCalenSetting* setting = CCalenSetting::InstanceL();
       
   210     CleanupReleasePushL( *setting );
       
   211     const CCalenCustomisationManager::CCalenPluginStatusArray& knownPlugins
       
   212                                                   = setting->PluginAvailability();
       
   213    
       
   214     TBool enabled = EFalse;
       
   215     if(knownPlugins.Count() > 0)
       
   216        {
       
   217        enabled = knownPlugins[0].iEnabled;
       
   218        }
       
   219     iInternalValue = enabled;
       
   220     CAknBinaryPopupSettingItem::LoadL();
       
   221     
       
   222     CleanupStack::PopAndDestroy( setting );
       
   223     TRACE_EXIT_POINT;
       
   224     }
       
   225 // End of file
       
   226 
       
   227