-
Notifications
You must be signed in to change notification settings - Fork 0
/
passphrasedialog.cpp
62 lines (50 loc) · 1.62 KB
/
passphrasedialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "passphrasedialog.h"
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QDialogButtonBox>
passphraseDialog::passphraseDialog(QWidget *parent):
QDialog(parent),
changeClicked(false) {
init();
}
void passphraseDialog::init() {
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *label = new QLabel("Enter the passphrase", this);
layout->addWidget(label);
linedit = new QLineEdit(this);
linedit->setEchoMode(QLineEdit::Password);
layout->addWidget(linedit);
okButton = new QPushButton("Ok",this);
changeButton = new QPushButton("Change Passphrase", this);
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox->addButton(changeButton, QDialogButtonBox::AcceptRole);
buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole);
okButton->setDefault(true);
layout->addWidget(buttonBox);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(changeButton, SIGNAL(clicked()), this, SLOT(changeClickedSlot()));
}
void passphraseDialog::changeClickedSlot() {
this->changeClicked = true;
}
QString passphraseDialog::getPassphrase(int &val, QWidget *parent) {
passphraseDialog dialog(parent);
QString passphrase = "";
bool accepted = (dialog.exec() == QDialog::Accepted);
if(accepted) {
if(dialog.changeClicked) {
val = 1;
}
else {
QLineEdit *linedit = dialog.linedit;
passphrase = linedit->text();
val = 0;
}
}
else {
val = -1;
}
return passphrase;
}