Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterUser.cpp
1#include "ParameterUser.h"
2#include "RabbitCommonTools.h"
3#include <QLoggingCategory>
4
5static Q_LOGGING_CATEGORY(log, "Client.Parameter.User")
6
7CParameterUser::CParameterUser(CParameterConnecter *parent, const QString &szPrefix)
8 : CParameterConnecter(parent, szPrefix)
9 , m_Type(QList<TYPE>() << TYPE::UserPassword)
10 , m_UsedType(TYPE::UserPassword)
11 , m_bSavePassword(false)
12 , m_bUseSystemFile(true)
13 , m_bSavePassphrase(false)
14{
15 m_TypeName = {{TYPE::None, tr("None")},
16 {TYPE::OnlyPassword, tr("Password")},
17 {TYPE::UserPassword, tr("Username and password")},
18 {TYPE::PublicKey, tr("Public key")},
19 {TYPE::OnlyPasswordX509None, tr("Password with X509 none")},
20 {TYPE::OnlyPasswordX509, tr("Password with X509")},
21 {TYPE::UserPasswordX509None, tr("Username and password with X509 none")},
22 {TYPE::UserPasswordX509, tr("Username and password with X509")}
23 };
24}
25
26int CParameterUser::OnLoad(QSettings &set)
27{
28 set.beginGroup("User");
29 SetUser(set.value("Name", GetUser()).toString());
30
31 set.beginGroup("Authentication");
32 QStringList type;
33 foreach(auto t, GetType()) {
34 type.push_back(QString::number((int)t));
35 }
36 QStringList vType;
37 vType = set.value("Type", type).toStringList();
38 QList<TYPE> lstType;
39 foreach(auto s, vType)
40 {
41 lstType.push_back((TYPE)s.toInt());
42 }
43 SetType(lstType);
44 SetUsedType((TYPE)set.value("Type/Used", (int)GetUsedType()).toInt());
45
46 SetSavePassword(set.value("SavePassword", GetSavePassword()).toBool());
47 if(GetSavePassword())
48 {
49 QString szPassword;
50 if(!LoadPassword(tr("Password"), "Password", szPassword, set))
51 SetPassword(szPassword);
52 }
53
54 set.beginGroup("PublicKey");
55 set.beginGroup("File");
56 SetUseSystemFile(set.value("UseSystemFile", GetUseSystemFile()).toBool());
57 SetPublicKeyFile(set.value("PublicKey",
58 GetPublicKeyFile()).toString());
59 SetPrivateKeyFile(set.value("PrivateKey",
60 GetPrivateKeyFile()).toString());
61 SetSavePassphrase(set.value("SavePassphrase", GetSavePassphrase()).toBool());
62 if(GetSavePassphrase()) {
63 QString szPassword;
64 if(!LoadPassword(tr("Passphrase"), "Passphrase", szPassword, set))
65 SetPassphrase(szPassword);
66 }
67
68 SetCAFile(set.value("CA", GetCAFile()).toString());
69 SetCRLFile(set.value("CRL", GetCRLFile()).toString());
70
71 set.endGroup();
72
73 set.endGroup();
74 set.endGroup();
75 set.endGroup();
76 return 0;
77}
78
79int CParameterUser::OnSave(QSettings &set)
80{
81 set.beginGroup("User");
82 set.setValue("Name", GetUser());
83
84 set.beginGroup("Authentication");
85 QStringList type;
86 foreach(auto t, GetType()) {
87 type.push_back(QString::number((int)t));
88 }
89 set.setValue("Type", type);
90 set.setValue("Type/Used", (int)GetUsedType());
91
92 set.setValue("SavePassword", GetSavePassword());
93 SavePassword("Password", GetPassword(), set, GetSavePassword());
94
95 set.beginGroup("PublicKey");
96 set.beginGroup("File");
97 set.setValue("UseSystemFile", GetUseSystemFile());
98 set.setValue("PublicKey", GetPublicKeyFile());
99 set.setValue("PrivateKey", GetPrivateKeyFile());
100 set.setValue("SavePassphrase", GetSavePassphrase());
101 SavePassword("Passphrase", GetPassphrase(), set, GetSavePassphrase());
102
103 set.setValue("CA", GetCAFile());
104 set.setValue("CRL", GetCRLFile());
105
106 set.endGroup();
107
108 set.endGroup();
109 set.endGroup();
110 set.endGroup();
111 return 0;
112}
113
114QList<CParameterUser::TYPE> CParameterUser::GetType() const
115{
116 return m_Type;
117}
118
119int CParameterUser::SetType(QList<TYPE> type)
120{
121 if(m_Type == type)
122 return 0;
123 m_Type = type;
124 SetModified(true);
125 return 0;
126}
127
128CParameterUser::TYPE CParameterUser::GetUsedType() const
129{
130 return m_UsedType;
131}
132
133int CParameterUser::SetUsedType(TYPE type)
134{
135 if(m_UsedType == type)
136 return 0;
137 m_UsedType = type;
138 SetModified(true);
139 return 0;
140}
141
142const QString CParameterUser::GetUser() const
143{
144 return m_szUser;
145}
146
147void CParameterUser::SetUser(const QString &szUser)
148{
149 if (m_szUser == szUser)
150 return;
151 m_szUser = szUser;
152 SetModified(true);
153}
154
155const QString CParameterUser::GetPassword() const
156{
157 return m_szPassword;
158}
159
160void CParameterUser::SetPassword(const QString &szPassword)
161{
162 if(m_szPassword == szPassword)
163 return;
164 m_szPassword = szPassword;
165 SetModified(true);
166}
167
168const bool CParameterUser::GetSavePassword() const
169{
170 return m_bSavePassword;
171}
172
174{
175 if (m_bSavePassword == save)
176 return;
177 m_bSavePassword = save;
178 SetModified(true);
179}
180
183{
184 if(!GetParameterClient()) {
185 QString szErr = "The CParameterClient is null";
186 qCritical(log) << szErr;
187 Q_ASSERT_X(false, "CParameterUser", szErr.toStdString().c_str());
188 return;
189 }
190
192 {
193 if(GetParameterClient()->GetEnableSystemUserToUser())
194 SetUser(RabbitCommon::CTools::GetCurrentUser());
195 SetSavePassword(GetParameterClient()->GetSavePassword());
196 SetSavePassphrase(GetParameterClient()->GetSavePassword());
197 }
198
199 return;
200}
202
205{
206 return m_bUseSystemFile;
207}
208
209int CParameterUser::SetUseSystemFile(bool use)
210{
211 if(m_bUseSystemFile == use)
212 return 0;
213 m_bUseSystemFile = use;
214 SetModified(true);
215 return 0;
216}
217
218QString CParameterUser::GetPassphrase() const
219{
220 return m_szPassphrase;
221}
222
223int CParameterUser::SetPassphrase(const QString passphrase)
224{
225 if(m_szPassphrase == passphrase)
226 return 0;
227 m_szPassphrase = passphrase;
228 SetModified(true);
229 return 0;
230}
231
232bool CParameterUser::GetSavePassphrase() const
233{
234 return m_bSavePassphrase;
235}
236
237int CParameterUser::SetSavePassphrase(bool bSave)
238{
239 if(m_bSavePassphrase == bSave)
240 return 0;
241 m_bSavePassphrase = bSave;
242 SetModified(true);
243 return 0;
244}
245
246QString CParameterUser::GetPublicKeyFile() const
247{
248 return m_szPublicKeyFile;
249}
250
251int CParameterUser::SetPublicKeyFile(const QString szFile)
252{
253 if(m_szPublicKeyFile == szFile)
254 return 0;
255 m_szPublicKeyFile = szFile;
256 SetModified(true);
257 return 0;
258}
259
260QString CParameterUser::GetPrivateKeyFile() const
261{
262 return m_szPrivateKeyFile;
263}
264
265int CParameterUser::SetPrivateKeyFile(const QString szFile)
266{
267 if(m_szPrivateKeyFile == szFile)
268 return 0;
269 m_szPrivateKeyFile = szFile;
270 SetModified(true);
271 return 0;
272}
273
274QString CParameterUser::GetCAFile() const
275{
276 return m_szCAFile;
277}
278
279int CParameterUser::SetCAFile(const QString &ca)
280{
281 if(m_szCAFile == ca)
282 return 0;
283 m_szCAFile = ca;
284 SetModified(true);
285 return 0;
286}
287
288QString CParameterUser::GetCRLFile() const
289{
290 return m_szCRLFile;
291}
292
293int CParameterUser::SetCRLFile(const QString &crl)
294{
295 if(m_szCRLFile == crl)
296 return 0;
297 m_szCRLFile = crl;
298 SetModified(true);
299 return 0;
300}
301
302QString CParameterUser::ConvertTypeToName(TYPE t)
303{
304 return m_TypeName[t];
305}
306
307int CParameterUser::SetTypeName(TYPE t, const QString& szName)
308{
309 m_TypeName[t] = szName;
310 return 0;
311}
the parameters of connecter interface.
CParameterClient * GetParameterClient()
Get CParameterClient.
It contains user and password It only valid in plugin.
void SetSavePassword(bool save)
Set save password.
virtual void slotSetParameterClient() override
[Initialize parameter after set CParameterClient]
bool GetUseSystemFile() const
[Initialize parameter after set CParameterClient]
int SetModified(bool bModified=true)
When setting parameters, if there is a modification, it is called.