Renames & Add new properties to QBatteryInfo
[qt:qtsystems.git] / src / systeminfo / simulator / qsysteminfobackend_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 "qsysteminfobackend_simulator_p.h"
44
45 #include <QMutex>
46
47 QT_BEGIN_NAMESPACE
48
49 QBatteryInfoSimulatorBackend *QBatteryInfoSimulatorBackend::globalSimulatorBackend = 0;
50 QDeviceInfoSimulatorBackend *QDeviceInfoSimulatorBackend::globalSimulatorBackend = 0;
51 QNetworkInfoSimulatorBackend *QNetworkInfoSimulatorBackend::globalSimulatorBackend = 0;
52
53
54 // QBatteryInfoSimulatorBackend
55
56 QBatteryInfoSimulatorBackend::QBatteryInfoSimulatorBackend(QObject *parent)
57     : QObject(parent)
58 {
59     data.index = 0;
60     data.currentFlow = 0;
61     data.cycleCount = -1;
62     data.maximumCapacity = -1;
63     data.remainingCapacity = -1;
64     data.remainingChargingTime = -1;
65     data.voltage = -1;
66     data.chargingState = QBatteryInfo::UnknownChargingState;
67     data.chargerType = QBatteryInfo::UnknownCharger;
68     data.levelStatus = QBatteryInfo::LevelUnknown;
69 }
70
71 QBatteryInfoSimulatorBackend::~QBatteryInfoSimulatorBackend()
72 {
73 }
74
75 QBatteryInfoSimulatorBackend *QBatteryInfoSimulatorBackend::getSimulatorBackend()
76 {
77     static QMutex mutex;
78
79     mutex.lock();
80     if (!globalSimulatorBackend)
81         globalSimulatorBackend = new QBatteryInfoSimulatorBackend();
82     mutex.unlock();
83
84     return globalSimulatorBackend;
85 }
86
87
88 int QBatteryInfoSimulatorBackend::getBatteryCount()
89 {
90     return 1;
91 }
92
93 int QBatteryInfoSimulatorBackend::getBatteryIndex() const
94 {
95     return data.index;
96 }
97
98 int QBatteryInfoSimulatorBackend::getLevel(int battery)
99 {
100     if (battery == 0) {
101         int maxCapacity = getMaximumCapacity(battery);
102         int remCapacity = getRemainingCemainingCapacity(battery);
103
104         if (maxCapacity == 0)
105             return -1;
106
107         return remCapacity * 100 / maxCapacity;
108     }
109
110     return -1;
111 }
112
113 int QBatteryInfoSimulatorBackend::getCurrentFlow(int battery)
114 {
115     if (battery == 0)
116         return data.currentFlow;
117     return -1;
118 }
119
120 int QBatteryInfoSimulatorBackend::getCycleCount(int battery)
121 {
122     if (battery == 0)
123         return data.cycleCount;
124
125     return -1;
126 }
127
128 int QBatteryInfoSimulatorBackend::getMaximumCapacity(int battery)
129 {
130     if (battery == 0)
131         return data.maximumCapacity;
132     return -1;
133 }
134
135 int QBatteryInfoSimulatorBackend::getRemainingCapacity(int battery)
136 {
137     if (battery == 0)
138         return data.remainingCapacity;
139     return -1;
140 }
141
142 int QBatteryInfoSimulatorBackend::getRemainingChargingTime(int battery)
143 {
144     if (battery == 0)
145         return data.remainingChargingTime;
146     return -1;
147 }
148
149 int QBatteryInfoSimulatorBackend::getVoltage(int battery)
150 {
151     if (battery == 0)
152         return data.voltage;
153     return -1;
154 }
155
156 QBatteryInfo::ChargingState QBatteryInfoSimulatorBackend::getChargingState(int battery)
157 {
158     if (battery == 0)
159         return data.chargingState;
160
161     return QBatteryInfo::UnknownChargingState;
162 }
163
164 QBatteryInfo::ChargerType QBatteryInfoSimulatorBackend::getChargerType()
165 {
166     return data.chargerType;
167 }
168
169 QBatteryInfo::LevelStatus QBatteryInfoSimulatorBackend::getLevelStatus(int battery)
170 {
171     if (battery == 0)
172         return data.levelStatus;
173
174     return QBatteryInfo::LevelUnknown;
175 }
176
177 QBatteryInfo::Health QBatteryInfoSimulatorBackend::getHealth(int battery)
178 {
179     if (battery == 0)
180         return data.health;
181
182     return QBatteryInfo::HealthUnknown;
183 }
184
185 float QBatteryInfoSimulatorBackend::getTemperature(int battery)
186 {
187     if (battery == 0)
188         return data.temperature;
189
190     return -1.0f;
191 }
192
193 void QBatteryInfoSimulatorBackend::setBatteryIndex(int batteryIndex)
194 {
195     if (data.index != batteryIndex) {
196         data.index = batteryIndex;
197         emit batteryIndexChanged(data.index);
198     }
199 }
200
201 void QBatteryInfoSimulatorBackend::setCurrentFlow(int flow)
202 {
203     if (data.currentFlow != flow) {
204         data.currentFlow = flow;
205         emit currentFlowChanged(flow);
206     }
207 }
208
209 void QBatteryInfoSimulatorBackend::setCycleCount(int cycleCount)
210 {
211     if (data.cycleCount != cycleCount) {
212         data.cycleCount = cycleCount;
213         emit cycleCountChanged(cycleCount);
214     }
215 }
216
217 void QBatteryInfoSimulatorBackend::setMaximumCapacity(int capacity)
218 {
219     if (data.maximumCapacity != capacity) {
220         int levelBefore = getLevel(0);
221         data.maximumCapacity = capacity;
222         int levelNow = getLevel(0);
223         if (levelBefore != levelNow) {
224             emit levelChanged(levelNow);
225         }
226     }
227 }
228
229 void QBatteryInfoSimulatorBackend::setRemainingCapacity(int capacity)
230 {
231     if (data.remainingCapacity != capacity) {
232         int levelBefore = getLevel(0);
233         data.remainingCapacity = capacity;
234         emit remainingCapacityChanged(capacity);
235         int levelNow = getLevel(0);
236         if (levelBefore != levelNow) {
237             emit levelChanged(levelNow);
238         }
239     }
240 }
241
242 void QBatteryInfoSimulatorBackend::setVoltage(int vol)
243 {
244     if (data.voltage != vol) {
245         data.voltage = vol;
246         emit voltageChanged(vol);
247     }
248 }
249
250 void QBatteryInfoSimulatorBackend::setRemainingChargingTime(int time)
251 {
252     if (data.remainingChargingTime != time) {
253         data.remainingChargingTime = time;
254         emit remainingChargingTimeChanged(time);
255     }
256 }
257
258 void QBatteryInfoSimulatorBackend::setChargingState(QBatteryInfo::ChargingState state)
259 {
260     if (data.chargingState != state) {
261         data.chargingState = state;
262         emit chargingStateChanged(state);
263     }
264 }
265
266 void QBatteryInfoSimulatorBackend::setChargerType(QBatteryInfo::ChargerType type)
267 {
268     if (data.chargerType != type) {
269         data.chargerType = type;
270         emit chargerTypeChanged(type);
271     }
272 }
273
274 void QBatteryInfoSimulatorBackend::setLevelStatus(QBatteryInfo::LevelStatus levelStatus)
275 {
276     if (data.levelStatus != levelStatus) {
277         data.levelStatus = levelStatus;
278         emit levelStatusChanged(levelStatus);
279     }
280 }
281
282 void QBatteryInfoSimulatorBackend::setHealth(QBatteryInfo::Health health)
283 {
284     if (data.health != health) {
285         data.health = health;
286         emit healthChanged(health);
287     }
288 }
289
290 void QBatteryInfoSimulatorBackend::setTemperature(float temperature)
291 {
292     if (!qFuzzyCompare(data.temperature, temperature)) {
293         data.temperature = temperature;
294         emit temperatureChanged(temperature);
295     }
296 }
297
298 // QDeviceInfoSimulatorBackend
299
300 QDeviceInfoSimulatorBackend::QDeviceInfoSimulatorBackend(QObject *parent)
301     : QObject(parent)
302 {
303     initFeatureList();
304     initImeiList();
305     initVersionList();
306     data.enabledLocks = QDeviceInfo::NoLock;
307     data.activatedLocks = QDeviceInfo::NoLock;
308     data.currentThermalState = QDeviceInfo::UnknownThermal;
309     data.manufacturer = QStringLiteral("Simulator Manufacturer");
310     data.model = QStringLiteral("Simulator Model");
311     data.productName =  QStringLiteral("Simulator Product Name");
312     data.uniqueDeviceID =  QStringLiteral("");
313 }
314
315 QDeviceInfoSimulatorBackend::~QDeviceInfoSimulatorBackend()
316 {
317 }
318
319 QDeviceInfoSimulatorBackend *QDeviceInfoSimulatorBackend::getSimulatorBackend()
320 {
321     static QMutex mutex;
322
323     mutex.lock();
324     if (!globalSimulatorBackend)
325         globalSimulatorBackend = new QDeviceInfoSimulatorBackend();
326     mutex.unlock();
327
328     return globalSimulatorBackend;
329 }
330
331 void QDeviceInfoSimulatorBackend::initFeatureList()
332 {
333     data.featureList.insert(QDeviceInfo::BluetoothFeature, false);
334     data.featureList.insert(QDeviceInfo::CameraFeature, false);
335     data.featureList.insert(QDeviceInfo::FmRadioFeature, false);
336     data.featureList.insert(QDeviceInfo::FmTransmitterFeature, false);
337     data.featureList.insert(QDeviceInfo::InfraredFeature, false);
338     data.featureList.insert(QDeviceInfo::LedFeature, false);
339     data.featureList.insert(QDeviceInfo::MemoryCardFeature, false);
340     data.featureList.insert(QDeviceInfo::UsbFeature, false);
341     data.featureList.insert(QDeviceInfo::VibrationFeature, false);
342     data.featureList.insert(QDeviceInfo::WlanFeature, false);
343     data.featureList.insert(QDeviceInfo::SimFeature, false);
344     data.featureList.insert(QDeviceInfo::PositioningFeature, false);
345     data.featureList.insert(QDeviceInfo::VideoOutFeature, false);
346     data.featureList.insert(QDeviceInfo::HapticsFeature, false);
347     data.featureList.insert(QDeviceInfo::NfcFeature, false);
348 }
349
350 void QDeviceInfoSimulatorBackend::initImeiList()
351 {
352     data.imeiList.insert(0, QStringLiteral("000000000000000"));
353     data.imeiList.insert(0, QStringLiteral("111111111111111"));
354 }
355
356 void QDeviceInfoSimulatorBackend::initVersionList()
357 {
358     data.versionList[QDeviceInfo::Os] = QStringLiteral("1.0");
359     data.versionList[QDeviceInfo::Firmware] = QStringLiteral("1.0");
360 }
361
362 bool QDeviceInfoSimulatorBackend::hasFeature(QDeviceInfo::Feature feature)
363 {
364     QHash<QDeviceInfo::Feature, bool>::const_iterator i = data.featureList.find(feature);
365     if (i != data.featureList.end())
366         return i.value();
367
368     return false;
369 }
370
371 int QDeviceInfoSimulatorBackend::getImeiCount()
372 {
373     return data.imeiList.count();
374 }
375
376 QDeviceInfo::LockTypeFlags QDeviceInfoSimulatorBackend::getActivatedLocks()
377 {
378     return data.activatedLocks;
379 }
380
381 QDeviceInfo::LockTypeFlags QDeviceInfoSimulatorBackend::getEnabledLocks()
382 {
383     return data.enabledLocks;
384 }
385
386 QDeviceInfo::ThermalState QDeviceInfoSimulatorBackend::getThermalState()
387 {
388     return data.currentThermalState;
389 }
390
391 QString QDeviceInfoSimulatorBackend::getImei(int num)
392 {
393     if (num >= 0 && num < data.imeiList.count())
394         return data.imeiList.at(num);
395     return QString();
396 }
397
398 QString QDeviceInfoSimulatorBackend::getManufacturer()
399 {
400     return data.manufacturer;
401 }
402
403 QString QDeviceInfoSimulatorBackend::getModel()
404 {
405     return data.model;
406 }
407
408 QString QDeviceInfoSimulatorBackend::getProductName()
409 {
410     return data.productName;
411 }
412
413 QString QDeviceInfoSimulatorBackend::getUniqueDeviceID()
414 {
415     return data.uniqueDeviceID;
416 }
417
418 QString QDeviceInfoSimulatorBackend::getVersion(QDeviceInfo::Version version)
419 {
420     QMap<QDeviceInfo::Version, QString>::const_iterator i = data.versionList.find(version);
421     if (i != data.versionList.end())
422         return i.value();
423
424     return QString();
425 }
426
427 void QDeviceInfoSimulatorBackend::setFeature(QDeviceInfo::Feature feature, bool enable)
428 {
429     QHash<QDeviceInfo::Feature, bool>::iterator i = data.featureList.find(feature);
430     if (i != data.featureList.end() && i.value() != enable)
431         data.featureList[feature] = enable;
432 }
433
434 void QDeviceInfoSimulatorBackend::setActivatedLocks(QDeviceInfo::LockTypeFlags flag)
435 {
436     if (data.activatedLocks != flag) {
437         data.activatedLocks = flag;
438         emit activatedLocksChanged(flag);
439     }
440 }
441
442 void QDeviceInfoSimulatorBackend::setEnabledLocks(QDeviceInfo::LockTypeFlags flag)
443 {
444     if (data.enabledLocks != flag) {
445         data.enabledLocks = flag;
446         emit enabledLocksChanged(flag);
447     }
448 }
449
450 void QDeviceInfoSimulatorBackend::setThermalState(QDeviceInfo::ThermalState state)
451 {
452     if (data.currentThermalState != state) {
453         data.currentThermalState = state;
454         emit thermalStateChanged(state);
455     }
456
457 }
458
459 void QDeviceInfoSimulatorBackend::setImei(int num, QString imei)
460 {
461     if (num >= 0 && num < data.imeiList.count()) {
462         if (data.imeiList[num] != imei)
463             data.imeiList[num] = imei;
464     }
465 }
466
467 void QDeviceInfoSimulatorBackend::setManufacturer(QString manufacturer)
468 {
469     if (data.manufacturer != manufacturer)
470         data.manufacturer = manufacturer;
471 }
472
473 void QDeviceInfoSimulatorBackend::setModel(QString model)
474 {
475     if (data.model != model)
476         data.model = model;
477 }
478
479 void QDeviceInfoSimulatorBackend::setProductName(QString name)
480 {
481     if (data.productName != name)
482         data.productName = name;
483 }
484
485 void QDeviceInfoSimulatorBackend::setUniqueDeviceID(QString id)
486 {
487     if (data.uniqueDeviceID != id)
488         data.uniqueDeviceID = id;
489 }
490
491 void QDeviceInfoSimulatorBackend::setVersion(QDeviceInfo::Version version, QString versionString)
492 {
493     QMap<QDeviceInfo::Version, QString>::iterator i = data.versionList.find(version);
494     if (i != data.versionList.end() && i.value() != versionString)
495         data.versionList[version] = versionString;
496 }
497
498 // QNetworkInfoSimulatorBackend
499
500 QNetworkInfoSimulatorBackend::QNetworkInfoSimulatorBackend(QNetworkInfo *parent)
501     : QObject(parent)
502 {
503 }
504
505 QNetworkInfoSimulatorBackend::~QNetworkInfoSimulatorBackend()
506 {
507 }
508
509 QNetworkInfoSimulatorBackend *QNetworkInfoSimulatorBackend::getSimulatorBackend()
510 {
511     static QMutex mutex;
512
513     mutex.lock();
514     if (!globalSimulatorBackend)
515         globalSimulatorBackend = new QNetworkInfoSimulatorBackend();
516     mutex.unlock();
517
518     return globalSimulatorBackend;
519 }
520
521 QNetworkInfoData::BasicNetworkInfo *QNetworkInfoSimulatorBackend::basicNetworkInfo(QNetworkInfo::NetworkMode mode, int interface)
522 {
523     QNetworkInfoData::BasicNetworkInfo *basic = 0;
524     if (interface >= 0) {
525         switch (mode) {
526         case QNetworkInfo::GsmMode:
527         case QNetworkInfo::CdmaMode:
528         case QNetworkInfo::WcdmaMode:
529         case QNetworkInfo::LteMode:
530         case QNetworkInfo::TdscdmaMode:
531             if (interface < data.cellularInfo.count())
532                 basic = &(data.cellularInfo[interface].basicNetworkInfo);
533             break;
534         case QNetworkInfo::WlanMode:
535             if (interface < data.wLanInfo.count()) {
536                 basic = &(data.wLanInfo[interface].basicNetworkInfo);
537             }
538             break;
539         case QNetworkInfo::EthernetMode:
540             if (interface <= data.ethernetInfo.count())
541                 basic = &(data.ethernetInfo[interface].basicNetworkInfo);
542             break;
543         case QNetworkInfo::BluetoothMode:
544             if (interface <= data.bluetoothInfo.count())
545                 basic = &(data.bluetoothInfo[interface].basicNetworkInfo);
546             break;
547         default:
548             break;
549         }
550     }
551     return basic;
552 }
553
554 bool QNetworkInfoSimulatorBackend::isValidInterface(QNetworkInfo::NetworkMode mode, int interface)
555 {
556     switch (mode) {
557     case QNetworkInfo::GsmMode:
558     case QNetworkInfo::CdmaMode:
559     case QNetworkInfo::WcdmaMode:
560     case QNetworkInfo::LteMode:
561     case QNetworkInfo::TdscdmaMode:
562         if (interface >= 0 && interface < data.cellularInfo.count())
563             return true;
564         else
565             return false;
566     case QNetworkInfo::WlanMode:
567         if (interface >= 0 && interface < data.wLanInfo.count())
568             return true;
569         else
570             return false;
571     case QNetworkInfo::EthernetMode:
572         if (interface >= 0 && interface < data.ethernetInfo.count())
573             return true;
574         else
575             return false;
576     case QNetworkInfo::BluetoothMode:
577         if (interface >= 0 && interface < data.bluetoothInfo.count())
578             return true;
579         else
580             return false;
581     default:
582         break;
583     }
584     return false;
585 }
586
587 QNetworkInfo::NetworkMode QNetworkInfoSimulatorBackend::getCurrentNetworkMode()
588 {
589     if (getNetworkStatus(QNetworkInfo::EthernetMode, 0) == QNetworkInfo::HomeNetwork)
590         return QNetworkInfo::EthernetMode;
591     else if (getNetworkStatus(QNetworkInfo::WlanMode, 0) == QNetworkInfo::HomeNetwork)
592         return QNetworkInfo::WlanMode;
593     else if (getNetworkStatus(QNetworkInfo::BluetoothMode, 0) == QNetworkInfo::HomeNetwork)
594         return QNetworkInfo::BluetoothMode;
595     else if (getNetworkStatus(QNetworkInfo::WimaxMode, 0) == QNetworkInfo::HomeNetwork)
596         return QNetworkInfo::WimaxMode;
597     else if (getNetworkStatus(QNetworkInfo::LteMode, 0) == QNetworkInfo::HomeNetwork)
598         return QNetworkInfo::LteMode;
599     else if (getNetworkStatus(QNetworkInfo::WcdmaMode, 0) == QNetworkInfo::HomeNetwork)
600         return QNetworkInfo::WcdmaMode;
601     else if (getNetworkStatus(QNetworkInfo::CdmaMode, 0) == QNetworkInfo::HomeNetwork)
602         return QNetworkInfo::CdmaMode;
603     else if (getNetworkStatus(QNetworkInfo::GsmMode, 0) == QNetworkInfo::HomeNetwork)
604         return QNetworkInfo::GsmMode;
605     else if (getNetworkStatus(QNetworkInfo::TdscdmaMode, 0) == QNetworkInfo::HomeNetwork)
606         return QNetworkInfo::TdscdmaMode;
607     else if (getNetworkStatus(QNetworkInfo::WimaxMode, 0) == QNetworkInfo::Roaming)
608         return QNetworkInfo::WimaxMode;
609     else if (getNetworkStatus(QNetworkInfo::LteMode, 0) == QNetworkInfo::Roaming)
610         return QNetworkInfo::LteMode;
611     else if (getNetworkStatus(QNetworkInfo::WcdmaMode, 0) == QNetworkInfo::Roaming)
612         return QNetworkInfo::WcdmaMode;
613     else if (getNetworkStatus(QNetworkInfo::CdmaMode, 0) == QNetworkInfo::Roaming)
614         return QNetworkInfo::CdmaMode;
615     else if (getNetworkStatus(QNetworkInfo::GsmMode, 0) == QNetworkInfo::Roaming)
616         return QNetworkInfo::GsmMode;
617     else if (getNetworkStatus(QNetworkInfo::TdscdmaMode, 0) == QNetworkInfo::Roaming)
618         return QNetworkInfo::TdscdmaMode;
619     else
620         return QNetworkInfo::UnknownMode;
621 }
622
623 QString QNetworkInfoSimulatorBackend::getNetworkName(QNetworkInfo::NetworkMode mode, int interface)
624 {
625     if (isValidInterface(mode, interface)) {
626         QNetworkInfoData::BasicNetworkInfo *basic = basicNetworkInfo(mode, interface);
627         return basic->name;
628     }
629     return QString();
630 }
631
632 int QNetworkInfoSimulatorBackend::getNetworkSignalStrength(QNetworkInfo::NetworkMode mode, int interface)
633 {
634     if (isValidInterface(mode, interface)) {
635         QNetworkInfoData::BasicNetworkInfo *basic = basicNetworkInfo(mode, interface);
636         return basic->signalStrength;
637     }
638     return -1;
639 }
640
641 QNetworkInfo::NetworkStatus QNetworkInfoSimulatorBackend::getNetworkStatus(QNetworkInfo::NetworkMode mode, int interface)
642 {
643     if (isValidInterface(mode, interface)) {
644         QNetworkInfoData::BasicNetworkInfo *basic = basicNetworkInfo(mode, interface);
645         return basic->status;
646     }
647     return QNetworkInfo::UnknownStatus;
648 }
649
650 QNetworkInfo::NetworkMode QNetworkInfoSimulatorBackend::getMode(QNetworkInfo::NetworkMode mode, int interface)
651 {
652     switch (mode) {
653     case QNetworkInfo::GsmMode:
654     case QNetworkInfo::CdmaMode:
655     case QNetworkInfo::WcdmaMode:
656     case QNetworkInfo::LteMode:
657     case QNetworkInfo::TdscdmaMode:
658         if (isValidInterface(mode, interface)) {
659             QNetworkInfoData::BasicNetworkInfo *basic = basicNetworkInfo(mode, interface);
660             return basic->mode;
661         }
662     case QNetworkInfo::WlanMode:
663         if (isValidInterface(mode, interface))
664             return QNetworkInfo::WlanMode;
665     case QNetworkInfo::EthernetMode:
666         if (isValidInterface(mode, interface))
667             return QNetworkInfo::EthernetMode;
668     case QNetworkInfo::BluetoothMode:
669         if (isValidInterface(mode, interface))
670             return QNetworkInfo::BluetoothMode;
671     default:
672         break;
673     }
674     return QNetworkInfo::UnknownMode;
675 }
676
677 QString QNetworkInfoSimulatorBackend::getMacAddress(QNetworkInfo::NetworkMode mode, int interface)
678 {
679     if (interface >= 0) {
680         switch (mode) {
681         case QNetworkInfo::WlanMode:
682             if (isValidInterface(mode, interface))
683                 return data.wLanInfo[interface].macAddress;
684             break;
685         case QNetworkInfo::EthernetMode:
686             if (isValidInterface(mode, interface))
687                 return data.ethernetInfo[interface].macAddress;
688             break;
689         case QNetworkInfo::BluetoothMode:
690             if (isValidInterface(mode, interface))
691                 return data.bluetoothInfo[interface].btAddress;
692             break;
693         default:
694             break;
695         }
696     }
697     return QString();
698 }
699
700 #ifndef QT_NO_NETWORKINTERFACE
701 QNetworkInterface QNetworkInfoSimulatorBackend::getInterfaceForMode(QNetworkInfo::NetworkMode mode, int interface)
702 {
703     Q_UNUSED(mode)
704     Q_UNUSED(interface)
705     return QNetworkInterface();
706 }
707 #endif // QT_NO_NETWORKINTERFACE
708
709 QString QNetworkInfoSimulatorBackend::getImsi(int interface)
710 {
711     if (isValidInterface(QNetworkInfo::GsmMode, interface))
712         return data.cellularInfo[interface].imsi;
713     else
714         return QString();
715 }
716
717 QString QNetworkInfoSimulatorBackend::getCellId(int interface)
718 {
719     if (isValidInterface(QNetworkInfo::GsmMode, interface))
720         return data.cellularInfo[interface].cellId;
721     else
722         return QString();
723 }
724
725 QString QNetworkInfoSimulatorBackend::getCurrentMobileCountryCode(int interface)
726 {
727     if (isValidInterface(QNetworkInfo::GsmMode, interface))
728         return data.cellularInfo[interface].currentMobileCountryCode;
729     else
730         return QString();
731 }
732
733 QString QNetworkInfoSimulatorBackend::getCurrentMobileNetworkCode(int interface)
734 {
735     if (isValidInterface(QNetworkInfo::GsmMode, interface))
736         return data.cellularInfo[interface].currentMobileNetworkCode;
737     else
738         return QString();
739 }
740
741 QString QNetworkInfoSimulatorBackend::getHomeMobileCountryCode(int interface)
742 {
743     if (isValidInterface(QNetworkInfo::GsmMode, interface))
744         return data.cellularInfo[interface].homeMobileCountryCode;
745     else
746         return QString();
747 }
748
749 QString QNetworkInfoSimulatorBackend::getHomeMobileNetworkCode(int interface)
750 {
751     if (isValidInterface(QNetworkInfo::GsmMode, interface))
752         return data.cellularInfo[interface].homeMobileNetworkCode;
753     else
754         return QString();
755 }
756
757 QString QNetworkInfoSimulatorBackend::getLocationAreaCode(int interface)
758 {
759     if (isValidInterface(QNetworkInfo::GsmMode, interface))
760         return data.cellularInfo[interface].locationAreaCode;
761     else
762         return QString();
763 }
764
765 QNetworkInfo::CellDataTechnology QNetworkInfoSimulatorBackend::getCurrentCellDataTechnology(int interface)
766 {
767     if (isValidInterface(QNetworkInfo::GsmMode, interface))
768         return data.cellularInfo[interface].cellData;
769     else
770         return QNetworkInfo::UnknownDataTechnology;
771 }
772
773 int QNetworkInfoSimulatorBackend::getNetworkInterfaceCount(QNetworkInfo::NetworkMode mode)
774 {
775     switch (mode) {
776     case QNetworkInfo::GsmMode:
777     case QNetworkInfo::CdmaMode:
778     case QNetworkInfo::WcdmaMode:
779     case QNetworkInfo::LteMode:
780     case QNetworkInfo::TdscdmaMode:
781         return data.cellularInfo.count();
782     case QNetworkInfo::WlanMode:
783         return data.wLanInfo.count();
784     case QNetworkInfo::EthernetMode:
785         return data.ethernetInfo.count();
786     case QNetworkInfo::BluetoothMode:
787         return data.bluetoothInfo.count();
788     default:
789         break;
790     }
791     return -1;
792 }
793
794 void QNetworkInfoSimulatorBackend::setImsi(int interface, const QString &id)
795 {
796     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].imsi != id))
797         data.cellularInfo[interface].imsi = id;
798 }
799
800 void QNetworkInfoSimulatorBackend::setCellId(int interface, const QString &id)
801 {
802     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].cellId != id)) {
803         data.cellularInfo[interface].cellId = id;
804         emit cellIdChanged(interface, id);
805     }
806 }
807
808 void QNetworkInfoSimulatorBackend::setLocationAreaCode(int interface, const QString &code)
809 {
810     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].locationAreaCode != code)) {
811         data.cellularInfo[interface].locationAreaCode = code;
812         emit locationAreaCodeChanged(interface, code);
813     }
814 }
815
816 void QNetworkInfoSimulatorBackend::setCurrentMobileCountryCode(int interface, const QString &code)
817 {
818     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].currentMobileCountryCode != code)) {
819         data.cellularInfo[interface].currentMobileCountryCode = code;
820         emit currentMobileCountryCodeChanged(interface, code);
821     }
822 }
823
824 void QNetworkInfoSimulatorBackend::setCurrentMobileNetworkCode(int interface, const QString &code)
825 {
826     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].currentMobileNetworkCode != code)) {
827         data.cellularInfo[interface].currentMobileNetworkCode = code;
828         emit currentMobileNetworkCodeChanged(interface, code);
829     }
830 }
831
832 void QNetworkInfoSimulatorBackend::setHomeMobileCountryCode(int interface, const QString &code)
833 {
834     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].homeMobileCountryCode != code))
835         data.cellularInfo[interface].homeMobileCountryCode = code;
836 }
837
838 void QNetworkInfoSimulatorBackend::setHomeMobileNetworkCode(int interface, const QString &code)
839 {
840     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].homeMobileNetworkCode != code))
841         data.cellularInfo[interface].homeMobileNetworkCode = code;
842 }
843
844 void QNetworkInfoSimulatorBackend::setCellDataTechnology(int interface, QNetworkInfo::CellDataTechnology cellData)
845 {
846     if (isValidInterface(QNetworkInfo::GsmMode, interface) && (data.cellularInfo[interface].cellData != cellData)) {
847         data.cellularInfo[interface].cellData = cellData;
848         emit currentCellDataTechnologyChanged(interface, cellData);
849     }
850 }
851
852 void QNetworkInfoSimulatorBackend::setMode(int interface, QNetworkInfo::NetworkMode mode)
853 {
854     switch (mode) {
855     case QNetworkInfo::GsmMode:
856     case QNetworkInfo::CdmaMode:
857     case QNetworkInfo::WcdmaMode:
858     case QNetworkInfo::LteMode:
859     case QNetworkInfo::TdscdmaMode:
860         if (isValidInterface(mode, interface) && (data.cellularInfo[interface].basicNetworkInfo.mode != mode))
861             data.cellularInfo[interface].basicNetworkInfo.mode = mode;
862     default:
863         break;
864     }
865 }
866
867 void QNetworkInfoSimulatorBackend::setNetworkName(QNetworkInfo::NetworkMode mode, int interface, const QString &name)
868 {
869     if (isValidInterface(mode, interface)) {
870         QNetworkInfoData::BasicNetworkInfo *basic = basicNetworkInfo(mode, interface);
871         if (basic != 0 && basic->name != name) {
872             basic->name = name;
873             emit networkNameChanged(mode, interface, name);
874         }
875     }
876 }
877
878 void QNetworkInfoSimulatorBackend::setNetworkMacAddress(QNetworkInfo::NetworkMode mode, int interface, const QString &mac)
879 {
880     if (interface >= 0) {
881         switch (mode) {
882         case QNetworkInfo::WlanMode:
883             if (isValidInterface(mode, interface))
884                 data.wLanInfo[interface].macAddress = mac;
885             break;
886         case QNetworkInfo::EthernetMode:
887             if (isValidInterface(mode, interface))
888                 data.ethernetInfo[interface].macAddress = mac;
889             break;
890         case QNetworkInfo::BluetoothMode:
891             if (isValidInterface(mode, interface))
892                 data.bluetoothInfo[interface].btAddress = mac;
893             break;
894         default:
895             break;
896         }
897     }
898 }
899
900 void QNetworkInfoSimulatorBackend::setNetworkSignalStrength(QNetworkInfo::NetworkMode mode, int interface, int strength)
901 {
902     if (isValidInterface(mode, interface)) {
903         QNetworkInfoData::BasicNetworkInfo* basic = basicNetworkInfo(mode, interface);
904         if (basic != 0 && basic->signalStrength != strength) {
905             basic->signalStrength = strength;
906             emit networkSignalStrengthChanged(mode, interface, strength);
907         }
908     }
909 }
910
911 void QNetworkInfoSimulatorBackend::setNetworkStatus(QNetworkInfo::NetworkMode mode, int interface, QNetworkInfo::NetworkStatus status)
912 {
913     if (isValidInterface(mode, interface)) {
914         QNetworkInfoData::BasicNetworkInfo* basic = basicNetworkInfo(mode, interface);
915         if (basic != 0 && basic->status != status) {
916             basic->status = status;
917             emit networkStatusChanged(mode, interface, status);
918         }
919     }
920 }
921
922 void QNetworkInfoSimulatorBackend::addEthernetInterface(QNetworkInfoData::EthernetInfo info)
923 {
924     data.ethernetInfo.append(info);
925     emit networkInterfaceCountChanged(info.basicNetworkInfo.mode, getNetworkInterfaceCount(info.basicNetworkInfo.mode));
926 }
927
928 void QNetworkInfoSimulatorBackend::addWlanInterface(QNetworkInfoData::WLanInfo info)
929 {
930     data.wLanInfo.append(info);
931     emit networkInterfaceCountChanged(info.basicNetworkInfo.mode, getNetworkInterfaceCount(info.basicNetworkInfo.mode));
932 }
933
934 void QNetworkInfoSimulatorBackend::addCellularInterface(QNetworkInfoData::CellularInfo info)
935 {
936     data.cellularInfo.append(info);
937     emit networkInterfaceCountChanged(info.basicNetworkInfo.mode, getNetworkInterfaceCount(info.basicNetworkInfo.mode));
938 }
939
940 void QNetworkInfoSimulatorBackend::addBluetoothInterface(QNetworkInfoData::BluetoothInfo info)
941 {
942     data.bluetoothInfo.append(info);
943     emit networkInterfaceCountChanged(info.basicNetworkInfo.mode, getNetworkInterfaceCount(info.basicNetworkInfo.mode));
944 }
945
946 void QNetworkInfoSimulatorBackend::removeInterface(QNetworkInfo::NetworkMode mode, int interface)
947 {
948     clearOrRemoveInterface(mode, interface, false);
949 }
950
951 void QNetworkInfoSimulatorBackend::clearInterface(QNetworkInfo::NetworkMode mode)
952 {
953     clearOrRemoveInterface(mode, 0, true);
954 }
955
956 void QNetworkInfoSimulatorBackend::clearOrRemoveInterface(QNetworkInfo::NetworkMode mode, int interface, bool clear)
957 {
958     switch (mode) {
959     case QNetworkInfo::GsmMode:
960     case QNetworkInfo::CdmaMode:
961     case QNetworkInfo::WcdmaMode:
962     case QNetworkInfo::LteMode:
963     case QNetworkInfo::TdscdmaMode:
964         if (isValidInterface(mode, interface)) {
965             clear ? data.cellularInfo.clear() : data.cellularInfo.remove(interface);
966             emit networkInterfaceCountChanged(mode, getNetworkInterfaceCount(mode));
967         }
968         break;
969     case QNetworkInfo::WlanMode:
970         if (isValidInterface(mode, interface)) {
971             clear ? data.wLanInfo.clear() : data.wLanInfo.remove(interface);
972             emit networkInterfaceCountChanged(mode, getNetworkInterfaceCount(mode));
973         }
974         break;
975     case QNetworkInfo::EthernetMode:
976         if (isValidInterface(mode, interface)) {
977             clear ? data.ethernetInfo.clear() : data.ethernetInfo.remove(interface);
978             emit networkInterfaceCountChanged(mode, getNetworkInterfaceCount(mode));
979         }
980         break;
981     case QNetworkInfo::BluetoothMode:
982         if (isValidInterface(mode, interface)) {
983             clear ? data.bluetoothInfo.clear() : data.bluetoothInfo.remove(interface);
984             emit networkInterfaceCountChanged(mode, getNetworkInterfaceCount(mode));
985         }
986         break;
987     default:
988         break;
989     }
990 }
991
992 QT_END_NAMESPACE