1#include "ParameterUserUI.h"
2#include "ui_ParameterUserUI.h"
4#include <QLoggingCategory>
6static Q_LOGGING_CATEGORY(log,
"Client.Parameter.User.UI")
14 ui->leUser->setPlaceholderText(tr(
"Input user name"));
15 ui->lePassword->setPlaceholderText(tr(
"Input password"));
16 ui->lePublicFile->setPlaceholderText(tr(
"Please input the public key file"));
17 ui->lePrivateFile->setPlaceholderText(tr(
"Please input the private key file"));
18 ui->lePassphrase->setPlaceholderText(tr(
"Please input the passphrase of private key file"));
20 on_cbType_currentIndexChanged(0);
21 on_cbSystemFile_stateChanged(ui->cbSystemFile->isChecked());
24CParameterUserUI::~CParameterUserUI()
31 m_pUser = qobject_cast<CParameterUser*>(pParameter);
32 if(!m_pUser)
return -1;
34 ui->leUser->setText(m_pUser->GetUser());
36 for(
auto t: m_pUser->GetType()) {
37 ui->cbType->addItem(m_pUser->ConvertTypeToName(t), (int)t);
40 int index = ui->cbType->findData((
int)m_pUser->GetUsedType());
42 qDebug(log) <<
"Forget set use type?";
44 ui->cbType->setCurrentIndex(index);
45 ui->cbType->setVisible(1 < m_pUser->GetType().length());
46 ui->lbType->setVisible(1 < m_pUser->GetType().length());
48 qDebug(log) <<
"CParameterUserUI::SetParameter:" << index;
50 ui->lePassword->setText(m_pUser->GetPassword());
51 ui->pbSave->setChecked(m_pUser->GetSavePassword());
55 ui->lePublicFile->setText(m_pUser->GetPublicKeyFile());
56 ui->lePrivateFile->setText(m_pUser->GetPrivateKeyFile());
57 ui->lePassphrase->setText(m_pUser->GetPassphrase());
58 ui->pbSavePassphrase->setChecked(m_pUser->GetSavePassphrase());
59 on_pbSavePassphrase_clicked();
67 if(!m_pUser)
return -1;
71 m_pUser->SetUser(ui->leUser->text());
72 m_pUser->SetPassword(ui->lePassword->text());
75 m_pUser->SetPublicKeyFile(ui->lePublicFile->text());
76 m_pUser->SetPrivateKeyFile(ui->lePrivateFile->text());
77 m_pUser->SetPassphrase(ui->lePassphrase->text());
78 m_pUser->SetSavePassphrase(ui->pbSavePassphrase->isChecked());
85 switch(ui->lePassword->echoMode())
87 case QLineEdit::Password:
88 ui->lePassword->setEchoMode(QLineEdit::Normal);
89 ui->pbShow->setIcon(QIcon::fromTheme(
"eye-off"));
91 case QLineEdit::Normal:
92 ui->lePassword->setEchoMode(QLineEdit::Password);
93 ui->pbShow->setIcon(QIcon::fromTheme(
"eye-on"));
96 ui->pbShow->setIcon(QIcon::fromTheme(
"eye-on"));
100void CParameterUserUI::on_pbSave_clicked()
102 if(!parent()->inherits(
"CParameterNetUI"))
return;
103 if(ui->pbSave->isChecked())
105 ui->lePassword->setEnabled(
true);
106 ui->lePassword->setPlaceholderText(tr(
"Input password"));
108 ui->lePassword->setPlaceholderText(tr(
"Please checked save password to enable"));
109 ui->lePassword->setEnabled(
false);
113void CParameterUserUI::on_pbBrowsePublicFile_clicked()
116#if defined(Q_OS_LINUX)
119 QString szFile = QFileDialog::getOpenFileName(
this, tr(
"Open public key file"), dir);
122 ui->lePublicFile->setText(szFile);
125void CParameterUserUI::on_pbBrowsePrivateFile_clicked()
128#if defined(Q_OS_LINUX)
131 QString szFile = QFileDialog::getOpenFileName(
this, tr(
"Open public key file"), dir);
134 ui->lePrivateFile->setText(szFile);
137void CParameterUserUI::on_cbType_currentIndexChanged(
int index)
140 qDebug(log) <<
"CParameterUserUI::on_cbType_currentIndexChanged:" << index;
144 bUser = !(CParameterUser::TYPE::OnlyPassword == type
145 || CParameterUser::TYPE::None == type
146 || CParameterUser::TYPE::OnlyPasswordX509 == type
148 ui->lbUser->setVisible(bUser);
149 ui->leUser->setVisible(bUser);
151 bool bPassword =
false;
152 bPassword = !(CParameterUser::TYPE::None == type
153 || CParameterUser::TYPE::PublicKey == type);
154 ui->lbPassword->setVisible(bPassword);
155 ui->lePassword->setVisible(bPassword);
156 ui->pbSave->setVisible(bPassword);
157 ui->pbShow->setVisible(bPassword);
159 bool bPublicKey =
false;
160 bPublicKey = CParameterUser::TYPE::PublicKey == type;
161 ui->lbPublicFile->setVisible(bPublicKey);
162 ui->lePublicFile->setVisible(bPublicKey);
163 ui->pbBrowsePublicFile->setVisible(bPublicKey);
164 ui->lbPrivateFile->setVisible(bPublicKey);
165 ui->lePrivateFile->setVisible(bPublicKey);
166 ui->pbBrowsePrivateFile->setVisible(bPublicKey);
167 ui->lbPassphrase->setVisible(bPublicKey);
168 ui->lePassphrase->setVisible(bPublicKey);
169 ui->pbShowPassphrase->setVisible(bPublicKey);
170 ui->pbSavePassphrase->setVisible(bPublicKey);
171 ui->cbSystemFile->setVisible(bPublicKey);
174 bCA = CParameterUser::TYPE::OnlyPasswordX509 == type
175 || CParameterUser::TYPE::UserPasswordX509 == type;
176 ui->lbCAFile->setVisible(bCA);
177 ui->leCAFile->setVisible(bCA);
178 ui->pbBrowseCAFile->setVisible(bCA);
179 ui->lbCRLFile->setVisible(bCA);
180 ui->leCRLFile->setVisible(bCA);
181 ui->pbBrowseCRLFile->setVisible(bCA);
184void CParameterUserUI::on_pbShowPassphrase_clicked()
186 switch(ui->lePassphrase->echoMode())
188 case QLineEdit::Password:
189 ui->lePassphrase->setEchoMode(QLineEdit::Normal);
190 ui->pbShowPassphrase->setIcon(QIcon::fromTheme(
"eye-off"));
192 case QLineEdit::Normal:
193 ui->lePassphrase->setEchoMode(QLineEdit::Password);
194 ui->pbShowPassphrase->setIcon(QIcon::fromTheme(
"eye-on"));
197 ui->pbShowPassphrase->setIcon(QIcon::fromTheme(
"eye-on"));
201void CParameterUserUI::on_pbSavePassphrase_clicked()
203 if(!parent()->inherits(
"CParameterNetUI"))
return;
204 if(ui->pbSavePassphrase->isChecked())
206 ui->lePassphrase->setEnabled(
true);
207 ui->lePassphrase->setPlaceholderText(tr(
"Input passphrase"));
209 ui->lePassphrase->setPlaceholderText(tr(
"Please checked save passphrase to enable"));
210 ui->lePassphrase->setEnabled(
false);
214void CParameterUserUI::on_cbSystemFile_stateChanged(
int arg1)
216 ui->lePublicFile->setEnabled(!ui->cbSystemFile->isChecked());
217 ui->pbBrowsePublicFile->setEnabled(!ui->cbSystemFile->isChecked());
218 ui->lePrivateFile->setEnabled(!ui->cbSystemFile->isChecked());
219 ui->pbBrowsePrivateFile->setEnabled(!ui->cbSystemFile->isChecked());
222void CParameterUserUI::on_pbBrowseCAFile_clicked()
225#if defined(Q_OS_LINUX)
228 QString szFile = QFileDialog::getOpenFileName(
this, tr(
"Open X509 certificate authentication file"), dir);
231 ui->leCAFile->setText(szFile);
234void CParameterUserUI::on_pbBrowseCRLFile_clicked()
237#if defined(Q_OS_LINUX)
240 QString szFile = QFileDialog::getOpenFileName(
this, tr(
"Open X509 Certificate Revocation List file"), dir);
243 ui->leCRLFile->setText(szFile);
CParameterClient * GetParameterClient()
Get CParameterClient.
The parameter UI interface.
void on_pbShow_clicked()
[Parameter commone functions]
int SetParameter(CParameter *pParameter)
[Parameter commone functions]
int Accept()
Accept parameters.
void SetSavePassword(bool save)
Set save password.
@ OnlyPasswordX509None
Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.