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-19 08:52:00 -04:00
|
|
|
#include "core/Database.h"
|
2012-06-06 13:59:10 -04:00
|
|
|
#include "core/Group.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())
|
2012-05-19 08:52:00 -04:00
|
|
|
, m_db(0)
|
2012-04-19 10:20:20 -04:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
2012-05-19 08:52:00 -04:00
|
|
|
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(save()));
|
2012-04-19 10:20:20 -04:00
|
|
|
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
2012-05-19 08:52:00 -04:00
|
|
|
connect(m_ui->historyMaxItemsCheckBox, SIGNAL(toggled(bool)),
|
|
|
|
m_ui->historyMaxItemsSpinBox, SLOT(setEnabled(bool)));
|
|
|
|
connect(m_ui->historyMaxSizeCheckBox, SIGNAL(toggled(bool)),
|
|
|
|
m_ui->historyMaxSizeSpinBox, SLOT(setEnabled(bool)));
|
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-19 08:52:00 -04:00
|
|
|
void DatabaseSettingsWidget::load(Database* db)
|
2012-04-19 10:20:20 -04:00
|
|
|
{
|
2012-05-19 08:52:00 -04:00
|
|
|
m_db = db;
|
|
|
|
|
|
|
|
Metadata* meta = m_db->metadata();
|
|
|
|
|
|
|
|
m_ui->dbNameEdit->setText(meta->name());
|
|
|
|
m_ui->dbDescriptionEdit->setText(meta->description());
|
|
|
|
m_ui->recycleBinEnabledCheckBox->setChecked(meta->recycleBinEnabled());
|
|
|
|
m_ui->defaultUsernameEdit->setText(meta->defaultUserName());
|
|
|
|
m_ui->transformRoundsSpinBox->setValue(m_db->transformRounds());
|
|
|
|
if (meta->historyMaxItems() > -1) {
|
|
|
|
m_ui->historyMaxItemsSpinBox->setValue(meta->historyMaxItems());
|
2012-05-10 07:15:43 -04:00
|
|
|
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);
|
|
|
|
}
|
2012-05-19 09:04:05 -04:00
|
|
|
int historyMaxSizeMiB = qRound(meta->historyMaxSize() / qreal(1048576));
|
|
|
|
if (historyMaxSizeMiB > 0) {
|
|
|
|
m_ui->historyMaxSizeSpinBox->setValue(historyMaxSizeMiB);
|
2012-05-10 07:15:43 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-19 08:52:00 -04:00
|
|
|
void DatabaseSettingsWidget::save()
|
2012-05-10 07:15:43 -04:00
|
|
|
{
|
2012-05-19 08:52:00 -04:00
|
|
|
Metadata* meta = m_db->metadata();
|
2012-05-10 07:15:43 -04:00
|
|
|
|
2012-05-19 08:52:00 -04:00
|
|
|
meta->setName(m_ui->dbNameEdit->text());
|
|
|
|
meta->setDescription(m_ui->dbDescriptionEdit->text());
|
|
|
|
meta->setDefaultUserName(m_ui->defaultUsernameEdit->text());
|
|
|
|
meta->setRecycleBinEnabled(m_ui->recycleBinEnabledCheckBox->isChecked());
|
|
|
|
m_db->setTransformRounds(m_ui->transformRoundsSpinBox->value());
|
2012-05-10 07:15:43 -04:00
|
|
|
|
2012-06-06 13:59:10 -04:00
|
|
|
bool truncate = false;
|
|
|
|
|
|
|
|
int historyMaxItems;
|
2012-05-10 07:15:43 -04:00
|
|
|
if (m_ui->historyMaxItemsCheckBox->isChecked()) {
|
2012-06-06 13:59:10 -04:00
|
|
|
historyMaxItems = m_ui->historyMaxItemsSpinBox->value();
|
2012-05-10 07:15:43 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-06-06 13:59:10 -04:00
|
|
|
historyMaxItems = -1;
|
|
|
|
}
|
|
|
|
if (historyMaxItems != meta->historyMaxItems()) {
|
|
|
|
meta->setHistoryMaxItems(historyMaxItems);
|
|
|
|
truncate = true;
|
2012-05-10 07:15:43 -04:00
|
|
|
}
|
2012-06-06 13:59:10 -04:00
|
|
|
|
|
|
|
int historyMaxSize;
|
2012-05-10 07:15:43 -04:00
|
|
|
if (m_ui->historyMaxSizeCheckBox->isChecked()) {
|
2012-06-06 13:59:10 -04:00
|
|
|
historyMaxSize = m_ui->historyMaxSizeSpinBox->value() * 1048576;
|
2012-05-10 07:15:43 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-06-06 13:59:10 -04:00
|
|
|
historyMaxSize = -1;
|
|
|
|
}
|
|
|
|
if (historyMaxSize != meta->historyMaxSize()) {
|
|
|
|
meta->setHistoryMaxSize(historyMaxSize);
|
|
|
|
truncate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (truncate) {
|
|
|
|
truncateHistories();
|
2012-05-10 07:15:43 -04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:20:20 -04:00
|
|
|
Q_EMIT editFinished(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatabaseSettingsWidget::reject()
|
|
|
|
{
|
|
|
|
Q_EMIT editFinished(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();
|
|
|
|
}
|
2012-06-06 13:59:10 -04:00
|
|
|
|
|
|
|
void DatabaseSettingsWidget::truncateHistories()
|
|
|
|
{
|
|
|
|
QList<Entry*> allEntries = m_db->rootGroup()->entriesRecursive(false);
|
|
|
|
Q_FOREACH (Entry* entry, allEntries) {
|
|
|
|
entry->truncateHistory();
|
|
|
|
}
|
|
|
|
}
|