Skip to content

Commit 033edea

Browse files
committed
#3366 note: add setting for checksum checking
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 9c6683d commit 033edea

File tree

5 files changed

+509
-462
lines changed

5 files changed

+509
-462
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 25.11.5
44

5+
- There now is checkbox in the _General settings_ to enable the checksum checking
6+
(for [#3366](https://github.com/pbek/QOwnNotes/issues/3366))
7+
- By default this feature is now turned off, because of too many side effects
58
- Possible flickering of the text diff dialog when disabled has been improved
69
[#3396](https://github.com/pbek/QOwnNotes/issues/3396)
710

@@ -10,6 +13,7 @@
1013
- In the diff dialog shown the checksum checking of [#3366](https://github.com/pbek/QOwnNotes/issues/3366)
1114
doesn't match you can now choose not to show the dialog again, then the selected
1215
dialog result will be chosen automatically the next time [#3396](https://github.com/pbek/QOwnNotes/issues/3396)
16+
- You can reset that decision in the _General settings_
1317

1418
## 25.11.3
1519

src/dialogs/settingsdialog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ void SettingsDialog::storeSettings() {
516516
ui->acceptAllExternalModificationsCheckBox->isChecked());
517517
settings.setValue(QStringLiteral("ignoreAllExternalNoteFolderChanges"),
518518
ui->ignoreAllExternalNoteFolderChangesCheckBox->isChecked());
519+
settings.setValue(QStringLiteral("enableNoteChecksumChecks"),
520+
ui->enableNoteChecksumChecks->isChecked());
519521
settings.setValue(QStringLiteral("newNoteAskHeadline"),
520522
ui->newNoteAskHeadlineCheckBox->isChecked());
521523
settings.setValue(QStringLiteral("useUNIXNewline"), ui->useUNIXNewlineCheckBox->isChecked());
@@ -916,6 +918,8 @@ void SettingsDialog::readSettings() {
916918
settings.value(QStringLiteral("acceptAllExternalModifications")).toBool());
917919
ui->ignoreAllExternalNoteFolderChangesCheckBox->setChecked(
918920
settings.value(QStringLiteral("ignoreAllExternalNoteFolderChanges")).toBool());
921+
ui->enableNoteChecksumChecks->setChecked(
922+
settings.value(QStringLiteral("enableNoteChecksumChecks"), false).toBool());
919923
ui->newNoteAskHeadlineCheckBox->setChecked(
920924
settings.value(QStringLiteral("newNoteAskHeadline")).toBool());
921925
ui->useUNIXNewlineCheckBox->setChecked(

src/dialogs/settingsdialog.ui

Lines changed: 99 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,37 +4106,38 @@
41064106
<string>Notes</string>
41074107
</property>
41084108
<layout class="QGridLayout" name="gridLayout_5">
4109-
<item row="0" column="0" colspan="2">
4110-
<widget class="QCheckBox" name="notifyAllExternalModificationsCheckBox">
4109+
<item row="2" column="0" colspan="2">
4110+
<widget class="QCheckBox" name="acceptAllExternalModificationsCheckBox">
41114111
<property name="toolTip">
4112-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked you will always be notified about external modifications, even if current note wasn't edited in the last minute. Recommended is &lt;span style=&quot; font-style:italic;&quot;&gt;unchecked&lt;/span&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
4112+
<string>Check this if you want to accept all external modifications while you are editing the current note.</string>
41134113
</property>
41144114
<property name="text">
4115-
<string>Notify about all external modifications of the current note</string>
4115+
<string>Accept all external modifications of the current note</string>
41164116
</property>
41174117
</widget>
41184118
</item>
4119-
<item row="9" column="0" colspan="2">
4120-
<widget class="QCheckBox" name="restoreLastNoteAtStartupCheckBox">
4119+
<item row="5" column="1">
4120+
<widget class="QLabel" name="noteSaveIntervalTimeLabel">
41214121
<property name="toolTip">
4122-
<string>Disable this if you want to launch the application without opening a note</string>
4122+
<string>You might run into sync troubles with older versions of ownCloud sync when going far below 10 sec.
4123+
Just test yourself if you get sync conflicts and set a higher value if so.</string>
41234124
</property>
41244125
<property name="text">
4125-
<string>Open last accessed note at application startup</string>
4126+
<string>note save interval time [sec]</string>
41264127
</property>
41274128
</widget>
41284129
</item>
4129-
<item row="1" column="0" colspan="2">
4130-
<widget class="QCheckBox" name="ignoreAllExternalModificationsCheckBox">
4130+
<item row="0" column="0" colspan="2">
4131+
<widget class="QCheckBox" name="notifyAllExternalModificationsCheckBox">
41314132
<property name="toolTip">
4132-
<string>Check this if you want to ignore all external modifications while you are editing the current note.</string>
4133+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked you will always be notified about external modifications, even if current note wasn't edited in the last minute. Recommended is &lt;span style=&quot; font-style:italic;&quot;&gt;unchecked&lt;/span&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
41334134
</property>
41344135
<property name="text">
4135-
<string>Ignore all external modifications of the current note</string>
4136+
<string>Notify about all external modifications of the current note</string>
41364137
</property>
41374138
</widget>
41384139
</item>
4139-
<item row="7" column="0" colspan="2">
4140+
<item row="8" column="0" colspan="2">
41404141
<widget class="QCheckBox" name="newNoteAskHeadlineCheckBox">
41414142
<property name="toolTip">
41424143
<string>By default the headline will generated automatically</string>
@@ -4146,7 +4147,7 @@
41464147
</property>
41474148
</widget>
41484149
</item>
4149-
<item row="15" column="0" colspan="2">
4150+
<item row="16" column="0" colspan="2">
41504151
<widget class="QCheckBox" name="startInReadOnlyModeCheckBox">
41514152
<property name="toolTip">
41524153
<string notr="true">note://, file://media, file://attachments</string>
@@ -4156,55 +4157,17 @@
41564157
</property>
41574158
</widget>
41584159
</item>
4159-
<item row="12" column="0" colspan="2">
4160-
<widget class="QCheckBox" name="imageScaleDownCheckBox">
4161-
<property name="text">
4162-
<string>Scale images down when inserted into notes</string>
4163-
</property>
4164-
</widget>
4165-
</item>
4166-
<item row="8" column="0" colspan="2">
4167-
<widget class="QCheckBox" name="useUNIXNewlineCheckBox">
4168-
<property name="toolTip">
4169-
<string>You can use this for example under Windows if you have troubles with newlines in the ownCloud / Nextcloud notes app</string>
4170-
</property>
4171-
<property name="text">
4172-
<string>Use UNIX newline instead of native newline characters</string>
4173-
</property>
4174-
</widget>
4175-
</item>
4176-
<item row="2" column="0" colspan="2">
4177-
<widget class="QCheckBox" name="acceptAllExternalModificationsCheckBox">
4178-
<property name="toolTip">
4179-
<string>Check this if you want to accept all external modifications while you are editing the current note.</string>
4180-
</property>
4181-
<property name="text">
4182-
<string>Accept all external modifications of the current note</string>
4183-
</property>
4184-
</widget>
4185-
</item>
4186-
<item row="4" column="1">
4187-
<widget class="QLabel" name="noteSaveIntervalTimeLabel">
4188-
<property name="toolTip">
4189-
<string>You might run into sync troubles with older versions of ownCloud sync when going far below 10 sec.
4190-
Just test yourself if you get sync conflicts and set a higher value if so.</string>
4191-
</property>
4192-
<property name="text">
4193-
<string>note save interval time [sec]</string>
4194-
</property>
4195-
</widget>
4196-
</item>
4197-
<item row="11" column="0" colspan="2">
4198-
<widget class="QCheckBox" name="automaticNoteFolderDatabaseClosingCheckBox">
4160+
<item row="3" column="0" colspan="2">
4161+
<widget class="QCheckBox" name="ignoreAllExternalNoteFolderChangesCheckBox">
41994162
<property name="toolTip">
4200-
<string>Automatically close the note folder database to prevent problems with sync tools</string>
4163+
<string>Do this at your own risk!</string>
42014164
</property>
42024165
<property name="text">
4203-
<string>Automatically close the note folder database</string>
4166+
<string>Ignore all external note folder changes</string>
42044167
</property>
42054168
</widget>
42064169
</item>
4207-
<item row="13" column="0" colspan="2">
4170+
<item row="14" column="0" colspan="2">
42084171
<widget class="QFrame" name="imageScalingFrame">
42094172
<property name="frameShape">
42104173
<enum>QFrame::Shape::NoFrame</enum>
@@ -4269,37 +4232,7 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
42694232
</layout>
42704233
</widget>
42714234
</item>
4272-
<item row="3" column="0" colspan="2">
4273-
<widget class="QCheckBox" name="ignoreAllExternalNoteFolderChangesCheckBox">
4274-
<property name="toolTip">
4275-
<string>Do this at your own risk!</string>
4276-
</property>
4277-
<property name="text">
4278-
<string>Ignore all external note folder changes</string>
4279-
</property>
4280-
</widget>
4281-
</item>
4282-
<item row="10" column="0" colspan="2">
4283-
<widget class="QCheckBox" name="restoreCursorPositionCheckBox">
4284-
<property name="toolTip">
4285-
<string>When opening notes the cursor position inside the note will now be restored to the position when the note was last visited in the current session</string>
4286-
</property>
4287-
<property name="text">
4288-
<string>Restore cursor position when opening a note</string>
4289-
</property>
4290-
</widget>
4291-
</item>
4292-
<item row="14" column="0" colspan="2">
4293-
<widget class="QCheckBox" name="legacyLinkingCheckBox">
4294-
<property name="toolTip">
4295-
<string notr="true">note://, file://media, file://attachments</string>
4296-
</property>
4297-
<property name="text">
4298-
<string>Use legacy way to link to notes, images and attachments</string>
4299-
</property>
4300-
</widget>
4301-
</item>
4302-
<item row="4" column="0">
4235+
<item row="5" column="0">
43034236
<widget class="QSpinBox" name="noteSaveIntervalTime">
43044237
<property name="toolTip">
43054238
<string/>
@@ -4318,7 +4251,17 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
43184251
</property>
43194252
</widget>
43204253
</item>
4321-
<item row="16" column="0" colspan="2">
4254+
<item row="9" column="0" colspan="2">
4255+
<widget class="QCheckBox" name="useUNIXNewlineCheckBox">
4256+
<property name="toolTip">
4257+
<string>You can use this for example under Windows if you have troubles with newlines in the ownCloud / Nextcloud notes app</string>
4258+
</property>
4259+
<property name="text">
4260+
<string>Use UNIX newline instead of native newline characters</string>
4261+
</property>
4262+
</widget>
4263+
</item>
4264+
<item row="17" column="0" colspan="2">
43224265
<widget class="QFrame" name="autoReadOnlyModeFrame">
43234266
<property name="frameShape">
43244267
<enum>QFrame::Shape::NoFrame</enum>
@@ -4375,6 +4318,73 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
43754318
</layout>
43764319
</widget>
43774320
</item>
4321+
<item row="1" column="0" colspan="2">
4322+
<widget class="QCheckBox" name="ignoreAllExternalModificationsCheckBox">
4323+
<property name="toolTip">
4324+
<string>Check this if you want to ignore all external modifications while you are editing the current note.</string>
4325+
</property>
4326+
<property name="text">
4327+
<string>Ignore all external modifications of the current note</string>
4328+
</property>
4329+
</widget>
4330+
</item>
4331+
<item row="15" column="0" colspan="2">
4332+
<widget class="QCheckBox" name="legacyLinkingCheckBox">
4333+
<property name="toolTip">
4334+
<string notr="true">note://, file://media, file://attachments</string>
4335+
</property>
4336+
<property name="text">
4337+
<string>Use legacy way to link to notes, images and attachments</string>
4338+
</property>
4339+
</widget>
4340+
</item>
4341+
<item row="11" column="0" colspan="2">
4342+
<widget class="QCheckBox" name="restoreCursorPositionCheckBox">
4343+
<property name="toolTip">
4344+
<string>When opening notes the cursor position inside the note will now be restored to the position when the note was last visited in the current session</string>
4345+
</property>
4346+
<property name="text">
4347+
<string>Restore cursor position when opening a note</string>
4348+
</property>
4349+
</widget>
4350+
</item>
4351+
<item row="12" column="0" colspan="2">
4352+
<widget class="QCheckBox" name="automaticNoteFolderDatabaseClosingCheckBox">
4353+
<property name="toolTip">
4354+
<string>Automatically close the note folder database to prevent problems with sync tools</string>
4355+
</property>
4356+
<property name="text">
4357+
<string>Automatically close the note folder database</string>
4358+
</property>
4359+
</widget>
4360+
</item>
4361+
<item row="13" column="0" colspan="2">
4362+
<widget class="QCheckBox" name="imageScaleDownCheckBox">
4363+
<property name="text">
4364+
<string>Scale images down when inserted into notes</string>
4365+
</property>
4366+
</widget>
4367+
</item>
4368+
<item row="10" column="0" colspan="2">
4369+
<widget class="QCheckBox" name="restoreLastNoteAtStartupCheckBox">
4370+
<property name="toolTip">
4371+
<string>Disable this if you want to launch the application without opening a note</string>
4372+
</property>
4373+
<property name="text">
4374+
<string>Open last accessed note at application startup</string>
4375+
</property>
4376+
</widget>
4377+
</item>
4378+
<item row="4" column="0" colspan="2">
4379+
<widget class="QCheckBox" name="enableNoteChecksumChecks">
4380+
<property name="toolTip">
4381+
<string>Do this at your own risk!</string>
4382+
</property>
4383+
<property name="text">
4384+
<string>Use checksums to detect external modifications to unsaved notes</string>
4385+
</property>
4386+
</widget>
4387+
</item>
43784388
</layout>
43794389
</widget>
43804390
</item>

src/entities/note.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,16 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
14781478
const bool ignoreAllExternalModifications =
14791479
settings.value(QStringLiteral("ignoreAllExternalModifications")).toBool();
14801480

1481+
// Check if checksum checks are enabled
1482+
const bool enableNoteChecksumChecks =
1483+
settings.value(QStringLiteral("enableNoteChecksumChecks"), false).toBool();
1484+
14811485
// Static set to track files that currently have a TextDiffDialog open
14821486
static QSet<QString> filesWithOpenDiffDialog;
14831487

14841488
// Check if the file was modified externally by comparing checksums
1485-
if (!ignoreAllExternalModifications && fileExists() && !_fileChecksum.isEmpty()) {
1489+
if (enableNoteChecksumChecks && !ignoreAllExternalModifications && fileExists() &&
1490+
!_fileChecksum.isEmpty()) {
14861491
// Read the current file content
14871492
QFile checkFile(fullNoteFilePath());
14881493
if (checkFile.open(QIODevice::ReadOnly)) {
@@ -1643,8 +1648,12 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
16431648
file.flush();
16441649
file.close();
16451650

1646-
// Update the checksum after writing to disk
1647-
this->_fileChecksum = calculateChecksum(text);
1651+
// Update the checksum after writing to disk (if enabled)
1652+
if (enableNoteChecksumChecks) {
1653+
this->_fileChecksum = calculateChecksum(text);
1654+
} else {
1655+
this->_fileChecksum.clear();
1656+
}
16481657

16491658
this->_hasDirtyData = false;
16501659
this->_fileLastModified = QDateTime::currentDateTime();
@@ -1938,8 +1947,15 @@ bool Note::updateNoteTextFromDisk() {
19381947
// strangely it sometimes gets null
19391948
if (this->_noteText.isNull()) this->_noteText = QLatin1String("");
19401949

1941-
// Calculate and store the checksum of the loaded text
1942-
this->_fileChecksum = calculateChecksum(this->_noteText);
1950+
// Calculate and store the checksum of the loaded text (if enabled)
1951+
const SettingsService settings;
1952+
const bool enableNoteChecksumChecks =
1953+
settings.value(QStringLiteral("enableNoteChecksumChecks"), false).toBool();
1954+
if (enableNoteChecksumChecks) {
1955+
this->_fileChecksum = calculateChecksum(this->_noteText);
1956+
} else {
1957+
this->_fileChecksum.clear();
1958+
}
19431959

19441960
return true;
19451961
}
@@ -2289,8 +2305,15 @@ void Note::createFromFile(QFile &file, int noteSubFolderId, bool withNoteNameHoo
22892305

22902306
this->_fileLastModified = fileInfo.lastModified();
22912307

2292-
// Calculate the checksum before storing
2293-
this->_fileChecksum = calculateChecksum(this->_noteText);
2308+
// Calculate the checksum before storing (if enabled)
2309+
const SettingsService settings;
2310+
const bool enableNoteChecksumChecks =
2311+
settings.value(QStringLiteral("enableNoteChecksumChecks"), false).toBool();
2312+
if (enableNoteChecksumChecks) {
2313+
this->_fileChecksum = calculateChecksum(this->_noteText);
2314+
} else {
2315+
this->_fileChecksum.clear();
2316+
}
22942317

22952318
this->store();
22962319

0 commit comments

Comments
 (0)