forked from InvictusInnovations/keyhotee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginDialog.cpp
115 lines (99 loc) · 3.32 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "LoginDialog.hpp"
#include "ui_LoginDialog.h"
#include "KeyhoteeApplication.hpp"
#include <QMessageBox>
#include <QSettings>
#include <bts/application.hpp>
#include <fc/log/logger.hpp>
#include <fc/thread/thread.hpp>
LoginDialog::LoginDialog(TKeyhoteeApplication& mainApp, QWidget* parent)
: QDialog(parent),
ui(new Ui::LoginDialog),
_mainApp(mainApp)
{
ui->setupUi(this);
ui->password->setFocus();
#ifdef Q_OS_MAC
ui->frame->setStyleSheet(QStringLiteral("image: url(:/images/keyhotee.icns);"));
#else
ui->frame->setStyleSheet(QStringLiteral("image: url(:/images/keyhotee.png);"));
#endif
ui->frame->setFrameShape(QFrame::NoFrame);
connect(ui->login, &QPushButton::clicked, this, &LoginDialog::onLogin);
connect(ui->newProfile, &QPushButton::clicked, this, &LoginDialog::onNew);
connect(ui->quit, &QPushButton::clicked, this, &LoginDialog::onQuit);
auto profile_name_to_load = _mainApp.getLoadedProfileName();
_selected_profile_ok = false;
auto profiles = bts::application::instance()->get_profiles();
for(const auto& profileName : profiles)
{
QString profileItem = QString::fromStdWString(profileName);
/// FIXME - fc::log cannot get std::wstring
wlog( "profiles ${p}", ("p", profileItem.toStdString()) );
ui->profileSelection->addItem(profileItem);
if(profile_name_to_load == profileItem)
{
ui->profileSelection->setCurrentIndex(ui->profileSelection->count()-1);
_selected_profile_ok = true;
}
}
}
LoginDialog::~LoginDialog()
{
delete ui;
}
void LoginDialog::onLogin()
{
try
{
password = ui->password->text().toStdString();
auto profileName = ui->profileSelection->currentText().toStdWString();
auto profile = bts::application::instance()->load_profile(profileName,password);
if (profile)
{
_mainApp.setLoadedProfileName(ui->profileSelection->currentText());
QSettings settings("Invictus Innovations", "Keyhotee");
settings.setValue("last_profile", ui->profileSelection->currentText());
accept();
}
}
catch (const fc::db_in_use_exception& e)
{
elog("error ${w}", ("w", e.to_detail_string()) );
QMessageBox::warning(this,tr("Keyhotee login"), tr("Unable to load profile: ") +
ui->profileSelection->currentText());
}
catch (const fc::exception& e)
{
elog("error ${w}", ("w", e.to_detail_string()) );
//TODO: We need to display a message to user when profile load fails because
// it can't be opened (versus just a bad password specified). One reason
// a profile load can fail is because it's already locked (opened by another
// Keyhotee process, for example). Unfortunately displaying such a message
// requires untangling the exception thrown, so leaving this as-is for now.
// QMessageBox::warning(this,tr("Unable to load profile"),e.to_detail_string().c_str());
}
ui->password->setText(QString());
ui->password->setFocus();
shake();
}
void LoginDialog::onNew()
{
close();
_mainApp.displayProfileWizard();
}
void LoginDialog::shake()
{
move(pos() + QPoint(10, 0) );
fc::usleep(fc::microseconds(50 * 1000) );
move(pos() + QPoint(-20, 0) );
fc::usleep(fc::microseconds(50 * 1000) );
move(pos() + QPoint(20, 0) );
fc::usleep(fc::microseconds(50 * 1000) );
move(pos() + QPoint(-10, 0) );
}
void LoginDialog::onQuit()
{
_mainApp.quit();
reject();
}