]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
Clean obsolete ifdefs since dolphin requires KF 5.101+
[dolphin.git] / src / settings / dolphinsettingsdialog.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "dolphinsettingsdialog.h"
8
9 #include "config-dolphin.h"
10 #include "contextmenu/contextmenusettingspage.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinmainwindow.h"
13 #include "interface/interfacesettingspage.h"
14 #include "trash/trashsettingspage.h"
15 #include "viewmodes/viewsettingspage.h"
16 #if HAVE_KUSERFEEDBACK
17 #include "userfeedback/dolphinfeedbackprovider.h"
18 #include "userfeedback/userfeedbacksettingspage.h"
19 #endif
20
21 #include <KAuthorized>
22 #include <KLocalizedString>
23 #include <KMessageBox>
24 #include <KWindowConfig>
25
26 #include <kwidgetsaddons_version.h>
27
28 #include <QCloseEvent>
29 #include <QPushButton>
30
31 DolphinSettingsDialog::DolphinSettingsDialog(const QUrl &url, QWidget *parent, KActionCollection *actions)
32 : KPageDialog(parent)
33 , m_pages()
34 , m_unsavedChanges(false)
35
36 {
37 const QSize minSize = minimumSize();
38 setMinimumSize(QSize(540, minSize.height()));
39
40 setFaceType(List);
41 setWindowTitle(i18nc("@title:window", "Configure"));
42 QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
43 box->button(QDialogButtonBox::Apply)->setEnabled(false);
44 box->button(QDialogButtonBox::Ok)->setDefault(true);
45 setButtonBox(box);
46
47 connect(box->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
48 connect(box->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
49 connect(box->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &DolphinSettingsDialog::restoreDefaults);
50
51 // Interface
52 InterfaceSettingsPage *interfaceSettingsPage = new InterfaceSettingsPage(this);
53 KPageWidgetItem *interfaceSettingsFrame = addPage(interfaceSettingsPage, i18nc("@title:group Interface settings", "Interface"));
54 interfaceSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
55 connect(interfaceSettingsPage, &InterfaceSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
56
57 // View
58 ViewSettingsPage *viewSettingsPage = new ViewSettingsPage(url, this);
59 KPageWidgetItem *viewSettingsFrame = addPage(viewSettingsPage, i18nc("@title:group", "View"));
60 viewSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-icons")));
61 connect(viewSettingsPage, &ViewSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
62
63 // Context Menu
64 auto contextMenuSettingsPage = new ContextMenuSettingsPage(this,
65 actions,
66 {QStringLiteral("add_to_places"),
67 QStringLiteral("sort"),
68 QStringLiteral("view_mode"),
69 QStringLiteral("open_in_new_tab"),
70 QStringLiteral("open_in_new_window"),
71 QStringLiteral("copy_location"),
72 QStringLiteral("duplicate"),
73 QStringLiteral("open_terminal_here"),
74 QStringLiteral("copy_to_inactive_split_view"),
75 QStringLiteral("move_to_inactive_split_view")});
76 KPageWidgetItem *contextMenuSettingsFrame = addPage(contextMenuSettingsPage, i18nc("@title:group", "Context Menu"));
77 contextMenuSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-menu-edit")));
78 connect(contextMenuSettingsPage, &ContextMenuSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
79
80 // Trash
81 SettingsPageBase *trashSettingsPage = nullptr;
82 #ifndef Q_OS_WIN
83 trashSettingsPage = createTrashSettingsPage(this);
84 #endif
85 if (trashSettingsPage) {
86 trashSettings = addPage(trashSettingsPage, i18nc("@title:group", "Trash"));
87 trashSettings->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
88 connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
89 }
90
91 #if HAVE_KUSERFEEDBACK
92 // User Feedback
93 UserFeedbackSettingsPage *feedbackSettingsPage = nullptr;
94 if (DolphinFeedbackProvider::instance()->isEnabled()) {
95 feedbackSettingsPage = new UserFeedbackSettingsPage(this);
96 auto feedbackSettingsFrame = addPage(feedbackSettingsPage, i18nc("@title:group", "User Feedback"));
97 feedbackSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-locale")));
98 connect(feedbackSettingsPage, &UserFeedbackSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
99 }
100 #endif
101
102 m_pages.append(interfaceSettingsPage);
103 m_pages.append(viewSettingsPage);
104 m_pages.append(contextMenuSettingsPage);
105 if (trashSettingsPage) {
106 m_pages.append(trashSettingsPage);
107 }
108 #if HAVE_KUSERFEEDBACK
109 if (feedbackSettingsPage) {
110 m_pages.append(feedbackSettingsPage);
111 }
112 #endif
113
114 const KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), "SettingsDialog");
115 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
116 }
117
118 DolphinSettingsDialog::~DolphinSettingsDialog()
119 {
120 KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), "SettingsDialog");
121 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
122 }
123
124 void DolphinSettingsDialog::enableApply()
125 {
126 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
127 m_unsavedChanges = true;
128 }
129
130 void DolphinSettingsDialog::applySettings()
131 {
132 for (SettingsPageBase *page : qAsConst(m_pages)) {
133 page->applySettings();
134 }
135
136 Q_EMIT settingsChanged();
137
138 GeneralSettings *settings = GeneralSettings::self();
139 if (settings->modifiedStartupSettings()) {
140 // Reset the modified startup settings hint. The changed startup settings
141 // have been applied already due to emitting settingsChanged().
142 settings->setModifiedStartupSettings(false);
143 settings->save();
144 }
145 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
146 m_unsavedChanges = false;
147 }
148
149 void DolphinSettingsDialog::restoreDefaults()
150 {
151 for (SettingsPageBase *page : qAsConst(m_pages)) {
152 page->restoreDefaults();
153 }
154 }
155
156 void DolphinSettingsDialog::closeEvent(QCloseEvent *event)
157 {
158 if (!m_unsavedChanges) {
159 event->accept();
160 return;
161 }
162
163 const auto response = KMessageBox::warningTwoActionsCancel(this,
164 i18n("You have unsaved changes. Do you want to apply the changes or discard them?"),
165 i18n("Warning"),
166 KStandardGuiItem::save(),
167 KStandardGuiItem::discard(),
168 KStandardGuiItem::cancel());
169 switch (response) {
170 case KMessageBox::PrimaryAction:
171 applySettings();
172 Q_FALLTHROUGH();
173 case KMessageBox::SecondaryAction:
174 event->accept();
175 break;
176 case KMessageBox::Cancel:
177 event->ignore();
178 break;
179 default:
180 break;
181 }
182 }
183
184 SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
185 {
186 if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
187 return nullptr;
188 }
189
190 return new TrashSettingsPage(parent);
191 }
192
193 #include "moc_dolphinsettingsdialog.cpp"