83 lines
2.5 KiB
C++
83 lines
2.5 KiB
C++
#include "ParametersProvider.hpp"
|
|
|
|
ParametersProvider::ParametersProvider(QWidget *parent)
|
|
: QDialog(parent) {
|
|
auto *layout = new QVBoxLayout;
|
|
|
|
auto *user = new QLabel("Username", this);
|
|
userField = new QLineEdit;
|
|
|
|
auto *pass = new QLabel("Password", this);
|
|
passField = new QLineEdit;
|
|
passField->setEchoMode(QLineEdit::Password);
|
|
|
|
auto *imap = new QLabel("IMAP Server", this);
|
|
imapField = new QLineEdit;
|
|
|
|
auto *port = new QLabel("Port", this);
|
|
portField = new QLineEdit;
|
|
portField->setValidator(new QIntValidator(1, 1000, this));
|
|
|
|
auto *startButton = new QPushButton("OK", this);
|
|
|
|
layout->addWidget(user);
|
|
layout->addWidget(userField);
|
|
layout->addWidget(pass);
|
|
layout->addWidget(passField);
|
|
layout->addWidget(imap);
|
|
layout->addWidget(imapField);
|
|
layout->addWidget(port);
|
|
layout->addWidget(portField);
|
|
layout->addStretch(1);
|
|
layout->addWidget(startButton);
|
|
|
|
this->setLayout(layout);
|
|
|
|
resize(300, 450);
|
|
|
|
connect(startButton, &QPushButton::clicked, this, &ParametersProvider::start);
|
|
|
|
// Keychain
|
|
connect(&keychain, &KeychainClass::keyRead, this, &ParametersProvider::keyRead);
|
|
keychain.readKey(Keychain::passKey);
|
|
|
|
// Do not override the defaults
|
|
userField->setText(mSettings.value("Username").toString());
|
|
imapField->setText(mSettings.value("Server").toString());
|
|
portField->setText(mSettings.value("Port").toString());
|
|
|
|
if (imapField->text().isEmpty())
|
|
imapField->setText("imap.gmail.com");
|
|
if (portField->text().isEmpty())
|
|
portField->setText("993");
|
|
}
|
|
|
|
void ParametersProvider::keyRead(const QString &key, const QString &value) {
|
|
if (key == Keychain::passKey)
|
|
passField->setText(value);
|
|
}
|
|
|
|
void ParametersProvider::start() {
|
|
sett.port = portField->text().toInt();
|
|
sett.userS = userField->text().toStdString();
|
|
sett.passS = passField->text().toStdString();
|
|
sett.imapS = imapField->text().toStdString();
|
|
|
|
// Saved login data
|
|
keychain.writeKey(Keychain::passKey, QString::fromStdString(sett.passS));
|
|
mSettings.setValue("Username", QString::fromStdString(sett.userS));
|
|
mSettings.setValue("Server", QString::fromStdString(sett.imapS));
|
|
mSettings.setValue("Port", QString::fromStdString(std::to_string(sett.port)));
|
|
|
|
close();
|
|
emit done();
|
|
}
|
|
|
|
void ParametersProvider::setFocusInternal() {
|
|
activateWindow();
|
|
userField->setFocus();
|
|
}
|
|
|
|
const ParametersProvider::settings &ParametersProvider::getSettings() {
|
|
return sett;
|
|
} |