gssettingsuis/Gs/GSAutoKeyguardPlugin/Src/GSAutoKeyguardPlugin.cpp
changeset 0 8c5d936e5675
child 17 3b47783fdf16
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     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:  View for Autokeyguard sub-folder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <coeaui.h>
       
    21 #include <hlplch.h>             // For HlpLauncher
       
    22 #include <bautils.h>
       
    23 #include <gulicon.h>
       
    24 #include <eikfrlbd.h>
       
    25 #include <eiktxlbx.h>
       
    26 #include <aknradiobuttonsettingpage.h>
       
    27 #include <aknPopup.h>
       
    28 #include <aknlists.h>
       
    29 #include <RSSSettings.h>
       
    30 #include <AknQueryDialog.h>
       
    31 #include <aknnotedialog.h>
       
    32 #include <aknViewAppUi.h>
       
    33 #include <bldvariant.hrh>
       
    34 #include <featmgr.h>
       
    35 #include <StringLoader.h>
       
    36 #include <BTSapDomainPSKeys.h>
       
    37 #include <e32property.h>
       
    38 #include <gsautokeyguardplugin.mbg>
       
    39 #include <GSAutoKeyguardPluginRsc.rsg>
       
    40 #include <gsprivatepluginproviderids.h>
       
    41 #include <gsmainview.h>
       
    42 #include <gsbasecontainer.h>
       
    43 
       
    44 #include "GSAutoKeyguardPlugin.h"
       
    45 #include "GSAutoKeyguardPluginContainer.h"
       
    46 #include "GSAutoKeyguardPlugin.hrh"
       
    47 #include <centralrepository.h> 
       
    48 #include "GSAutoKeyguardPluginAutoKeyguardSettingPage.h"
       
    49 #include "GSAutoKeyguardPluginAutoKeyguardTimeQuery.h"
       
    50 
       
    51 
       
    52 // EXTERNAL DATA STRUCTURES
       
    53 
       
    54 // EXTERNAL FUNCTION PROTOTYPES  
       
    55 
       
    56 // CONSTANTS
       
    57 
       
    58 // MACROS
       
    59 
       
    60 // LOCAL CONSTANTS AND MACROS
       
    61 
       
    62 _LIT( KGSAutoKeyguardPluginResourceFileName, "z:GSAutoKeyguardPluginRsc.rsc" );
       
    63 _LIT( KGSAutoKeyguardPluginIconDirAndName, "z:GSAutoKeyguardPlugin.mbm");
       
    64 // MODULE DATA STRUCTURES
       
    65 
       
    66 // LOCAL FUNCTION PROTOTYPES
       
    67 
       
    68 // FORWARD DECLARATIONS
       
    69 
       
    70 /**
       
    71 * CCugQuery
       
    72 * It defines CCugQuery used in closed user group settings
       
    73 */
       
    74 class CCugQuery
       
    75     : public CAknNumberQueryDialog
       
    76     {
       
    77     public: // Constructors and destructors
       
    78         /**
       
    79         * C++ constructor.
       
    80         */
       
    81         CCugQuery( TInt& aNumber,const TTone aTone = ENoTone );
       
    82     protected: // From base classes
       
    83         /**
       
    84         * From CCAknNumberQueryDialog Left softkey is allways OK.
       
    85         */
       
    86         void  UpdateLeftSoftKeyL();
       
    87     };
       
    88 
       
    89 // ============================= LOCAL FUNCTIONS ==============================
       
    90 
       
    91 // ========================= MEMBER FUNCTIONS =================================
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // GSAutoKeyguardPlugin::NewL()
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 CGSAutoKeyguardPlugin* CGSAutoKeyguardPlugin::NewL( TAny* /*aInitParams*/ )
       
    98     {
       
    99     CGSAutoKeyguardPlugin* self = new( ELeave ) CGSAutoKeyguardPlugin();
       
   100     
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();    
       
   103     CleanupStack::Pop( self );
       
   104 
       
   105     return self;
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // GSAutoKeyguardPlugin::CGSAutoKeyguardPlugin()
       
   111 // 
       
   112 // ---------------------------------------------------------------------------
       
   113 CGSAutoKeyguardPlugin::CGSAutoKeyguardPlugin()
       
   114     : iResourceLoader( *iCoeEnv )
       
   115     {    
       
   116     }
       
   117 
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CGSAutoKeyguardPlugin::ConstructL()
       
   121 // 
       
   122 // Symbian OS two-phased constructor
       
   123 // ---------------------------------------------------------------------------
       
   124 void CGSAutoKeyguardPlugin::ConstructL()
       
   125     {
       
   126     FeatureManager::InitializeLibL();
       
   127 
       
   128     iModel = CGSAutoKeyguardPluginModel::NewL();
       
   129     //PS listener initialization
       
   130     iBtSapListener = CGSPubSubsListener::NewL( 
       
   131                      KPSUidBluetoothSapConnectionState,
       
   132                      KBTSapConnectionState, this );
       
   133 
       
   134     // Find the resource file
       
   135     TParse parse;
       
   136     parse.Set( KGSAutoKeyguardPluginResourceFileName, 
       
   137                &KDC_RESOURCE_FILES_DIR, NULL );
       
   138     TFileName fileName( parse.FullName() );
       
   139     
       
   140     // Get language of resource file
       
   141     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   142 
       
   143     // Open resource file
       
   144     iResourceLoader.OpenL( fileName );
       
   145     
       
   146     BaseConstructL( R_GS_AUTO_KEYGUARD_VIEW );
       
   147 
       
   148     }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CGSAutoKeyguardPlugin::~CGSAutoKeyguardPlugin()
       
   153 // 
       
   154 // 
       
   155 // ---------------------------------------------------------------------------
       
   156 CGSAutoKeyguardPlugin::~CGSAutoKeyguardPlugin()
       
   157     {
       
   158     FeatureManager::UnInitializeLib();
       
   159     // close resource loader
       
   160     iResourceLoader.Close();
       
   161     
       
   162     if ( iModel )
       
   163         {
       
   164             delete iModel;
       
   165         }
       
   166         
       
   167     if(iBtSapListener)
       
   168         {
       
   169             delete iBtSapListener;
       
   170         }
       
   171  
       
   172     }
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // TUid CGSAutoKeyguardPlugin::Id()
       
   177 // 
       
   178 // 
       
   179 // ---------------------------------------------------------------------------
       
   180 TUid CGSAutoKeyguardPlugin::Id() const
       
   181     {
       
   182     return KGSAutoKeyguardPluginUid;
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CGSAutoKeyguardPlugin::HandleCommandL()
       
   188 // 
       
   189 // 
       
   190 // ---------------------------------------------------------------------------
       
   191 void CGSAutoKeyguardPlugin::HandleCommandL( TInt aCommand )
       
   192     {
       
   193     switch ( aCommand )
       
   194         {
       
   195         case EGSCmdAppChange:
       
   196         case EAknSoftkeyChange:
       
   197             {           
       
   198              HandleListBoxSelectionL();
       
   199             }
       
   200             break;
       
   201         case EAknSoftkeyBack:
       
   202             iAppUi->ActivateLocalViewL( KGSDeviceManagementPluginUid );  
       
   203             break;
       
   204         case EAknCmdHelp:
       
   205             {
       
   206             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   207                 {
       
   208                 HlpLauncher::LaunchHelpApplicationL(
       
   209                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   210                 }
       
   211             }
       
   212             break;
       
   213         default:
       
   214             iAppUi->HandleCommandL( aCommand );
       
   215             break;
       
   216         }
       
   217     }
       
   218 
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CGSAutoKeyguardPlugin::UpdateListBoxL
       
   222 // 
       
   223 // Update the current item in the listbox.
       
   224 // ---------------------------------------------------------------------------
       
   225 void CGSAutoKeyguardPlugin::UpdateListBoxL( TInt aItemId )
       
   226     {
       
   227     Container()->UpdateListBoxL( aItemId );
       
   228     }
       
   229 
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CGSAutoKeyguardPlugin::DoActivateL(...)
       
   233 // 
       
   234 // 
       
   235 // ---------------------------------------------------------------------------
       
   236 void CGSAutoKeyguardPlugin::DoActivateL( const TVwsViewId& aPrevViewId, 
       
   237                                    TUid aCustomMessageId, 
       
   238                                    const TDesC8& aCustomMessage )
       
   239     {
       
   240     CGSBaseView::DoActivateL( aPrevViewId, aCustomMessageId, aCustomMessage );    
       
   241     }
       
   242 
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // CGSAutoKeyguardPlugin::Container
       
   246 // 
       
   247 // Return handle to container class.
       
   248 // ----------------------------------------------------------------------------
       
   249 //
       
   250 CGSAutoKeyguardPluginContainer* CGSAutoKeyguardPlugin::Container()
       
   251     {
       
   252     return static_cast<CGSAutoKeyguardPluginContainer*>( iContainer );
       
   253     }
       
   254 
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CGSAutoKeyguardPlugin::NewContainerL()
       
   258 // 
       
   259 // Creates new iContainer.
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CGSAutoKeyguardPlugin::NewContainerL()
       
   263     {
       
   264     iContainer = new( ELeave ) CGSAutoKeyguardPluginContainer( iModel );
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CGSAutoKeyguardPlugin::HandleListBoxSelectionL()
       
   270 // 
       
   271 // 
       
   272 // ---------------------------------------------------------------------------
       
   273 void CGSAutoKeyguardPlugin::HandleListBoxSelectionL() 
       
   274     {
       
   275     const TInt currentFeatureId = Container()->CurrentFeatureId();
       
   276     TInt maxPeriod(0);
       
   277     switch ( currentFeatureId )
       
   278         {
       
   279         case EGSSettIdAutoKeyguard:
       
   280             maxPeriod = iModel->AutoKeyguardMaxPeriod();
       
   281             SetAutoKeyguardTimeL(iModel->AutoKeyguardPeriod(), maxPeriod);
       
   282         	break;
       
   283         default:
       
   284             break;
       
   285         }
       
   286     
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CGSAutoKeyguardPlugin::SetAutoKeyguardTimeL()
       
   291 // 
       
   292 // 
       
   293 // ---------------------------------------------------------------------------
       
   294 void CGSAutoKeyguardPlugin::SetAutoKeyguardTimeL(TInt aPeriod, TInt aMaxPeriod)
       
   295     {
       
   296     TInt currentItem = 0; 
       
   297     CDesCArrayFlat* items =  iCoeEnv->ReadDesC16ArrayResourceL( R_AUTOKEYGUARD_LBX );
       
   298     CleanupStack::PushL(items);
       
   299     if (aPeriod == 0)
       
   300         {
       
   301         currentItem = 0;  // autokeyguard off
       
   302         }
       
   303     else
       
   304         {
       
   305         currentItem = 1;  // user defined
       
   306         }
       
   307     TInt64 periodInMicroseconds(aPeriod);
       
   308     periodInMicroseconds *= 1000000;
       
   309 	TTime period(periodInMicroseconds);
       
   310 	
       
   311 	TInt64 maxPeriodInMicroseconds(aMaxPeriod);
       
   312     maxPeriodInMicroseconds *= 1000000;	
       
   313 	TTime maximum(maxPeriodInMicroseconds);
       
   314 	
       
   315     CAutoKeyguardSettingPage* dlg = new (ELeave)CAutoKeyguardSettingPage(R_AUTOKEYGUARD_SETTING_PAGE, 
       
   316                                                                             currentItem, items, &period, maxPeriodInMicroseconds);
       
   317     if (!dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged))
       
   318         {
       
   319         CleanupStack::PopAndDestroy();    // items       
       
   320         return;
       
   321         }
       
   322     CleanupStack::PopAndDestroy();    // items
       
   323     TDateTime keyGuardTime = period.DateTime();
       
   324     //convert the period to seconds
       
   325     TInt newPeriod = (keyGuardTime.Minute() * 60) + keyGuardTime.Second();
       
   326     iModel->SetAutoKeyguardPeriod(newPeriod);
       
   327     UpdateListBoxL( EGSSettIdAutoKeyguard );
       
   328     }
       
   329     
       
   330 // ---------------------------------------------------------------------------
       
   331 // CGSAutoKeyguardPlugin::HandleResourceChangeL( TInt aType )
       
   332 // Updates view layout
       
   333 //  
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void CGSAutoKeyguardPlugin::HandleResourceChangeL( TInt aType )
       
   337     {
       
   338     if( aType == KAknsMessageSkinChange ||
       
   339         aType == KEikDynamicLayoutVariantSwitch )
       
   340         {
       
   341         //iContainer->HandleResourceChangeL( aType );
       
   342         }
       
   343     }
       
   344 
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CGSAutoKeyguardPlugin::HandleNotifyPSL
       
   348 //
       
   349 // Handling PS keys change
       
   350 // ---------------------------------------------------------------------------
       
   351 //  
       
   352 void CGSAutoKeyguardPlugin::HandleNotifyPSL( const TUid aUid, const TInt& aKey,
       
   353                                        const TRequestStatus& /* aStatus */ )
       
   354     {
       
   355     if ( aUid == KPSUidBluetoothSapConnectionState && 
       
   356          aKey == KBTSapConnectionState )
       
   357         {
       
   358         Visible();
       
   359         }
       
   360     }
       
   361 
       
   362 
       
   363 // ========================= From CGSPluginInterface ==================
       
   364 
       
   365 // ----------------------------------------------------------------------------
       
   366 // CGSAutoKeyguardPlugin::GetCaption
       
   367 // 
       
   368 // Return application/view caption.
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 void CGSAutoKeyguardPlugin::GetCaptionL( TDes& aCaption ) const
       
   372     {
       
   373     // the resource file is already opened.
       
   374     HBufC* result = StringLoader::LoadL( R_GS_AUTO_KEYGUARD_VIEW_CAPTION );
       
   375     
       
   376     aCaption.Copy( *result );
       
   377     delete result;
       
   378     }
       
   379     
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // CGSAutoKeyguardPlugin::PluginProviderCategory
       
   383 // 
       
   384 // A means to identify the location of this plug-in in the framework.
       
   385 // ----------------------------------------------------------------------------
       
   386 //
       
   387 TInt CGSAutoKeyguardPlugin::PluginProviderCategory() const
       
   388     {
       
   389     //To identify internal plug-ins.
       
   390     return KGSPluginProviderInternal;
       
   391     }
       
   392     
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 // CGSAutoKeyguardPlugin::Visible
       
   396 // 
       
   397 // Provides the visibility status of self to framework.
       
   398 // ----------------------------------------------------------------------------
       
   399 //    
       
   400 TBool CGSAutoKeyguardPlugin::Visible() const
       
   401     {
       
   402     TInt btSapConnectionState;
       
   403     TBool visible = ETrue;
       
   404 
       
   405     iBtSapListener->Get( btSapConnectionState );
       
   406 
       
   407     if ( btSapConnectionState == EBTSapConnected )
       
   408         {
       
   409         visible = EFalse;
       
   410         }
       
   411     
       
   412     return visible;
       
   413     }    
       
   414     
       
   415 // ----------------------------------------------------------------------------
       
   416 // CGSAutoKeyguardPlugin::DynInitMenuPaneL()
       
   417 // 
       
   418 // Display the dynamic menu
       
   419 // ----------------------------------------------------------------------------
       
   420 void CGSAutoKeyguardPlugin::DynInitMenuPaneL( TInt aResourceId,
       
   421                                           CEikMenuPane* aMenuPane )
       
   422     {
       
   423 
       
   424 	// show or hide the 'help' menu item when supported
       
   425     if( aResourceId == R_GS_AUTO_KEYGUARD_MENU_ITEM_HELP )
       
   426         {
       
   427         User::LeaveIfNull( aMenuPane );    
       
   428         if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   429             {
       
   430             aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse );
       
   431             }
       
   432         else
       
   433             {
       
   434             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   435             }
       
   436         }
       
   437 
       
   438     }
       
   439 // -----------------------------------------------------------------------------
       
   440 // CGSCallDivertPlugin::CreateIconL()
       
   441 //
       
   442 //
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 CGulIcon* CGSAutoKeyguardPlugin::CreateIconL( const TUid aIconType )
       
   446     {
       
   447     //EMbm<Mbm_file_name><Bitmap_name>
       
   448     CGulIcon* icon;
       
   449     TParse* fp = new( ELeave ) TParse();
       
   450     CleanupStack::PushL( fp );
       
   451     fp->Set( KGSAutoKeyguardPluginIconDirAndName, &KDC_BITMAP_DIR, NULL );
       
   452 
       
   453     if( aIconType == KGSIconTypeLbxItem )
       
   454         {
       
   455         icon = AknsUtils::CreateGulIconL(
       
   456         AknsUtils::SkinInstance(),
       
   457         KAknsIIDQgnPropCpDevKeyguard,
       
   458         fp->FullName(),
       
   459         EMbmGsautokeyguardpluginQgn_prop_cp_dev_keyguard, 
       
   460         EMbmGsautokeyguardpluginQgn_prop_cp_dev_keyguard_mask );
       
   461         }
       
   462     else
       
   463         {
       
   464         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   465         }
       
   466 
       
   467     CleanupStack::PopAndDestroy( fp );
       
   468 
       
   469     return icon;
       
   470     } 
       
   471 // End of File