]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
"Group by" exists, group sorting rule is separate from sorting rule. Very WIP and...
[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("group"),
69 QStringLiteral("view_mode"),
70 QStringLiteral("open_in_new_tab"),
71 QStringLiteral("open_in_new_window"),
72 QStringLiteral("open_in_split_view"),
73 QStringLiteral("copy_location"),
74 QStringLiteral("duplicate"),
75 QStringLiteral("open_terminal_here"),
76 QStringLiteral("copy_to_inactive_split_view"),
77 QStringLiteral("move_to_inactive_split_view")});
78 KPageWidgetItem *contextMenuSettingsFrame = addPage(contextMenuSettingsPage, i18nc("@title:group", "Context Menu"));
79 contextMenuSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-menu-edit")));
80 connect(contextMenuSettingsPage, &ContextMenuSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
81
82 // Trash
83 SettingsPageBase *trashSettingsPage = nullptr;
84 #ifndef Q_OS_WIN
85 trashSettingsPage = createTrashSettingsPage(this);
86 #endif
87 if (trashSettingsPage) {
88 trashSettings = addPage(trashSettingsPage, i18nc("@title:group", "Trash"));
89 trashSettings->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
90 connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
91 }
92
93 #if HAVE_KUSERFEEDBACK
94 // User Feedback
95 UserFeedbackSettingsPage *feedbackSettingsPage = nullptr;
96 if (DolphinFeedbackProvider::instance()->isEnabled()) {
97 feedbackSettingsPage = new UserFeedbackSettingsPage(this);
98 auto feedbackSettingsFrame = addPage(feedbackSettingsPage, i18nc("@title:group", "User Feedback"));
99 feedbackSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-locale")));
100 connect(feedbackSettingsPage, &UserFeedbackSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
101 }
102 #endif
103
104 m_pages.append(interfaceSettingsPage);
105 m_pages.append(viewSettingsPage);
106 m_pages.append(contextMenuSettingsPage);
107 if (trashSettingsPage) {
108 m_pages.append(trashSettingsPage);
109 }
110 #if HAVE_KUSERFEEDBACK
111 if (feedbackSettingsPage) {
112 m_pages.append(feedbackSettingsPage);
113 }
114 #endif
115
116 const KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), QStringLiteral("SettingsDialog"));
117 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
118 }
119
120 DolphinSettingsDialog::~DolphinSettingsDialog()
121 {
122 KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), QStringLiteral("SettingsDialog"));
123 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
124 }
125
126 void DolphinSettingsDialog::enableApply()
127 {
128 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
129 m_unsavedChanges = true;
130 }
131
132 void DolphinSettingsDialog::applySettings()
133 {
134 for (SettingsPageBase *page : std::as_const(m_pages)) {
135 page->applySettings();
136 }
137
138 Q_EMIT settingsChanged();
139
140 GeneralSettings *settings = GeneralSettings::self();
141 if (settings->modifiedStartupSettings()) {
142 // Reset the modified startup settings hint. The changed startup settings
143 // have been applied already due to emitting settingsChanged().
144 settings->setModifiedStartupSettings(false);
145 settings->save();
146 }
147 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
148 m_unsavedChanges = false;
149 }
150
151 void DolphinSettingsDialog::restoreDefaults()
152 {
153 for (SettingsPageBase *page : std::as_const(m_pages)) {
154 page->restoreDefaults();
155 }
156 }
157
158 void DolphinSettingsDialog::closeEvent(QCloseEvent *event)
159 {
160 if (!m_unsavedChanges) {
161 event->accept();
162 return;
163 }
164
165 const auto response = KMessageBox::warningTwoActionsCancel(this,
166 i18n("You have unsaved changes. Do you want to apply the changes or discard them?"),
167 i18n("Warning"),
168 KStandardGuiItem::save(),
169 KStandardGuiItem::discard(),
170 KStandardGuiItem::cancel());
171 switch (response) {
172 case KMessageBox::PrimaryAction:
173 applySettings();
174 Q_FALLTHROUGH();
175 case KMessageBox::SecondaryAction:
176 event->accept();
177 break;
178 case KMessageBox::Cancel:
179 event->ignore();
180 break;
181 default:
182 break;
183 }
184 }
185
186 SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
187 {
188 if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
189 return nullptr;
190 }
191
192 return new TrashSettingsPage(parent);
193 }
194
195 #include "moc_dolphinsettingsdialog.cpp"