Skip to content

Commit 78178d8

Browse files
committed
#3573 trash: add selectable trash modes on Qt 5.15+
1 parent 068344b commit 78178d8

10 files changed

Lines changed: 219 additions & 45 deletions

File tree

CHANGELOG.md

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

33
## 26.4.17
44

5+
- Renamed the **Local trash** settings page to **Trash**, added a Qt 5.15+
6+
**trash mode** selector for **No trashing**, **System trash**, and
7+
**Local trash**, switched note deletion to `QFile::moveToTrash()` when
8+
**System trash** is selected, and now only show the **Local trash** action
9+
when local trash support is enabled (for [#3573](https://github.com/pbek/QOwnNotes/issues/3573))
510
- Restored the long-standing **note editor** behavior where pressing the bare
611
`Up` arrow on the first line moves the cursor to the start of that line, by
712
handling the boundary navigation in `keyPressEvent` so it also works again on

src/dialogs/settingsdialog.ui

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,19 @@
378378
<iconset theme="appointment-new" resource="../breeze-qownnotes.qrc">
379379
<normaloff>:/icons/breeze-qownnotes/16x16/appointment-new.svg</normaloff>:/icons/breeze-qownnotes/16x16/appointment-new.svg</iconset>
380380
</property>
381-
</item>
382-
<item>
383-
<property name="text">
384-
<string>Local trash</string>
385-
</property>
386-
<property name="whatsThis">
387-
<string notr="true">17</string>
388-
</property>
389-
<property name="icon">
390-
<iconset theme="trash-empty" resource="../breeze-qownnotes.qrc">
391-
<normaloff>:/icons/breeze-qownnotes/16x16/trash-empty.svg</normaloff>:/icons/breeze-qownnotes/16x16/trash-empty.svg</iconset>
392-
</property>
393-
</item>
381+
</item>
382+
<item>
383+
<property name="text">
384+
<string>Trash</string>
385+
</property>
386+
<property name="whatsThis">
387+
<string notr="true">17</string>
388+
</property>
389+
<property name="icon">
390+
<iconset theme="trash-empty" resource="../breeze-qownnotes.qrc">
391+
<normaloff>:/icons/breeze-qownnotes/16x16/trash-empty.svg</normaloff>:/icons/breeze-qownnotes/16x16/trash-empty.svg</iconset>
392+
</property>
393+
</item>
394394
</item>
395395
<item>
396396
<property name="text">

src/entities/note.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,6 +3098,13 @@ bool Note::removeNoteFile() {
30983098
QFile file(fullNoteFilePath());
30993099
qDebug() << __func__ << " - 'this->fileName': " << this->_fileName;
31003100
qDebug() << __func__ << " - 'file': " << file.fileName();
3101+
3102+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
3103+
if (TrashItem::isSystemTrashEnabled()) {
3104+
return file.moveToTrash();
3105+
}
3106+
#endif
3107+
31013108
return file.remove();
31023109
}
31033110

src/entities/trashitem.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,37 @@ int TrashItem::countAll() {
513513
return 0;
514514
}
515515

516-
bool TrashItem::isLocalTrashEnabled() {
516+
TrashItem::TrashMode TrashItem::trashMode() {
517517
SettingsService settings;
518-
return settings.value(QStringLiteral("localTrash/supportEnabled"), true).toBool();
518+
519+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
520+
if (settings.contains(QStringLiteral("localTrash/mode"))) {
521+
switch (settings.value(QStringLiteral("localTrash/mode")).toInt()) {
522+
case static_cast<int>(TrashMode::NoTrashing):
523+
return TrashMode::NoTrashing;
524+
case static_cast<int>(TrashMode::SystemTrash):
525+
return TrashMode::SystemTrash;
526+
case static_cast<int>(TrashMode::LocalTrash):
527+
return TrashMode::LocalTrash;
528+
default:
529+
break;
530+
}
531+
}
532+
#endif
533+
534+
return settings.value(QStringLiteral("localTrash/supportEnabled"), true).toBool()
535+
? TrashMode::LocalTrash
536+
: TrashMode::NoTrashing;
537+
}
538+
539+
bool TrashItem::isLocalTrashEnabled() { return trashMode() == TrashMode::LocalTrash; }
540+
541+
bool TrashItem::isSystemTrashEnabled() {
542+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
543+
return trashMode() == TrashMode::SystemTrash;
544+
#else
545+
return false;
546+
#endif
519547
}
520548

521549
/**

src/entities/trashitem.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
#include <QFile>
55
#include <QSqlQuery>
66
#include <QUrl>
7+
#include <QtGlobal>
78

89
class Note;
910
class NoteSubFolder;
1011

1112
class TrashItem {
1213
public:
14+
enum class TrashMode {
15+
NoTrashing = 0,
16+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
17+
SystemTrash = 1,
18+
#endif
19+
LocalTrash = 2,
20+
};
21+
1322
explicit TrashItem();
1423

1524
int getId();
@@ -80,8 +89,12 @@ class TrashItem {
8089

8190
QString restorationFilePath();
8291

92+
static TrashMode trashMode();
93+
8394
static bool isLocalTrashEnabled();
8495

96+
static bool isSystemTrashEnabled();
97+
8598
static bool expireItems();
8699

87100
static QList<TrashItem> fetchAllExpired();

src/mainwindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,8 @@ void MainWindow::readSettingsFromSettingsDialog(const bool isAppLaunch) {
26192619
ui->actionShow_note_git_versions_external->setVisible(false);
26202620
#endif
26212621

2622+
updateLocalTrashActionVisibility();
2623+
26222624
// show or hide 'Find or create ...' search in Note Subfolders & Tags Panels
26232625
ui->noteSubFolderLineEdit->setHidden(
26242626
settings.value(QStringLiteral("noteSubfoldersPanelHideSearch")).toBool());
@@ -2727,6 +2729,10 @@ void MainWindow::readSettingsFromSettingsDialog(const bool isAppLaunch) {
27272729
}
27282730
}
27292731

2732+
void MainWindow::updateLocalTrashActionVisibility() {
2733+
ui->actionShow_local_trash->setVisible(TrashItem::isLocalTrashEnabled());
2734+
}
2735+
27302736
/**
27312737
* Initializes the item height of the tree widgets
27322738
*/

src/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ class MainWindow : public QMainWindow {
718718

719719
void initMcpService();
720720

721+
void updateLocalTrashActionVisibility();
722+
721723
void on_actionJump_to_note_list_panel_triggered();
722724

723725
void on_actionJump_to_tags_panel_triggered();

src/widgets/settings/localtrashsettingswidget.cpp

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,117 @@
1414

1515
#include "localtrashsettingswidget.h"
1616

17+
#include <entities/trashitem.h>
1718
#include <services/settingsservice.h>
1819

1920
#include "ui_localtrashsettingswidget.h"
2021

2122
LocalTrashSettingsWidget::LocalTrashSettingsWidget(QWidget *parent)
2223
: QWidget(parent), ui(new Ui::LocalTrashSettingsWidget) {
2324
ui->setupUi(this);
25+
26+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
27+
ui->legacyTrashSupportGroupBox->setVisible(false);
28+
#else
29+
ui->trashModeGroupBox->setVisible(false);
30+
#endif
31+
32+
updateTrashSettingsState();
2433
}
2534

2635
LocalTrashSettingsWidget::~LocalTrashSettingsWidget() { delete ui; }
2736

2837
void LocalTrashSettingsWidget::readSettings() {
2938
SettingsService settings;
3039

40+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
41+
switch (TrashItem::trashMode()) {
42+
case TrashItem::TrashMode::NoTrashing:
43+
ui->noTrashRadioButton->setChecked(true);
44+
break;
45+
case TrashItem::TrashMode::SystemTrash:
46+
ui->systemTrashRadioButton->setChecked(true);
47+
break;
48+
case TrashItem::TrashMode::LocalTrash:
49+
ui->localTrashRadioButton->setChecked(true);
50+
break;
51+
default:
52+
ui->localTrashRadioButton->setChecked(true);
53+
break;
54+
}
55+
#else
3156
ui->localTrashEnabledCheckBox->setChecked(
3257
settings.value(QStringLiteral("localTrash/supportEnabled"), true).toBool());
58+
#endif
59+
3360
ui->localTrashClearCheckBox->setChecked(
3461
settings.value(QStringLiteral("localTrash/autoCleanupEnabled"), true).toBool());
3562
ui->localTrashClearTimeSpinBox->setValue(
3663
settings.value(QStringLiteral("localTrash/autoCleanupDays"), 30).toInt());
64+
65+
updateTrashSettingsState();
3766
}
3867

3968
void LocalTrashSettingsWidget::storeSettings() {
4069
SettingsService settings;
4170

71+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
72+
TrashItem::TrashMode mode = TrashItem::TrashMode::NoTrashing;
73+
74+
if (ui->systemTrashRadioButton->isChecked()) {
75+
mode = TrashItem::TrashMode::SystemTrash;
76+
} else if (ui->localTrashRadioButton->isChecked()) {
77+
mode = TrashItem::TrashMode::LocalTrash;
78+
}
79+
80+
settings.setValue(QStringLiteral("localTrash/mode"), static_cast<int>(mode));
81+
settings.setValue(QStringLiteral("localTrash/supportEnabled"),
82+
mode == TrashItem::TrashMode::LocalTrash);
83+
#else
4284
settings.setValue(QStringLiteral("localTrash/supportEnabled"),
4385
ui->localTrashEnabledCheckBox->isChecked());
86+
#endif
87+
4488
settings.setValue(QStringLiteral("localTrash/autoCleanupEnabled"),
4589
ui->localTrashClearCheckBox->isChecked());
4690
settings.setValue(QStringLiteral("localTrash/autoCleanupDays"),
4791
ui->localTrashClearTimeSpinBox->value());
4892
}
4993

5094
void LocalTrashSettingsWidget::on_localTrashEnabledCheckBox_toggled(bool checked) {
51-
ui->localTrashGroupBox->setEnabled(checked);
95+
Q_UNUSED(checked)
96+
updateTrashSettingsState();
5297
}
5398

5499
void LocalTrashSettingsWidget::on_localTrashClearCheckBox_toggled(bool checked) {
55-
ui->localTrashClearFrame->setEnabled(checked);
100+
Q_UNUSED(checked)
101+
updateTrashSettingsState();
102+
}
103+
104+
void LocalTrashSettingsWidget::on_noTrashRadioButton_toggled(bool checked) {
105+
Q_UNUSED(checked)
106+
updateTrashSettingsState();
107+
}
108+
109+
void LocalTrashSettingsWidget::on_systemTrashRadioButton_toggled(bool checked) {
110+
Q_UNUSED(checked)
111+
updateTrashSettingsState();
112+
}
113+
114+
void LocalTrashSettingsWidget::on_localTrashRadioButton_toggled(bool checked) {
115+
Q_UNUSED(checked)
116+
updateTrashSettingsState();
117+
}
118+
119+
void LocalTrashSettingsWidget::updateTrashSettingsState() {
120+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
121+
const bool localTrashEnabled = ui->localTrashRadioButton->isChecked();
122+
#else
123+
const bool localTrashEnabled = ui->localTrashEnabledCheckBox->isChecked();
124+
#endif
125+
126+
ui->localTrashGroupBox->setEnabled(localTrashEnabled);
127+
ui->localTrashClearCheckBox->setEnabled(localTrashEnabled);
128+
ui->localTrashClearFrame->setEnabled(localTrashEnabled &&
129+
ui->localTrashClearCheckBox->isChecked());
56130
}

src/widgets/settings/localtrashsettingswidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma once
1616

1717
#include <QWidget>
18+
#include <QtGlobal>
1819

1920
namespace Ui {
2021
class LocalTrashSettingsWidget;
@@ -33,7 +34,12 @@ class LocalTrashSettingsWidget : public QWidget {
3334
private slots:
3435
void on_localTrashEnabledCheckBox_toggled(bool checked);
3536
void on_localTrashClearCheckBox_toggled(bool checked);
37+
void on_noTrashRadioButton_toggled(bool checked);
38+
void on_systemTrashRadioButton_toggled(bool checked);
39+
void on_localTrashRadioButton_toggled(bool checked);
3640

3741
private:
3842
Ui::LocalTrashSettingsWidget *ui;
43+
44+
void updateTrashSettingsState();
3945
};

0 commit comments

Comments
 (0)