|
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 #include "hsdeviceinfolistener.h" |
|
19 #include <QDebug> |
|
20 |
|
21 #ifdef Q_OS_SYMBIAN |
|
22 #include <e32property.h> |
|
23 #include <startupdomainpskeys.h> |
|
24 #endif |
|
25 /*! |
|
26 |
|
27 */ |
|
28 HsDeviceInfoListener::HsDeviceInfoListener(QObject *parent) |
|
29 : QObject(parent), |
|
30 mCurrentNetworkMode(QSystemNetworkInfo::UnknownMode), |
|
31 mStatus(NoService) |
|
32 { |
|
33 mNetworkInfo = new QSystemNetworkInfo(this); |
|
34 mDeviceInfo = new QSystemDeviceInfo(this); |
|
35 |
|
36 connect(mNetworkInfo, SIGNAL(networkStatusChanged(QSystemNetworkInfo::NetworkMode, QSystemNetworkInfo::NetworkStatus)), SLOT(onNetworkStatusChanged(QSystemNetworkInfo::NetworkMode, QSystemNetworkInfo::NetworkStatus))); |
|
37 connect(mNetworkInfo, SIGNAL(networkNameChanged(QSystemNetworkInfo::NetworkMode,const QString &)), SLOT(onNetworkNameChanged(QSystemNetworkInfo::NetworkMode,const QString &))); |
|
38 connect(mDeviceInfo, SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)), SLOT(onCurrentProfileChanged(QSystemDeviceInfo::Profile))); |
|
39 |
|
40 updateCurrentNetworkMode(); |
|
41 updateStatus(); |
|
42 } |
|
43 |
|
44 /*! |
|
45 |
|
46 */ |
|
47 HsDeviceInfoListener::~HsDeviceInfoListener() |
|
48 { |
|
49 } |
|
50 |
|
51 /*! |
|
52 |
|
53 */ |
|
54 QString HsDeviceInfoListener::operatorName() const |
|
55 { |
|
56 return QSystemNetworkInfo::networkName(mCurrentNetworkMode); |
|
57 } |
|
58 |
|
59 /*! |
|
60 |
|
61 */ |
|
62 HsDeviceInfoListener::HsDeviceInfoStatus HsDeviceInfoListener::status() const |
|
63 { |
|
64 return mStatus; |
|
65 } |
|
66 |
|
67 /*! |
|
68 |
|
69 */ |
|
70 void HsDeviceInfoListener::onNetworkStatusChanged(QSystemNetworkInfo::NetworkMode networkMode, QSystemNetworkInfo::NetworkStatus networkStatus) |
|
71 { |
|
72 Q_UNUSED(networkMode); |
|
73 Q_UNUSED(networkStatus); |
|
74 updateCurrentNetworkMode(); |
|
75 updateStatus(); |
|
76 } |
|
77 |
|
78 /*! |
|
79 |
|
80 */ |
|
81 void HsDeviceInfoListener::onNetworkNameChanged(QSystemNetworkInfo::NetworkMode networkMode,const QString &networkName) |
|
82 { |
|
83 Q_UNUSED(networkMode); |
|
84 updateCurrentNetworkMode(); |
|
85 if(mCurrentNetworkMode != QSystemNetworkInfo::UnknownMode) { |
|
86 qDebug() << "HsDeviceInfoListener::onNetworkNameChanged() - " << networkName; |
|
87 emit networkNameChanged(networkName); |
|
88 } |
|
89 updateStatus(); |
|
90 } |
|
91 |
|
92 /*! |
|
93 |
|
94 */ |
|
95 void HsDeviceInfoListener::onCurrentProfileChanged(QSystemDeviceInfo::Profile profile) |
|
96 { |
|
97 Q_UNUSED(profile); |
|
98 updateStatus(); |
|
99 } |
|
100 |
|
101 /*! |
|
102 |
|
103 */ |
|
104 QSystemNetworkInfo::NetworkStatus HsDeviceInfoListener::networkStatus() |
|
105 { |
|
106 return mNetworkInfo->networkStatus(mCurrentNetworkMode); |
|
107 } |
|
108 |
|
109 /*! |
|
110 |
|
111 */ |
|
112 void HsDeviceInfoListener::updateCurrentNetworkMode() |
|
113 { |
|
114 //We are keen only GSM and WCDMA network connections. |
|
115 //Other networks (WLAN etc.) are treated as UnknowMode. |
|
116 qDebug() << "HsDeviceInfoListener::updateCurrentNetworkMode() - Entry: mCurrentNetworkMode == " |
|
117 << mCurrentNetworkMode; |
|
118 if(isConnected(QSystemNetworkInfo::GsmMode)) { |
|
119 mCurrentNetworkMode = QSystemNetworkInfo::GsmMode; |
|
120 } else if (isConnected(QSystemNetworkInfo::WcdmaMode)) { |
|
121 mCurrentNetworkMode = QSystemNetworkInfo::WcdmaMode; |
|
122 } else { |
|
123 mCurrentNetworkMode = QSystemNetworkInfo::UnknownMode; |
|
124 } |
|
125 qDebug() << "HsDeviceInfoListener::updateCurrentNetworkMode() - Exit: mCurrentNetworkMode == " |
|
126 << mCurrentNetworkMode; |
|
127 } |
|
128 |
|
129 /*! |
|
130 |
|
131 */ |
|
132 bool HsDeviceInfoListener::isConnected(QSystemNetworkInfo::NetworkMode mode) |
|
133 { |
|
134 bool connected = false; |
|
135 |
|
136 qDebug() << "HsDeviceInfoListener::isConnected():"; |
|
137 qDebug() << " - Mode:" << (mode == QSystemNetworkInfo::WcdmaMode ? "WcdmaMode" : "GsmMode"); |
|
138 QSystemNetworkInfo::NetworkStatus status = mNetworkInfo->networkStatus(mode); |
|
139 switch (status) { |
|
140 case QSystemNetworkInfo::Connected: |
|
141 qDebug() << " - Status: Connected"; |
|
142 //Fall through |
|
143 case QSystemNetworkInfo::HomeNetwork: |
|
144 qDebug() << " - Status: HomeNetwork"; |
|
145 //Fall through |
|
146 case QSystemNetworkInfo::Roaming: |
|
147 qDebug() << " - Status: Roaming"; |
|
148 connected = true; |
|
149 break; |
|
150 default: |
|
151 qDebug() << " - Status: " << status; |
|
152 break; |
|
153 }; |
|
154 |
|
155 qDebug() << " - Is connected:" << connected; |
|
156 |
|
157 return connected; |
|
158 } |
|
159 |
|
160 /*! |
|
161 |
|
162 */ |
|
163 void HsDeviceInfoListener::updateStatus() |
|
164 { |
|
165 qDebug() << "HsDeviceInfoListener::updateStatus() - Entry: mStatus == " |
|
166 << mStatus; |
|
167 |
|
168 HsDeviceInfoStatus currentStatus; |
|
169 if ( mDeviceInfo->currentProfile() == QSystemDeviceInfo::OfflineProfile && |
|
170 simStatus() != QSystemDeviceInfo::SimNotAvailable) { |
|
171 currentStatus = OfflineProfile; |
|
172 } else if (mCurrentNetworkMode == QSystemNetworkInfo::UnknownMode) { |
|
173 currentStatus = NoService; |
|
174 } else { |
|
175 currentStatus = ServiceAvailable; |
|
176 } |
|
177 |
|
178 if(mStatus != currentStatus) { |
|
179 mStatus = currentStatus; |
|
180 emit statusChanged(mStatus); |
|
181 } |
|
182 qDebug() << "HsDeviceInfoListener::updateStatus() - Exit: mStatus == " |
|
183 << mStatus; |
|
184 } |
|
185 |
|
186 /*! |
|
187 |
|
188 */ |
|
189 QSystemDeviceInfo::SimStatus HsDeviceInfoListener::simStatus() const |
|
190 { |
|
191 QSystemDeviceInfo::SimStatus qtSimStatus = QSystemDeviceInfo::SimNotAvailable; |
|
192 |
|
193 #ifdef Q_OS_SYMBIAN |
|
194 TInt simCardStatus(ESimNotPresent); |
|
195 RProperty symbianSimStatus; |
|
196 qt_symbian_throwIfError( symbianSimStatus.Attach( KPSUidStartup, KPSSimStatus ) ); |
|
197 qt_symbian_throwIfError( symbianSimStatus.Get( simCardStatus ) ); |
|
198 symbianSimStatus.Close(); |
|
199 |
|
200 switch (simCardStatus) { |
|
201 case ESimUsable: |
|
202 // The Sim card is fully usable. |
|
203 qtSimStatus = QSystemDeviceInfo::SingleSimAvailable; |
|
204 qDebug() << "HsDeviceInfoListener::simStatus() - SingleSimAvailable"; |
|
205 break; |
|
206 default: |
|
207 //ESimReadable == The SIM card is not fully usable, but the emergency number can be read. |
|
208 //ESimNotReady == The Sim card is present but not ready or usable. |
|
209 //ESimNotPresent == The Sim card is not present. |
|
210 //ESimNotSupported == SIM/RUIM is not supported. Some CDMA phones do not support a SIM/RUIM at all. |
|
211 qtSimStatus = QSystemDeviceInfo::SimNotAvailable; |
|
212 qDebug() << "HsDeviceInfoListener::simStatus() - SimNotAvailable"; |
|
213 break; |
|
214 }; |
|
215 #else |
|
216 qtSimStatus = mDeviceInfo->simStatus(); |
|
217 #endif |
|
218 |
|
219 return qtSimStatus; |
|
220 } |