2012-04-19 10:20:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DatabaseSettingsWidget.h"
|
|
|
|
#include "ui_DatabaseSettingsWidget.h"
|
|
|
|
|
2012-05-10 07:15:43 -04:00
|
|
|
#include "core/Metadata.h"
|
2012-05-12 09:39:55 -04:00
|
|
|
#include "keys/CompositeKey.h"
|
2012-04-19 10:20:20 -04:00
|
|
|
|
|
|
|
DatabaseSettingsWidget::DatabaseSettingsWidget(QWidget* parent)
|
2012-04-24 07:23:09 -04:00
|
|
|
: DialogyWidget(parent)
|
2012-04-19 10:20:20 -04:00
|
|
|
, m_ui(new Ui::DatabaseSettingsWidget())
|
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
|
|
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(changeSettings()));
|
|
|
|
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
2012-05-10 07:15:43 -04:00
|
|
|
connect(m_ui->historyMaxItemsCheckBox, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(toggleHistoryMaxItemsSpinBox(int)));
|
|
|
|
connect(m_ui->historyMaxSizeCheckBox, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(toggleHistoryMaxSizeSpinBox(int)));
|
2012-05-12 09:39:55 -04:00
|
|
|
connect(m_ui->transformBenchmarkButton, SIGNAL(clicked()), SLOT(transformRoundsBenchmark()));
|
2012-04-19 10:20:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DatabaseSettingsWidget::~DatabaseSettingsWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-14 10:27:59 -04:00
|
|
|
void DatabaseSettingsWidget::setForms(const QString& dbName, const QString& dbDescription,
|
|
|
|
const QString& defaultUsername, bool recylceBinEnabled,
|
2012-05-10 07:15:43 -04:00
|
|
|
int transformRounds, int historyMaxItems,
|
|
|
|
int historyMaxSize)
|
2012-04-19 10:20:20 -04:00
|
|
|
{
|
2012-04-19 12:10:53 -04:00
|
|
|
m_ui->dbNameEdit->setText(dbName);
|
|
|
|
m_ui->dbDescriptionEdit->setText(dbDescription);
|
|
|
|
if (recylceBinEnabled) {
|
|
|
|
m_ui->recycleBinEnabledCheckBox->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->recycleBinEnabledCheckBox->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
2012-04-23 14:10:07 -04:00
|
|
|
m_ui->defaultUsernameEdit->setText(defaultUsername);
|
2012-04-19 10:20:20 -04:00
|
|
|
m_ui->transformRoundsSpinBox->setValue(transformRounds);
|
2012-05-10 07:15:43 -04:00
|
|
|
if (historyMaxItems > -1) {
|
|
|
|
m_ui->historyMaxItemsSpinBox->setValue(historyMaxItems);
|
|
|
|
m_ui->historyMaxItemsCheckBox->setChecked(true);
|
|
|
|
}
|
|
|
|
else {
|
2012-05-14 13:10:42 -04:00
|
|
|
m_ui->historyMaxItemsSpinBox->setValue(Metadata::DefaultHistoryMaxItems);
|
2012-05-10 07:15:43 -04:00
|
|
|
m_ui->historyMaxItemsCheckBox->setChecked(false);
|
|
|
|
}
|
|
|
|
if (historyMaxSize > -1) {
|
|
|
|
m_ui->historyMaxSizeSpinBox->setValue(historyMaxSize);
|
|
|
|
m_ui->historyMaxSizeCheckBox->setChecked(true);
|
|
|
|
}
|
|
|
|
else {
|
2012-05-14 13:10:42 -04:00
|
|
|
m_ui->historyMaxSizeSpinBox->setValue(Metadata::DefaultHistoryMaxSize);
|
2012-05-10 07:15:43 -04:00
|
|
|
m_ui->historyMaxSizeCheckBox->setChecked(false);
|
|
|
|
}
|
2012-04-23 17:19:29 -04:00
|
|
|
|
|
|
|
m_ui->dbNameEdit->setFocus();
|
2012-04-19 10:20:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 DatabaseSettingsWidget::transformRounds()
|
|
|
|
{
|
|
|
|
return m_transformRounds;
|
|
|
|
}
|
|
|
|
|
2012-04-19 12:10:53 -04:00
|
|
|
QString DatabaseSettingsWidget::dbName()
|
|
|
|
{
|
|
|
|
return m_dbName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DatabaseSettingsWidget::dbDescription()
|
|
|
|
{
|
|
|
|
return m_dbDescription;
|
|
|
|
}
|
|
|
|
|
2012-04-23 14:10:07 -04:00
|
|
|
QString DatabaseSettingsWidget::defaultUsername()
|
|
|
|
{
|
|
|
|
return m_defaultUsername;
|
|
|
|
}
|
|
|
|
|
2012-04-19 12:10:53 -04:00
|
|
|
bool DatabaseSettingsWidget::recylceBinEnabled()
|
|
|
|
{
|
|
|
|
return m_recylceBinEnabled;
|
|
|
|
}
|
|
|
|
|
2012-05-10 07:15:43 -04:00
|
|
|
int DatabaseSettingsWidget::historyMaxItems()
|
|
|
|
{
|
|
|
|
return m_historyMaxItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DatabaseSettingsWidget::historyMaxSize()
|
|
|
|
{
|
|
|
|
return m_historyMaxSize;
|
|
|
|
}
|
|
|
|
|
2012-04-19 10:20:20 -04:00
|
|
|
void DatabaseSettingsWidget::changeSettings()
|
|
|
|
{
|
2012-04-19 12:10:53 -04:00
|
|
|
m_dbName = m_ui->dbNameEdit->text();
|
|
|
|
m_dbDescription = m_ui->dbDescriptionEdit->text();
|
2012-04-23 14:10:07 -04:00
|
|
|
m_defaultUsername = m_ui->defaultUsernameEdit->text();
|
2012-04-19 12:10:53 -04:00
|
|
|
if (m_ui->recycleBinEnabledCheckBox->checkState() == Qt::Checked) {
|
|
|
|
m_recylceBinEnabled = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_recylceBinEnabled = false;
|
|
|
|
}
|
2012-04-19 10:20:20 -04:00
|
|
|
m_transformRounds = m_ui->transformRoundsSpinBox->value();
|
2012-05-10 07:15:43 -04:00
|
|
|
if (m_ui->historyMaxItemsCheckBox->isChecked()) {
|
|
|
|
m_historyMaxItems = m_ui->historyMaxItemsSpinBox->value();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_historyMaxItems = -1;
|
|
|
|
}
|
|
|
|
if (m_ui->historyMaxSizeCheckBox->isChecked()) {
|
|
|
|
m_historyMaxSize = m_ui->historyMaxSizeSpinBox->value();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_historyMaxSize = -1;
|
|
|
|
}
|
|
|
|
|
2012-04-19 12:10:53 -04:00
|
|
|
|
2012-04-19 10:20:20 -04:00
|
|
|
Q_EMIT editFinished(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatabaseSettingsWidget::reject()
|
|
|
|
{
|
|
|
|
Q_EMIT editFinished(false);
|
|
|
|
}
|
|
|
|
|
2012-05-10 07:15:43 -04:00
|
|
|
void DatabaseSettingsWidget::toggleHistoryMaxItemsSpinBox(int state)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
m_ui->historyMaxItemsSpinBox->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->historyMaxItemsSpinBox->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatabaseSettingsWidget::toggleHistoryMaxSizeSpinBox(int state)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
m_ui->historyMaxSizeSpinBox->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->historyMaxSizeSpinBox->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2012-05-12 09:39:55 -04:00
|
|
|
|
|
|
|
void DatabaseSettingsWidget::transformRoundsBenchmark()
|
|
|
|
{
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
m_ui->transformRoundsSpinBox->setValue(CompositeKey::transformKeyBenchmark(1000));
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|