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