-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoginDialog.cpp
83 lines (67 loc) · 2 KB
/
LoginDialog.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <QLabel>
#include <QLineEdit>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QErrorMessage>
#include "BusyButton.h"
#include "SSHCredentials.h"
#include "LoginDialog.moc"
LoginDialog::LoginDialog(QWidget *parent)
: QDialog(parent)
{
QFormLayout *layout = new QFormLayout(this);
layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
wHost = new QLineEdit();
wHost->resize(150, wHost->height());
layout->addRow(tr("&Host: "), wHost);
wUsername = new QLineEdit();
layout->addRow(tr("&Username: "), wUsername);
wPassword = new QLineEdit();
wPassword->setEchoMode(QLineEdit::Password);
layout->addRow(tr("&Password: "), wPassword);
QDialogButtonBox *bbox = new QDialogButtonBox();
layout->addRow(bbox);
wConnect = new BusyButton("&Connect", this);
wConnect->setDefault(true);
connect(wConnect, SIGNAL(clicked()), this, SLOT(authenticate()));
bbox->addButton(wConnect, QDialogButtonBox::AcceptRole);
setWindowTitle(tr("Connect to scheduler"));
setFixedWidth(sizeHint().width() * 1.4);
setModal(true);
setLayout(layout);
}
void LoginDialog::authenticate()
{
SSHCredentials *cred = new SSHCredentials();
connect(cred, SIGNAL(authorized(SSHCredentials *)),
this, SLOT(authorized(SSHCredentials *)));
connect(cred, SIGNAL(denied(QString)),
this, SLOT(denied(QString)));
cred->Authenticate(wHost->text(), wUsername->text(), wPassword->text());
wConnect->SetBusyState("Connecting");
}
void LoginDialog::authorized(SSHCredentials *credentials)
{
hide();
emit accept(credentials);
}
void LoginDialog::denied(QString error)
{
QErrorMessage msg(this);
msg.showMessage(error);
msg.exec();
wConnect->StopBusyState();
}
void LoginDialog::setHost(QString const& host)
{
wHost->setText(host);
}
void LoginDialog::setUsername(QString const& username)
{
wUsername->setText(username);
}
void LoginDialog::setPassword(QString const& password)
{
wPassword->setText(password);
}