wlanutilities/wlansettingsui/src/wlansettingsuimodel.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     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: 
       
    15 *      Implementation of class TWlanSettingsUiModel.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <centralrepository.h>
       
    23 #include <wlanmgmtclient.h>
       
    24 #include <internetconnectivitycrkeys.h>
       
    25 #include <wlancontainer.h>
       
    26 #include "wlansettingsuimodel.h"
       
    27 #include "wlansettingsuipanic.h"
       
    28 
       
    29 #include <psmtypes.h>
       
    30 #include <psmsrvdomaincrkeys.h>
       
    31 #include <wlandevicesettingsinternalcrkeys.h>
       
    32 #include <featmgr.h>
       
    33 #include <mpmconnectscreenid.h>
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 const TInt KWlanSettingsUiSecondsInMinute = 60;
       
    38 
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CWlanSettingsUiModel::NewL
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 CWlanSettingsUiModel* CWlanSettingsUiModel::NewL
       
    46     (
       
    47     CMDBSession* aSession,
       
    48     CWlanMgmtClient* aWlanMgmtClient,
       
    49     CRepository* aRepository
       
    50     )
       
    51     {
       
    52     CWlanSettingsUiModel* self = new( ELeave ) 
       
    53          CWlanSettingsUiModel(aSession, 
       
    54                               aWlanMgmtClient,
       
    55                               aRepository);
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CWlanSettingsUiModel::CWlanSettingsUiModel
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CWlanSettingsUiModel::CWlanSettingsUiModel
       
    68     (
       
    69     CMDBSession* aSession,
       
    70     CWlanMgmtClient* aWlanMgmtClient,
       
    71     CRepository* aRepository
       
    72     )
       
    73 : iShowWlanAvail( KWlanSettingsUiDefaultShowWlanAvail ),
       
    74   iScanNetworks( KWlanSettingsUiDefaultScanNetwork ),
       
    75   iPowerSaving( KWlanSettingsUiDefaultPowerSaving ),
       
    76   iPsmMode( EFalse ),
       
    77   iSession( aSession ),
       
    78   iWlanMgmtClient( aWlanMgmtClient ),
       
    79   iRepository( aRepository ),
       
    80   iPsmSupported( EFalse )
       
    81     {
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CWlanSettingsUiModel::ConstructL
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CWlanSettingsUiModel::ConstructL()
       
    89     {
       
    90     FeatureManager::InitializeLibL();
       
    91     // Set the member variable to indicate if full/partial PSM is on.
       
    92     // This value stays the same for the whole WLAN Settings session,
       
    93     // i.e. we ignore any mode changes during the session.
       
    94     CheckPsmModeL();
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CWlanSettingsUiModel::~CWlanSettingsUiModel()
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 CWlanSettingsUiModel::~CWlanSettingsUiModel()
       
   103     {
       
   104      FeatureManager::UnInitializeLib();  
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CWlanSettingsUiModel::LoadSettingsL
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 void CWlanSettingsUiModel::LoadSettingsL()
       
   112     {
       
   113     TBool ownTransaction( EFalse );
       
   114     if( !iSession->IsInTransaction() )
       
   115         {
       
   116         ownTransaction = ETrue;
       
   117         iSession->OpenTransactionL();
       
   118         }
       
   119     TMDBElementId tableId = 0;
       
   120     
       
   121     tableId = CCDWlanDeviceSettingsRecord::TableIdL( *iSession );
       
   122         
       
   123     CCDWlanDeviceSettingsRecord* record = new( ELeave )
       
   124             CCDWlanDeviceSettingsRecord( tableId );         
       
   125     CleanupStack::PushL( record );
       
   126     
       
   127     record->iWlanDeviceSettingsType = KWlanUserSettings; 
       
   128     
       
   129     if( record->FindL( *iSession ) )
       
   130         {
       
   131         record->LoadL( *iSession );
       
   132         }
       
   133 
       
   134     // Read scan interval
       
   135 
       
   136     iScanNetworks = record->iBgScanInterval;
       
   137     FixScanNetworks( record->iSavedBgScanInterval );
       
   138  
       
   139     iPowerSaving = record->iWlanPowerMode;
       
   140     CleanupStack::PopAndDestroy( record ); 
       
   141     
       
   142     if ( ownTransaction )
       
   143         {
       
   144         iSession->CommitTransactionL();
       
   145           // Rollback operation.
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CWlanSettingsUiModel::SaveSettingsL
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 void CWlanSettingsUiModel::SaveSettingsL()
       
   154     {
       
   155     TBool ownTransaction( EFalse );
       
   156     if( !iSession->IsInTransaction() )
       
   157         {
       
   158         ownTransaction = ETrue;
       
   159         iSession->OpenTransactionL();
       
   160         }
       
   161     TMDBElementId tableId = 0;
       
   162     tableId = CCDWlanDeviceSettingsRecord::TableIdL( *iSession );
       
   163         
       
   164     CCDWlanDeviceSettingsRecord* record = new( ELeave )
       
   165             CCDWlanDeviceSettingsRecord( tableId );         
       
   166     
       
   167     CleanupStack::PushL( record );
       
   168     
       
   169     record->iWlanDeviceSettingsType = KWlanUserSettings; 
       
   170     
       
   171     if( record->FindL( *iSession ) )
       
   172         {
       
   173         record->LoadL( *iSession );
       
   174         }
       
   175     
       
   176     if ( iShowWlanAvail )
       
   177         {
       
   178         record->iBgScanInterval = iScanNetworks;
       
   179         }
       
   180     else
       
   181         {
       
   182         record->iBgScanInterval = KWlanSettingsUiScanNetworkNever;
       
   183         
       
   184         // Do not change the saved interval value if in full or partial PSM Mode.
       
   185         // We want to preserve the previous user-selected value in memory, not the
       
   186         // forced PSM mode value (automatic).
       
   187         if ( !PsmModeOn() )
       
   188             {
       
   189             record->iSavedBgScanInterval = iScanNetworks;
       
   190             }
       
   191         }
       
   192 
       
   193     record->iWlanPowerMode = iPowerSaving;
       
   194     
       
   195     // Whenever settings are modified, iUseDefaultSettings must be set to false.
       
   196     record->iUseDefaultSettings = EFalse;
       
   197 
       
   198     record->ModifyL( *iSession );
       
   199         
       
   200     CleanupStack::PopAndDestroy( record );        
       
   201     if ( ownTransaction )
       
   202         {
       
   203         iSession->CommitTransactionL();
       
   204         }
       
   205 
       
   206 #ifndef __WINS__
       
   207     // Notifying WLAN Engine about changes in settings
       
   208     iWlanMgmtClient->NotifyChangedSettings();
       
   209 #endif
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CWlanSettingsUiModel::FixScanNetworks
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CWlanSettingsUiModel::FixScanNetworks( TUint aSavedScanInterval )
       
   217     {    
       
   218     if ( iScanNetworks == KWlanSettingsUiScanNetworkNever )
       
   219         {
       
   220         iShowWlanAvail = EFalse;
       
   221   
       
   222         if( aSavedScanInterval == KWlanSettingsUiScanNetworkNever
       
   223             || iPsmMode )
       
   224             {
       
   225             iScanNetworks = KWlanSettingsUiDefaultScanNetwork;
       
   226             }
       
   227         else
       
   228             {
       
   229             iScanNetworks = FixScanInterval( aSavedScanInterval );
       
   230             }
       
   231         }   
       
   232              
       
   233     else
       
   234         {
       
   235         iShowWlanAvail = ETrue;
       
   236         iScanNetworks = FixScanInterval( iScanNetworks );
       
   237         }
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CWlanSettingsUiModel::FixScanInterval
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 TUint CWlanSettingsUiModel::FixScanInterval( TUint aScanInterval )
       
   246     {
       
   247     if( aScanInterval <=
       
   248         ( EWlanSettingsUiScanNetworkMax * KWlanSettingsUiSecondsInMinute ) )
       
   249         {
       
   250         // Return only full minutes
       
   251         return aScanInterval -
       
   252             ( aScanInterval % KWlanSettingsUiSecondsInMinute );
       
   253         }
       
   254     else
       
   255         {
       
   256         return KWlanSettingsUiScanNetworkAuto;
       
   257         }
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // CWlanSettingsUiModel::CheckPsmModeL
       
   262 // ---------------------------------------------------------
       
   263 //
       
   264 void CWlanSettingsUiModel::CheckPsmModeL()
       
   265     {		
       
   266     iPsmSupported = FeatureManager::FeatureSupported( KFeatureIdPowerSave ); 
       
   267     if( iPsmSupported )   
       
   268     {       	   
       
   269     TPsmsrvMode mode( EPsmsrvModeNormal );
       
   270 
       
   271     CRepository* cenrep = NULL;
       
   272 
       
   273     TRAP_IGNORE( cenrep = CRepository::NewL( KCRUidPowerSaveMode ) );
       
   274     
       
   275   	  if ( cenrep )
       
   276     	    {
       
   277       	  TInt crValue(0);
       
   278         	cenrep->Get( KPsmCurrentMode, crValue );
       
   279         	mode = static_cast<TPsmsrvMode>( crValue );
       
   280         	if ( mode == EPsmsrvModePowerSave || mode == EPsmsrvPartialMode )
       
   281                 {
       
   282                 iPsmMode = ETrue;
       
   283                 }
       
   284         	else 
       
   285         	    {
       
   286         	    iPsmMode = EFalse;
       
   287         	    }
       
   288         	
       
   289          delete cenrep;
       
   290        	 cenrep = NULL;                    
       
   291         }
       
   292       }  
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------
       
   296 // CWlanSettingsUiModel::ScanNetworks
       
   297 // ---------------------------------------------------------
       
   298 //              
       
   299 TUint CWlanSettingsUiModel::ScanNetworks()
       
   300     {
       
   301     if ( iScanNetworks == KWlanSettingsUiScanNetworkAuto )
       
   302         {
       
   303         return iScanNetworks;   
       
   304         }
       
   305     else
       
   306         {
       
   307         // Return scan time in minutes
       
   308         return ( iScanNetworks / KWlanSettingsUiSecondsInMinute );
       
   309         }
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------
       
   313 // CWlanSettingsUiModel::SetScanNetworks
       
   314 // ---------------------------------------------------------
       
   315 //        
       
   316 void CWlanSettingsUiModel::SetScanNetworks( TUint aScanNetworks )
       
   317     {
       
   318     if ( aScanNetworks == KWlanSettingsUiScanNetworkAuto )
       
   319         {
       
   320         iScanNetworks = aScanNetworks;
       
   321         }
       
   322     else
       
   323         {
       
   324         // Scan time stored in seconds
       
   325         iScanNetworks = aScanNetworks * KWlanSettingsUiSecondsInMinute;
       
   326         }
       
   327     }