Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2020-08-02 01:00:47 +0300
committerJonathan White <support@dmapps.us>2020-08-08 22:40:00 +0300
commitc538f0b907aaae5b8033b9bd370e7d9ea58488de (patch)
treeacf7c329ee25c1adfee1d56c4cacd1e75f57372f /src/gui/DatabaseWidget.cpp
parentfd7daf4c896ab59dd4c65c82a6b29920378b8a31 (diff)
Fixup saving non-data changes on database lock
* Fix #5107 * Change setting for non-data changes to Auto save on database lock (or not) instead of marking modified. * When enabled, database will be auto-saved if there are only non-data changes, but will not prompt the user if saving has failed. * When disabled, database will not auto-save if there are only non-data changes (same behavior as 2.5 and below) and will not mark the database dirty.
Diffstat (limited to 'src/gui/DatabaseWidget.cpp')
-rw-r--r--src/gui/DatabaseWidget.cpp83
1 files changed, 40 insertions, 43 deletions
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp
index 8aca27940..90f464422 100644
--- a/src/gui/DatabaseWidget.cpp
+++ b/src/gui/DatabaseWidget.cpp
@@ -1562,7 +1562,7 @@ bool DatabaseWidget::lock()
}
}
- if (m_db->isModified(true)) {
+ if (m_db->isModified()) {
bool saved = false;
// Attempt to save on exit, but don't block locking if it fails
if (config()->get(Config::AutoSaveOnExit).toBool()
@@ -1590,6 +1590,10 @@ bool DatabaseWidget::lock()
return false;
}
}
+ } else if (m_db->hasNonDataChanges() && config()->get(Config::AutoSaveNonDataChanges).toBool()) {
+ // Silently auto-save non-data changes, ignore errors
+ QString errorMessage;
+ performSave(errorMessage);
}
if (m_groupView->currentGroup()) {
@@ -1646,7 +1650,7 @@ void DatabaseWidget::reloadDatabaseFile()
QString error;
auto db = QSharedPointer<Database>::create(m_db->filePath());
if (db->open(database()->key(), &error)) {
- if (m_db->isModified(true)) {
+ if (m_db->isModified() || db->hasNonDataChanges()) {
// Ask if we want to merge changes into new database
auto result = MessageBox::question(
this,
@@ -1839,33 +1843,14 @@ bool DatabaseWidget::save()
m_blockAutoSave = true;
++m_saveAttempts;
- QPointer<QWidget> focusWidget(qApp->focusWidget());
-
- // TODO: Make this async
- // Lock out interactions
- m_entryView->setDisabled(true);
- m_groupView->setDisabled(true);
- QApplication::processEvents();
-
- bool useAtomicSaves = config()->get(Config::UseAtomicSaves).toBool();
QString errorMessage;
- bool ok = m_db->save(&errorMessage, useAtomicSaves, config()->get(Config::BackupBeforeSave).toBool());
-
- // Return control
- m_entryView->setDisabled(false);
- m_groupView->setDisabled(false);
-
- if (focusWidget) {
- focusWidget->setFocus();
- }
-
- if (ok) {
+ if (performSave(errorMessage)) {
m_saveAttempts = 0;
m_blockAutoSave = false;
return true;
}
- if (m_saveAttempts > 2 && useAtomicSaves) {
+ if (m_saveAttempts > 2 && config()->get(Config::UseAtomicSaves).toBool()) {
// Saving failed 3 times, issue a warning and attempt to resolve
auto result = MessageBox::question(this,
tr("Disable safe saves?"),
@@ -1913,33 +1898,45 @@ bool DatabaseWidget::saveAs()
bool ok = false;
if (!newFilePath.isEmpty()) {
- QPointer<QWidget> focusWidget(qApp->focusWidget());
+ QString errorMessage;
+ if (!performSave(errorMessage, newFilePath)) {
+ showMessage(tr("Writing the database failed: %1").arg(errorMessage),
+ MessageWidget::Error,
+ true,
+ MessageWidget::LongAutoHideTimeout);
+ }
+ }
- // Lock out interactions
- m_entryView->setDisabled(true);
- m_groupView->setDisabled(true);
- QApplication::processEvents();
+ return ok;
+}
- QString errorMessage;
- ok = m_db->saveAs(newFilePath,
+bool DatabaseWidget::performSave(QString& errorMessage, const QString& fileName)
+{
+ QPointer<QWidget> focusWidget(qApp->focusWidget());
+
+ // Lock out interactions
+ m_entryView->setDisabled(true);
+ m_groupView->setDisabled(true);
+ QApplication::processEvents();
+
+ bool ok;
+ if (fileName.isEmpty()) {
+ ok = m_db->save(&errorMessage,
+ config()->get(Config::UseAtomicSaves).toBool(),
+ config()->get(Config::BackupBeforeSave).toBool());
+ } else {
+ ok = m_db->saveAs(fileName,
&errorMessage,
config()->get(Config::UseAtomicSaves).toBool(),
config()->get(Config::BackupBeforeSave).toBool());
+ }
- // Return control
- m_entryView->setDisabled(false);
- m_groupView->setDisabled(false);
-
- if (focusWidget) {
- focusWidget->setFocus();
- }
+ // Return control
+ m_entryView->setDisabled(false);
+ m_groupView->setDisabled(false);
- if (!ok) {
- showMessage(tr("Writing the database failed: %1").arg(errorMessage),
- MessageWidget::Error,
- true,
- MessageWidget::LongAutoHideTimeout);
- }
+ if (focusWidget) {
+ focusWidget->setFocus();
}
return ok;