Renames & Add new properties to QBatteryInfo
[qt:qtsystems.git] / src / systeminfo / simulator / qsysteminfo_simulator.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of the QtSystems module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Digia.  For licensing terms and
15 ** conditions see http://qt.digia.com/licensing.  For further information
16 ** use the contact form at http://qt.digia.com/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 2.1 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL included in the
22 ** packaging of this file.  Please review the following information to
23 ** ensure the GNU Lesser General Public License version 2.1 requirements
24 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** In addition, as a special exception, Digia gives you certain additional
27 ** rights.  These rights are described in the Digia Qt LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #include "qsysteminfo_simulator_p.h"
44 #include "qsysteminfobackend_simulator_p.h"
45 #include "qsysteminfoconnection_simulator_p.h"
46
47 #if !defined(QT_NO_OFONO)
48 #  include "qnetworkinfo_linux_p.h"
49 #endif
50
51 #include <QtCore/qmetaobject.h>
52
53 QT_BEGIN_NAMESPACE
54
55 // QBatteryInfoSimulator
56
57 QBatteryInfoSimulator::QBatteryInfoSimulator(QBatteryInfo *parent)
58     : QObject(parent)
59     , q_ptr(parent)
60     , batteryInfoSimulatorBackend(QBatteryInfoSimulatorBackend::getSimulatorBackend())
61     , index(0)
62 {
63     SystemInfoConnection::ensureSimulatorConnection();
64 }
65
66 QBatteryInfoSimulator::QBatteryInfoSimulator(int batteryIndex, QBatteryInfo *parent)
67     : QObject(parent)
68     , q_ptr(parent)
69     , batteryInfoSimulatorBackend(QBatteryInfoSimulatorBackend::getSimulatorBackend())
70     , index(batteryIndex)
71 {
72     SystemInfoConnection::ensureSimulatorConnection();
73 }
74
75 QBatteryInfoSimulator::~QBatteryInfoSimulator()
76 {
77 }
78
79 int QBatteryInfoSimulator::batteryCount()
80 {
81     if (batteryInfoSimulatorBackend)
82         return batteryInfoSimulatorBackend->getBatteryCount();
83
84     return -1;
85 }
86
87 int QBatteryInfoSimulator::batteryIndex() const
88 {
89     if (batteryInfoSimulatorBackend)
90         return batteryInfoSimulatorBackend->getBatteryIndex();
91
92     return -1;
93 }
94
95 bool QBatteryInfoSimulator::isValid()
96 {
97     // valid if the index < total count.
98     return (batteryIndex() >= 0) && (batteryIndex() < batteryCount());
99 }
100
101 void QBatteryInfoSimulator::setBatteryIndex(int batteryIndex)
102 {
103     if (batteryInfoSimulatorBackend)
104         batteryInfoSimulatorBackend->setBatteryIndex(batteryIndex);
105 }
106
107 int QBatteryInfoSimulator::level()
108 {
109     if (batteryInfoSimulatorBackend)
110         return batteryInfoSimulatorBackend->getLevel(batteryInfoSimulatorBackend->getBatteryIndex());
111
112     return -1;
113 }
114
115 int QBatteryInfoSimulator::currentFlow(int battery)
116 {
117     if (batteryInfoSimulatorBackend)
118         return batteryInfoSimulatorBackend->getCurrentFlow(battery);
119
120     return 0;
121 }
122
123 int QBatteryInfoSimulator::currentFlow()
124 {
125     return currentFlow(batteryInfoSimulatorBackend->getBatteryIndex());
126 }
127
128 int QBatteryInfoSimulator::cycleCount()
129 {
130     if (batteryInfoSimulatorBackend)
131         return batteryInfoSimulatorBackend->getCycleCount(batteryInfoSimulatorBackend->getBatteryIndex());
132
133     return -1;
134 }
135
136 int QBatteryInfoSimulator::maximumCapacity(int battery)
137 {
138     if (batteryInfoSimulatorBackend)
139         return batteryInfoSimulatorBackend->getMaximumCapacity(battery);
140
141     return -1;
142 }
143
144 int QBatteryInfoSimulator::maximumCapacity()
145 {
146     return maximumCapacity(batteryInfoSimulatorBackend->getBatteryIndex());
147 }
148
149 int QBatteryInfoSimulator::remainingCapacity(int battery)
150 {
151     if (batteryInfoSimulatorBackend)
152         return batteryInfoSimulatorBackend->getRemainingCapacity(battery);
153
154     return -1;
155 }
156
157 int QBatteryInfoSimulator::remainingCapacity()
158 {
159     return remainingCapacity(batteryInfoSimulatorBackend->getBatteryIndex());
160 }
161
162 int QBatteryInfoSimulator::remainingChargingTime(int battery)
163 {
164     if (batteryInfoSimulatorBackend)
165         return batteryInfoSimulatorBackend->getRemainingChargingTime(battery);
166
167     return -1;
168 }
169
170 int QBatteryInfoSimulator::remainingChargingTime(int battery)
171 {
172     return remainingChargingTime(batteryInfoSimulatorBackend->getBatteryIndex());
173 }
174
175 int QBatteryInfoSimulator::voltage(int battery)
176 {
177     if (batteryInfoSimulatorBackend)
178         return batteryInfoSimulatorBackend->getVoltage(battery);
179
180     return -1;
181 }
182
183 int QBatteryInfoSimulator::voltage()
184 {
185     return voltage(batteryInfoSimulatorBackend->getBatteryIndex());
186 }
187
188 QBatteryInfo::ChargerType QBatteryInfoSimulator::chargerType()
189 {
190     if (batteryInfoSimulatorBackend)
191         return batteryInfoSimulatorBackend->getChargerType();
192
193     return QBatteryInfo::UnknownCharger;
194 }
195
196 QBatteryInfo::ChargingState QBatteryInfoSimulator::chargingState(int battery)
197 {
198     if (batteryInfoSimulatorBackend)
199         return batteryInfoSimulatorBackend->getChargingState(battery);
200
201     return QBatteryInfo::UnknownChargingState;
202 }
203
204 QBatteryInfo::ChargingState QBatteryInfoSimulator::chargingState()
205 {
206     return chargingState(batteryInfoSimulatorBackend->getBatteryIndex());
207 }
208
209 QBatteryInfo::LevelStatus QBatteryInfoSimulator::levelStatus(int battery)
210 {
211     if (batteryInfoSimulatorBackend)
212         return batteryInfoSimulatorBackend->getLevelStatus(battery);
213
214     return QBatteryInfo::LevelUnknown;
215 }
216
217 QBatteryInfo::LevelStatus QBatteryInfoSimulator::levelStatus()
218 {
219     return levelStatus(batteryInfoSimulatorBackend->getBatteryIndex());
220 }
221
222 QBatteryInfo::Health QBatteryInfoSimulator::health()
223 {
224     if (batteryInfoSimulatorBackend)
225         return batteryInfoSimulatorBackend->getHealth(batteryInfoSimulatorBackend->getBatteryIndex());
226
227     return QBatteryInfo::HealthUnknown;
228 }
229
230 float QBatteryInfoSimulator::temperature()
231 {
232     if (batteryInfoSimulatorBackend)
233         return batteryInfoSimulatorBackend->getTemperature(batteryInfoSimulatorBackend->getBatteryIndex());
234
235     return -1.0f;
236 }
237
238 extern QMetaMethod proxyToSourceSignal(const QMetaMethod &, QObject *);
239
240 void QBatteryInfoSimulator::connectNotify(const QMetaMethod &signal)
241 {
242     static const QMetaMethod batteryCountChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::batteryCountChanged);
243     static const QMetaMethod chargerTypeChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::chargerTypeChanged);
244     static const QMetaMethod chargingStateChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::chargingStateChanged);
245     static const QMetaMethod currentFlowChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::currentFlowChanged);
246     static const QMetaMethod remainingCapacityChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::remainingCapacityChanged);
247     static const QMetaMethod remainingChargingTimeChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::remainingChargingTimeChanged);
248     static const QMetaMethod voltageChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::voltageChanged);
249     static const QMetaMethod levelStatusChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::levelStatusChanged);
250
251     if (batteryInfoSimulatorBackend && (signal == batteryCountChangedSignal
252                                         || signal == currentFlowChangedSignal
253                                         || signal == voltageChangedSignal
254                                         || signal == remainingCapacityChangedSignal
255                                         || signal == remainingChargingTimeChangedSignal
256                                         || signal == chargerTypeChangedSignal
257                                         || signal == chargingStateChangedSignal
258                                         || signal == levelStatusChangedSignal)) {
259         QMetaMethod sourceSignal = proxyToSourceSignal(signal, batteryInfoSimulatorBackend);
260         connect(batteryInfoSimulatorBackend, sourceSignal, this, signal);
261     }
262 }
263
264 void QBatteryInfoSimulator::disconnectNotify(const QMetaMethod &signal)
265 {
266     static const QMetaMethod batteryCountChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::batteryCountChanged);
267     static const QMetaMethod chargerTypeChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::chargerTypeChanged);
268     static const QMetaMethod chargingStateChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::chargingStateChanged);
269     static const QMetaMethod currentFlowChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::currentFlowChanged);
270     static const QMetaMethod remainingCapacityChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::remainingCapacityChanged);
271     static const QMetaMethod remainingChargingTimeChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::remainingChargingTimeChanged);
272     static const QMetaMethod voltageChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::voltageChanged);
273     static const QMetaMethod levelStatusChangedSignal = QMetaMethod::fromSignal(&QBatteryInfoSimulator::levelStatusChanged);
274
275     if (batteryInfoSimulatorBackend && (signal == batteryCountChangedSignal
276                                         || signal == currentFlowChangedSignal
277                                         || signal == voltageChangedSignal
278                                         || signal == remainingCapacityChangedSignal
279                                         || signal == remainingChargingTimeChangedSignal
280                                         || signal == chargerTypeChangedSignal
281                                         || signal == chargingStateChangedSignal
282                                         || signal == levelStatusChangedSignal)) {
283         QMetaMethod sourceSignal = proxyToSourceSignal(signal, batteryInfoSimulatorBackend);
284         disconnect(batteryInfoSimulatorBackend, sourceSignal, this, signal);
285     }
286 }
287
288
289 // QDeviceInfoSimulator
290
291 QDeviceInfoSimulator::QDeviceInfoSimulator(QDeviceInfo *parent)
292     : QObject(parent)
293     , q_ptr(parent)
294     , deviceInfoSimulatorBackend(QDeviceInfoSimulatorBackend::getSimulatorBackend())
295 {
296     SystemInfoConnection::ensureSimulatorConnection();
297 }
298
299 QDeviceInfoSimulator::~QDeviceInfoSimulator()
300 {
301 }
302
303 bool QDeviceInfoSimulator::hasFeature(QDeviceInfo::Feature feature)
304 {
305     if (deviceInfoSimulatorBackend)
306         return deviceInfoSimulatorBackend->hasFeature(feature);
307
308     return false;
309 }
310
311 QDeviceInfo::LockTypeFlags QDeviceInfoSimulator::activatedLocks()
312 {
313     if (deviceInfoSimulatorBackend)
314         return deviceInfoSimulatorBackend->getActivatedLocks();
315
316     return QDeviceInfo::NoLock;
317 }
318
319 QDeviceInfo::LockTypeFlags QDeviceInfoSimulator::enabledLocks()
320 {
321     if (deviceInfoSimulatorBackend)
322         return deviceInfoSimulatorBackend->getEnabledLocks();
323
324     return QDeviceInfo::NoLock;
325 }
326
327 QDeviceInfo::ThermalState QDeviceInfoSimulator::thermalState()
328 {
329     if (deviceInfoSimulatorBackend)
330         return deviceInfoSimulatorBackend->getThermalState();
331
332     return QDeviceInfo::UnknownThermal;
333 }
334
335 int QDeviceInfoSimulator::imeiCount()
336 {
337     if (deviceInfoSimulatorBackend)
338         return deviceInfoSimulatorBackend->getImeiCount();
339
340     return -1;
341 }
342
343 QString QDeviceInfoSimulator::imei(int interface)
344 {
345     if (deviceInfoSimulatorBackend)
346         return deviceInfoSimulatorBackend->getImei(interface);
347
348     return QString();
349 }
350
351 QString QDeviceInfoSimulator::manufacturer()
352 {
353     if (deviceInfoSimulatorBackend)
354         return deviceInfoSimulatorBackend->getManufacturer();
355
356     return QString();
357 }
358
359 QString QDeviceInfoSimulator::model()
360 {
361     if (deviceInfoSimulatorBackend)
362         return deviceInfoSimulatorBackend->getModel();
363
364     return QString();
365 }
366
367 QString QDeviceInfoSimulator::productName()
368 {
369     if (deviceInfoSimulatorBackend)
370         return deviceInfoSimulatorBackend->getProductName();
371
372     return QString();
373 }
374
375 QString QDeviceInfoSimulator::uniqueDeviceID()
376 {
377     if (deviceInfoSimulatorBackend)
378         return deviceInfoSimulatorBackend->getUniqueDeviceID();
379
380     return QString();
381 }
382
383 QString QDeviceInfoSimulator::version(QDeviceInfo::Version type)
384 {
385     if (deviceInfoSimulatorBackend)
386         return deviceInfoSimulatorBackend->getVersion(type);
387
388     return QString();
389 }
390
391 QString QDeviceInfoSimulator::operatingSystemName()
392 {
393     return QString();
394 }
395
396 QString QDeviceInfoSimulator::boardName()
397 {
398     return QString();
399 }
400
401 void QDeviceInfoSimulator::connectNotify(const QMetaMethod &signal)
402 {
403     static const QMetaMethod activatedLocksChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::activatedLocksChanged);
404     static const QMetaMethod enabledLocksChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::enabledLocksChanged);
405     static const QMetaMethod thermalStateChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::thermalStateChanged);
406
407     if (signal == activatedLocksChangedSignal || signal == enabledLocksChangedSignal) {
408         if (deviceInfoSimulatorBackend) {
409             QMetaMethod sourceSignal = proxyToSourceSignal(signal, deviceInfoSimulatorBackend);
410             connect(deviceInfoSimulatorBackend, sourceSignal, this, signal);
411         }
412         return;
413     }
414
415     if (deviceInfoSimulatorBackend && signal == thermalStateChangedSignal) {
416         QMetaMethod sourceSignal = proxyToSourceSignal(signal, deviceInfoSimulatorBackend);
417         connect(deviceInfoSimulatorBackend, sourceSignal, this, signal);
418     }
419 }
420
421 void QDeviceInfoSimulator::disconnectNotify(const QMetaMethod &signal)
422 {
423     static const QMetaMethod activatedLocksChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::activatedLocksChanged);
424     static const QMetaMethod enabledLocksChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::enabledLocksChanged);
425     static const QMetaMethod thermalStateChangedSignal = QMetaMethod::fromSignal(&QDeviceInfoSimulator::thermalStateChanged);
426
427     if (signal == activatedLocksChangedSignal || signal == enabledLocksChangedSignal) {
428         if (deviceInfoSimulatorBackend) {
429             QMetaMethod sourceSignal = proxyToSourceSignal(signal, deviceInfoSimulatorBackend);
430             disconnect(deviceInfoSimulatorBackend, sourceSignal, this, signal);
431         }
432         return;
433     }
434
435     if (deviceInfoSimulatorBackend && signal == thermalStateChangedSignal) {
436         QMetaMethod sourceSignal = proxyToSourceSignal(signal, deviceInfoSimulatorBackend);
437         disconnect(deviceInfoSimulatorBackend, sourceSignal, this, signal);
438     }
439 }
440
441 bool QDeviceInfoSimulator::currentBluetoothPowerState()
442 {
443     return false;
444 }
445
446 // QNetworkInfoSimulator
447
448 QNetworkInfoSimulator::QNetworkInfoSimulator(QNetworkInfo *parent)
449     : QObject(parent)
450     , q_ptr(parent)
451     , networkInfoSimulatorBackend(QNetworkInfoSimulatorBackend::getSimulatorBackend())
452 #if !defined(QT_NO_OFONO)
453     , d_ptr(new QNetworkInfoPrivate())
454 #endif
455 {
456     SystemInfoConnection::ensureSimulatorConnection();
457 }
458
459 QNetworkInfoSimulator::~QNetworkInfoSimulator()
460 {
461 #if !defined(QT_NO_OFONO)
462     delete d_ptr;
463 #endif
464 }
465
466 int QNetworkInfoSimulator::networkInterfaceCount(QNetworkInfo::NetworkMode mode)
467 {
468 #if !defined(QT_NO_OFONO)
469     if (mode != QNetworkInfo::WlanMode) {
470         if (d_ptr)
471             return d_ptr->networkInterfaceCount(mode);
472         else
473             return -1;
474     }
475 #endif
476     if (networkInfoSimulatorBackend)
477         return networkInfoSimulatorBackend->getNetworkInterfaceCount(mode);
478     return -1;
479 }
480
481 int QNetworkInfoSimulator::networkSignalStrength(QNetworkInfo::NetworkMode mode, int interface)
482 {
483 #if !defined(QT_NO_OFONO)
484     if (mode != QNetworkInfo::WlanMode) {
485         if (d_ptr)
486             return d_ptr->networkSignalStrength(mode, interface);
487         else
488             return -1;
489     }
490 #endif
491     if (networkInfoSimulatorBackend)
492         return networkInfoSimulatorBackend->getNetworkSignalStrength(mode, interface);
493     return -1;
494 }
495
496 QNetworkInfo::CellDataTechnology QNetworkInfoSimulator::currentCellDataTechnology(int interface)
497 {
498 #if !defined(QT_NO_OFONO)
499         if (d_ptr)
500             return d_ptr->currentCellDataTechnology(interface);
501         else
502             return QNetworkInfo::UnknownDataTechnology;
503 #endif
504     if (networkInfoSimulatorBackend)
505         return networkInfoSimulatorBackend->getCurrentCellDataTechnology(interface);
506     return QNetworkInfo::UnknownDataTechnology;
507 }
508
509 QNetworkInfo::NetworkMode QNetworkInfoSimulator::currentNetworkMode()
510 {
511     QNetworkInfo::NetworkMode mode = QNetworkInfo::UnknownMode;
512     if (networkInfoSimulatorBackend)
513         mode = networkInfoSimulatorBackend->getCurrentNetworkMode();
514 #if !defined(QT_NO_OFONO)
515     QNetworkInfo::NetworkMode mode2 = QNetworkInfo::UnknownMode;
516         if (d_ptr)
517             mode2 = d_ptr->currentNetworkMode();
518         switch (mode) {
519         case QNetworkInfo::WlanMode:
520             if (mode2 == QNetworkInfo::EthernetMode)
521                 mode = mode2;
522             break;
523         default:
524             mode = mode2;
525             break;
526         }
527
528 #endif
529     return mode;
530 }
531
532 QNetworkInfo::NetworkStatus QNetworkInfoSimulator::networkStatus(QNetworkInfo::NetworkMode mode, int interface)
533 {
534 #if !defined(QT_NO_OFONO)
535     if (mode != QNetworkInfo::WlanMode) {
536         if (d_ptr)
537             return d_ptr->networkStatus(mode, interface);
538         else
539             return QNetworkInfo::UnknownStatus;
540     }
541 #endif
542     if (networkInfoSimulatorBackend)
543         return networkInfoSimulatorBackend->getNetworkStatus(mode, interface);
544     return QNetworkInfo::UnknownStatus;
545 }
546
547 #ifndef QT_NO_NETWORKINTERFACE
548 QNetworkInterface QNetworkInfoSimulator::interfaceForMode(QNetworkInfo::NetworkMode mode, int interface)
549 {
550 #if !defined(QT_NO_OFONO)
551     if (mode != QNetworkInfo::WlanMode) {
552         if (d_ptr)
553             return d_ptr->interfaceForMode(mode, interface);
554         else
555             return QNetworkInterface();
556     }
557 #endif
558     if (networkInfoSimulatorBackend)
559         return networkInfoSimulatorBackend->getInterfaceForMode(mode, interface);
560     return QNetworkInterface();
561 }
562 #endif // QT_NO_NETWORKINTERFACE
563
564 QString QNetworkInfoSimulator::cellId(int interface)
565 {
566 #if !defined(QT_NO_OFONO)
567     if (d_ptr)
568         return d_ptr->cellId(interface);
569     else
570         return QString();
571 #endif
572     if (networkInfoSimulatorBackend)
573         return networkInfoSimulatorBackend->getCellId(interface);
574     return QString();
575 }
576
577 QString QNetworkInfoSimulator::currentMobileCountryCode(int interface)
578 {
579 #if !defined(QT_NO_OFONO)
580     if (d_ptr)
581         return d_ptr->currentMobileCountryCode(interface);
582     else
583         return QString();
584 #endif
585     if (networkInfoSimulatorBackend)
586         return networkInfoSimulatorBackend->getCurrentMobileCountryCode(interface);
587     return QString();
588 }
589
590 QString QNetworkInfoSimulator::currentMobileNetworkCode(int interface)
591 {
592 #if !defined(QT_NO_OFONO)
593     if (d_ptr)
594         return d_ptr->currentMobileNetworkCode(interface);
595     else
596         return QString();
597 #endif
598     if (networkInfoSimulatorBackend)
599         return networkInfoSimulatorBackend->getCurrentMobileNetworkCode(interface);
600     return QString();
601 }
602
603 QString QNetworkInfoSimulator::homeMobileCountryCode(int interface)
604 {
605 #if !defined(QT_NO_OFONO)
606     if (d_ptr)
607         return d_ptr->homeMobileCountryCode(interface);
608     else
609         return QString();
610 #endif
611     if (networkInfoSimulatorBackend)
612         return networkInfoSimulatorBackend->getHomeMobileCountryCode(interface);
613     return QString();
614 }
615
616 QString QNetworkInfoSimulator::homeMobileNetworkCode(int interface)
617 {
618 #if !defined(QT_NO_OFONO)
619     if (d_ptr)
620         return d_ptr->homeMobileNetworkCode(interface);
621     else
622         return QString();
623 #endif
624     if (networkInfoSimulatorBackend)
625         return networkInfoSimulatorBackend->getHomeMobileNetworkCode(interface);
626     return QString();
627 }
628
629 QString QNetworkInfoSimulator::imsi(int interface)
630 {
631 #if !defined(QT_NO_OFONO)
632     if (d_ptr)
633         return d_ptr->imsi(interface);
634     else
635         return QString();
636 #endif
637     if (networkInfoSimulatorBackend)
638         return networkInfoSimulatorBackend->getImsi(interface);
639     return QString();
640 }
641
642 QString QNetworkInfoSimulator::locationAreaCode(int interface)
643 {
644 #if !defined(QT_NO_OFONO)
645     if (d_ptr)
646         return d_ptr->locationAreaCode(interface);
647     else
648         return QString();
649 #endif
650     if (networkInfoSimulatorBackend)
651         return networkInfoSimulatorBackend->getLocationAreaCode(interface);
652     return QString();
653 }
654
655 QString QNetworkInfoSimulator::macAddress(QNetworkInfo::NetworkMode mode, int interface)
656 {
657 #if !defined(QT_NO_OFONO)
658     if (mode != QNetworkInfo::WlanMode) {
659         if (d_ptr)
660             return d_ptr->macAddress(mode, interface);
661         else
662             return QString();
663     }
664 #endif
665     if (networkInfoSimulatorBackend)
666         return networkInfoSimulatorBackend->getMacAddress(mode, interface);
667     return QString();
668 }
669
670 QString QNetworkInfoSimulator::networkName(QNetworkInfo::NetworkMode mode, int interface)
671 {
672 #if !defined(QT_NO_OFONO)
673     if (mode != QNetworkInfo::WlanMode) {
674         if (d_ptr)
675             return d_ptr->networkName(mode, interface);
676         else
677             return QString();
678     }
679 #endif
680     if (networkInfoSimulatorBackend)
681         return networkInfoSimulatorBackend->getNetworkName(mode, interface);
682     return QString();
683 }
684
685 void QNetworkInfoSimulator::connectNotify(const QMetaMethod &signal)
686 {
687     static const QMetaMethod networkInterfaceCountChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkInterfaceCountChanged);
688     static const QMetaMethod currentNetworkModeChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::currentNetworkModeChanged);
689     static const QMetaMethod networkNameChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkNameChanged);
690     static const QMetaMethod networkSignalStrengthChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkSignalStrengthChanged);
691     static const QMetaMethod networkStatusChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkStatusChanged);
692
693 #if !defined(QT_NO_OFONO)
694     if (signal == networkInterfaceCountChangedSignal) {
695         if (networkInfoSimulatorBackend)
696             connect(networkInfoSimulatorBackend, SIGNAL(networkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), this, SLOT(onNetworkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), Qt::UniqueConnection);
697         if (d_ptr)
698             connect(d_ptr, SIGNAL(networkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), this, SLOT(onNetworkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), Qt::UniqueConnection);
699         return;
700     } else if (signal == currentNetworkModeChangedSignal) {
701         if (networkInfoSimulatorBackend)
702             connect(networkInfoSimulatorBackend, SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)), this, SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)), Qt::UniqueConnection);
703         if (d_ptr)
704             connect(d_ptr, SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)), this, SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)), Qt::UniqueConnection);
705         return;
706     } else if (signal == networkNameChangedSignal) {
707         if (networkInfoSimulatorBackend)
708             connect(networkInfoSimulatorBackend, SIGNAL(networkNameChanged(QNetworkInfo::NetworkMode,int,QString)), this, SLOT(onNetworkNameChanged(QNetworkInfo::NetworkMode,int,QString)), Qt::UniqueConnection);
709         if (d_ptr)
710             connect(d_ptr, SIGNAL(networkNameChanged(QNetworkInfo::NetworkMode,int,QString)), this, SLOT(onNetworkNameChanged(QNetworkInfo::NetworkMode,int,QString)), Qt::UniqueConnection);
711         return;
712     } else if (signal == networkSignalStrengthChangedSignal) {
713         if (networkInfoSimulatorBackend)
714             connect(networkInfoSimulatorBackend, SIGNAL(networkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), this, SLOT(onNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), Qt::UniqueConnection);
715         if (d_ptr)
716             connect(d_ptr, SIGNAL(networkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), this, SLOT(onNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), Qt::UniqueConnection);
717         return;
718     } else if (signal == networkStatusChangedSignal) {
719         if (networkInfoSimulatorBackend)
720             connect(networkInfoSimulatorBackend, SIGNAL(networkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), this, SLOT(onNetworkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), Qt::UniqueConnection);
721         if (d_ptr)
722             connect(d_ptr, SIGNAL(networkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), this, SLOT(onNetworkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), Qt::UniqueConnection);
723         return;
724     }
725 #endif
726     if (networkInfoSimulatorBackend) {
727         QMetaMethod sourceSignal = proxyToSourceSignal(signal, networkInfoSimulatorBackend);
728         connect(networkInfoSimulatorBackend, sourceSignal, this, signal, Qt::UniqueConnection);
729     }
730 }
731
732 void QNetworkInfoSimulator::disconnectNotify(const QMetaMethod &signal)
733 {
734     static const QMetaMethod networkInterfaceCountChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkInterfaceCountChanged);
735     static const QMetaMethod currentNetworkModeChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::currentNetworkModeChanged);
736     static const QMetaMethod networkNameChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkNameChanged);
737     static const QMetaMethod networkSignalStrengthChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkSignalStrengthChanged);
738     static const QMetaMethod networkStatusChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoSimulator::networkStatusChanged);
739
740 #if !defined(QT_NO_OFONO)
741     if (signal == networkInterfaceCountChangedSignal) {
742         if (networkInfoSimulatorBackend)
743             disconnect(networkInfoSimulatorBackend, SIGNAL(networkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), this, SLOT(onNetworkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)));
744         if (d_ptr)
745             disconnect(d_ptr, SIGNAL(networkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)), this, SLOT(onNetworkInterfaceCountChanged(QNetworkInfo::NetworkMode,int)));
746         return;
747     } else if (signal == currentNetworkModeChangedSignal) {
748         if (networkInfoSimulatorBackend)
749             disconnect(networkInfoSimulatorBackend, SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)), this, SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)));
750         if (d_ptr)
751             disconnect(d_ptr, SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)), this, SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)));
752         return;
753     } else if (signal == networkNameChangedSignal) {
754         if (networkInfoSimulatorBackend)
755             disconnect(networkInfoSimulatorBackend, SIGNAL(networkNameChanged(QNetworkInfo::NetworkMode,int,QString)), this, SLOT(onNetworkNameChanged(QNetworkInfo::NetworkMode,int,QString)));
756         if (d_ptr)
757             disconnect(d_ptr, SIGNAL(networkNameChanged(QNetworkInfo::NetworkMode,int,QString)), this, SLOT(onNetworkNameChanged(QNetworkInfo::NetworkMode,int,QString)));
758         return;
759     } else if (signal == networkSignalStrengthChangedSignal) {
760         if (networkInfoSimulatorBackend)
761             disconnect(networkInfoSimulatorBackend, SIGNAL(networkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), this, SLOT(onNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)));
762         if (d_ptr)
763             disconnect(d_ptr, SIGNAL(networkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)), this, SLOT(onNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode,int,int)));
764         return;
765     } else if (signal == networkStatusChangedSignal) {
766         if (networkInfoSimulatorBackend)
767             disconnect(networkInfoSimulatorBackend, SIGNAL(networkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), this, SLOT(onNetworkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)));
768         if (d_ptr)
769             disconnect(d_ptr, SIGNAL(networkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)), this, SLOT(onNetworkStatusChanged(QNetworkInfo::NetworkMode,int,QNetworkInfo::NetworkStatus)));
770         return;
771     }
772 #endif
773     if (networkInfoSimulatorBackend) {
774         QMetaMethod sourceSignal = proxyToSourceSignal(signal, networkInfoSimulatorBackend);
775         disconnect(networkInfoSimulatorBackend, sourceSignal, this, signal);
776     }
777 }
778
779 #if !defined(QT_NO_OFONO)
780
781 void QNetworkInfoSimulator::onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode)
782 {
783     Q_UNUSED(mode)
784     emit currentNetworkModeChanged(currentNetworkMode());
785 }
786
787 void QNetworkInfoSimulator::onNetworkInterfaceCountChanged(QNetworkInfo::NetworkMode mode, int count)
788 {
789     if (strcmp(sender()->metaObject()->className(), "QNetworkInfoSimulatorBackend") == 0) {
790         if (mode == QNetworkInfo::WlanMode)
791             emit networkInterfaceCountChanged(mode, count);
792     } else {
793         if (mode != QNetworkInfo::WlanMode)
794             emit networkInterfaceCountChanged(mode, count);
795     }
796 }
797
798 void QNetworkInfoSimulator::onNetworkNameChanged(QNetworkInfo::NetworkMode mode, int interface, const QString &name)
799 {
800     if (strcmp(sender()->metaObject()->className(), "QNetworkInfoSimulatorBackend") == 0) {
801         if (mode == QNetworkInfo::WlanMode)
802             emit networkNameChanged(mode, interface, name);
803     } else {
804         if (mode != QNetworkInfo::WlanMode)
805             emit networkNameChanged(mode, interface, name);
806     }
807 }
808
809 void QNetworkInfoSimulator::onNetworkSignalStrengthChanged(QNetworkInfo::NetworkMode mode, int interface, int strength)
810 {
811     if (strcmp(sender()->metaObject()->className(), "QNetworkInfoSimulatorBackend") == 0) {
812         if (mode == QNetworkInfo::WlanMode)
813             emit networkSignalStrengthChanged(mode, interface, strength);
814     } else {
815         if (mode != QNetworkInfo::WlanMode)
816             emit networkSignalStrengthChanged(mode, interface, strength);
817     }
818 }
819
820 void QNetworkInfoSimulator::onNetworkStatusChanged(QNetworkInfo::NetworkMode mode, int interface, QNetworkInfo::NetworkStatus status)
821 {
822     if (strcmp(sender()->metaObject()->className(), "QNetworkInfoSimulatorBackend") == 0) {
823         if (mode == QNetworkInfo::WlanMode)
824             emit networkStatusChanged(mode, interface, status);
825     } else {
826         if (mode != QNetworkInfo::WlanMode)
827             emit networkStatusChanged(mode, interface, status);
828     }
829 }
830
831 #endif
832
833 QT_END_NAMESPACE