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