wlanutilities/wlanentryplugin/src/wlanstatusinfo.cpp
changeset 31 e8f4211554fb
parent 19 10810c91db26
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
       
    15 * WLAN Status Info wrapper for WLAN entry plugin.
    15 */
    16 */
    16 
    17 
    17 // System includes
    18 // System includes
    18 
    19 
    19 #include <HbGlobal>
    20 #include <HbGlobal>
       
    21 #include <xqsettingsmanager.h>
       
    22 #include <wlandevicesettingsinternalcrkeys.h>
    20 
    23 
    21 // User includes
    24 // User includes
    22 
    25 
    23 #include "wlanqtutils.h"
    26 #include "wlanqtutils.h"
    24 #include "wlanqtutilswlaniap.h"
       
    25 
    27 
    26 #include "wlanstatusinfo.h"
    28 #include "wlanstatusinfo.h"
    27 
    29 
    28 #include "OstTraceDefinitions.h"
    30 #include "OstTraceDefinitions.h"
    29 #ifdef OST_TRACE_COMPILER_IN_USE
    31 #ifdef OST_TRACE_COMPILER_IN_USE
    31 #endif
    33 #endif
    32 
    34 
    33 /*!
    35 /*!
    34     \class WlanStatusInfo
    36     \class WlanStatusInfo
    35     \brief Class for maintaining and updating the WLAN status for the WLAN 
    37     \brief Class for maintaining and updating the WLAN status for the WLAN 
    36     Status Control Panel Plugin.
    38            Status Control Panel Plugin.
    37 
       
    38 */
    39 */
    39 
    40 
    40 // External function prototypes
    41 // External function prototypes
    41 
    42 
    42 // Local constants
    43 // Local constants
       
    44 
       
    45 //! Master WLAN ON/OFF setting key
       
    46 static const XQSettingsKey masterWlanKey(
       
    47     XQSettingsKey::TargetCentralRepository,
       
    48     KCRUidWlanDeviceSettingsRegistryId.iUid, 
       
    49     KWlanOnOff);
       
    50     
       
    51 //! WLAN  forced OFF setting key
       
    52 static const XQSettingsKey wlanForceKey(
       
    53     XQSettingsKey::TargetCentralRepository,
       
    54     KCRUidWlanDeviceSettingsRegistryId.iUid, 
       
    55     KWlanForceDisable);
    43 
    56 
    44 // ======== LOCAL FUNCTIONS ========
    57 // ======== LOCAL FUNCTIONS ========
    45 
    58 
    46 // ======== MEMBER FUNCTIONS ========
    59 // ======== MEMBER FUNCTIONS ========
    47 
    60 
    50 */
    63 */
    51 
    64 
    52 WlanStatusInfo::WlanStatusInfo(QObject *parent) :
    65 WlanStatusInfo::WlanStatusInfo(QObject *parent) :
    53     QObject(parent),
    66     QObject(parent),
    54     mWlanQtUtils(new WlanQtUtils()),
    67     mWlanQtUtils(new WlanQtUtils()),
       
    68     mSettingsManager(new XQSettingsManager(this)),
    55     mStatusText(""),
    69     mStatusText(""),
    56     mStatus(WlanStatusOff)
    70     mStatus(WlanStatusOff)
    57 {
    71 {
    58     OstTraceFunctionEntry1(WLANSTATUSINFO_WLANSTATUSINFO_ENTRY, this);
    72     OstTraceFunctionEntry0(WLANSTATUSINFO_WLANSTATUSINFO_ENTRY);
    59     
    73     
    60     // Listen for WLAN ON/OFF switching
    74     // Listen for WLAN ON/OFF switching
    61     bool connectStatus = connect(
    75     bool connectStatus = connect(
    62         mWlanQtUtils,
    76         mSettingsManager, 
    63         SIGNAL(masterWlanStatus(bool)),
    77         SIGNAL(valueChanged(XQSettingsKey, QVariant)),
    64         this,
    78         this, 
    65         SLOT(updateStatus()));
    79         SLOT(updateStatus()));
    66     Q_ASSERT(connectStatus == true);
    80     Q_ASSERT(connectStatus);
       
    81     mSettingsManager->startMonitoring(masterWlanKey);
       
    82     mSettingsManager->startMonitoring(wlanForceKey);
    67 
    83 
    68     // Listen for WLAN connection statuses
    84     // Listen for WLAN connection statuses
    69     connectStatus = connect(
    85     connectStatus = connect(
    70         mWlanQtUtils,
    86         mWlanQtUtils,
    71         SIGNAL(wlanNetworkOpened(int)),
    87         SIGNAL(wlanNetworkOpened(int)),
    72         this,
    88         this,
    73         SLOT(updateStatus()));
    89         SLOT(updateStatus()));
    74     Q_ASSERT(connectStatus == true);
    90     Q_ASSERT(connectStatus == true);
    75     connectStatus = connect(
    91     connectStatus = connect(
    76         mWlanQtUtils,
    92         mWlanQtUtils,
    77         SIGNAL(wlanNetworkClosed(int)),
    93         SIGNAL(wlanNetworkClosed(int, int)),
    78         this,
    94         this,
    79         SLOT(updateStatus()));
    95         SLOT(updateStatus()));
    80     Q_ASSERT(connectStatus == true);
    96     Q_ASSERT(connectStatus == true);
    81     
    97     
    82     // Set initial status
    98     // Set initial status
    83     updateStatus();
    99     updateStatus();
    84     
   100     
    85     OstTraceFunctionExit1(WLANSTATUSINFO_WLANSTATUSINFO_EXIT, this);
   101     OstTraceFunctionExit0(WLANSTATUSINFO_WLANSTATUSINFO_EXIT);
    86 }
   102 }
    87 
   103 
    88 /*!
   104 /*!
    89     Destructor.
   105     Destructor.
    90 */
   106 */
    91 
   107 
    92 WlanStatusInfo::~WlanStatusInfo()
   108 WlanStatusInfo::~WlanStatusInfo()
    93 {
   109 {
    94     OstTraceFunctionEntry1(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_ENTRY, this);
   110     OstTraceFunctionEntry0(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_ENTRY);
    95     
   111     
    96     delete mWlanQtUtils;
   112     delete mWlanQtUtils;
    97     
   113     
    98     OstTraceFunctionExit1(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_EXIT, this);
   114     OstTraceFunctionExit0(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_EXIT);
    99 }
   115 }
   100 
   116 
   101 /*!
   117 /*!
   102     Function for getting current WLAN status value (WlanStatusInfo::WlanStatus*).
   118     Function for getting current WLAN status value (WlanStatusInfo::WlanStatus*).
   103 */
   119 */
   104 
   120 
   105 int WlanStatusInfo::status()
   121 int WlanStatusInfo::status() const
   106 {
   122 {
   107     OstTraceFunctionEntry1(WLANSTATUSINFO_STATUS_ENTRY, this);    
   123     OstTraceFunctionEntry0(WLANSTATUSINFO_STATUS_ENTRY);    
   108     OstTraceFunctionExit1(WLANSTATUSINFO_STATUS_EXIT, this);
   124     OstTraceFunctionExit0(WLANSTATUSINFO_STATUS_EXIT);
   109     return mStatus;
   125     return mStatus;
   110 }
   126 }
   111 
   127 
   112 /*!
   128 /*!
   113     Returns the current WLAN status text.
   129     Returns the current WLAN status text.
   114 */
   130 */
   115 
   131 
   116 QString WlanStatusInfo::statusText()
   132 QString WlanStatusInfo::statusText() const
   117 {
   133 {
   118     OstTraceFunctionEntry1(WLANSTATUSINFO_STATUSTEXT_ENTRY, this);
   134     OstTraceFunctionEntry0(WLANSTATUSINFO_STATUSTEXT_ENTRY);
   119     OstTraceFunctionExit1(WLANSTATUSINFO_STATUSTEXT_EXIT, this);
   135     OstTraceFunctionExit0(WLANSTATUSINFO_STATUSTEXT_EXIT);
   120     return mStatusText;
   136     return mStatusText;
       
   137 }
       
   138 
       
   139 /*!
       
   140     Function for checking if WLAN is ON.
       
   141     WLAN is enabled if the WLAN OnOff key is true and the force disable
       
   142     wlan key is false.
       
   143     
       
   144     @return Returns true if WLAN is ON.
       
   145 */
       
   146 
       
   147 bool WlanStatusInfo::isWlanOn() const
       
   148 {
       
   149     OstTraceFunctionEntry0(WLANSTATUSINFO_ISWLANON_ENTRY);
       
   150 
       
   151     bool wlanOn = mSettingsManager->readItemValue(masterWlanKey).toBool();
       
   152     bool forcedOff = mSettingsManager->readItemValue(wlanForceKey).toBool();
       
   153 
       
   154     OstTraceExt2(
       
   155         TRACE_NORMAL,
       
   156         WLANSTATUSINFO_ISWLANON,
       
   157         "WlanStatusInfo::isWlanOn;wlanOn=%hhu;forcedOff=%hhu",
       
   158         wlanOn,
       
   159         forcedOff);
       
   160     
       
   161     OstTraceFunctionExit0(WLANSTATUSINFO_ISWLANON_EXIT);
       
   162     return wlanOn && !forcedOff;
   121 }
   163 }
   122 
   164 
   123 /*!
   165 /*!
   124     Slot used for updating the WLAN status.
   166     Slot used for updating the WLAN status.
   125 */
   167 */
   126 
   168 
   127 void WlanStatusInfo::updateStatus()
   169 void WlanStatusInfo::updateStatus()
   128 {
   170 {
   129     OstTraceFunctionEntry1(WLANSTATUSINFO_UPDATESTATUS_ENTRY, this);
   171     OstTraceFunctionEntry0(WLANSTATUSINFO_UPDATESTATUS_ENTRY);
   130 
   172 
   131     // Backup old status to detect changes
   173     // Backup old status to detect changes
   132     QString oldStatusText = mStatusText;
   174     QString oldStatusText = mStatusText;
   133     int connectedIapId = mWlanQtUtils->connectedWlanId();
   175 
   134     
       
   135     // Figure out current WLAN status
   176     // Figure out current WLAN status
   136     if (mWlanQtUtils->masterWlan() == false) {
   177     if (!isWlanOn()) {
   137         // WLAN is switched OFF.
   178         // WLAN is switched OFF.
   138         mStatus = WlanStatusOff;
   179         mStatus = WlanStatusOff;
   139         mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_off");
   180         mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_off");
   140     } else if (connectedIapId != WlanQtUtilsInvalidIapId) {
   181     } else if (mWlanQtUtils->connectionStatus() == WlanQtUtils::ConnStatusConnected) { 
   141         mStatus = WlanStatusConnected;
   182         mStatus = WlanStatusConnected;
   142         mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_connected_to_1")
   183         mStatusText = mWlanQtUtils->iapName(mWlanQtUtils->activeIap());
   143             .arg(mWlanQtUtils->iap(connectedIapId)->name());
       
   144     } else {
   184     } else {
   145         mStatus = WlanStatusIdle;
   185         mStatus = WlanStatusIdle;
   146         mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_wlan_is_on");
   186         mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_wlan_is_on");
   147     }
   187     }
   148 
   188 
   149     // Inform about update if the status really changed.
   189     // Inform about update if the status really changed.
   150     if (oldStatusText != mStatusText) {
   190     if (oldStatusText != mStatusText) {
   151         emit statusUpdated();
   191         emit statusUpdated();
   152     }
   192     }
   153     
   193     
   154     OstTraceFunctionExit1(WLANSTATUSINFO_UPDATESTATUS_EXIT, this);
   194     OstTraceFunctionExit0(WLANSTATUSINFO_UPDATESTATUS_EXIT);
   155 }
   195 }