1#include "ParameterUser.h"
2#include "RabbitCommonTools.h"
3#include <QLoggingCategory>
5static Q_LOGGING_CATEGORY(log,
"Client.Parameter.User")
9 , m_Type(QList<TYPE>() << TYPE::UserPassword)
10 , m_UsedType(TYPE::UserPassword)
11 , m_bSavePassword(false)
12 , m_bUseSystemFile(true)
13 , m_bSavePassphrase(false)
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")}
26int CParameterUser::OnLoad(QSettings &set)
28 set.beginGroup(
"User");
29 SetUser(set.value(
"Name", GetUser()).toString());
31 set.beginGroup(
"Authentication");
33 foreach(
auto t, GetType()) {
34 type.push_back(QString::number((
int)t));
37 vType = set.value(
"Type", type).toStringList();
39 foreach(
auto s, vType)
41 lstType.push_back((
TYPE)s.toInt());
44 SetUsedType((
TYPE)set.value(
"Type/Used", (
int)GetUsedType()).toInt());
50 if(!LoadPassword(tr(
"Password"),
"Password", szPassword, set))
51 SetPassword(szPassword);
54 set.beginGroup(
"PublicKey");
55 set.beginGroup(
"File");
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()) {
64 if(!LoadPassword(tr(
"Passphrase"),
"Passphrase", szPassword, set))
65 SetPassphrase(szPassword);
68 SetCAFile(set.value(
"CA", GetCAFile()).toString());
69 SetCRLFile(set.value(
"CRL", GetCRLFile()).toString());
79int CParameterUser::OnSave(QSettings &set)
81 set.beginGroup(
"User");
82 set.setValue(
"Name", GetUser());
84 set.beginGroup(
"Authentication");
86 foreach(
auto t, GetType()) {
87 type.push_back(QString::number((
int)t));
89 set.setValue(
"Type", type);
90 set.setValue(
"Type/Used", (
int)GetUsedType());
92 set.setValue(
"SavePassword", GetSavePassword());
93 SavePassword(
"Password", GetPassword(), set, GetSavePassword());
95 set.beginGroup(
"PublicKey");
96 set.beginGroup(
"File");
98 set.setValue(
"PublicKey", GetPublicKeyFile());
99 set.setValue(
"PrivateKey", GetPrivateKeyFile());
100 set.setValue(
"SavePassphrase", GetSavePassphrase());
101 SavePassword(
"Passphrase", GetPassphrase(), set, GetSavePassphrase());
103 set.setValue(
"CA", GetCAFile());
104 set.setValue(
"CRL", GetCRLFile());
114QList<CParameterUser::TYPE> CParameterUser::GetType()
const
119int CParameterUser::SetType(QList<TYPE> type)
133int CParameterUser::SetUsedType(TYPE type)
135 if(m_UsedType == type)
142const QString CParameterUser::GetUser()
const
147void CParameterUser::SetUser(
const QString &szUser)
149 if (m_szUser == szUser)
155const QString CParameterUser::GetPassword()
const
160void CParameterUser::SetPassword(
const QString &szPassword)
162 if(m_szPassword == szPassword)
164 m_szPassword = szPassword;
168const bool CParameterUser::GetSavePassword()
const
170 return m_bSavePassword;
175 if (m_bSavePassword == save)
177 m_bSavePassword = save;
185 QString szErr =
"The CParameterClient is null";
186 qCritical(log) << szErr;
187 Q_ASSERT_X(
false,
"CParameterUser", szErr.toStdString().c_str());
194 SetUser(RabbitCommon::CTools::GetCurrentUser());
206 return m_bUseSystemFile;
209int CParameterUser::SetUseSystemFile(
bool use)
211 if(m_bUseSystemFile == use)
213 m_bUseSystemFile = use;
218QString CParameterUser::GetPassphrase()
const
220 return m_szPassphrase;
223int CParameterUser::SetPassphrase(
const QString passphrase)
225 if(m_szPassphrase == passphrase)
227 m_szPassphrase = passphrase;
232bool CParameterUser::GetSavePassphrase()
const
234 return m_bSavePassphrase;
237int CParameterUser::SetSavePassphrase(
bool bSave)
239 if(m_bSavePassphrase == bSave)
241 m_bSavePassphrase = bSave;
246QString CParameterUser::GetPublicKeyFile()
const
248 return m_szPublicKeyFile;
251int CParameterUser::SetPublicKeyFile(
const QString szFile)
253 if(m_szPublicKeyFile == szFile)
255 m_szPublicKeyFile = szFile;
260QString CParameterUser::GetPrivateKeyFile()
const
262 return m_szPrivateKeyFile;
265int CParameterUser::SetPrivateKeyFile(
const QString szFile)
267 if(m_szPrivateKeyFile == szFile)
269 m_szPrivateKeyFile = szFile;
274QString CParameterUser::GetCAFile()
const
279int CParameterUser::SetCAFile(
const QString &ca)
288QString CParameterUser::GetCRLFile()
const
293int CParameterUser::SetCRLFile(
const QString &crl)
295 if(m_szCRLFile == crl)
302QString CParameterUser::ConvertTypeToName(TYPE t)
304 return m_TypeName[t];
307int CParameterUser::SetTypeName(TYPE t,
const QString& szName)
309 m_TypeName[t] = szName;
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.