|
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 * |
|
16 */ |
|
17 |
|
18 #include <networkhandlingproxy.h> |
|
19 #include <cnwsession.h> |
|
20 #include <xqsettingsmanager.h> |
|
21 #include <xqsettingskey.h> |
|
22 #include <settingsinternalcrkeys.h> |
|
23 #include "infowidgetnetworkhandler.h" |
|
24 #include "infowidgetlogging.h" |
|
25 |
|
26 /*! |
|
27 \class InfoWidgetNetworkHandler |
|
28 \brief Handles network specific functionality of |
|
29 Operator info widget |
|
30 */ |
|
31 |
|
32 // Local constants |
|
33 const int KMcnValueOff = 0; |
|
34 const int KMcnValueOn = 1; |
|
35 |
|
36 /*! |
|
37 InfoWidgetNetworkHandler::InfoWidgetNetworkHandler() |
|
38 */ |
|
39 InfoWidgetNetworkHandler::InfoWidgetNetworkHandler(QObject *parent) |
|
40 : |
|
41 QObject(parent), |
|
42 m_nwSession(NULL) |
|
43 { |
|
44 DPRINT; |
|
45 |
|
46 if (!createSession()) { |
|
47 DCRITICAL << ": session creation failed!"; |
|
48 } |
|
49 } |
|
50 |
|
51 /*! |
|
52 InfoWidgetNetworkHandler::~InfoWidgetNetworkHandler() |
|
53 */ |
|
54 InfoWidgetNetworkHandler::~InfoWidgetNetworkHandler() |
|
55 { |
|
56 DPRINT; |
|
57 |
|
58 // Disable MCN setting, |
|
59 // display client is being deleted |
|
60 disableMcn(); |
|
61 } |
|
62 |
|
63 /*! |
|
64 InfoWidgetNetworkHandler::createSession() |
|
65 */ |
|
66 bool InfoWidgetNetworkHandler::createSession() |
|
67 { |
|
68 DPRINT; |
|
69 bool success(false); |
|
70 if (!m_nwSession) { |
|
71 try { |
|
72 QT_TRAP_THROWING(m_nwSession.reset( |
|
73 CreateL(*this, m_nwInfo))); |
|
74 } catch (const std::exception& ex) { |
|
75 DCRITICAL << ": exception " << ex.what(); |
|
76 } |
|
77 |
|
78 if (!m_nwSession.isNull()) { |
|
79 DPRINT << ": session created"; |
|
80 success = true; |
|
81 } |
|
82 } else { |
|
83 DWARNING << ": session already created!"; |
|
84 } |
|
85 |
|
86 return success; |
|
87 } |
|
88 |
|
89 /*! |
|
90 InfoWidgetNetworkHandler::sessionExists() |
|
91 */ |
|
92 bool InfoWidgetNetworkHandler::sessionExists() |
|
93 { |
|
94 return !m_nwSession.isNull(); |
|
95 } |
|
96 |
|
97 /*! |
|
98 InfoWidgetNetworkHandler::suspend() |
|
99 */ |
|
100 void InfoWidgetNetworkHandler::suspend() |
|
101 { |
|
102 DPRINT; |
|
103 } |
|
104 |
|
105 /*! |
|
106 InfoWidgetNetworkHandler::resume() |
|
107 */ |
|
108 void InfoWidgetNetworkHandler::resume() |
|
109 { |
|
110 DPRINT; |
|
111 } |
|
112 |
|
113 /*! |
|
114 InfoWidgetNetworkHandler::serviceProviderName() |
|
115 */ |
|
116 QString InfoWidgetNetworkHandler::serviceProviderName() const |
|
117 { |
|
118 QString qBuf; |
|
119 qBuf = QString((QChar*)m_nwInfo.iSPName.Ptr(), |
|
120 m_nwInfo.iSPName.Length()); |
|
121 DPRINT << ": serviceProviderName: " << qBuf; |
|
122 |
|
123 return qBuf; |
|
124 } |
|
125 |
|
126 /*! |
|
127 InfoWidgetNetworkHandler::serviceProviderNameDisplayRequired() |
|
128 */ |
|
129 bool InfoWidgetNetworkHandler::serviceProviderNameDisplayRequired() const |
|
130 { |
|
131 bool displayRequired(true); |
|
132 if (m_nwInfo.iServiceProviderNameDisplayReq == |
|
133 RMobilePhone::KDisplaySPNNotRequired) { |
|
134 displayRequired = false; |
|
135 } |
|
136 return displayRequired; |
|
137 } |
|
138 |
|
139 /*! |
|
140 InfoWidgetNetworkHandler::homeZoneTextTag() |
|
141 */ |
|
142 QString InfoWidgetNetworkHandler::homeZoneTextTag() const |
|
143 { |
|
144 QString qBuf; |
|
145 qBuf = QString((QChar*)m_nwInfo.iViagTextTag.Ptr(), |
|
146 m_nwInfo.iViagTextTag.Length()); |
|
147 return qBuf; |
|
148 } |
|
149 |
|
150 /*! |
|
151 InfoWidgetNetworkHandler::homeZoneIndicatorType() |
|
152 */ |
|
153 int InfoWidgetNetworkHandler::homeZoneIndicatorType() const |
|
154 { |
|
155 int indicatorType = m_nwInfo.iViagIndicatorType; |
|
156 return indicatorType; |
|
157 } |
|
158 |
|
159 /*! |
|
160 InfoWidgetNetworkHandler::enableMcn() |
|
161 */ |
|
162 void InfoWidgetNetworkHandler::enableMcn() |
|
163 { |
|
164 DPRINT; |
|
165 if (!readMcnDisplayState()) { |
|
166 DPRINT << ": enabling mcn display cenrep"; |
|
167 writeMcnDisplayState(true); |
|
168 } |
|
169 } |
|
170 |
|
171 /*! |
|
172 InfoWidgetNetworkHandler::disableMcn() |
|
173 */ |
|
174 void InfoWidgetNetworkHandler::disableMcn() |
|
175 { |
|
176 DPRINT; |
|
177 if (readMcnDisplayState()) { |
|
178 DPRINT << ": disabling mcn display cenrep"; |
|
179 writeMcnDisplayState(false); |
|
180 } |
|
181 } |
|
182 |
|
183 /*! |
|
184 InfoWidgetNetworkHandler::mcnName() |
|
185 */ |
|
186 QString InfoWidgetNetworkHandler::mcnName() const |
|
187 { |
|
188 QString qBuf; |
|
189 qBuf = QString((QChar*)m_nwInfo.iMCNName.Ptr(), |
|
190 m_nwInfo.iMCNName.Length()); |
|
191 DPRINT << ": mcnName: " << qBuf; |
|
192 return qBuf; |
|
193 } |
|
194 |
|
195 /*! |
|
196 InfoWidgetNetworkHandler::mcnIndicatorType() |
|
197 */ |
|
198 int InfoWidgetNetworkHandler::mcnIndicatorType() const |
|
199 { |
|
200 DPRINT << ": mcnIndicatorType: " << m_nwInfo.iMCNIndicatorType; |
|
201 return m_nwInfo.iMCNIndicatorType; |
|
202 } |
|
203 |
|
204 /*! |
|
205 InfoWidgetNetworkHandler::networkRegistrationStatus() |
|
206 */ |
|
207 int InfoWidgetNetworkHandler::networkRegistrationStatus() const |
|
208 { |
|
209 DPRINT << ": networkRegistrationStatus: " |
|
210 << static_cast<int>(m_nwInfo.iRegistrationStatus); |
|
211 return static_cast<int>(m_nwInfo.iRegistrationStatus); |
|
212 } |
|
213 |
|
214 /*! |
|
215 InfoWidgetNetworkHandler::isOnline() |
|
216 |
|
217 Check if network registration status is registered and |
|
218 return status accordingly |
|
219 */ |
|
220 bool InfoWidgetNetworkHandler::isOnline() const |
|
221 { |
|
222 bool online(false); |
|
223 |
|
224 switch (networkRegistrationStatus()) { |
|
225 case ENWRegisteredBusy: // Fall through |
|
226 case ENWRegisteredOnHomeNetwork: // Fall through |
|
227 case ENWRegisteredRoaming: |
|
228 online = true; |
|
229 break; |
|
230 default: |
|
231 break; |
|
232 } |
|
233 |
|
234 DPRINT << ": online: " << online; |
|
235 return online; |
|
236 } |
|
237 |
|
238 /*! |
|
239 InfoWidgetNetworkHandler::HandleNetworkMessage() |
|
240 |
|
241 Implementation for MNWMessageObserver callback |
|
242 function |
|
243 */ |
|
244 void InfoWidgetNetworkHandler::HandleNetworkMessage( |
|
245 const TNWMessages aMessage ) |
|
246 { |
|
247 DPRINT << ": message: " << aMessage; |
|
248 |
|
249 bool acceptedMessage = false; |
|
250 switch (aMessage) { |
|
251 case ENWMessageCurrentCellInfoMessage: // Fall through |
|
252 case ENWMessageServiceProviderNameChange: // Fall through |
|
253 case ENWMessageNetworkRegistrationStatusChange: // Fall through |
|
254 acceptedMessage = true; |
|
255 break; |
|
256 default: |
|
257 // not interesting message, filter out |
|
258 DPRINT << ": message filtered out"; |
|
259 acceptedMessage = false; |
|
260 } |
|
261 |
|
262 if (acceptedMessage) { |
|
263 int result = 0; |
|
264 QT_TRYCATCH_ERROR(result, emit networkDataChanged()); |
|
265 if (0 != result) { |
|
266 DPRINT << ": Exception occured while emitting signal:" << result; |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 /*! |
|
272 InfoWidgetNetworkHandler::HandleNetworkError() |
|
273 |
|
274 Implementation for MNWMessageObserver callback |
|
275 function |
|
276 */ |
|
277 void InfoWidgetNetworkHandler::HandleNetworkError( |
|
278 const TNWOperation aOperation, |
|
279 TInt aErrorCode ) |
|
280 { |
|
281 DPRINT << ": operation: " << aOperation << |
|
282 " error code: " << aErrorCode; |
|
283 |
|
284 // Reset invalid data |
|
285 switch (aOperation) { |
|
286 case MNWMessageObserver::ENWGetServiceProviderName: |
|
287 m_nwInfo.iServiceProviderNameDisplayReq = |
|
288 RMobilePhone::KDisplaySPNNotRequired; |
|
289 m_nwInfo.iSPName.Zero(); |
|
290 break; |
|
291 default: |
|
292 break; |
|
293 } |
|
294 |
|
295 // Emit error signal |
|
296 int result = 0; |
|
297 QT_TRYCATCH_ERROR(result, emit networkError( |
|
298 static_cast<int>(aOperation), static_cast<int>(aErrorCode))); |
|
299 if (0 != result) { |
|
300 DPRINT << ": Exception occured while emitting signal:" << result; |
|
301 } |
|
302 } |
|
303 |
|
304 /*! |
|
305 InfoWidgetNetworkHandler::writeMcnDisplayState() |
|
306 |
|
307 Handler for cenrep key writing |
|
308 */ |
|
309 void InfoWidgetNetworkHandler::writeMcnDisplayState(bool enabled) |
|
310 { |
|
311 QScopedPointer<XQSettingsManager> settingsManager(new XQSettingsManager); |
|
312 XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, |
|
313 KCRUidNetworkSettings.iUid, KSettingsMcnDisplay); |
|
314 int value; |
|
315 if (enabled) { |
|
316 value = KMcnValueOn; |
|
317 } else { |
|
318 value = KMcnValueOff; |
|
319 } |
|
320 |
|
321 bool result = settingsManager->writeItemValue(settingsKey, value); |
|
322 DPRINT << ": write success: " << result << " mcn enabled: " << enabled; |
|
323 |
|
324 } |
|
325 |
|
326 /*! |
|
327 InfoWidgetNetworkHandler::readMcnDisplayState() |
|
328 */ |
|
329 bool InfoWidgetNetworkHandler::readMcnDisplayState() |
|
330 { |
|
331 QScopedPointer<XQSettingsManager> settingsManager(new XQSettingsManager); |
|
332 XQSettingsKey settingsKey(XQSettingsKey::TargetCentralRepository, |
|
333 KCRUidNetworkSettings.iUid, KSettingsMcnDisplay); |
|
334 bool success(false); |
|
335 int value = settingsManager->readItemValue( |
|
336 settingsKey, |
|
337 XQSettingsManager::TypeInt).toInt(&success); |
|
338 |
|
339 bool mcnEnabled(false); |
|
340 if (success && value == KMcnValueOn) { |
|
341 mcnEnabled = true; |
|
342 } |
|
343 |
|
344 DPRINT << ": read success: " << success << " mcn enabled: " << mcnEnabled; |
|
345 return mcnEnabled; |
|
346 } |
|
347 |
|
348 |
|
349 // End of File. |