|
1 /* |
|
2 * Copyright (c) 2009 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 * WLAN Status Info wrapper for WLAN entry plugin. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 #include <HbGlobal> |
|
21 #include <xqsettingsmanager.h> |
|
22 #include <wlandevicesettingsinternalcrkeys.h> |
|
23 |
|
24 // User includes |
|
25 |
|
26 #include "wlanqtutils.h" |
|
27 |
|
28 #include "wlanstatusinfo.h" |
|
29 |
|
30 #include "OstTraceDefinitions.h" |
|
31 #ifdef OST_TRACE_COMPILER_IN_USE |
|
32 #include "wlanstatusinfoTraces.h" |
|
33 #endif |
|
34 |
|
35 /*! |
|
36 \class WlanStatusInfo |
|
37 \brief Class for maintaining and updating the WLAN status for the WLAN |
|
38 Status Control Panel Plugin. |
|
39 */ |
|
40 |
|
41 // External function prototypes |
|
42 |
|
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); |
|
56 |
|
57 // ======== LOCAL FUNCTIONS ======== |
|
58 |
|
59 // ======== MEMBER FUNCTIONS ======== |
|
60 |
|
61 /*! |
|
62 Constructor. |
|
63 */ |
|
64 |
|
65 WlanStatusInfo::WlanStatusInfo(QObject *parent) : |
|
66 QObject(parent), |
|
67 mWlanQtUtils(new WlanQtUtils()), |
|
68 mSettingsManager(new XQSettingsManager(this)), |
|
69 mStatusText(""), |
|
70 mStatus(WlanStatusOff) |
|
71 { |
|
72 OstTraceFunctionEntry0(WLANSTATUSINFO_WLANSTATUSINFO_ENTRY); |
|
73 |
|
74 // Listen for WLAN ON/OFF switching |
|
75 bool connectStatus = connect( |
|
76 mSettingsManager, |
|
77 SIGNAL(valueChanged(XQSettingsKey, QVariant)), |
|
78 this, |
|
79 SLOT(updateStatus())); |
|
80 Q_ASSERT(connectStatus); |
|
81 mSettingsManager->startMonitoring(masterWlanKey); |
|
82 mSettingsManager->startMonitoring(wlanForceKey); |
|
83 |
|
84 // Listen for WLAN connection statuses |
|
85 connectStatus = connect( |
|
86 mWlanQtUtils, |
|
87 SIGNAL(wlanNetworkOpened(int)), |
|
88 this, |
|
89 SLOT(updateStatus())); |
|
90 Q_ASSERT(connectStatus == true); |
|
91 connectStatus = connect( |
|
92 mWlanQtUtils, |
|
93 SIGNAL(wlanNetworkClosed(int, int)), |
|
94 this, |
|
95 SLOT(updateStatus())); |
|
96 Q_ASSERT(connectStatus == true); |
|
97 |
|
98 // Set initial status |
|
99 updateStatus(); |
|
100 |
|
101 OstTraceFunctionExit0(WLANSTATUSINFO_WLANSTATUSINFO_EXIT); |
|
102 } |
|
103 |
|
104 /*! |
|
105 Destructor. |
|
106 */ |
|
107 |
|
108 WlanStatusInfo::~WlanStatusInfo() |
|
109 { |
|
110 OstTraceFunctionEntry0(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_ENTRY); |
|
111 |
|
112 delete mWlanQtUtils; |
|
113 |
|
114 OstTraceFunctionExit0(DUP1_WLANSTATUSINFO_WLANSTATUSINFO_EXIT); |
|
115 } |
|
116 |
|
117 /*! |
|
118 Function for getting current WLAN status value (WlanStatusInfo::WlanStatus*). |
|
119 */ |
|
120 |
|
121 int WlanStatusInfo::status() const |
|
122 { |
|
123 OstTraceFunctionEntry0(WLANSTATUSINFO_STATUS_ENTRY); |
|
124 OstTraceFunctionExit0(WLANSTATUSINFO_STATUS_EXIT); |
|
125 return mStatus; |
|
126 } |
|
127 |
|
128 /*! |
|
129 Returns the current WLAN status text. |
|
130 */ |
|
131 |
|
132 QString WlanStatusInfo::statusText() const |
|
133 { |
|
134 OstTraceFunctionEntry0(WLANSTATUSINFO_STATUSTEXT_ENTRY); |
|
135 OstTraceFunctionExit0(WLANSTATUSINFO_STATUSTEXT_EXIT); |
|
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; |
|
163 } |
|
164 |
|
165 /*! |
|
166 Slot used for updating the WLAN status. |
|
167 */ |
|
168 |
|
169 void WlanStatusInfo::updateStatus() |
|
170 { |
|
171 OstTraceFunctionEntry0(WLANSTATUSINFO_UPDATESTATUS_ENTRY); |
|
172 |
|
173 // Backup old status to detect changes |
|
174 QString oldStatusText = mStatusText; |
|
175 |
|
176 // Figure out current WLAN status |
|
177 if (!isWlanOn()) { |
|
178 // WLAN is switched OFF. |
|
179 mStatus = WlanStatusOff; |
|
180 mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_off"); |
|
181 } else if (mWlanQtUtils->connectionStatus() == WlanQtUtils::ConnStatusConnected) { |
|
182 mStatus = WlanStatusConnected; |
|
183 mStatusText = mWlanQtUtils->iapName(mWlanQtUtils->activeIap()); |
|
184 } else { |
|
185 mStatus = WlanStatusIdle; |
|
186 mStatusText = hbTrId("txt_occ_dblist_wireless_lan_val_wlan_is_on"); |
|
187 } |
|
188 |
|
189 // Inform about update if the status really changed. |
|
190 if (oldStatusText != mStatusText) { |
|
191 emit statusUpdated(); |
|
192 } |
|
193 |
|
194 OstTraceFunctionExit0(WLANSTATUSINFO_UPDATESTATUS_EXIT); |
|
195 } |