mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-03-11 08:54:48 +00:00
The Database, DatabaseWidget, and DatabaseTabWidget classes share many responsibilities in inconsistent ways resulting in impenetrable and unmaintainable code and a diverse set of bugs and architecture restrictions. This patch reworks the architecture, responsibilities of, and dependencies between these classes. The core changes are: * Move loading and saving logic from widgets into the Database class * Get rid of the DatabaseManagerStruct and move all the information contained in it into the Database * Let database objects keep track of modifications and dirty/clean state instead of handing this to external widgets * Move GUI interactions for loading and saving from the DatabaseTabWidget into the DatabaseWidget (resolves #2494 as a side-effect) * Heavily clean up DatabaseTabWidget and degrade it to a slightly glorified QTabWidget * Use QSharedPointers for all Database objects * Remove the modifiedImmediate signal and replace it with a markAsModified() method * Implement proper tabName() method instead of reading back titles from GUI widgets (resolves #1389 and its duplicates #2146 #855) * Fix unwanted AES-KDF downgrade if database uses Argon2 and has CustomData * Improve code This patch is also the first major step towards solving issues #476 and #2322.
154 lines
4.8 KiB
C++
154 lines
4.8 KiB
C++
/*
|
|
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
|
* 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 "DatabaseSettingsDialog.h"
|
|
#include "ui_DatabaseSettingsDialog.h"
|
|
#include "DatabaseSettingsWidgetGeneral.h"
|
|
#include "DatabaseSettingsWidgetEncryption.h"
|
|
#include "DatabaseSettingsWidgetMasterKey.h"
|
|
#ifdef WITH_XC_BROWSER
|
|
#include "DatabaseSettingsWidgetBrowser.h"
|
|
#endif
|
|
|
|
#include "core/Config.h"
|
|
#include "core/FilePath.h"
|
|
#include "core/Database.h"
|
|
#include "touchid/TouchID.h"
|
|
|
|
DatabaseSettingsDialog::DatabaseSettingsDialog(QWidget* parent)
|
|
: DialogyWidget(parent)
|
|
, m_ui(new Ui::DatabaseSettingsDialog())
|
|
, m_generalWidget(new DatabaseSettingsWidgetGeneral(this))
|
|
, m_securityTabWidget(new QTabWidget(this))
|
|
, m_masterKeyWidget(new DatabaseSettingsWidgetMasterKey(this))
|
|
, m_encryptionWidget(new DatabaseSettingsWidgetEncryption(this))
|
|
#ifdef WITH_XC_BROWSER
|
|
, m_browserWidget(new DatabaseSettingsWidgetBrowser(this))
|
|
#endif
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(save()));
|
|
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
|
|
|
m_ui->categoryList->addCategory(tr("General"), FilePath::instance()->icon("categories", "preferences-other"));
|
|
m_ui->categoryList->addCategory(tr("Security"), FilePath::instance()->icon("actions", "document-encrypt"));
|
|
m_ui->stackedWidget->addWidget(m_generalWidget);
|
|
|
|
m_ui->stackedWidget->addWidget(m_securityTabWidget);
|
|
m_securityTabWidget->addTab(m_masterKeyWidget, tr("Master Key"));
|
|
m_securityTabWidget->addTab(m_encryptionWidget, tr("Encryption Settings"));
|
|
|
|
m_ui->stackedWidget->setCurrentIndex(0);
|
|
m_securityTabWidget->setCurrentIndex(0);
|
|
|
|
connect(m_securityTabWidget, SIGNAL(currentChanged(int)), SLOT(pageChanged()));
|
|
connect(m_ui->categoryList, SIGNAL(categoryChanged(int)), m_ui->stackedWidget, SLOT(setCurrentIndex(int)));
|
|
connect(m_ui->advancedSettingsToggle, SIGNAL(toggled(bool)), SLOT(toggleAdvancedMode(bool)));
|
|
|
|
#ifdef WITH_XC_BROWSER
|
|
m_ui->categoryList->addCategory(tr("Browser Integration"), FilePath::instance()->icon("apps", "internet-web-browser"));
|
|
m_ui->stackedWidget->addWidget(m_browserWidget);
|
|
#endif
|
|
|
|
pageChanged();
|
|
}
|
|
|
|
DatabaseSettingsDialog::~DatabaseSettingsDialog()
|
|
{
|
|
}
|
|
|
|
void DatabaseSettingsDialog::load(QSharedPointer<Database> db)
|
|
{
|
|
m_ui->categoryList->setCurrentCategory(0);
|
|
m_generalWidget->load(db);
|
|
m_masterKeyWidget->load(db);
|
|
m_encryptionWidget->load(db);
|
|
#ifdef WITH_XC_BROWSER
|
|
m_browserWidget->load(db);
|
|
#endif
|
|
m_ui->advancedSettingsToggle->setChecked(config()->get("GUI/AdvancedSettings", false).toBool());
|
|
m_db = db;
|
|
}
|
|
|
|
/**
|
|
* Show page and tab with database master key settings.
|
|
*/
|
|
void DatabaseSettingsDialog::showMasterKeySettings()
|
|
{
|
|
m_ui->categoryList->setCurrentCategory(1);
|
|
m_securityTabWidget->setCurrentIndex(0);
|
|
}
|
|
|
|
void DatabaseSettingsDialog::save()
|
|
{
|
|
if (!m_generalWidget->save()) {
|
|
return;
|
|
}
|
|
|
|
if (!m_masterKeyWidget->save()) {
|
|
return;
|
|
}
|
|
|
|
if (!m_encryptionWidget->save()) {
|
|
return;
|
|
}
|
|
|
|
#ifdef WITH_XC_TOUCHID
|
|
TouchID::getInstance().reset(m_db ? m_db->filePath() : "");
|
|
#endif
|
|
|
|
emit editFinished(true);
|
|
}
|
|
|
|
void DatabaseSettingsDialog::reject()
|
|
{
|
|
emit editFinished(false);
|
|
}
|
|
|
|
void DatabaseSettingsDialog::pageChanged()
|
|
{
|
|
int pageIndex = m_ui->stackedWidget->currentIndex();
|
|
|
|
bool enabled = (pageIndex == Page::General && m_generalWidget->hasAdvancedMode());
|
|
|
|
if (Page::Security == pageIndex) {
|
|
int tabIndex = m_securityTabWidget->currentIndex();
|
|
enabled = (tabIndex == 0 && m_masterKeyWidget->hasAdvancedMode());
|
|
enabled |= (tabIndex == 1 && m_encryptionWidget->hasAdvancedMode());
|
|
}
|
|
|
|
m_ui->advancedSettingsToggle->setEnabled(enabled);
|
|
}
|
|
|
|
void DatabaseSettingsDialog::toggleAdvancedMode(bool advanced)
|
|
{
|
|
if (m_generalWidget->hasAdvancedMode()) {
|
|
m_generalWidget->setAdvancedMode(advanced);
|
|
}
|
|
|
|
if (m_masterKeyWidget->hasAdvancedMode()) {
|
|
m_masterKeyWidget->setAdvancedMode(advanced);
|
|
}
|
|
|
|
if (m_encryptionWidget->hasAdvancedMode()) {
|
|
m_encryptionWidget->setAdvancedMode(advanced);
|
|
}
|
|
|
|
config()->set("GUI/AdvancedSettings", advanced);
|
|
}
|