Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterUserUI.cpp
1#include "ParameterUserUI.h"
2#include "ui_ParameterUserUI.h"
3#include "QFileDialog"
4#include <QLoggingCategory>
5
6static Q_LOGGING_CATEGORY(log, "Client.Parameter.User.UI")
7
9 : CParameterUI(parent),
10 ui(new Ui::CParameterUserUI),
11 m_pUser(nullptr)
12{
13 ui->setupUi(this);
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"));
19 // 调整窗口的初始大小。
20 on_cbType_currentIndexChanged(0);
21 on_cbSystemFile_stateChanged(ui->cbSystemFile->isChecked());
22}
23
24CParameterUserUI::~CParameterUserUI()
25{
26 delete ui;
27}
28
30{
31 m_pUser = qobject_cast<CParameterUser*>(pParameter);
32 if(!m_pUser) return -1;
33
34 ui->leUser->setText(m_pUser->GetUser());
35
36 for(auto t: m_pUser->GetType()) {
37 ui->cbType->addItem(m_pUser->ConvertTypeToName(t), (int)t);
38 }
39
40 int index = ui->cbType->findData((int)m_pUser->GetUsedType());
41 if(-1 == index) {
42 qDebug(log) << "Forget set use type?";
43 } else
44 ui->cbType->setCurrentIndex(index);
45 ui->cbType->setVisible(1 < m_pUser->GetType().length());
46 ui->lbType->setVisible(1 < m_pUser->GetType().length());
47
48 qDebug(log) << "CParameterUserUI::SetParameter:" << index;
49
50 ui->lePassword->setText(m_pUser->GetPassword());
51 ui->pbSave->setChecked(m_pUser->GetSavePassword());
52 on_pbSave_clicked();
53 ui->pbShow->setEnabled(m_pUser->GetParameterClient()->GetViewPassowrd());
54
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();
60 ui->pbShowPassphrase->setEnabled(m_pUser->GetParameterClient()->GetViewPassowrd());
61
62 return 0;
63}
64
66{
67 if(!m_pUser) return -1;
68
69 m_pUser->SetUsedType((CParameterUser::TYPE)ui->cbType->currentData().toInt());
70
71 m_pUser->SetUser(ui->leUser->text());
72 m_pUser->SetPassword(ui->lePassword->text());
73 m_pUser->SetSavePassword(ui->pbSave->isChecked());
74
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());
79
80 return 0;
81}
82
84{
85 switch(ui->lePassword->echoMode())
86 {
87 case QLineEdit::Password:
88 ui->lePassword->setEchoMode(QLineEdit::Normal);
89 ui->pbShow->setIcon(QIcon::fromTheme("eye-off"));
90 break;
91 case QLineEdit::Normal:
92 ui->lePassword->setEchoMode(QLineEdit::Password);
93 ui->pbShow->setIcon(QIcon::fromTheme("eye-on"));
94 break;
95 default:
96 ui->pbShow->setIcon(QIcon::fromTheme("eye-on"));
97 }
98}
99
100void CParameterUserUI::on_pbSave_clicked()
101{
102 if(!parent()->inherits("CParameterNetUI")) return;
103 if(ui->pbSave->isChecked())
104 {
105 ui->lePassword->setEnabled(true);
106 ui->lePassword->setPlaceholderText(tr("Input password"));
107 } else {
108 ui->lePassword->setPlaceholderText(tr("Please checked save password to enable"));
109 ui->lePassword->setEnabled(false);
110 }
111}
112
113void CParameterUserUI::on_pbBrowsePublicFile_clicked()
114{
115 QString dir;
116#if defined(Q_OS_LINUX)
117 dir = "~/.ssh";
118#endif
119 QString szFile = QFileDialog::getOpenFileName(this, tr("Open public key file"), dir);
120 if(szFile.isEmpty())
121 return;
122 ui->lePublicFile->setText(szFile);
123}
124
125void CParameterUserUI::on_pbBrowsePrivateFile_clicked()
126{
127 QString dir;
128#if defined(Q_OS_LINUX)
129 dir = "~/.ssh";
130#endif
131 QString szFile = QFileDialog::getOpenFileName(this, tr("Open public key file"), dir);
132 if(szFile.isEmpty())
133 return;
134 ui->lePrivateFile->setText(szFile);
135}
136
137void CParameterUserUI::on_cbType_currentIndexChanged(int index)
138{
139 Q_UNUSED(index);
140 qDebug(log) << "CParameterUserUI::on_cbType_currentIndexChanged:" << index;
141
142 CParameterUser::TYPE type = static_cast<CParameterUser::TYPE>(ui->cbType->currentData().toInt());
143 bool bUser = false;
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);
150
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);
158
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);
172
173 bool bCA = false;
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);
182}
183
184void CParameterUserUI::on_pbShowPassphrase_clicked()
185{
186 switch(ui->lePassphrase->echoMode())
187 {
188 case QLineEdit::Password:
189 ui->lePassphrase->setEchoMode(QLineEdit::Normal);
190 ui->pbShowPassphrase->setIcon(QIcon::fromTheme("eye-off"));
191 break;
192 case QLineEdit::Normal:
193 ui->lePassphrase->setEchoMode(QLineEdit::Password);
194 ui->pbShowPassphrase->setIcon(QIcon::fromTheme("eye-on"));
195 break;
196 default:
197 ui->pbShowPassphrase->setIcon(QIcon::fromTheme("eye-on"));
198 }
199}
200
201void CParameterUserUI::on_pbSavePassphrase_clicked()
202{
203 if(!parent()->inherits("CParameterNetUI")) return;
204 if(ui->pbSavePassphrase->isChecked())
205 {
206 ui->lePassphrase->setEnabled(true);
207 ui->lePassphrase->setPlaceholderText(tr("Input passphrase"));
208 } else {
209 ui->lePassphrase->setPlaceholderText(tr("Please checked save passphrase to enable"));
210 ui->lePassphrase->setEnabled(false);
211 }
212}
213
214void CParameterUserUI::on_cbSystemFile_stateChanged(int arg1)
215{
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());
220}
221
222void CParameterUserUI::on_pbBrowseCAFile_clicked()
223{
224 QString dir;
225#if defined(Q_OS_LINUX)
226 dir = "~/.vnc";
227#endif
228 QString szFile = QFileDialog::getOpenFileName(this, tr("Open X509 certificate authentication file"), dir);
229 if(szFile.isEmpty())
230 return;
231 ui->leCAFile->setText(szFile);
232}
233
234void CParameterUserUI::on_pbBrowseCRLFile_clicked()
235{
236 QString dir;
237#if defined(Q_OS_LINUX)
238 dir = "~/.vnc";
239#endif
240 QString szFile = QFileDialog::getOpenFileName(this, tr("Open X509 Certificate Revocation List file"), dir);
241 if(szFile.isEmpty())
242 return;
243 ui->leCRLFile->setText(szFile);
244}
CParameterClient * GetParameterClient()
Get CParameterClient.
The parameter UI interface.
Definition ParameterUI.h:15
The user parameters UI.
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.
Parameter interface.
Definition Parameter.h:169