-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdownpara.cpp
More file actions
208 lines (192 loc) · 5.42 KB
/
shutdownpara.cpp
File metadata and controls
208 lines (192 loc) · 5.42 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "shutdownpara.h"
ShutdownPara::ShutdownPara()
{
shutdownType=SHUTDOWN_TYPE::NONE;
//计算机,默认为本机
// bMultiMachine=false;
// computer.append();
//参数:
bForce=false;
bTimeout=false;
iTimeout=60;
bToFirmware=false;
bFastBoot=false;
bToAdvancedOpt=false;
bAutoLogin=false;
bComment=false;
sComment="";
bReason=false;
reasonType=REASON_TYPE::NOREASON;
majorReason=false;
minorReason=false;
condition="";
}
ShutdownPara::ShutdownPara(const ShutdownPara& p)
{
shutdownType=p.shutdownType;
//计算机,默认为本机
// bMultiMachine=false;
// computer.append();
//参数:
bForce=p.bForce;
bTimeout=p.bTimeout;
iTimeout=p.iTimeout;
bToFirmware=p.bToFirmware;
bFastBoot=p.bFastBoot;
bToAdvancedOpt=p.bToAdvancedOpt;
bAutoLogin=p.bAutoLogin;
bComment=p.bComment;
sComment=p.sComment;
bReason=p.bReason;
reasonType=p.reasonType;
majorReason=p.majorReason;
minorReason=p.minorReason;
condition=p.condition;
}
TCHAR* ShutdownPara::getMachineName(int i){
static TCHAR retval[256];
memcpy(retval,computer[i].toStdWString().data(),256*sizeof(TCHAR));
return retval;
}
TCHAR* ShutdownPara::getMesssage(){
static TCHAR retval[512];
memcpy(retval,
bComment?sComment.toStdWString().data():L"",
512*sizeof(TCHAR));
return retval;
}
DWORD ShutdownPara::getTimeout()
{
return bTimeout?iTimeout:60;
}
DWORD ShutdownPara::getFlags(){
DWORD dwFlag=0;
if(shutdownType==SHUTDOWN)
dwFlag|=SHUTDOWN_POWEROFF;
if(shutdownType==RESTART)
dwFlag|=SHUTDOWN_RESTART;
if(bForce)
dwFlag|=SHUTDOWN_FORCE_OTHERS;
if(bFastBoot)
dwFlag|=SHUTDOWN_HYBRID;
if(bToFirmware)
{
//待实现
;
}
if(bToAdvancedOpt)
dwFlag|=0x400;
if(bAutoLogin)
dwFlag|=SHUTDOWN_RESTARTAPPS;
return dwFlag;
}
DWORD ShutdownPara::getReason(){
DWORD retval=0;
if(bReason==false)
return 0;
else
{
switch(reasonType){
case PLANNED:
retval|=SHTDN_REASON_FLAG_PLANNED;
break;
case CUSTOM:
retval|=SHTDN_REASON_FLAG_USER_DEFINED;
case NOREASON:
case UNPLANNED:
break;
};
retval|=majorReason;
retval|=minorReason;
}
return retval;
}
DWORD ShutdownPara::getComputerListlength(){
return this->computer.length();
}
void ShutdownPara::addMachine(QString n){
if(not this->computer.contains(n))
{
this->computer.append(n);
}
emit this->machineListChanged(computer);
}
void ShutdownPara::removeMachine(QString n){
{
this->computer.removeOne(n);
}
emit machineListChanged(computer);
}
void ShutdownPara::set(const ShutdownPara* x){
shutdownType=x->shutdownType;
//计算机,默认为本机
// bMultiMachine=false;
// computer.append();
//参数:
bForce=x->bForce;
bTimeout=x->bTimeout;
iTimeout=x->iTimeout;
bToFirmware=x->bToFirmware;
bFastBoot=x->bFastBoot;
bToAdvancedOpt=x->bToAdvancedOpt;
bAutoLogin=x->bAutoLogin;
bComment=x->bComment;
sComment=QString(x->sComment);
bReason=x->bReason;
reasonType=x->reasonType;
majorReason=x->majorReason;
minorReason=x->minorReason;
this->computer.clear();
//深拷贝QList
for (int i=0;i<x->computer.length();i++)
{
this->computer.append(x->computer[i]);
}
this->condition=x->condition;
}
QJsonObject ShutdownPara::toJsonObject(QString name) const {
QJsonObject obj;
obj["presetName"] = name;
obj["shutdownType"] = int(shutdownType);
obj["computer"] = QJsonArray::fromStringList(computer);
obj["bForce"] = bForce;
obj["bTimeout"] = bTimeout;
obj["iTimeout"] = iTimeout;
obj["bToFirmware"] = bToFirmware;
obj["bFastBoot"] = bFastBoot;
obj["bToAdvancedOpt"] = bToAdvancedOpt;
obj["bAutoLogin"] = bAutoLogin;
obj["bComment"] = bComment;
obj["sComment"] = sComment;
obj["bReason"] = bReason;
obj["reasonType"] = reasonType;
obj["majorReason"] = majorReason;
obj["minorReason"] = minorReason;
obj["condition"] = condition;
return obj;
}
//返回预配置的名称
QString ShutdownPara::fromJsonObject(const QJsonObject& obj) {
shutdownType = (SHUTDOWN_TYPE)(obj["shutdownType"].toInt());
//computer拷贝
QJsonArray jsComputer=obj["computer"].toArray();
for(int i=0 ; i< jsComputer.count() ; i++)
{
computer.append(jsComputer[i].toString());
}
bForce = obj["bForce"].toBool();
bTimeout = obj["bTimeout"].toBool();
iTimeout = obj["iTimeout"].toInt();
bToFirmware = obj["bToFirmware"].toBool();
bFastBoot = obj["bFastBoot"].toBool();
bToAdvancedOpt = obj["bToAdvancedOpt"].toBool();
bAutoLogin = obj["bAutoLogin"].toBool();
bComment = obj["bComment"].toBool();
sComment = obj["sComment"].toString();
bReason = obj["bReason"].toBool();
reasonType = static_cast<REASON_TYPE>(obj["reasonType"].toInt());
majorReason = obj["majorReason"].toInt();
minorReason = obj["minorReason"].toInt();
condition = obj["condition"].toString();
return obj["presetName"].toString();
}