]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[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 <dolphinapplication.h>
24 #include <dolphinmainwindow.h>
25 #include "dolphin_generalsettings.h"
26 #include "general/generalsettingspage.h"
27 #include "navigation/navigationsettingspage.h"
28 #include "services/servicessettingspage.h"
29 #include "startup/startupsettingspage.h"
30 #include "viewmodes/viewsettingspage.h"
31 #include "trash/trashsettingspage.h"
32
33 #include <KLocale>
34 #include <KMessageBox>
35 #include <KIcon>
36
37 #include <QPushButton>
38 #include <QDialogButtonBox>
39
40 DolphinSettingsDialog::DolphinSettingsDialog(const KUrl& url, QWidget* parent) :
41 KPageDialog(parent),
42 m_pages()
43
44 {
45 const QSize minSize = minimumSize();
46 setMinimumSize(QSize(512, minSize.height()));
47
48 setFaceType(List);
49 setWindowTitle(i18nc("@title:window", "Dolphin Preferences"));
50 QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok
51 | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
52 box->button(QDialogButtonBox::Apply)->setEnabled(false);
53 box->button(QDialogButtonBox::Ok)->setDefault(true);
54 setButtonBox(box);
55
56 // Startup
57 StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
58 KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
59 i18nc("@title:group", "Startup"));
60 startupSettingsFrame->setIcon(KIcon("go-home"));
61 connect(startupSettingsPage, &StartupSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
62
63 // View Modes
64 ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(this);
65 KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage,
66 i18nc("@title:group", "View Modes"));
67 viewSettingsFrame->setIcon(KIcon("view-choose"));
68 connect(viewSettingsPage, &ViewSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
69
70 // Navigation
71 NavigationSettingsPage* navigationSettingsPage = new NavigationSettingsPage(this);
72 KPageWidgetItem* navigationSettingsFrame = addPage(navigationSettingsPage,
73 i18nc("@title:group", "Navigation"));
74 navigationSettingsFrame->setIcon(KIcon("input-mouse"));
75 connect(navigationSettingsPage, &NavigationSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
76
77 // Services
78 ServicesSettingsPage* servicesSettingsPage = new ServicesSettingsPage(this);
79 KPageWidgetItem* servicesSettingsFrame = addPage(servicesSettingsPage,
80 i18nc("@title:group", "Services"));
81 servicesSettingsFrame->setIcon(KIcon("services"));
82 connect(servicesSettingsPage, &ServicesSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
83
84 // Trash
85 TrashSettingsPage* trashSettingsPage = new TrashSettingsPage(this);
86 KPageWidgetItem* trashSettingsFrame = addPage(trashSettingsPage,
87 i18nc("@title:group", "Trash"));
88 trashSettingsFrame->setIcon(KIcon("user-trash"));
89 connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
90
91 // General
92 GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
93 KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
94 i18nc("@title:group General settings", "General"));
95 generalSettingsFrame->setIcon(KIcon("system-run"));
96 connect(generalSettingsPage, &GeneralSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
97
98 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
99 #pragma message("TODO: port")
100 //restoreDialogSize(dialogConfig);
101
102 m_pages.append(startupSettingsPage);
103 m_pages.append(viewSettingsPage);
104 m_pages.append(navigationSettingsPage);
105 m_pages.append(servicesSettingsPage);
106 m_pages.append(trashSettingsPage);
107 m_pages.append(generalSettingsPage);
108 }
109
110 DolphinSettingsDialog::~DolphinSettingsDialog()
111 {
112 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
113 #pragma message("TODO: port")
114 //saveDialogSize(dialogConfig);
115 }
116
117 void DolphinSettingsDialog::slotButtonClicked(int button)
118 {
119 if ((button == QDialogButtonBox::Ok) || (button == QDialogButtonBox::Apply)) {
120 applySettings();
121 } else if (button == QDialogButtonBox::RestoreDefaults) {
122 restoreDefaults();
123 }
124
125 #pragma message("TODO: port")
126 //KPageDialog::slotButtonClicked(button);
127 }
128
129 void DolphinSettingsDialog::enableApply()
130 {
131 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
132 }
133
134 void DolphinSettingsDialog::applySettings()
135 {
136 foreach (SettingsPageBase* page, m_pages) {
137 page->applySettings();
138 }
139
140 emit settingsChanged();
141
142 GeneralSettings* settings = GeneralSettings::self();
143 if (settings->modifiedStartupSettings()) {
144 // Reset the modified startup settings hint. The changed startup settings
145 // have been applied already due to emitting settingsChanged().
146 settings->setModifiedStartupSettings(false);
147 settings->writeConfig();
148 }
149 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
150 }
151
152 void DolphinSettingsDialog::restoreDefaults()
153 {
154 foreach (SettingsPageBase* page, m_pages) {
155 page->restoreDefaults();
156 }
157 }
158
159 #include "dolphinsettingsdialog.moc"