Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterWakeOnLan.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QtGlobal>
4#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
5#include <QRegExpValidator>
6#include <QRegExp>
7#else
8#include <QRegularExpression>
9#include <QRegularExpressionValidator>
10#endif
11
12#include "ParameterWakeOnLan.h"
13
14CParameterWakeOnLan::CParameterWakeOnLan(QObject *parent)
15 : CParameterConnecter(parent)
16 , m_Net(this)
17 , m_bEnable(false)
18 , m_HostState(HostState::Offline)
19 , m_nPort(9)
20 , m_bSavePassword(false)
21 , m_nRepeat(3)
22 , m_nInterval(500)
23 , m_nTimeOut(5000)
24{}
25
26int CParameterWakeOnLan::OnLoad(QSettings &set)
27{
28 int nRet = 0;
29 set.beginGroup("WakeOnLan");
30 SetEnable(set.value("Enable", GetEnable()).toBool());
31 SetMac(set.value("Mac", GetMac()).toString());
32 SetBroadcastAddress(
33 set.value("BoardAddress", GetBroadcastAddress()).toString());
34 SetNetworkInterface(set.value("NetworkInterface", GetNetworkInterface()).toString());
35 SetPort(set.value("Port", GetPort()).toUInt());
36 SetPassword(set.value("Password", GetPassword()).toString());
37 SetSavePassword(set.value("Password/Save", GetSavePassword()).toBool());
38 SetRepeat(set.value("Repeat", GetRepeat()).toInt());
39 SetInterval(set.value("Interval", GetInterval()).toInt());
40 SetTimeOut(set.value("TimeOut", GetTimeOut()).toInt());
41 set.endGroup();
42 return nRet;
43}
44
45int CParameterWakeOnLan::OnSave(QSettings &set)
46{
47 int nRet = 0;
48 set.beginGroup("WakeOnLan");
49 set.setValue("Enable", GetEnable());
50 set.setValue("Mac", GetMac());
51 set.setValue("BoardAddress", GetBroadcastAddress());
52 set.setValue("NetworkInterface", GetNetworkInterface());
53 set.setValue("Port", GetPort());
54 set.setValue("Password", GetPassword());
55 set.setValue("Password/Save", GetSavePassword());
56 set.setValue("Repeat", GetRepeat());
57 set.setValue("Interval", GetInterval());
58 set.setValue("TimeOut", GetTimeOut());
59 set.endGroup();
60 return nRet;
61}
62
64{
65#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
66 QRegExp rxMac("^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$");
67 QRegExpValidator macValidator(rxMac, this);
68 QRegExp rxIP("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$");
69 QRegExpValidator ipValidator(rxIP, this);
70 QRegExp rxPassword("(.{6})?|^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$");
71 QRegExpValidator passwordValidator(rxPassword, this);
72#else
73 QRegularExpression rxMac("^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$");
74 QRegularExpressionValidator macValidator(rxMac, this);
75 QRegularExpression rxIP("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$");
76 QRegularExpressionValidator ipValidator(rxIP, this);
77 QRegularExpression rxPassword("(.{6})?|^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$");
78 QRegularExpressionValidator passwordValidator(rxPassword, this);
79#endif
80 if(!GetEnable())
81 return false;
82 QString szMac = GetMac();
83 int pos = 0;
84 if(QValidator::Acceptable != macValidator.validate(szMac, pos))
85 return false;
86 QString szBroadAddress = GetBroadcastAddress();
87 if(QValidator::Acceptable != ipValidator.validate(szBroadAddress, pos))
88 return false;
89 QString szPassword = GetPassword();
90 if(QValidator::Acceptable != passwordValidator.validate(szPassword, pos))
91 return false;
92
93 return true;
94}
95
96void CParameterWakeOnLan::slotSetParameterClient()
97{
99 {
100 SetSavePassword(GetParameterClient()->GetSavePassword());
101 }
102}
103
104const bool CParameterWakeOnLan::GetEnable() const
105{
106 return m_bEnable;
107}
108
109int CParameterWakeOnLan::SetEnable(bool bEnable)
110{
111 if(m_bEnable == bEnable)
112 return 0;
113 m_bEnable = bEnable;
114 SetModified(true);
115 return 0;
116}
117
118const QString CParameterWakeOnLan::GetMac() const
119{
120 return m_szMac;
121}
122
123int CParameterWakeOnLan::SetMac(const QString &szMac)
124{
125 if(m_szMac == szMac)
126 return 0;
127 m_szMac = szMac;
128 SetModified(true);
129 return 0;
130}
131
132const QString CParameterWakeOnLan::GetBroadcastAddress() const
133{
134 return m_szBoardcastAddress;
135}
136
137int CParameterWakeOnLan::SetBroadcastAddress(const QString &szBroadcastAddress)
138{
139 if(m_szBoardcastAddress == szBroadcastAddress)
140 return 0;
141 m_szBoardcastAddress = szBroadcastAddress;
142 SetModified(true);
143 return 0;
144}
145
147{
148 return m_szNetworkInteface;
149}
150
151int CParameterWakeOnLan::SetNetworkInterface(const QString& szName)
152{
153 if(m_szNetworkInteface == szName)
154 return 0;
155 m_szNetworkInteface = szName;
156 SetModified(true);
157 return 0;
158}
159
160const quint16 CParameterWakeOnLan::GetPort() const
161{
162 return m_nPort;
163}
164
165int CParameterWakeOnLan::SetPort(quint16 port)
166{
167 if(m_nPort == port)
168 return 0;
169 m_nPort = port;
170 SetModified(true);
171 return 0;
172}
173
174const QString CParameterWakeOnLan::GetPassword() const
175{
176 return m_szPassword;
177}
178
179int CParameterWakeOnLan::SetPassword(const QString &szPassword)
180{
181 if(m_szPassword == szPassword)
182 return 0;
183 m_szPassword = szPassword;
184 SetModified(true);
185 return 0;
186}
187
188const bool CParameterWakeOnLan::GetSavePassword() const
189{
190 return m_bSavePassword;
191}
192
194{
195 if(m_bSavePassword == save)
196 return 0;
197 m_bSavePassword = save;
198 SetModified(true);
199 return 0;
200}
201
202const int CParameterWakeOnLan::GetRepeat() const
203{
204 return m_nRepeat;
205}
206
207int CParameterWakeOnLan::SetRepeat(int nRepeat)
208{
209 if(m_nRepeat == nRepeat)
210 return 0;
211 m_nRepeat = nRepeat;
212 SetModified(true);
213 return 0;
214}
215
217{
218 return m_nInterval;
219}
220
222{
223 if(m_nInterval == nInterval)
224 return 0;
225 m_nInterval = nInterval;
226 SetModified(true);
227 return 0;
228}
229
231{
232 return m_nTimeOut;
233}
234
236{
237 if(m_nTimeOut == nTimeout)
238 return 0;
239 m_nTimeOut = nTimeout;
240 SetModified(true);
241 return 0;
242}
243
244CParameterWakeOnLan::HostState CParameterWakeOnLan::GetHostState() const
245{
246 return m_HostState;
247}
248
249void CParameterWakeOnLan::SetHostState(HostState newHostState)
250{
251 if (m_HostState == newHostState)
252 return;
253 m_HostState = newHostState;
254 emit sigHostStateChanged();
255}
the parameters of connecter interface.
CParameterClient * GetParameterClient()
Get CParameterClient.
virtual int OnLoad(QSettings &set) override
Unit: ms.
int SetTimeOut(int nTimeout)
Unit: ms.
int SetSavePassword(bool save)
Set save password.
int SetInterval(int nInterval)
Unit: ms.
const QString GetNetworkInterface() const
Get network interface.
virtual bool OnCheckValidity() override
Check validity.
const int GetTimeOut() const
Unit: ms.
const int GetInterval() const
Unit: ms.
int SetModified(bool bModified=true)
When setting parameters, if there is a modification, it is called.