162 lines
4.7 KiB
C++
Executable File
162 lines
4.7 KiB
C++
Executable File
#include "LoginWnd.h"
|
|
#include "ui_LoginUi.h"
|
|
|
|
#include <QGraphicsDropShadowEffect>
|
|
#include <QFileDialog>
|
|
#include <QDebug>
|
|
#include <QSqlDatabase>
|
|
|
|
|
|
LoginWnd::LoginWnd(QWidget *parent)
|
|
: QDialog(parent)
|
|
, m_ui(new Ui::LoginWnd)
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
connect(m_ui->pbHeart, &QPushButton::clicked,
|
|
this, &LoginWnd::slotHeart);
|
|
|
|
// SQLite:
|
|
connect(m_ui->pbLoadFile, &QPushButton::clicked, this, &LoginWnd::slotLoadFile);
|
|
connect(m_ui->tbChooseFile, &QToolButton::clicked, this, &LoginWnd::slotChooseFile);
|
|
connect(m_ui->pbExit_2, &QPushButton::clicked, this, &LoginWnd::reject);
|
|
|
|
// DBMS:
|
|
connect(m_ui->pbLogin, &QPushButton::clicked, this, &LoginWnd::accept);
|
|
connect(m_ui->pbExit, &QPushButton::clicked, this, &LoginWnd::reject);
|
|
|
|
// Common:
|
|
connect(m_ui->pbLoad, &QPushButton::clicked, this, &LoginWnd::slotLoadPreset);
|
|
connect(m_ui->pbSave, &QPushButton::clicked, this, &LoginWnd::slotSavePreset);
|
|
|
|
fillPresetComboBox();
|
|
|
|
|
|
// set typical values
|
|
m_ui->leDatabase->setText(QStringLiteral("lts_ets_pro"));
|
|
m_ui->leUsername->setText(QStringLiteral("ets_exm"));
|
|
|
|
m_ui->leHostname->setPlaceholderText(QStringLiteral("on-site: try 'EXCDBS01'"));
|
|
|
|
m_ui->cbDriver->addItems(QSqlDatabase::drivers());
|
|
const int idx = m_ui->cbDriver->findText(QStringLiteral("QPSQL"));
|
|
if (idx >= 0)
|
|
m_ui->cbDriver->setCurrentIndex(idx);
|
|
}
|
|
|
|
LoginWnd::~LoginWnd()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void LoginWnd::slotLoadFile()
|
|
{
|
|
if (m_ui->leFilename->text().isEmpty())
|
|
return;
|
|
|
|
accept(); // just to make clear that the user cannot login to a database, so he has to click explicitly on "Load File"
|
|
}
|
|
|
|
|
|
void LoginWnd::slotChooseFile()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select File-based Database"),
|
|
QString(), // last wd
|
|
tr("All Files (*.*)"));
|
|
|
|
if (fileName.isEmpty())
|
|
return;
|
|
|
|
m_ui->leFilename->setText(fileName);
|
|
}
|
|
|
|
|
|
void LoginWnd::fillPresetComboBox()
|
|
{
|
|
m_ui->cbPresets->clear();
|
|
|
|
const PresetManager::PresetList &presetList = presetManager.getPresetList();
|
|
|
|
for (const Preset &preset : qAsConst(presetList))
|
|
m_ui->cbPresets->addItem(preset.name);
|
|
|
|
if (!presetList.isEmpty())
|
|
{
|
|
setDefaultLoginData(presetList.first().loginData);
|
|
m_ui->cbPresets->setCurrentIndex(0);
|
|
}
|
|
}
|
|
|
|
|
|
void LoginWnd::slotLoadPreset()
|
|
{
|
|
setDefaultLoginData(presetManager.getPresetList().at(m_ui->cbPresets->currentIndex()).loginData);
|
|
}
|
|
|
|
void LoginWnd::slotSavePreset()
|
|
{
|
|
presetManager.savePreset(getLoginData(), this);
|
|
|
|
fillPresetComboBox();
|
|
setDefaultLoginData(presetManager.getPresetList().at(m_ui->cbPresets->count()-1).loginData); // set default to last (new) preset
|
|
m_ui->cbPresets->setCurrentIndex(m_ui->cbPresets->count()-1); // set index to last (new) preset
|
|
}
|
|
|
|
|
|
void LoginWnd::setDefaultLoginData(const LoginData &defaultLoginData)
|
|
{
|
|
if (!defaultLoginData.filename.isEmpty()) // no username, etc needed if that's a file
|
|
{
|
|
m_ui->leFilename->setText(defaultLoginData.filename);
|
|
m_ui->leDatabase->setText(QString());
|
|
m_ui->leUsername->setText(QString());
|
|
m_ui->lePassword->setText(QString());
|
|
m_ui->leHostname->setText(QString());
|
|
m_ui->sbPort->setValue(-1);
|
|
}
|
|
else
|
|
{
|
|
m_ui->leFilename->setText(QString());
|
|
m_ui->leDatabase->setText(defaultLoginData.database);
|
|
m_ui->leUsername->setText(defaultLoginData.username);
|
|
m_ui->lePassword->setText(defaultLoginData.password);
|
|
m_ui->leHostname->setText(defaultLoginData.hostname);
|
|
m_ui->cbDriver->setCurrentIndex(m_ui->cbDriver->findText(defaultLoginData.driver));
|
|
m_ui->sbPort->setValue(defaultLoginData.port);
|
|
}
|
|
}
|
|
|
|
|
|
LoginData LoginWnd::getLoginData() const
|
|
{
|
|
LoginData ld;
|
|
|
|
ld.driver = m_ui->cbDriver->currentText();
|
|
ld.database = m_ui->leDatabase->text();
|
|
ld.username = m_ui->leUsername->text();
|
|
ld.password = m_ui->lePassword->text();
|
|
ld.hostname = m_ui->leHostname->text();
|
|
ld.port = m_ui->sbPort->value();
|
|
ld.filename = m_ui->leFilename->text();
|
|
|
|
return ld;
|
|
}
|
|
|
|
void LoginWnd::slotHeart()
|
|
{
|
|
QWidget* w = new QWidget;
|
|
w->setAttribute(Qt::WA_DeleteOnClose); // delete when closed
|
|
QVBoxLayout* b = new QVBoxLayout;
|
|
QLabel* l = new QLabel(QStringLiteral("<html><body>Geschmiedet mit %1 , ohne Kostenträger, für das Team.<br>Diese Software wurde in meiner Freizeit entwickelt, bitte habt Verständnis für Bugs und Geduld für Fixes. Danke! - Euer Mike Wille, SLSE 2016, 17</body></html>").arg(QChar(0x2764)));
|
|
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect;
|
|
shadow->setOffset(0,0);
|
|
shadow->setBlurRadius(22);
|
|
shadow->setColor(QColor("blue"));
|
|
l->setGraphicsEffect(shadow);
|
|
b->addWidget(l);
|
|
w->setLayout(b);
|
|
|
|
w->show();
|
|
}
|