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