|
14 | 14 |
|
15 | 15 | #include "localtrashsettingswidget.h" |
16 | 16 |
|
| 17 | +#include <entities/trashitem.h> |
17 | 18 | #include <services/settingsservice.h> |
18 | 19 |
|
19 | 20 | #include "ui_localtrashsettingswidget.h" |
20 | 21 |
|
21 | 22 | LocalTrashSettingsWidget::LocalTrashSettingsWidget(QWidget *parent) |
22 | 23 | : QWidget(parent), ui(new Ui::LocalTrashSettingsWidget) { |
23 | 24 | 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(); |
24 | 33 | } |
25 | 34 |
|
26 | 35 | LocalTrashSettingsWidget::~LocalTrashSettingsWidget() { delete ui; } |
27 | 36 |
|
28 | 37 | void LocalTrashSettingsWidget::readSettings() { |
29 | 38 | SettingsService settings; |
30 | 39 |
|
| 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 |
31 | 56 | ui->localTrashEnabledCheckBox->setChecked( |
32 | 57 | settings.value(QStringLiteral("localTrash/supportEnabled"), true).toBool()); |
| 58 | +#endif |
| 59 | + |
33 | 60 | ui->localTrashClearCheckBox->setChecked( |
34 | 61 | settings.value(QStringLiteral("localTrash/autoCleanupEnabled"), true).toBool()); |
35 | 62 | ui->localTrashClearTimeSpinBox->setValue( |
36 | 63 | settings.value(QStringLiteral("localTrash/autoCleanupDays"), 30).toInt()); |
| 64 | + |
| 65 | + updateTrashSettingsState(); |
37 | 66 | } |
38 | 67 |
|
39 | 68 | void LocalTrashSettingsWidget::storeSettings() { |
40 | 69 | SettingsService settings; |
41 | 70 |
|
| 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 |
42 | 84 | settings.setValue(QStringLiteral("localTrash/supportEnabled"), |
43 | 85 | ui->localTrashEnabledCheckBox->isChecked()); |
| 86 | +#endif |
| 87 | + |
44 | 88 | settings.setValue(QStringLiteral("localTrash/autoCleanupEnabled"), |
45 | 89 | ui->localTrashClearCheckBox->isChecked()); |
46 | 90 | settings.setValue(QStringLiteral("localTrash/autoCleanupDays"), |
47 | 91 | ui->localTrashClearTimeSpinBox->value()); |
48 | 92 | } |
49 | 93 |
|
50 | 94 | void LocalTrashSettingsWidget::on_localTrashEnabledCheckBox_toggled(bool checked) { |
51 | | - ui->localTrashGroupBox->setEnabled(checked); |
| 95 | + Q_UNUSED(checked) |
| 96 | + updateTrashSettingsState(); |
52 | 97 | } |
53 | 98 |
|
54 | 99 | 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()); |
56 | 130 | } |
0 commit comments