From 1c24b2c5c48ae30ccaa8de35a757a67e1aa5dc56 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Thu, 10 May 2012 13:15:43 +0200 Subject: [PATCH] Add gui option for history max items and size to database settings widget. --- src/core/Metadata.cpp | 7 ++- src/core/Metadata.h | 3 ++ src/gui/DatabaseSettingsWidget.cpp | 68 ++++++++++++++++++++++- src/gui/DatabaseSettingsWidget.h | 9 +++- src/gui/DatabaseSettingsWidget.ui | 86 +++++++++++++++++++++++++----- src/gui/DatabaseWidget.cpp | 6 ++- 6 files changed, 162 insertions(+), 17 deletions(-) diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index ac0ba709a..a5a35b2d4 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -31,8 +31,8 @@ Metadata::Metadata(Database* parent) m_recycleBinEnabled = true; m_masterKeyChangeRec = -1; m_masterKeyChangeForce = -1; - m_historyMaxItems = 10; - m_historyMaxSize = 6291456; + m_historyMaxItems = defaultHistoryMaxItems; + m_historyMaxSize = defaultHistoryMaxSize; QDateTime now = Tools::currentDateTimeUtc(); m_nameChanged = now; @@ -52,6 +52,9 @@ Metadata::Metadata(Database* parent) m_updateDatetime = true; } +const int Metadata::defaultHistoryMaxItems = 10; +const int Metadata::defaultHistoryMaxSize = 6291456; + template bool Metadata::set(P& property, const V& value) { if (property != value) { diff --git a/src/core/Metadata.h b/src/core/Metadata.h index f00e07abe..62f01b15f 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -69,6 +69,9 @@ public: int historyMaxSize() const; QHash customFields() const; + static const int defaultHistoryMaxItems; + static const int defaultHistoryMaxSize; + void setGenerator(const QString& value); void setName(const QString& value); void setNameChanged(const QDateTime& value); diff --git a/src/gui/DatabaseSettingsWidget.cpp b/src/gui/DatabaseSettingsWidget.cpp index c15119575..6d6da9822 100644 --- a/src/gui/DatabaseSettingsWidget.cpp +++ b/src/gui/DatabaseSettingsWidget.cpp @@ -18,6 +18,8 @@ #include "DatabaseSettingsWidget.h" #include "ui_DatabaseSettingsWidget.h" +#include "core/Metadata.h" + DatabaseSettingsWidget::DatabaseSettingsWidget(QWidget* parent) : DialogyWidget(parent) @@ -27,6 +29,10 @@ DatabaseSettingsWidget::DatabaseSettingsWidget(QWidget* parent) connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(changeSettings())); connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject())); + connect(m_ui->historyMaxItemsCheckBox, SIGNAL(stateChanged(int)), + this, SLOT(toggleHistoryMaxItemsSpinBox(int))); + connect(m_ui->historyMaxSizeCheckBox, SIGNAL(stateChanged(int)), + this, SLOT(toggleHistoryMaxSizeSpinBox(int))); } DatabaseSettingsWidget::~DatabaseSettingsWidget() @@ -35,7 +41,8 @@ DatabaseSettingsWidget::~DatabaseSettingsWidget() void DatabaseSettingsWidget::setForms(QString dbName, QString dbDescription, QString defaultUsername, bool recylceBinEnabled, - int transformRounds) + int transformRounds, int historyMaxItems, + int historyMaxSize) { m_ui->dbNameEdit->setText(dbName); m_ui->dbDescriptionEdit->setText(dbDescription); @@ -47,6 +54,22 @@ void DatabaseSettingsWidget::setForms(QString dbName, QString dbDescription, } m_ui->defaultUsernameEdit->setText(defaultUsername); m_ui->transformRoundsSpinBox->setValue(transformRounds); + if (historyMaxItems > -1) { + m_ui->historyMaxItemsSpinBox->setValue(historyMaxItems); + m_ui->historyMaxItemsCheckBox->setChecked(true); + } + else { + m_ui->historyMaxItemsSpinBox->setValue(Metadata::defaultHistoryMaxItems); + m_ui->historyMaxItemsCheckBox->setChecked(false); + } + if (historyMaxSize > -1) { + m_ui->historyMaxSizeSpinBox->setValue(historyMaxSize); + m_ui->historyMaxSizeCheckBox->setChecked(true); + } + else { + m_ui->historyMaxSizeSpinBox->setValue(Metadata::defaultHistoryMaxSize); + m_ui->historyMaxSizeCheckBox->setChecked(false); + } m_ui->dbNameEdit->setFocus(); } @@ -76,6 +99,16 @@ bool DatabaseSettingsWidget::recylceBinEnabled() return m_recylceBinEnabled; } +int DatabaseSettingsWidget::historyMaxItems() +{ + return m_historyMaxItems; +} + +int DatabaseSettingsWidget::historyMaxSize() +{ + return m_historyMaxSize; +} + void DatabaseSettingsWidget::changeSettings() { m_dbName = m_ui->dbNameEdit->text(); @@ -88,6 +121,19 @@ void DatabaseSettingsWidget::changeSettings() m_recylceBinEnabled = false; } m_transformRounds = m_ui->transformRoundsSpinBox->value(); + 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; + } + Q_EMIT editFinished(true); } @@ -97,3 +143,23 @@ void DatabaseSettingsWidget::reject() Q_EMIT editFinished(false); } +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); + } + +} diff --git a/src/gui/DatabaseSettingsWidget.h b/src/gui/DatabaseSettingsWidget.h index 8652757ba..25de991ec 100644 --- a/src/gui/DatabaseSettingsWidget.h +++ b/src/gui/DatabaseSettingsWidget.h @@ -38,12 +38,15 @@ public: void setForms(QString dbName, QString dbDescription, QString defaultUsername, bool recylceBinEnabled, - int transformRounds); + int transformRounds, int historyMaxItems, + int historyMaxSize); quint64 transformRounds(); QString dbName(); QString dbDescription(); QString defaultUsername(); bool recylceBinEnabled(); + int historyMaxItems(); + int historyMaxSize(); Q_SIGNALS: void editFinished(bool accepted); @@ -51,6 +54,8 @@ Q_SIGNALS: private Q_SLOTS: void changeSettings(); void reject(); + void toggleHistoryMaxItemsSpinBox(int state); + void toggleHistoryMaxSizeSpinBox(int state); private: const QScopedPointer m_ui; @@ -60,6 +65,8 @@ private: QString m_defaultUsername; bool m_recylceBinEnabled; quint64 m_transformRounds; + int m_historyMaxItems; + int m_historyMaxSize; Q_DISABLE_COPY(DatabaseSettingsWidget) }; diff --git a/src/gui/DatabaseSettingsWidget.ui b/src/gui/DatabaseSettingsWidget.ui index 71344200a..49e10c3b9 100644 --- a/src/gui/DatabaseSettingsWidget.ui +++ b/src/gui/DatabaseSettingsWidget.ui @@ -42,9 +42,6 @@ - - - @@ -52,6 +49,9 @@ + + + @@ -75,13 +75,6 @@ - - - - true - - - @@ -89,8 +82,12 @@ - - + + + + true + + @@ -99,6 +96,71 @@ + + + + + + + History max size: + + + + + + + + + + + + + + + + + 0 + 0 + + + + 2000000000 + + + + + + + + + History max items: + + + + + + + + + + + + + + + + + 0 + 0 + + + + 2000000000 + + + + + diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index a53b25ba7..7e5dae9cd 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -276,6 +276,8 @@ void DatabaseWidget::updateSettings(bool accepted) m_db->metadata()->setDefaultUserName(m_databaseSettingsWidget->defaultUsername()); m_db->metadata()->setRecycleBinEnabled(m_databaseSettingsWidget->recylceBinEnabled()); m_db->metadata()->setName(m_databaseSettingsWidget->dbName()); + m_db->metadata()->setHistoryMaxItems(m_databaseSettingsWidget->historyMaxItems()); + m_db->metadata()->setHistoryMaxSize(m_databaseSettingsWidget->historyMaxSize()); } setCurrentIndex(0); @@ -303,7 +305,9 @@ void DatabaseWidget::switchToDatabaseSettings() m_db->metadata()->description(), m_db->metadata()->defaultUserName(), m_db->metadata()->recycleBinEnabled(), - m_db->transformRounds()); + m_db->transformRounds(), + m_db->metadata()->historyMaxItems(), + m_db->metadata()->historyMaxSize()); setCurrentIndex(4); }