wlanutilities/cpwlansettingsplugin/src/wlansettings.cpp
changeset 19 10810c91db26
child 53 bdc64aa9b954
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
       
     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 
       
    24 // User includes
       
    25 
       
    26 #include "wlansettings.h"
       
    27 
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "wlansettingsTraces.h"
       
    31 #endif
       
    32 
       
    33 /*!
       
    34    \class WlanSettings
       
    35    \brief WlanSettings is a wrapper class for CWlanSettingsImpl.
       
    36 */
       
    37 
       
    38 // External function prototypes
       
    39 
       
    40 // Local constants
       
    41 /**  Default value for Scan Interval. */
       
    42 const int KDefaultScanInterval = 5;
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 /*!
       
    47     Constructor.
       
    48 */
       
    49 
       
    50 WlanSettings::WlanSettings() :
       
    51     QObject(), mPsmKeyValue(0)
       
    52 {
       
    53 
       
    54     OstTraceFunctionEntry1(WLANSETTINGS_WLANSETTINGS_ENTRY, this);
       
    55     OstTraceFunctionExit1(WLANSETTINGS_WLANSETTINGS_EXIT, this);
       
    56 }
       
    57 
       
    58 /*!
       
    59     Destructor.
       
    60 */
       
    61 
       
    62 WlanSettings::~WlanSettings()
       
    63 {
       
    64     OstTraceFunctionEntry1(DUP1_WLANSETTINGS_WLANSETTINGS_ENTRY, this);
       
    65 
       
    66     delete mImpl;
       
    67     
       
    68     OstTraceFunctionExit1(DUP1_WLANSETTINGS_WLANSETTINGS_EXIT, this);
       
    69 }
       
    70 
       
    71 /*!
       
    72     Creates the CWlanSettingsImpl object for reading/writing settings.
       
    73     \return Error code.
       
    74 */
       
    75 
       
    76 int WlanSettings::init()
       
    77 {
       
    78     OstTraceFunctionEntry1(WLANSETTINGS_INIT_ENTRY, this);
       
    79     
       
    80     readPsmKey();
       
    81     
       
    82     TRAPD(error,(mImpl = CWlanSettingsPrivate::NewL(mPsmKeyValue)));
       
    83     
       
    84     OstTraceFunctionExit1(WLANSETTINGS_INIT_EXIT, this);
       
    85     return error;
       
    86 }
       
    87 
       
    88 
       
    89 void WlanSettings::readPsmKey()
       
    90 {
       
    91     OstTraceFunctionEntry1(WLANSETTINGS_READPSMKEY_ENTRY, this);
       
    92     
       
    93     QScopedPointer<XQSettingsManager> settingsManager;
       
    94     settingsManager.reset(new XQSettingsManager());
       
    95 
       
    96     XQSettingsKey key(XQSettingsKey::TargetCentralRepository,
       
    97             KCRUidPowerSaveMode.iUid, KPsmCurrentMode);
       
    98 
       
    99     QVariant keyValue = settingsManager->readItemValue(key);
       
   100 
       
   101     mPsmKeyValue = keyValue.toInt();
       
   102     
       
   103     OstTraceFunctionExit1(WLANSETTINGS_READPSMKEY_EXIT, this);
       
   104 }
       
   105 
       
   106 /*!
       
   107     Reads the WLAN setting values.
       
   108     \return Error code.
       
   109 */
       
   110 
       
   111 int WlanSettings::loadSettings()
       
   112 {
       
   113     OstTraceFunctionEntry1(WLANSETTINGS_LOADSETTINGS_ENTRY, this);
       
   114     
       
   115     TRAPD(error, mImpl->LoadDBSettingsL());
       
   116     
       
   117     OstTraceFunctionExit1(WLANSETTINGS_LOADSETTINGS_EXIT, this);
       
   118     return error;
       
   119 }
       
   120 
       
   121 /*!
       
   122     Function to get the scan network type.
       
   123     \return ScanNetworkType which is automatic or user-defined.
       
   124 */
       
   125 
       
   126 WlanSettings::ScanNetworkType WlanSettings::scanNetworkType()
       
   127 {
       
   128     OstTraceFunctionEntry1(WLANSETTINGS_SCANNETWORKTYPE_ENTRY, this);
       
   129     
       
   130     ScanNetworkType scanType;
       
   131     uint scanInterval = mImpl->ScanInterval();
       
   132     
       
   133     if (scanInterval == KWlanSettingsScanNetworkAuto) {
       
   134         scanType = EScanNetworkAuto;
       
   135     }
       
   136     else {
       
   137         scanType = EScanNetworkUserDefined;
       
   138     }
       
   139     
       
   140     OstTraceFunctionExit1(WLANSETTINGS_SCANNETWORKTYPE_EXIT, this);
       
   141     return scanType;
       
   142 }
       
   143 
       
   144 /*!
       
   145     Function to get the scan interval.
       
   146     \return Scan interval  in minutes.
       
   147 */
       
   148 
       
   149 uint WlanSettings::scanInterval()
       
   150 {
       
   151     OstTraceFunctionEntry1(WLANSETTINGS_SCANINTERVAL_ENTRY, this);
       
   152     
       
   153     uint scanInterval = mImpl->ScanInterval();
       
   154     
       
   155     if (scanInterval == KWlanSettingsScanNetworkAuto) {
       
   156         scanInterval = KDefaultScanInterval;
       
   157     }
       
   158     
       
   159     OstTraceFunctionExit1(WLANSETTINGS_SCANINTERVAL_EXIT, this);
       
   160     return scanInterval;
       
   161 }
       
   162 
       
   163 /*!
       
   164     Function to get Power Saving Option.
       
   165     \return True if Power Saving option is enabled, otherwise False.
       
   166 */
       
   167 
       
   168 int WlanSettings::isPowerSavingEnabled() const
       
   169 {
       
   170     return mImpl->PowerSaving();
       
   171 }
       
   172 
       
   173 /*!
       
   174     Function to set Power Saving Option.
       
   175     \param powerSavingOption True to enable or false to disable power saving option. 
       
   176     \return Error code.
       
   177 */
       
   178 
       
   179 int WlanSettings::setWlanPowerSaving(int powerSavingOption)
       
   180 {
       
   181     OstTraceFunctionEntry1(WLANSETTINGS_SETWLANPOWERSAVING_ENTRY, this);
       
   182     
       
   183     mImpl->SetPowerSaving(powerSavingOption);
       
   184     TRAPD(error, mImpl->SaveDBSettingsL(CWlanSettingsPrivate::EWlanPowerSaving));
       
   185 
       
   186     OstTraceFunctionExit1(WLANSETTINGS_SETWLANPOWERSAVING_EXIT, this);
       
   187     return error;
       
   188 }
       
   189 
       
   190 /*!
       
   191     Function to set Scan interval.
       
   192     \param scanInterval Scan interval in minutes. 
       
   193     \return Error code.
       
   194 */
       
   195 
       
   196 int WlanSettings::setWlanScanInterval(uint scanInterval)
       
   197 {
       
   198     OstTraceFunctionEntry1(WLANSETTINGS_SETWLANSCANINTERVAL_ENTRY, this);
       
   199     
       
   200     mImpl->SetScanInterval(scanInterval);
       
   201     TRAPD(error, mImpl->SaveDBSettingsL(CWlanSettingsPrivate::EWlanScanInterval));
       
   202 
       
   203     OstTraceFunctionExit1(WLANSETTINGS_SETWLANSCANINTERVAL_EXIT, this);
       
   204     return error;
       
   205 }
       
   206 
       
   207 /*!
       
   208     Function to get Join WLAN networks option.
       
   209     \return 0 for Known, 1 for Manual.
       
   210 */
       
   211 
       
   212 int WlanSettings::joinWlanMode() const
       
   213 {
       
   214     return mImpl->JoinWlanMode();
       
   215 }
       
   216 
       
   217 /*!
       
   218     Function to set Join WLAN networks option.
       
   219     \param mode 0 for Known, 1 for Manual. 
       
   220     \return Error code.
       
   221 */
       
   222 
       
   223 int WlanSettings::setJoinWlanMode(int mode)
       
   224 {
       
   225     OstTraceFunctionEntry1(WLANSETTINGS_SETJOINWLANMODE_ENTRY, this);
       
   226     
       
   227     TRAPD(error, mImpl->SaveJoinWlanSettingL(mode));
       
   228     
       
   229     OstTraceFunctionExit1(WLANSETTINGS_SETJOINWLANMODE_EXIT, this);
       
   230     return error;
       
   231 }
       
   232 
       
   233 /*!
       
   234     Function to get Power Saving status of the device.
       
   235     \return True if Power Saving is enabled.
       
   236 */
       
   237 
       
   238 int WlanSettings::isPsmEnabled() const
       
   239 {
       
   240     return mImpl->IsPsmEnabled();
       
   241 }