Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterVnc.cpp
1#include "ParameterVnc.h"
2#include "rfb/encodings.h"
3
4CParameterVnc::CParameterVnc(QObject *parent)
5 : CParameterBase(parent)
6{
7 m_Net.SetPort(5900);
8
9 //TODO: add authentication
10 auto &user = m_Net.m_User;
11 user.SetType(QList<CParameterUser::TYPE>()
12 << CParameterUser::TYPE::None
13 << CParameterUser::TYPE::OnlyPassword
15 << CParameterUser::TYPE::OnlyPasswordX509
16 << CParameterUser::TYPE::UserPassword
17 << CParameterUser::TYPE::UserPasswordX509None
18 << CParameterUser::TYPE::UserPasswordX509
19 );
20 user.SetUsedType(CParameterUser::TYPE::OnlyPassword);
21 user.SetTypeName(CParameterUser::TYPE::OnlyPassword, tr("Standard VNC authentication (insecure without encryption)"));
22 user.SetTypeName(CParameterUser::TYPE::UserPassword, tr("Username and password (insecure without encryption)"));
23 user.SetTypeName(CParameterUser::TYPE::OnlyPasswordX509, tr("Standard VNC authentication (secure with x509 encryption)"));
24 user.SetTypeName(CParameterUser::TYPE::OnlyPasswordX509None, tr("Standard VNC authentication (secure with x509 none encryption)"));
25 user.SetTypeName(CParameterUser::TYPE::UserPasswordX509, tr("Username and password (secure with x509 encryption)"));
26 user.SetTypeName(CParameterUser::TYPE::UserPasswordX509None, tr("Username and password (secure with x509 none encryption)"));
27
28 m_bShared = true;
29 m_bBufferEndRefresh = false;
30
31 m_bAutoSelect = true;
32 m_nColorLevel = CParameterVnc::Full;
33 m_nPreferredEncoding = rfb::encodingTight;
34 m_bCompressLevel = true;
35 m_nCompressLevel = 2;
36 m_bNoJpeg = false;
37 m_nQualityLevel = 8;
38
39 SetIce(false);
40 SetSignalPort(5222);
41 SetStunPort(3748);
42 SetTurnPort(3748);
43}
44
45int CParameterVnc::OnLoad(QSettings &set)
46{
47 int nRet = 0;
48 nRet = CParameterBase::OnLoad(set);
49 if(nRet) return nRet;
50
51 set.beginGroup("VNC");
52 SetShared(set.value("Shared", GetShared()).toBool());
53 SetBufferEndRefresh(set.value("BufferEndRefresh",
54 GetBufferEndRefresh()).toBool());
55
56 SetAutoSelect(set.value("AutoSelect", GetAutoSelect()).toBool());
57 SetColorLevel(static_cast<COLOR_LEVEL>(set.value("ColorLevel",
58 GetColorLevel()).toInt()));
59 SetPreferredEncoding(set.value("Encoding", GetPreferredEncoding()).toInt());
60 SetEnableCompressLevel(set.value("EnableCompressLevel",
61 GetEnableCompressLevel()).toBool());
62 SetCompressLevel(set.value("CompressLevel",
63 GetCompressLevel()).toInt());
64 SetNoJpeg(set.value("NoJpeg", GetNoJpeg()).toBool());
65 SetQualityLevel(set.value("QualityLevel", GetQualityLevel()).toInt());
66 set.endGroup();
67
68 set.beginGroup("ICE");
69 SetIce(set.value("Enable", GetIce()).toBool());
70 SetSignalServer(set.value("Signal/Server",
71 GetSignalServer()).toString());
72 SetSignalPort(set.value("Signal/Port", GetSignalPort()).toUInt());
73 SetSignalUser(set.value("Signal/User", GetSignalUser()).toString());
74 if(m_Net.m_User.GetSavePassword())
75 {
76 QString szPassword;
77 if(!LoadPassword(tr("Ice signal password"), "Signal/password",
78 szPassword, set))
79 SetSignalPassword(szPassword);
80 }
81 SetPeerUser(set.value("Peer/User", GetPeerUser()).toString());
82 SetStunServer(set.value("Stun/Server", GetStunServer()).toString());
83 SetStunPort(set.value("Stun/Port", GetStunPort()).toUInt());
84 SetTurnServer(set.value("Turn/Server", GetTurnServer()).toString());
85 SetTurnPort(set.value("Turn/Port", GetTurnPort()).toUInt());
86 SetTurnUser(set.value("Turn/User", GetTurnUser()).toString());
87 if(m_Net.m_User.GetSavePassword())
88 {
89 QString szPassword;
90 if(!LoadPassword(tr("Ice turn password"), "Turn/password",
91 szPassword, set))
92 SetTurnPassword(szPassword);
93 }
94 set.endGroup();
95
96 return 0;
97}
98
99int CParameterVnc::OnSave(QSettings &set)
100{
101 int nRet = 0;
102 nRet = CParameterBase::OnSave(set);
103 if(nRet) return nRet;
104
105 set.beginGroup("VNC");
106 set.setValue("Shared", GetShared());
107 set.setValue("BufferEndRefresh", GetBufferEndRefresh());
108 set.setValue("AutoSelect", GetAutoSelect());
109 set.setValue("ColorLevel", GetColorLevel());
110 set.setValue("Encoding", GetPreferredEncoding());
111 set.setValue("EnableCompressLevel", GetEnableCompressLevel());
112 set.setValue("CompressLevel", GetCompressLevel());
113 set.setValue("NoJpeg", GetNoJpeg());
114 set.setValue("QualityLevel", GetQualityLevel());
115 set.endGroup();
116
117 set.beginGroup("ICE");
118 set.setValue("Enable", GetIce());
119 set.setValue("Signal/Server", GetSignalServer());
120 set.setValue("Signal/Port", GetSignalPort());
121 set.setValue("Signal/User", GetSignalUser());
122 SavePassword("Signal/password", GetSignalPassword(), set);
123 set.setValue("Peer/User", GetPeerUser());
124 set.setValue("Stun/Server", GetStunServer());
125 set.setValue("Stun/Port", GetStunPort());
126 set.setValue("Turn/Server", GetTurnServer());
127 set.setValue("Turn/Port", GetTurnPort());
128 set.setValue("Turn/User", GetTurnUser());
129 SavePassword("Turn/password", GetTurnPassword(), set);
130 set.endGroup();
131
132 return 0;
133}
134
136{
137 if(GetIce())
138 {
139 if(GetSignalServer().isEmpty() || GetSignalPort() <= 0
140 || GetSignalUser().isEmpty() || GetSignalPassword().isEmpty()
141 || GetStunServer().isEmpty() || GetStunPort() <= 0)
142 return false;
143 return true;
144 }
145
146 if(m_Net.GetHost().isEmpty()
147 || m_Net.GetPort() <= 0
148 || m_Net.m_User.GetPassword().isEmpty())
149 return false;
150 return true;
151}
152
153bool CParameterVnc::GetShared() const
154{
155 return m_bShared;
156}
157
158void CParameterVnc::SetShared(bool newShared)
159{
160 if(m_bShared == newShared)
161 return;
162 m_bShared = newShared;
163 SetModified(true);
164}
165
166bool CParameterVnc::GetBufferEndRefresh() const
167{
168 return m_bBufferEndRefresh;
169}
170
171void CParameterVnc::SetBufferEndRefresh(bool newBufferEndRefresh)
172{
173 if(m_bBufferEndRefresh == newBufferEndRefresh)
174 return;
175 m_bBufferEndRefresh = newBufferEndRefresh;
176 SetModified(true);
177}
178
179bool CParameterVnc::GetAutoSelect() const
180{
181 return m_bAutoSelect;
182}
183
184void CParameterVnc::SetAutoSelect(bool newAutoSelect)
185{
186 if(m_bAutoSelect == newAutoSelect)
187 return;
188 m_bAutoSelect = newAutoSelect;
189 SetModified(true);
190}
191
192CParameterVnc::COLOR_LEVEL CParameterVnc::GetColorLevel() const
193{
194 return m_nColorLevel;
195}
196
197void CParameterVnc::SetColorLevel(COLOR_LEVEL newColorLevel)
198{
199 if(m_nColorLevel == newColorLevel)
200 return;
201 m_nColorLevel = newColorLevel;
202 SetModified(true);
203}
204
205int CParameterVnc::GetPreferredEncoding() const
206{
207 return m_nPreferredEncoding;
208}
209
210void CParameterVnc::SetPreferredEncoding(int newEncoding)
211{
212 if(m_nPreferredEncoding == newEncoding)
213 return;
214 m_nPreferredEncoding = newEncoding;
215 SetModified(true);
216}
217
218bool CParameterVnc::GetEnableCompressLevel() const
219{
220 return m_bCompressLevel;
221}
222
223void CParameterVnc::SetEnableCompressLevel(bool newCompressLevel)
224{
225 if(m_bCompressLevel == newCompressLevel)
226 return;
227 m_bCompressLevel = newCompressLevel;
228 SetModified(true);
229}
230
231int CParameterVnc::GetCompressLevel() const
232{
233 return m_nCompressLevel;
234}
235
236void CParameterVnc::SetCompressLevel(int newCompressLevel)
237{
238 if(m_nCompressLevel == newCompressLevel)
239 return;
240 m_nCompressLevel = newCompressLevel;
241 SetModified(true);
242}
243
244bool CParameterVnc::GetNoJpeg() const
245{
246 return m_bNoJpeg;
247}
248
249void CParameterVnc::SetNoJpeg(bool newNoJpeg)
250{
251 if(m_bNoJpeg == newNoJpeg)
252 return;
253 m_bNoJpeg = newNoJpeg;
254 SetModified(true);
255}
256
257int CParameterVnc::GetQualityLevel() const
258{
259 return m_nQualityLevel;
260}
261
262void CParameterVnc::SetQualityLevel(int newQualityLevel)
263{
264 if(m_nQualityLevel == newQualityLevel)
265 return;
266 m_nQualityLevel = newQualityLevel;
267 SetModified(true);
268}
269
270bool CParameterVnc::GetIce() const
271{
272 return m_bIce;
273}
274
275void CParameterVnc::SetIce(bool newIce)
276{
277 if(m_bIce == newIce)
278 return;
279 m_bIce = newIce;
280 SetModified(true);
281}
282
283const QString &CParameterVnc::GetSignalServer() const
284{
285 return m_szSignalServer;
286}
287
288void CParameterVnc::SetSignalServer(const QString &newSignalServer)
289{
290 if(m_szSignalServer == newSignalServer)
291 return;
292 m_szSignalServer = newSignalServer;
293 SetModified(true);
294}
295
296quint16 CParameterVnc::GetSignalPort() const
297{
298 return m_nSignalPort;
299}
300
301void CParameterVnc::SetSignalPort(quint16 newSignalPort)
302{
303 if(m_nSignalPort == newSignalPort)
304 return;
305 m_nSignalPort = newSignalPort;
306 SetModified(true);
307}
308
309const QString &CParameterVnc::GetSignalUser() const
310{
311 return m_szSignalUser;
312}
313
314void CParameterVnc::SetSignalUser(const QString &newSignalUser)
315{
316 if(m_szSignalUser == newSignalUser)
317 return;
318 m_szSignalUser = newSignalUser;
319 SetModified(true);
320}
321
322const QString &CParameterVnc::GetSignalPassword() const
323{
324 return m_szSignalPassword;
325}
326
327void CParameterVnc::SetSignalPassword(const QString &newSignalPassword)
328{
329 if(m_szSignalPassword == newSignalPassword)
330 return;
331 m_szSignalPassword = newSignalPassword;
332 SetModified(true);
333}
334
335const QString &CParameterVnc::GetPeerUser() const
336{
337 return m_szPeerUser;
338}
339
340void CParameterVnc::SetPeerUser(const QString &newPeerUser)
341{
342 if(m_szPeerUser == newPeerUser)
343 return;
344 m_szPeerUser = newPeerUser;
345 SetModified(true);
346}
347
348const QString &CParameterVnc::GetStunServer() const
349{
350 return m_szStunServer;
351}
352
353void CParameterVnc::SetStunServer(const QString &newStunServer)
354{
355 if(m_szStunServer == newStunServer)
356 return;
357 m_szStunServer = newStunServer;
358 SetModified(true);
359}
360
361quint16 CParameterVnc::GetStunPort() const
362{
363 return m_nStunPort;
364}
365
366void CParameterVnc::SetStunPort(quint16 newStunPort)
367{
368 if(m_nStunPort == newStunPort)
369 return;
370 m_nStunPort = newStunPort;
371 SetModified(true);
372}
373
374const QString &CParameterVnc::GetTurnServer() const
375{
376 return m_szTurnServer;
377}
378
379void CParameterVnc::SetTurnServer(const QString &newTurnServer)
380{
381 if(m_szTurnServer == newTurnServer)
382 return;
383 m_szTurnServer = newTurnServer;
384 SetModified(true);
385}
386
387quint16 CParameterVnc::GetTurnPort() const
388{
389 return m_nTurnPort;
390}
391
392void CParameterVnc::SetTurnPort(quint16 newTurnPort)
393{
394 if(m_nTurnPort == newTurnPort)
395 return;
396 m_nTurnPort = newTurnPort;
397 SetModified(true);
398}
399
400const QString &CParameterVnc::GetTurnUser() const
401{
402 return m_szTurnUser;
403}
404
405void CParameterVnc::SetTurnUser(const QString &newTurnUser)
406{
407 if(m_szTurnUser == newTurnUser)
408 return;
409 m_szTurnUser = newTurnUser;
410 SetModified(true);
411}
412
413const QString &CParameterVnc::GetTurnPassword() const
414{
415 return m_szTurnPassword;
416}
417
418void CParameterVnc::SetTurnPassword(const QString &newTurnPassword)
419{
420 if(m_szTurnPassword == newTurnPassword)
421 return;
422 m_szTurnPassword = newTurnPassword;
423 SetModified(true);
424}
The interface of connecter parameters.
CParameterUser m_User
[Instance user]
@ OnlyPasswordX509None
Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.
virtual bool OnCheckValidity() override
Check whether the parameters are complete to decide whether to open the parameter dialog.
int SetModified(bool bModified=true)
When setting parameters, if there is a modification, it is called.