Renames & Add new properties to QBatteryInfo
[qt:qtsystems.git] / src / systeminfo / simulator / qsysteminfodata_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 "qsysteminfodata_simulator_p.h"
44 #include <QtCore/QDataStream>
45
46 QT_BEGIN_NAMESPACE
47
48 void qt_registerSystemInfoTypes()
49 {
50     qRegisterMetaTypeStreamOperators<QNetworkInfoData>("QNetworkInfoData");
51     qRegisterMetaTypeStreamOperators<QNetworkInfoData::BasicNetworkInfo>("QNetworkInfoData::BasicNetworkInfo");
52     qRegisterMetaTypeStreamOperators<QNetworkInfoData::EthernetInfo>("QNetworkInfoData::EthernetInfo");
53     qRegisterMetaTypeStreamOperators<QNetworkInfoData::WLanInfo>("QNetworkInfoData::WLanInfo");
54     qRegisterMetaTypeStreamOperators<QNetworkInfoData::CellularInfo>("QNetworkInfoData::CellularInfo");
55     qRegisterMetaTypeStreamOperators<QNetworkInfoData::BluetoothInfo>("QNetworkInfoData::BluetoothInfo");
56     qRegisterMetaTypeStreamOperators<QDeviceInfoData>("QDeviceInfoData");
57     qRegisterMetaTypeStreamOperators<QBatteryInfoData>("QBatteryInfoData");
58     qRegisterMetaTypeStreamOperators<QStorageInfoData>("QStorageInfoData");
59     qRegisterMetaTypeStreamOperators<QStorageInfoData::DriveInfo>("QStorageInfoData::DriveInfo");
60     qRegisterMetaTypeStreamOperators<QScreenSaverData>("QScreenSaverData");
61 }
62
63 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData::BasicNetworkInfo &s)
64 {
65     out << s.name;
66     out << static_cast<qint32>(s.signalStrength) << static_cast<qint32>(s.mode)
67         << static_cast<qint32>(s.status);
68     return out;
69 }
70
71 QDataStream &operator>>(QDataStream &in, QNetworkInfoData::BasicNetworkInfo &s)
72 {
73     in >> s.name;
74     qint32 signalStrength;
75     in >> signalStrength;
76     s.signalStrength = signalStrength;
77     qint32 mode, status;
78     in >> mode;
79     in >> status;
80     s.mode = static_cast<QNetworkInfo::NetworkMode>(mode);
81     s.status = static_cast<QNetworkInfo::NetworkStatus>(status);
82     return in;
83 }
84
85 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData::EthernetInfo &s)
86 {
87     out << s.basicNetworkInfo;
88     out << s.macAddress;
89
90     return out;
91 }
92
93 QDataStream &operator>>(QDataStream &in, QNetworkInfoData::EthernetInfo &s)
94 {
95     in >> s.basicNetworkInfo;
96     in >> s.macAddress;
97
98     return in;
99 }
100
101 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData::WLanInfo &s)
102 {
103     out << s.basicNetworkInfo;
104     out << s.macAddress;
105     return out;
106 }
107
108 QDataStream &operator>>(QDataStream &in, QNetworkInfoData::WLanInfo &s)
109 {
110     in >> s.basicNetworkInfo;
111     in >> s.macAddress;
112     return in;
113 }
114
115 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData::BluetoothInfo &s)
116 {
117     out << s.basicNetworkInfo;
118     out << s.btAddress;
119     return out;
120 }
121
122 QDataStream &operator>>(QDataStream &in, QNetworkInfoData::BluetoothInfo &s)
123 {
124     in >> s.basicNetworkInfo;
125     in >> s.btAddress;
126     return in;
127 }
128
129 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData::CellularInfo &s)
130 {
131     out << s.basicNetworkInfo;
132     out << s.imsi << s.cellId << s.locationAreaCode;
133     out << s.currentMobileCountryCode << s.currentMobileNetworkCode;
134     out << s.homeMobileCountryCode << s.homeMobileNetworkCode;
135     out << static_cast<qint32>(s.cellData);
136
137     return out;
138 }
139
140 QDataStream &operator>>(QDataStream &in, QNetworkInfoData::CellularInfo &s)
141 {
142     in >> s.basicNetworkInfo;
143     qint32 cellData;
144     in >> s.imsi >> s.cellId >> s.locationAreaCode;
145     in >> s.currentMobileCountryCode >> s.currentMobileNetworkCode;
146     in >> s.homeMobileCountryCode >> s.homeMobileNetworkCode;
147     in >> cellData;
148     s.cellData = static_cast<QNetworkInfo::CellDataTechnology>(cellData);
149
150     return in;
151 }
152
153 QDataStream &operator<<(QDataStream &out, const QNetworkInfoData &s)
154 {
155     out << s.ethernetInfo;
156     out << s.wLanInfo;
157     out << s.cellularInfo;
158     out << s.bluetoothInfo;
159
160     return out;
161 }
162
163 QDataStream &operator>>(QDataStream &in, QNetworkInfoData &s)
164 {
165     in >> s.ethernetInfo;
166     in >> s.wLanInfo;
167     in >> s.cellularInfo;
168     in >> s.bluetoothInfo;
169
170     return in;
171 }
172
173 QDataStream &operator<<(QDataStream &out, const QDeviceInfoData &s)
174 {
175     out << s.manufacturer << s.model << s.productName << s.uniqueDeviceID;
176     out << s.imeiList;
177     out << s.featureList;
178     out << s.versionList;
179     out << static_cast<qint32>(s.enabledLocks) << static_cast<qint32>(s.activatedLocks)
180         << static_cast<qint32>(s.currentThermalState);
181
182     return out;
183 }
184
185 QDataStream &operator>>(QDataStream &in, QDeviceInfoData &s)
186 {
187     in >> s.manufacturer >> s.model >> s.productName >> s.uniqueDeviceID;
188     in >> s.imeiList;
189     in >> s.featureList;
190     in >> s.versionList;
191     qint32 enabledLocks, activatedLocks, currentThermalState;
192     in >> enabledLocks >> activatedLocks >> currentThermalState;
193     s.enabledLocks = static_cast<QDeviceInfo::LockTypeFlags>(enabledLocks);
194     s.activatedLocks = static_cast<QDeviceInfo::LockTypeFlags>(activatedLocks);
195     s.currentThermalState = static_cast<QDeviceInfo::ThermalState>(currentThermalState);
196
197     return in;
198 }
199
200 QDataStream &operator<<(QDataStream &out, const QDeviceInfo::Feature s)
201 {
202     out << static_cast<qint32>(s);
203     return out;
204 }
205
206 QDataStream &operator>>(QDataStream &in, QDeviceInfo::Feature &s)
207 {
208     qint32 v;
209     in >> v;
210     s = static_cast<QDeviceInfo::Feature>(v);
211     return in;
212 }
213
214 QDataStream &operator<<(QDataStream &out, const QDeviceInfo::Version s)
215 {
216     out << static_cast<qint32>(s);
217     return out;
218 }
219
220 QDataStream &operator>>(QDataStream &in, QDeviceInfo::Version &s)
221 {
222     qint32 v;
223     in >> v;
224     s = static_cast<QDeviceInfo::Version>(v);
225     return in;
226 }
227
228 QDataStream &operator<<(QDataStream &out, const QBatteryInfoData &s)
229 {
230     out << static_cast<qint32>(s.chargingState) << static_cast<qint32>(s.chargerType)
231         << static_cast<qint32>(s.energyMeasurementUnit) << static_cast<qint32>(s.levelStatus);;
232
233     out << static_cast<qint32>(s.currentFlow) << static_cast<qint32>(s.maximumCapacity)
234         << static_cast<qint32>(s.remainingCapacity) << static_cast<qint32>(s.remainingChargingTime)
235         << static_cast<qint32>(s.voltage);
236
237     return out;
238 }
239
240 QDataStream &operator>>(QDataStream &in, QBatteryInfoData &s)
241 {
242     qint32 chargingState, chargerType, energyMeasurementUnit, batteryStatus;
243     in >> chargingState >> chargerType >> energyMeasurementUnit >> batteryStatus;
244
245     s.chargingState = static_cast<QBatteryInfo::ChargingState>(chargingState);
246     s.chargerType = static_cast<QBatteryInfo::ChargerType>(chargerType);
247     s.energyMeasurementUnit = static_cast<QBatteryInfo::EnergyUnit>(energyMeasurementUnit);
248     s.levelStatus = static_cast<QBatteryInfo::LevelStatus>(batteryStatus);
249
250     qint32 currentFlow, maximumCapacity, remainingCapacity, remainingChargingTime, voltage;
251     in >> currentFlow >> maximumCapacity >> remainingCapacity >> remainingChargingTime >> voltage;
252
253     s.currentFlow = currentFlow;
254     s.maximumCapacity = maximumCapacity;
255     s.remainingCapacity = remainingCapacity;
256     s.remainingChargingTime = remainingChargingTime;
257     s.voltage = voltage;
258
259     return in;
260 }
261
262 QDataStream &operator<<(QDataStream &out, const QStorageInfoData &s)
263 {
264     out << s.drives;
265     return out;
266 }
267
268 QDataStream &operator>>(QDataStream &in, QStorageInfoData &s)
269 {
270     in >> s.drives;
271     return in;
272 }
273
274 QDataStream &operator<<(QDataStream &out, const QStorageInfoData::DriveInfo &s)
275 {
276     out << s.totalSpace << s.availableSpace;
277     out << s.uri;
278     out << static_cast<qint32>(s.type);
279
280     return out;
281 }
282
283 QDataStream &operator>>(QDataStream &in, QStorageInfoData::DriveInfo &s)
284 {
285     in >> s.totalSpace >> s.availableSpace;
286     in >> s.uri;
287     qint32 type;
288     in >> type;
289     s.type = static_cast<QStorageInfo::DriveType>(type);
290
291     return in;
292 }
293
294 QDataStream &operator<<(QDataStream &out, const QScreenSaverData &s)
295 {
296     out << s.screenSaverEnabled;
297     return out;
298 }
299
300 QDataStream &operator>>(QDataStream &in, QScreenSaverData &s)
301 {
302     in >> s.screenSaverEnabled;
303     return in;
304 }
305
306 QT_END_NAMESPACE
307
308