block auto-reload and auto-save during merge confirmation

This commit is contained in:
Tamino Bauknecht 2024-02-29 17:47:10 +01:00
parent 31bc5292a9
commit a2af060432
No known key found for this signature in database
GPG Key ID: 77837396BE935C6C
2 changed files with 13 additions and 2 deletions

View File

@ -227,6 +227,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
connectDatabaseSignals();
m_blockAutoSave = false;
m_blockAutoReload = false;
m_autosaveTimer = new QTimer(this);
m_autosaveTimer->setSingleShot(true);
@ -1191,6 +1192,10 @@ void DatabaseWidget::mergeDatabase(bool accepted)
return;
}
// block auto-reload and auto-save while merging
m_blockAutoSave = true;
m_blockAutoReload = true;
auto* mergeDialog = new MergeDialog(srcDb, m_db, this);
connect(mergeDialog, &MergeDialog::databaseMerged, [this](bool changed) {
if (changed) {
@ -1216,6 +1221,10 @@ void DatabaseWidget::mergeDatabase(bool accepted)
connect(mergeDialog, &MergeDialog::rejected, [this]() {
showMessage(tr("Merge aborted - database was not modified."), MessageWidget::Information);
});
connect(mergeDialog, &MergeDialog::finished, [this](auto) {
m_blockAutoSave = false;
m_blockAutoReload = false;
});
mergeDialog->open();
}
@ -1853,8 +1862,8 @@ bool DatabaseWidget::lock()
void DatabaseWidget::reloadDatabaseFile()
{
// Ignore reload if we are locked, saving, or currently editing an entry or group
if (!m_db || isLocked() || isEntryEditActive() || isGroupEditActive() || isSaving()) {
// Ignore reload if we are locked, saving, merging or currently editing an entry or group
if (!m_db || m_blockAutoReload || isLocked() || isEntryEditActive() || isGroupEditActive() || isSaving()) {
return;
}
@ -1893,6 +1902,7 @@ void DatabaseWidget::reloadDatabaseFile()
MessageBox::Merge);
if (result == MessageBox::Merge) {
// TODO: use MergeDialog
// Merge the old database into the new one
Merger merger(m_db.data(), db.data());
merger.merge();

View File

@ -318,6 +318,7 @@ private:
// Autoreload
bool m_blockAutoSave;
bool m_blockAutoReload;
// Autosave delay
QPointer<QTimer> m_autosaveTimer;