64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#include "login_dialog.hh"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QFormLayout>
|
|
#include <QLabel>
|
|
#include <QMessageBox>
|
|
#include <QVBoxLayout>
|
|
|
|
namespace kappachat {
|
|
|
|
LoginDialog::LoginDialog(QWidget *parent, DeltachatContext *context)
|
|
: QDialog{parent},
|
|
m_context{context},
|
|
m_email{new QLineEdit},
|
|
m_password{new QLineEdit} {
|
|
connect(m_context, &DeltachatContext::configureProgress, this,
|
|
&LoginDialog::configureProgress);
|
|
|
|
auto form = new QFormLayout;
|
|
form->addRow(new QLabel{"Email:"}, m_email);
|
|
form->addRow(new QLabel{"Password:"}, m_password);
|
|
m_password->setEchoMode(QLineEdit::Password);
|
|
|
|
auto buttons =
|
|
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
auto vbox = new QVBoxLayout{this};
|
|
vbox->addLayout(form);
|
|
vbox->addWidget(buttons);
|
|
|
|
setWindowTitle("Login");
|
|
setModal(true);
|
|
|
|
if (!m_context->isConfigured()) {
|
|
show();
|
|
}
|
|
}
|
|
|
|
void LoginDialog::accept() {
|
|
m_context->setConfig("addr", m_email->text());
|
|
m_context->setConfig("mail_pw", m_password->text());
|
|
m_context->configure();
|
|
QDialog::accept();
|
|
}
|
|
|
|
void LoginDialog::configureProgress(int permille, QString message) {
|
|
if (!permille) {
|
|
QMessageBox messagebox;
|
|
messagebox.setText("Login failed.");
|
|
if (message.length() > 500) {
|
|
messagebox.setDetailedText(message);
|
|
} else {
|
|
messagebox.setInformativeText(message);
|
|
}
|
|
messagebox.setIcon(QMessageBox::Critical);
|
|
messagebox.exec();
|
|
show();
|
|
}
|
|
}
|
|
|
|
} // namespace kappachat
|