-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.cpp
102 lines (88 loc) · 2.51 KB
/
profile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Powersched
* Copyright (C) 2019 Jiri Babocky
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "profile.h"
Profile::Profile(const QString &name, uint16_t standby, uint16_t suspend, uint16_t off, bool awake){
_name = name;
_standby = standby;
_suspend = suspend;
_off = off;
_awake = awake;
}
Profile::Profile(const QJsonObject& data){
_name = "";
if (!data.contains("name") || !data.contains("standby") || !data.contains("suspend") || !data.contains("off") || !data.contains("awake"))
return;
if (data["standby"].isDouble())
_standby = data["standby"].toInt();
else
return;
if (data["suspend"].isDouble())
_suspend = data["suspend"].toInt();
else
return;
if (data["off"].isDouble())
_off = data["off"].toInt();
else
return;
if (data["awake"].isBool())
_awake = data["awake"].toBool();
else
return;
if (data["name"].isString())
_name = data["name"].toString();
else
return;
}
QJsonObject Profile::toJson() const{
QJsonObject result;
result.insert("name", QJsonValue(_name));
result.insert("standby", QJsonValue(_standby));
result.insert("suspend", QJsonValue(_suspend));
result.insert("off", QJsonValue(_off));
result.insert("awake", QJsonValue(_awake));
return result;
}
QString Profile::name() const{
return _name;
}
uint16_t Profile::standby() const{
return _standby;
}
uint16_t Profile::suspend() const{
return _suspend;
}
uint16_t Profile::off() const{
return _off;
}
bool Profile::awake() const{
return _awake;
}
void Profile::setName(const QString &name){
_name = name;
}
void Profile::setStandby(uint16_t standby){
_standby = standby;
}
void Profile::setSuspend(uint16_t suspend){
_suspend = suspend;
}
void Profile::setOff(uint16_t off){
_off = off;
}
void Profile::setAwake(bool awake){
_awake = awake;
}