wlanutilities/cpwlansettingsplugin/src/wlansettings.cpp
branchRCL_3
changeset 24 63be7eb3fc78
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
       
     1 /*
       
     2 * Copyright (c) 2010 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 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <xqsettingsmanager.h>
       
    21 #include <xqsettingskey.h>
       
    22 #include <psmsrvdomaincrkeys.h>
       
    23 #include <psmtypes.h>
       
    24 
       
    25 // User includes
       
    26 
       
    27 #include "wlansettings_s60_p.h"
       
    28 #include "wlansettings.h"
       
    29 
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "wlansettingsTraces.h"
       
    33 #endif
       
    34 
       
    35 /*!
       
    36    \class WlanSettings
       
    37    \brief WlanSettings is a wrapper class for CWlanSettingsImpl.
       
    38 */
       
    39 
       
    40 // External function prototypes
       
    41 
       
    42 // Local constants
       
    43 
       
    44 //! Device Power Saving Mode setting key
       
    45 static const XQSettingsKey devicePowerSavingKey(
       
    46     XQSettingsKey::TargetCentralRepository,
       
    47     KCRUidPowerSaveMode.iUid, 
       
    48     KPsmCurrentMode);
       
    49     
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 /*!
       
    53     Constructor.
       
    54 */
       
    55 
       
    56 WlanSettings::WlanSettings() :
       
    57     QObject(),
       
    58     mSettingsManager(new XQSettingsManager(this)),
       
    59     mDevicePowerSavingMode(0),
       
    60     mDevicePowerSavingModeUpToDate(false)
       
    61 {
       
    62     OstTraceFunctionEntry0( WLANSETTINGS_WLANSETTINGS_ENTRY );
       
    63     OstTraceFunctionExit0( WLANSETTINGS_WLANSETTINGS_EXIT );
       
    64 }
       
    65 
       
    66 /*!
       
    67     Destructor.
       
    68 */
       
    69 
       
    70 WlanSettings::~WlanSettings()
       
    71 {
       
    72     OstTraceFunctionEntry0( DUP1_WLANSETTINGS_WLANSETTINGS_ENTRY );
       
    73 
       
    74     delete d_ptr;
       
    75     
       
    76     OstTraceFunctionExit0( DUP1_WLANSETTINGS_WLANSETTINGS_EXIT );
       
    77 }
       
    78 
       
    79 /*!
       
    80     Creates the CWlanSettingsImpl object for reading/writing settings.
       
    81     \return Error code.
       
    82 */
       
    83 
       
    84 int WlanSettings::init()
       
    85 {
       
    86     OstTraceFunctionEntry0( WLANSETTINGS_INIT_ENTRY );
       
    87     
       
    88     // Listen for changes in the key value
       
    89     bool connectStatus = connect(
       
    90         mSettingsManager,
       
    91         SIGNAL(valueChanged(XQSettingsKey, QVariant)),
       
    92         this,
       
    93         SLOT(devicePowerSavingKeyChanged()));
       
    94     Q_ASSERT(connectStatus);
       
    95     mSettingsManager->startMonitoring(devicePowerSavingKey);
       
    96     
       
    97     TRAPD(error,(d_ptr = CWlanSettingsPrivate::NewL(this)));
       
    98     
       
    99     OstTraceFunctionExit0( WLANSETTINGS_INIT_EXIT );
       
   100     return error;
       
   101 }
       
   102 
       
   103 /*!
       
   104     Reads the value of the Device Power Saving Mode setting.
       
   105 */
       
   106 
       
   107 void WlanSettings::readDevicePowerSavingKey()
       
   108 {
       
   109     OstTraceFunctionEntry0( WLANSETTINGS_READDEVICEPOWERSAVINGKEY_ENTRY );
       
   110     
       
   111     mDevicePowerSavingMode = 
       
   112         mSettingsManager->readItemValue(devicePowerSavingKey).toInt();
       
   113 
       
   114     mDevicePowerSavingModeUpToDate = true;
       
   115     
       
   116     OstTrace1(
       
   117         TRACE_NORMAL,
       
   118         WLANSETTINGS_READDEVICEPOWERSAVINGKEY,
       
   119         "WlanSettings::readDevicePowerSavingKey;powerSaving=%d",
       
   120         mDevicePowerSavingMode );
       
   121 
       
   122     OstTraceFunctionExit0( WLANSETTINGS_READDEVICEPOWERSAVINGKEY_EXIT );
       
   123 }
       
   124 
       
   125 /*!
       
   126     Slot for handling updates in the Device Power Saving Mode setting.
       
   127 */
       
   128 
       
   129 void WlanSettings::devicePowerSavingKeyChanged()
       
   130 {
       
   131     OstTraceFunctionEntry0( WLANSETTINGS_DEVICEPOWERSAVINGKEYCHANGED_ENTRY );
       
   132     
       
   133     // Remember that we need to read the setting value again before
       
   134     // using it, and notify UI of the change.
       
   135     mDevicePowerSavingModeUpToDate = false;
       
   136     emit devicePowerSavingUpdated();
       
   137     
       
   138     OstTraceFunctionExit0( WLANSETTINGS_DEVICEPOWERSAVINGKEYCHANGED_EXIT );
       
   139 }
       
   140 
       
   141 /*!
       
   142     Reads the WLAN setting values.
       
   143     \return Error code.
       
   144 */
       
   145 
       
   146 int WlanSettings::loadSettings()
       
   147 {
       
   148     OstTraceFunctionEntry0( WLANSETTINGS_LOADSETTINGS_ENTRY );
       
   149     
       
   150     TRAPD(error, d_ptr->LoadDBSettingsL());
       
   151     
       
   152     OstTrace1(
       
   153         TRACE_NORMAL,
       
   154         WLANSETTINGS_LOADSETTINGS,
       
   155         "WlanSettings::loadSettings;error=%d",
       
   156         error );
       
   157     
       
   158     OstTraceFunctionExit0( WLANSETTINGS_LOADSETTINGS_EXIT );
       
   159     return error;
       
   160 }
       
   161 
       
   162 /*!
       
   163     Function to get the scan network type.
       
   164     \return ScanNetworkType which is automatic or user-defined.
       
   165 */
       
   166 
       
   167 WlanSettings::ScanNetworkType WlanSettings::scanNetworkType()
       
   168 {
       
   169     OstTraceFunctionEntry0( WLANSETTINGS_SCANNETWORKTYPE_ENTRY );
       
   170     
       
   171     ScanNetworkType scanType;
       
   172     if (d_ptr->ScanInterval() == ScanNetworkAuto) {
       
   173         scanType = EScanNetworkAuto;
       
   174     } else {
       
   175         scanType = EScanNetworkUserDefined;
       
   176     }
       
   177     
       
   178     OstTrace1(
       
   179         TRACE_NORMAL,
       
   180         WLANSETTINGS_SCANNETWORKTYPE,
       
   181         "WlanSettings::scanNetworkType;scanType=%d",
       
   182         scanType );
       
   183     
       
   184     OstTraceFunctionExit0( WLANSETTINGS_SCANNETWORKTYPE_EXIT );
       
   185     return scanType;
       
   186 }
       
   187 
       
   188 /*!
       
   189     Function to get the scan interval.
       
   190     \return Scan interval  in minutes.
       
   191 */
       
   192 
       
   193 uint WlanSettings::scanInterval()
       
   194 {
       
   195     OstTraceFunctionEntry0( WLANSETTINGS_SCANINTERVAL_ENTRY );
       
   196     
       
   197     uint scanInterval = d_ptr->ScanInterval();
       
   198     
       
   199     OstTrace1(
       
   200         TRACE_NORMAL,
       
   201         WLANSETTINGS_SCANINTERVAL,
       
   202         "WlanSettings::scanInterval;scanInterval=%u",
       
   203         scanInterval );
       
   204     
       
   205     OstTraceFunctionExit0( WLANSETTINGS_SCANINTERVAL_EXIT );
       
   206     return scanInterval;
       
   207 }
       
   208 
       
   209 /*!
       
   210     Function to get Wlan Power Saving Option.
       
   211     \return True if Power Saving option is enabled, otherwise False.
       
   212 */
       
   213 
       
   214 bool WlanSettings::isWlanPowerSavingEnabled() const
       
   215 {
       
   216     OstTraceFunctionEntry0( WLANSETTINGS_ISWLANPOWERSAVINGENABLED_ENTRY );
       
   217     OstTraceFunctionExit0( WLANSETTINGS_ISWLANPOWERSAVINGENABLED_EXIT );
       
   218     return d_ptr->PowerSaving();
       
   219 }
       
   220 
       
   221 /*!
       
   222     Function to set Power Saving Option.
       
   223     \param powerSavingOption True to enable or false to disable power saving option. 
       
   224     \return Error code.
       
   225 */
       
   226 
       
   227 int WlanSettings::setWlanPowerSaving(int powerSavingOption)
       
   228 {
       
   229     OstTraceFunctionEntry0( WLANSETTINGS_SETWLANPOWERSAVING_ENTRY );
       
   230     
       
   231     d_ptr->SetPowerSaving(powerSavingOption);
       
   232     TRAPD(error, d_ptr->SaveDBSettingsL(CWlanSettingsPrivate::EWlanPowerSaving));
       
   233 
       
   234     OstTraceFunctionExit0( WLANSETTINGS_SETWLANPOWERSAVING_EXIT );
       
   235     return error;
       
   236 }
       
   237 
       
   238 /*!
       
   239     Function to set Scan interval.
       
   240     \param scanInterval Scan interval in minutes. 
       
   241     \return Error code.
       
   242 */
       
   243 
       
   244 int WlanSettings::setWlanScanInterval(uint scanInterval)
       
   245 {
       
   246     OstTraceFunctionEntry0( WLANSETTINGS_SETWLANSCANINTERVAL_ENTRY );
       
   247     
       
   248     d_ptr->SetScanInterval(scanInterval);
       
   249     TRAPD(error, d_ptr->SaveDBSettingsL(CWlanSettingsPrivate::EWlanScanInterval));
       
   250 
       
   251     OstTraceFunctionExit0( WLANSETTINGS_SETWLANSCANINTERVAL_EXIT );
       
   252     return error;
       
   253 }
       
   254 
       
   255 /*!
       
   256     Function to get Join WLAN networks option.
       
   257     \return 0 for Known, 1 for Manual.
       
   258 */
       
   259 
       
   260 int WlanSettings::joinWlanMode() const
       
   261 {
       
   262     OstTraceFunctionEntry0( WLANSETTINGS_JOINWLANMODE_ENTRY );
       
   263     OstTraceFunctionExit0( WLANSETTINGS_JOINWLANMODE_EXIT );
       
   264     return d_ptr->JoinWlanMode();
       
   265 }
       
   266 
       
   267 /*!
       
   268     Function to set Join WLAN networks option.
       
   269     \param mode 0 for Known, 1 for Manual. 
       
   270     \return Error code.
       
   271 */
       
   272 
       
   273 int WlanSettings::setJoinWlanMode(int mode)
       
   274 {
       
   275     OstTraceFunctionEntry0( WLANSETTINGS_SETJOINWLANMODE_ENTRY );
       
   276     
       
   277     TRAPD(error, d_ptr->SaveJoinWlanSettingL(mode));
       
   278     
       
   279     OstTraceFunctionExit0( WLANSETTINGS_SETJOINWLANMODE_EXIT );
       
   280     return error;
       
   281 }
       
   282 
       
   283 /*!
       
   284     Function to get Power Saving status of the device.
       
   285     \return True if Power Saving is enabled.
       
   286 */
       
   287 
       
   288 bool WlanSettings::isDevicePowerSavingEnabled()
       
   289 {
       
   290     OstTraceFunctionEntry0( WLANSETTINGS_ISDEVICEPOWERSAVINGENABLED_ENTRY );
       
   291     
       
   292     if (!mDevicePowerSavingModeUpToDate) {
       
   293         readDevicePowerSavingKey();
       
   294     }
       
   295     if (mDevicePowerSavingMode == EPsmsrvModeNormal) {
       
   296         OstTraceFunctionExit0( WLANSETTINGS_ISDEVICEPOWERSAVINGENABLED_EXIT );
       
   297         return false;
       
   298     } else {
       
   299         OstTraceFunctionExit0( DUP1_WLANSETTINGS_ISDEVICEPOWERSAVINGENABLED_EXIT );
       
   300         return true;
       
   301     }
       
   302 }