-
Notifications
You must be signed in to change notification settings - Fork 1
/
keydialog.cpp
53 lines (48 loc) · 1.27 KB
/
keydialog.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
#include "keydialog.h"
#include "ui_keydialog.h"
KeyDialog::KeyDialog(QWidget *parent) :QDialog(parent),ui(new Ui::KeyDialog)
{
ui->setupUi(this);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
}
KeyDialog::~KeyDialog()
{
delete ui;
}
QByteArray KeyDialog::getKey()
{
key = QByteArray();
ui->lineEdit->clear();
show();
QEventLoop loop;
connect(this, SIGNAL(buttonClickProcessed()), &loop, SLOT(quit()));
loop.exec();
disconnect(this, SIGNAL(buttonClickProcessed()), &loop, SLOT(quit()));
close();
return key;
}
void KeyDialog::okButtonClicked()
{
QString hex = ui->lineEdit->text();
if(hex.size() != 64)
{
QMessageBox::warning(this, "Error", "Key length should be 256");
return;
}
QByteArray result = QByteArray::fromHex(hex.toLatin1());
if(result.length() != 32)
{
QMessageBox::warning(this, "Error", "Wrong format");
return;
}
key = result;
ok = true;
emit buttonClickProcessed();
}
void KeyDialog::cancelButtonClicked()
{
ok = false;
emit buttonClickProcessed();
}