Skip to content

Commit

Permalink
#2802 add: settings to enter read-only mode after an amount of time
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Jul 13, 2023
1 parent 2e1198b commit 508eafd
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# QOwnNotes Changelog

## 23.7.2
- there now is a new checkbox in the *General Settings* to automatically enable read-only mode
after a certain amount of time of inactivity (for [#2802](https://github.com/pbek/QOwnNotes/issues/2802))
- added more Korean, Dutch translation (thank you venusgirl, stephanp)

## 23.7.1
- since the [TuxFamily](https://www.tuxfamily.org/) upload server has been very
unreliable and down for several days, we have now switched to GitHub releases
Expand Down
4 changes: 4 additions & 0 deletions src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ void SettingsDialog::storeSettings() {
ui->automaticNoteFolderDatabaseClosingCheckBox->isChecked());
settings.setValue(QStringLiteral("legacyLinking"), ui->legacyLinkingCheckBox->isChecked());
settings.setValue(QStringLiteral("startInReadOnlyMode"), ui->startInReadOnlyModeCheckBox->isChecked());
settings.setValue(QStringLiteral("autoReadOnlyMode"), ui->autoReadOnlyModeCheckBox->isChecked());
settings.setValue(QStringLiteral("autoReadOnlyModeTimeout"), ui->autoReadOnlyModeTimeoutSpinBox->value());

settings.setValue(QStringLiteral("webSocketServerService/port"),
ui->webSocketServerServicePortSpinBox->value());
Expand Down Expand Up @@ -1309,6 +1311,8 @@ void SettingsDialog::readSettings() {
Utils::Misc::doAutomaticNoteFolderDatabaseClosing());
ui->legacyLinkingCheckBox->setChecked(settings.value(QStringLiteral("legacyLinking")).toBool());
ui->startInReadOnlyModeCheckBox->setChecked(settings.value(QStringLiteral("startInReadOnlyMode")).toBool());
ui->autoReadOnlyModeCheckBox->setChecked(settings.value(QStringLiteral("autoReadOnlyMode")).toBool());
ui->autoReadOnlyModeTimeoutSpinBox->setValue(settings.value(QStringLiteral("autoReadOnlyModeTimeout"), 30).toInt());

ui->webSocketServerServicePortSpinBox->setValue(WebSocketServerService::getSettingsPort());
ui->bookmarksTagLineEdit->setText(WebSocketServerService::getBookmarksTag());
Expand Down
197 changes: 127 additions & 70 deletions src/dialogs/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
<item>
<widget class="QStackedWidget" name="settingsStackedWidget">
<property name="currentIndex">
<number>21</number>
<number>7</number>
</property>
<widget class="QWidget" name="noteFoldersPage">
<layout class="QGridLayout" name="gridLayout_19">
Expand Down Expand Up @@ -4000,43 +4000,53 @@
<string>Notes</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="ignoreAllExternalModificationsCheckBox">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="notifyAllExternalModificationsCheckBox">
<property name="toolTip">
<string>Check this if you want to ignore all external modifications while you are editing the current note.</string>
<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>
</property>
<property name="text">
<string>Ignore all external modifications of the current note</string>
<string>Notify about all external modifications of the current note</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="acceptAllExternalModificationsCheckBox">
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="restoreLastNoteAtStartupCheckBox">
<property name="toolTip">
<string>Check this if you want to accept all external modifications while you are editing the current note.</string>
<string>Disable this if you want to launch the application without opening a note</string>
</property>
<property name="text">
<string>Accept all external modifications of the current note</string>
<string>Open last accessed note at application startup</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="restoreLastNoteAtStartupCheckBox">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="ignoreAllExternalModificationsCheckBox">
<property name="toolTip">
<string>Disable this if you want to launch the application without opening a note</string>
<string>Check this if you want to ignore all external modifications while you are editing the current note.</string>
</property>
<property name="text">
<string>Open last accessed note at application startup</string>
<string>Ignore all external modifications of the current note</string>
</property>
</widget>
</item>
<item row="14" column="0" colspan="2">
<widget class="QCheckBox" name="legacyLinkingCheckBox">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="newNoteAskHeadlineCheckBox">
<property name="toolTip">
<string>By default the headline will generated automatically</string>
</property>
<property name="text">
<string>The shortcut to create a new note asks for a headline</string>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<widget class="QCheckBox" name="startInReadOnlyModeCheckBox">
<property name="toolTip">
<string notr="true">note://, file://media, file://attachments</string>
</property>
<property name="text">
<string>Use legacy way to link to notes, images and attachments</string>
<string>Start application in read-only mode</string>
</property>
</widget>
</item>
Expand All @@ -4047,13 +4057,44 @@
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="restoreCursorPositionCheckBox">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="useUNIXNewlineCheckBox">
<property name="toolTip">
<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>
<string>You can use this for example under Windows if you have troubles with newlines in the ownCloud / Nextcloud notes app</string>
</property>
<property name="text">
<string>Restore cursor position when opening a note</string>
<string>Use UNIX newline instead of native newline characters</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="acceptAllExternalModificationsCheckBox">
<property name="toolTip">
<string>Check this if you want to accept all external modifications while you are editing the current note.</string>
</property>
<property name="text">
<string>Accept all external modifications of the current note</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="noteSaveIntervalTimeLabel">
<property name="toolTip">
<string>You might run into sync troubles with older versions of ownCloud sync when going far below 10 sec.
Just test yourself if you get sync conflicts and set a higher value if so.</string>
</property>
<property name="text">
<string>note save interval time [sec]</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QCheckBox" name="automaticNoteFolderDatabaseClosingCheckBox">
<property name="toolTip">
<string>Automatically close the note folder database to prevent problems with sync tools</string>
</property>
<property name="text">
<string>Automatically close the note folder database</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -4122,44 +4163,33 @@
</layout>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="useUNIXNewlineCheckBox">
<property name="toolTip">
<string>You can use this for example under Windows if you have troubles with newlines in the ownCloud / Nextcloud notes app</string>
</property>
<property name="text">
<string>Use UNIX newline instead of native newline characters</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="noteSaveIntervalTimeLabel">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="ignoreAllExternalNoteFolderChangesCheckBox">
<property name="toolTip">
<string>You might run into sync troubles with older versions of ownCloud sync when going far below 10 sec.
Just test yourself if you get sync conflicts and set a higher value if so.</string>
<string>Do this at your own risk!</string>
</property>
<property name="text">
<string>note save interval time [sec]</string>
<string>Ignore all external note folder changes</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="ignoreAllExternalNoteFolderChangesCheckBox">
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="restoreCursorPositionCheckBox">
<property name="toolTip">
<string>Do this at your own risk!</string>
<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>
</property>
<property name="text">
<string>Ignore all external note folder changes</string>
<string>Restore cursor position when opening a note</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="newNoteAskHeadlineCheckBox">
<item row="14" column="0" colspan="2">
<widget class="QCheckBox" name="legacyLinkingCheckBox">
<property name="toolTip">
<string>By default the headline will generated automatically</string>
<string notr="true">note://, file://media, file://attachments</string>
</property>
<property name="text">
<string>The shortcut to create a new note asks for a headline</string>
<string>Use legacy way to link to notes, images and attachments</string>
</property>
</widget>
</item>
Expand All @@ -4182,34 +4212,61 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QCheckBox" name="automaticNoteFolderDatabaseClosingCheckBox">
<property name="toolTip">
<string>Automatically close the note folder database to prevent problems with sync tools</string>
</property>
<property name="text">
<string>Automatically close the note folder database</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="notifyAllExternalModificationsCheckBox">
<property name="toolTip">
<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>
</property>
<property name="text">
<string>Notify about all external modifications of the current note</string>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<widget class="QCheckBox" name="startInReadOnlyModeCheckBox">
<property name="toolTip">
<string notr="true">note://, file://media, file://attachments</string>
<item row="16" column="0" colspan="2">
<widget class="QFrame" name="autoReadOnlyModeFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>Start application in read-only mode</string>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_84">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="autoReadOnlyModeCheckBox">
<property name="text">
<string>When inactive, enter read-only mode automatically after:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="autoReadOnlyModeTimeoutSpinBox">
<property name="suffix">
<string extracomment="short for seconds"> sec</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -7021,8 +7078,8 @@ Just test yourself if you get sync conflicts and set a higher value if so.</stri
<tabstop>enableSocketServerCheckBox</tabstop>
</tabstops>
<resources>
<include location="../breeze-dark-qownnotes.qrc"/>
<include location="../breeze-qownnotes.qrc"/>
<include location="../breeze-dark-qownnotes.qrc"/>
</resources>
<connections>
<connection>
Expand Down
35 changes: 34 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+PgUp")), this);
connect(shortcut, &QShortcut::activated, this, &MainWindow::on_actionPrevious_Note_triggered);

_autoReadOnlyModeTimer = new QTimer(this);
_autoReadOnlyModeTimer->setSingleShot(true);
connect(_autoReadOnlyModeTimer, &QTimer::timeout, this, &MainWindow::autoReadOnlyModeTimerSlot);

// read the settings (shortcuts have to be defined before that)
readSettings();

Expand Down Expand Up @@ -2334,7 +2338,7 @@ void MainWindow::readSettings() {
settings.remove(QStringLiteral("GAnalytics-cid"));
}

// let us select a folder if we haven't find one in the settings
// let us select a folder if we haven't found one in the settings
if (this->notesPath.isEmpty()) {
selectOwnCloudNotesFolder();
}
Expand Down Expand Up @@ -2421,6 +2425,23 @@ void MainWindow::readSettings() {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
});
#endif

// Enable/disable auto read-only mode
if (!startAutoReadOnlyModeIfEnabled()) {
_autoReadOnlyModeTimer->stop();
}
}

bool MainWindow::startAutoReadOnlyModeIfEnabled() {
QSettings settings;

if (settings.value(QStringLiteral("autoReadOnlyMode")).toBool()) {
_autoReadOnlyModeTimer->start(settings.value(QStringLiteral("autoReadOnlyModeTimeout")).toInt() * 1000);

return true;
}

return false;
}

/**
Expand Down Expand Up @@ -2889,6 +2910,16 @@ void MainWindow::noteViewUpdateTimerSlot() {
_noteViewUpdateTimer->start(2000);
}

void MainWindow::autoReadOnlyModeTimerSlot() {
// Disable note editing if it was enabled
if (ui->actionAllow_note_editing->isChecked()) {
ui->actionAllow_note_editing->trigger();
}

// Start timer again
startAutoReadOnlyModeIfEnabled();
}

void MainWindow::storeUpdatedNotesToDisk() {
// disconnect the watcher before saving on disk
FileWatchDisabler disable(this);
Expand Down Expand Up @@ -5349,6 +5380,8 @@ void MainWindow::on_noteTextEdit_textChanged() {
if (debounceTime > 0) {
_noteViewUpdateTimer->start(debounceTime);
}

startAutoReadOnlyModeIfEnabled();
}

void MainWindow::noteTextEditTextWasUpdated() {
Expand Down

0 comments on commit 508eafd

Please sign in to comment.