]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
Modernize Settings window
[dolphin.git] / src / settings / dolphinsettingsdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphinsettingsdialog.h"
22
23 #include "dolphin_generalsettings.h"
24 #include "dolphinmainwindow.h"
25 #include "general/generalsettingspage.h"
26 #include "navigation/navigationsettingspage.h"
27 #include "services/servicessettingspage.h"
28 #include "startup/startupsettingspage.h"
29 #include "trash/trashsettingspage.h"
30 #include "viewmodes/viewsettingspage.h"
31
32 #include <KAuthorized>
33 #include <KLocalizedString>
34 #include <KWindowConfig>
35
36 #include <QPushButton>
37
38 DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent) :
39 KPageDialog(parent),
40 m_pages()
41
42 {
43 const QSize minSize = minimumSize();
44 setMinimumSize(QSize(540, minSize.height()));
45
46 setFaceType(List);
47 setWindowTitle(i18nc("@title:window", "Dolphin Preferences"));
48 QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok
49 | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
50 box->button(QDialogButtonBox::Apply)->setEnabled(false);
51 box->button(QDialogButtonBox::Ok)->setDefault(true);
52 setButtonBox(box);
53
54 connect(box->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
55 connect(box->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
56 connect(box->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &DolphinSettingsDialog::restoreDefaults);
57
58 // General
59 GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
60 KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
61 i18nc("@title:group General settings", "General"));
62 generalSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
63 connect(generalSettingsPage, &GeneralSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
64
65 // Startup
66 StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
67 KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
68 i18nc("@title:group", "Startup"));
69 startupSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("go-home")));
70 connect(startupSettingsPage, &StartupSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
71
72 // View Modes
73 ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(this);
74 KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage,
75 i18nc("@title:group", "View Modes"));
76 viewSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
77 connect(viewSettingsPage, &ViewSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
78
79 // Navigation
80 NavigationSettingsPage* navigationSettingsPage = new NavigationSettingsPage(this);
81 KPageWidgetItem* navigationSettingsFrame = addPage(navigationSettingsPage,
82 i18nc("@title:group", "Navigation"));
83 navigationSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("edit-select")));
84 connect(navigationSettingsPage, &NavigationSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
85
86 // Services
87 ServicesSettingsPage* servicesSettingsPage = new ServicesSettingsPage(this);
88 KPageWidgetItem* servicesSettingsFrame = addPage(servicesSettingsPage,
89 i18nc("@title:group", "Services"));
90 servicesSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("flag")));
91 connect(servicesSettingsPage, &ServicesSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
92
93 // Trash
94 auto* trashSettingsPage = createTrashSettingsPage(this);
95 if (trashSettingsPage) {
96 KPageWidgetItem* trashSettingsFrame = addPage(trashSettingsPage,
97 i18nc("@title:group", "Trash"));
98 trashSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("trash-empty")));
99 connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
100 }
101
102 m_pages.append(generalSettingsPage);
103 m_pages.append(startupSettingsPage);
104 m_pages.append(viewSettingsPage);
105 m_pages.append(navigationSettingsPage);
106 m_pages.append(servicesSettingsPage);
107 if (trashSettingsPage) {
108 m_pages.append(trashSettingsPage);
109 }
110
111 const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "SettingsDialog");
112 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
113 }
114
115 DolphinSettingsDialog::~DolphinSettingsDialog()
116 {
117 KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "SettingsDialog");
118 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
119 }
120
121 void DolphinSettingsDialog::enableApply()
122 {
123 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
124 }
125
126 void DolphinSettingsDialog::applySettings()
127 {
128 foreach (SettingsPageBase* page, m_pages) {
129 page->applySettings();
130 }
131
132 emit settingsChanged();
133
134 GeneralSettings* settings = GeneralSettings::self();
135 if (settings->modifiedStartupSettings()) {
136 // Reset the modified startup settings hint. The changed startup settings
137 // have been applied already due to emitting settingsChanged().
138 settings->setModifiedStartupSettings(false);
139 settings->save();
140 }
141 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
142 }
143
144 void DolphinSettingsDialog::restoreDefaults()
145 {
146 foreach (SettingsPageBase* page, m_pages) {
147 page->restoreDefaults();
148 }
149 }
150
151 SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
152 {
153 if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
154 return nullptr;
155 }
156
157 return new TrashSettingsPage(parent);
158 }