gssettingsuis/Gs/GSAutoKeyguardPlugin/Src/GSAutoKeyguardPluginContainer.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2005 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:  Container for the Device & SIM security sub-folder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "GSAutoKeyguardPluginContainer.h"
       
    20 #include "GSAutoKeyguardPluginModel.h"
       
    21 #include "GSAutoKeyguardPlugin.hrh"
       
    22 
       
    23 #include <bldvariant.hrh>
       
    24 #include <aknlists.h>
       
    25 #include <etelmm.h>
       
    26 #include <RSSSettings.h>
       
    27 #include <StringLoader.h>
       
    28 #include <featmgr.h>
       
    29 #include <csxhelp/cp.hlp.hrh>
       
    30 #include <gsfwviewuids.h>
       
    31 #include <gsautokeyguardpluginrsc.rsg>
       
    32 #include <gslistbox.h>
       
    33 #include <AknsConstants.h>
       
    34 
       
    35 // EXTERNAL DATA STRUCTURES
       
    36 
       
    37 // EXTERNAL FUNCTION PROTOTYPES  
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 // MACROS
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 
       
    48 // LOCAL FUNCTION PROTOTYPES
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 
       
    52 // ============================= LOCAL FUNCTIONS ==============================
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CGSAutoKeyguardPluginContainer::ConstructL()
       
    57 // 
       
    58 // Symbian OS two phased constructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CGSAutoKeyguardPluginContainer::ConstructL( const TRect& aRect )
       
    62     { 
       
    63     iListBox = new( ELeave ) CAknSettingStyleListBox;
       
    64     if(AknLayoutUtils::PenEnabled())
       
    65         {
       
    66             BaseConstructL( aRect, R_GS_AUTO_KEYGUARD_VIEW_TITLE, R_TOUCH_AUTO_KEYGUARD_LBX );
       
    67         }
       
    68     else
       
    69         {
       
    70             BaseConstructL( aRect, R_GS_AUTO_KEYGUARD_VIEW_TITLE, R_AUTO_KEYGUARD_LBX );
       
    71         }
       
    72         
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CGSAutoKeyguardPluginContainer::~CGSSettListSecurityContainer()
       
    78 // 
       
    79 // Destructor 
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 
       
    83 CGSAutoKeyguardPluginContainer::~CGSAutoKeyguardPluginContainer()
       
    84     {
       
    85     if(iAutoKeyguardItems)
       
    86         {
       
    87             delete iAutoKeyguardItems;
       
    88         }
       
    89 	
       
    90 	if(iListboxItemArray)
       
    91         {
       
    92            delete iListboxItemArray; 
       
    93         }
       
    94       
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CGSAutoKeyguardPluginContainer::CGSAutoKeyguardPluginContainer()
       
   100 // 
       
   101 // Constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CGSAutoKeyguardPluginContainer::CGSAutoKeyguardPluginContainer(
       
   105                           CGSAutoKeyguardPluginModel* aModel )
       
   106     : iModel ( aModel )
       
   107     {
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CGSAutoKeyguardPluginContainer::ConstructListBoxL()
       
   113 // 
       
   114 //  
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CGSAutoKeyguardPluginContainer::ConstructListBoxL( TInt aResLbxId )
       
   118     {
       
   119 
       
   120     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   121     iListboxItemArray = CGSListBoxItemTextArray::NewL( aResLbxId, 
       
   122                         *iListBox, *iCoeEnv );
       
   123     iListBox->Model()->SetItemTextArray( iListboxItemArray );
       
   124     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   125 	iAutoKeyguardItems = iCoeEnv->ReadDesC16ArrayResourceL( R_AUTOKEYGUARD_ARRAY );
       
   126     CreateListBoxItemsL();
       
   127     }
       
   128 
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CGSSettListIdleContainer::CreateListBoxItemsL()
       
   132 // 
       
   133 //  
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CGSAutoKeyguardPluginContainer::CreateListBoxItemsL()
       
   137     {
       
   138 	MakeAutoKeyguardItemL();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CGSSettListIdleContainer::UpdateListBoxL( TInt aFeatureId )
       
   143 // 
       
   144 //  
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CGSAutoKeyguardPluginContainer::UpdateListBoxL( TInt aFeatureId )
       
   148     {
       
   149     switch( aFeatureId )
       
   150         {
       
   151         case EGSSettIdAutoKeyguard:
       
   152         	MakeAutoKeyguardItemL();
       
   153         	break;
       
   154         default:
       
   155             return;
       
   156         }
       
   157     
       
   158     iListBox->HandleItemAdditionL();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CGSAutoKeyguardPluginContainer::MakeAutoKeyguardItemL()
       
   163 // 
       
   164 //  
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CGSAutoKeyguardPluginContainer::MakeAutoKeyguardItemL()
       
   168     {
       
   169     #ifdef RD_AUTO_KEYGUARD
       
   170     
       
   171     HBufC* dynamicText = HBufC::NewLC( KGSBufSize128 );
       
   172     TPtr ptrBuffer ( dynamicText->Des() );
       
   173 
       
   174     TInt period = iModel->AutoKeyguardPeriod();
       
   175     
       
   176     //calculate minutes and seconds
       
   177     TInt minutes = 0;
       
   178     TInt sec = 0;
       
   179     if(period >= 60)
       
   180     {
       
   181     	minutes = period / 60;	
       
   182     }    
       
   183     sec = period - minutes * 60;
       
   184     
       
   185     if((minutes > 1 ) && (sec > 0))
       
   186     {
       
   187 	    CArrayFixFlat<TInt> *minSec=new(ELeave)CArrayFixFlat<TInt>( 2 ); 
       
   188 	    CleanupStack::PushL(minSec);
       
   189 	    minSec->AppendL(minutes);
       
   190 	    minSec->AppendL(sec);
       
   191 	    
       
   192 	    //Load the resource string; this function replaces the %0N and %1N in the
       
   193         //localisation string with numbers from the array having the same index as the number preceding the N.
       
   194         HBufC* tempDynamicText = StringLoader::LoadL( R_AUTO_KEYGUARD_MINSEC, *minSec, iCoeEnv);
       
   195         ptrBuffer = tempDynamicText->Des();
       
   196         delete tempDynamicText;
       
   197         CleanupStack::PopAndDestroy( minSec );
       
   198     }
       
   199     else if ((minutes == 1 ) && (sec > 0))
       
   200     {
       
   201     	CArrayFixFlat<TInt> *minSec=new(ELeave)CArrayFixFlat<TInt>( 2 ); 
       
   202 	    CleanupStack::PushL(minSec);
       
   203 	    minSec->AppendL(minutes);
       
   204 	    minSec->AppendL(sec);
       
   205 	    
       
   206 	    //Load the resource string; this function replaces the %0N and %1N in the
       
   207         //localisation string with numbers from the array having the same index as the number preceding the N.
       
   208         HBufC* tempDynamicText = StringLoader::LoadL( R_AUTO_KEYGUARD_ONE_MIN_SEC, *minSec, iCoeEnv); 
       
   209         ptrBuffer = tempDynamicText->Des();
       
   210         delete tempDynamicText;
       
   211         CleanupStack::PopAndDestroy( minSec );
       
   212     }
       
   213     else if ((minutes > 1 ) && (sec == 0))
       
   214     {
       
   215     	TBuf<KGSBufSize128> tempString;
       
   216     	StringLoader::Format( tempString, 
       
   217                          	( ( *iAutoKeyguardItems )[3] ),
       
   218                           		-1, // no index in the key string
       
   219                           		minutes );                
       
   220     	ptrBuffer = tempString;	
       
   221     }
       
   222     else if ((minutes == 1 ) && (sec == 0))
       
   223     {  
       
   224         TBuf<KGSBufSize128> tempString;
       
   225     	StringLoader::Format( tempString, 
       
   226                          	( ( *iAutoKeyguardItems )[2] ),
       
   227                           		-1, // no index in the key string
       
   228                           		minutes );
       
   229     	ptrBuffer = tempString;	
       
   230     }
       
   231     else if ((minutes == 0 ) && (sec > 0))
       
   232     {
       
   233     	TBuf<KGSBufSize128> tempString;
       
   234     	StringLoader::Format( tempString, 
       
   235                          	( ( *iAutoKeyguardItems )[1] ),
       
   236                           		-1, // no index in the key string
       
   237                           		sec );                       
       
   238     	ptrBuffer = tempString;
       
   239     }
       
   240     else //both are 0, period is not user defined
       
   241     {
       
   242     	ptrBuffer = ( *iAutoKeyguardItems )[0];
       
   243     }
       
   244     
       
   245      
       
   246     iListboxItemArray->SetDynamicTextL( EGSSettIdAutoKeyguard, ptrBuffer );
       
   247     CleanupStack::PopAndDestroy( dynamicText );
       
   248     iListboxItemArray->SetItemVisibilityL( EGSSettIdAutoKeyguard, 
       
   249                        CGSListBoxItemTextArray::EVisible );
       
   250     #endif //RD_AUTO_KEYGUARD
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CGSAutoKeyguardPluginContainer::CurrentFeatureId()
       
   255 //  
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 TInt CGSAutoKeyguardPluginContainer::CurrentFeatureId() const
       
   259     {
       
   260     return iListboxItemArray->CurrentFeature( );
       
   261     }
       
   262 
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CGSAutoKeyguardPluginContainer::GetHelpContext() const
       
   266 // Gets Help 
       
   267 //  
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CGSAutoKeyguardPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   271     {
       
   272     aContext.iMajor = KUidGS;
       
   273     // aContext.iContext = KCP_HLP_DEVICE_LOCKING; // This was used before, when keylock and keguard had the same help file
       
   274     _LIT(KCP_HLP_AUTOKEYGUARD_LOCAL, "CP_HLP_AUTOKEYGUARD");	// the global KCP_HLP_AUTOKEYGUARD is defined only on some products but not all.
       
   275     aContext.iContext = KCP_HLP_AUTOKEYGUARD_LOCAL;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CGSAutoKeyguardPluginContainer::HandleResourceChangeL()
       
   280 // 
       
   281 // Updates view layout 
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CGSAutoKeyguardPluginContainer::HandleResourceChangeL( TInt aType )
       
   285     {
       
   286     if( aType == KAknsMessageSkinChange ||
       
   287         aType == KEikDynamicLayoutVariantSwitch )
       
   288         {
       
   289         TRect mainPaneRect;
       
   290         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   291                                            mainPaneRect );
       
   292         SetRect( mainPaneRect );
       
   293         DrawNow();
       
   294         }
       
   295     }    
       
   296     
       
   297 //End of File