diff --git a/src/core/Database.cpp b/src/core/Database.cpp index 6e69af5b09..852904e163 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -202,8 +202,12 @@ bool Database::save(QString* error, bool atomic, bool backup) */ bool Database::save(const QString& filePath, QString* error, bool atomic, bool backup) { - Q_ASSERT(!m_data.isReadOnly); - if (m_data.isReadOnly) { + // Disallow saving to the same file if read-only + if (m_data.isReadOnly && filePath == m_data.filePath) { + Q_ASSERT_X(false, "Database::save", "Could not save, database file is read-only."); + if (error) { + *error = tr("Could not save, database file is read-only."); + } return false; } @@ -741,10 +745,6 @@ bool Database::isModified() const void Database::markAsModified() { - if (isReadOnly()) { - return; - } - m_modified = true; if (m_emitModified) { startModifiedTimer(); @@ -780,8 +780,6 @@ Database* Database::databaseByFilePath(const QString& filePath) void Database::startModifiedTimer() { - Q_ASSERT(!m_data.isReadOnly); - if (!m_emitModified) { return; } diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 4effa99f99..31badc5826 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -984,7 +984,10 @@ void DatabaseWidget::unlockDatabase(bool accepted) } replaceDatabase(db); if (db->isReadOnly()) { - showMessage(tr("File opened in read only mode."), MessageWidget::Warning, false, -1); + showMessage(tr("This database is opened in read-only mode. Autosave is disabled."), + MessageWidget::Warning, + false, + -1); } restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock); @@ -1225,7 +1228,7 @@ void DatabaseWidget::onGroupChanged(Group* group) void DatabaseWidget::onDatabaseModified() { - if (!m_blockAutoSave && config()->get("AutoSaveAfterEveryChange").toBool()) { + if (!m_blockAutoSave && config()->get("AutoSaveAfterEveryChange").toBool() && !m_db->isReadOnly()) { save(); } else { // Only block once, then reset