|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QObject> |
|
43 #include <QTimer> |
|
44 |
|
45 #include <wlanmgmtclient.h> |
|
46 #include <wlanmgmtinterface.h> |
|
47 #include <wlanmgmtcommon.h> |
|
48 #include "wlaninfo_s60.h" |
|
49 |
|
50 const int KWlanInfoSignalStrengthMax = 60; |
|
51 const int KWlanInfoSignalStrengthMin = 100; |
|
52 |
|
53 CWlanInfo::CWlanInfo(QObject *parent) : QObject(parent) |
|
54 , m_wlanStatus(false) |
|
55 , m_wlanSsid() |
|
56 , m_wlanSignalStrength(-1) |
|
57 { |
|
58 #ifndef __WINSCW__ |
|
59 TRAP_IGNORE( |
|
60 m_wlanMgmtClient = CWlanMgmtClient::NewL(); |
|
61 m_wlanMgmtClient->ActivateNotificationsL(*this); |
|
62 ) |
|
63 |
|
64 m_timer = new QTimer(this); |
|
65 connect(m_timer, SIGNAL(timeout()), this, SLOT(checkWlanInfo())); |
|
66 m_timer->setInterval(1000); |
|
67 m_timer->start(); |
|
68 #endif |
|
69 } |
|
70 |
|
71 CWlanInfo::~CWlanInfo() |
|
72 { |
|
73 m_wlanMgmtClient->CancelNotifications(); |
|
74 delete m_wlanMgmtClient; |
|
75 } |
|
76 |
|
77 QString CWlanInfo::wlanNetworkName() const |
|
78 { |
|
79 return m_wlanSsid; |
|
80 } |
|
81 |
|
82 int CWlanInfo::wlanNetworkSignalStrength() const |
|
83 { |
|
84 return m_wlanSignalStrength; |
|
85 } |
|
86 |
|
87 bool CWlanInfo::wlanNetworkConnectionStatus() const |
|
88 { |
|
89 return m_wlanStatus; |
|
90 } |
|
91 |
|
92 void CWlanInfo::checkWlanInfo() |
|
93 { |
|
94 #ifndef __WINSCW__ |
|
95 TWlanConnectionMode connectionMode; |
|
96 TInt err = m_wlanMgmtClient->GetConnectionMode(connectionMode); |
|
97 if (err == KErrNone && connectionMode != EWlanConnectionModeNotConnected) { |
|
98 m_wlanStatus = true; |
|
99 emit wlanNetworkStatusChanged(); |
|
100 } else { |
|
101 stopPolling(); |
|
102 return; |
|
103 } |
|
104 |
|
105 TWlanSsid ssid; |
|
106 err = m_wlanMgmtClient->GetConnectionSsid(ssid); |
|
107 ssid.ZeroTerminate(); |
|
108 if (err == KErrNone && m_wlanSsid != (char*)ssid.Ptr()) { |
|
109 m_wlanSsid = (char*)ssid.Ptr(); |
|
110 emit wlanNetworkNameChanged(); |
|
111 } |
|
112 |
|
113 TInt32 signalQuality; |
|
114 err = m_wlanMgmtClient->GetConnectionSignalQuality(signalQuality); |
|
115 |
|
116 if (err == KErrNone && m_wlanSignalStrength != signalQuality) { |
|
117 if (signalQuality <= KWlanInfoSignalStrengthMax && signalQuality >= 0) |
|
118 m_wlanSignalStrength = 100; |
|
119 else if (signalQuality >= KWlanInfoSignalStrengthMin) |
|
120 m_wlanSignalStrength = 0; |
|
121 else { |
|
122 m_wlanSignalStrength = (KWlanInfoSignalStrengthMin - signalQuality) * 100 / |
|
123 (KWlanInfoSignalStrengthMin - KWlanInfoSignalStrengthMax); |
|
124 } |
|
125 emit wlanNetworkSignalStrengthChanged(); |
|
126 } |
|
127 #endif |
|
128 } |
|
129 |
|
130 void CWlanInfo::ConnectionStateChanged(TWlanConnectionMode aNewState) |
|
131 { |
|
132 if (aNewState == EWlanConnectionModeNotConnected) |
|
133 stopPolling(); |
|
134 else { |
|
135 m_timer->start(); |
|
136 checkWlanInfo(); |
|
137 } |
|
138 } |
|
139 |
|
140 void CWlanInfo::stopPolling() |
|
141 { |
|
142 m_timer->stop(); |
|
143 m_wlanStatus = false; |
|
144 m_wlanSsid = ""; |
|
145 m_wlanSignalStrength = 0; |
|
146 |
|
147 emit wlanNetworkStatusChanged(); |
|
148 emit wlanNetworkNameChanged(); |
|
149 emit wlanNetworkSignalStrengthChanged(); |
|
150 } |