]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
Merge remote-tracking branch 'origin/KDE/4.9'
[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 DolphinSettingsDialog::DolphinSettingsDialog(const KUrl& url, QWidget* parent) :
38 KPageDialog(parent),
39 m_pages()
40
41 {
42 const QSize minSize = minimumSize();
43 setMinimumSize(QSize(512, minSize.height()));
44
45 setFaceType(List);
46 setCaption(i18nc("@title:window", "Dolphin Preferences"));
47 setButtons(Ok | Apply | Cancel | Default);
48 enableButtonApply(false);
49 setDefaultButton(Ok);
50
51 // Startup
52 StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
53 KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
54 i18nc("@title:group", "Startup"));
55 startupSettingsFrame->setIcon(KIcon("go-home"));
56 connect(startupSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
57
58 // View Modes
59 ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(this);
60 KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage,
61 i18nc("@title:group", "View Modes"));
62 viewSettingsFrame->setIcon(KIcon("view-choose"));
63 connect(viewSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
64
65 // Navigation
66 NavigationSettingsPage* navigationSettingsPage = new NavigationSettingsPage(this);
67 KPageWidgetItem* navigationSettingsFrame = addPage(navigationSettingsPage,
68 i18nc("@title:group", "Navigation"));
69 navigationSettingsFrame->setIcon(KIcon("input-mouse"));
70 connect(navigationSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
71
72 // Services
73 ServicesSettingsPage* servicesSettingsPage = new ServicesSettingsPage(this);
74 KPageWidgetItem* servicesSettingsFrame = addPage(servicesSettingsPage,
75 i18nc("@title:group", "Services"));
76 servicesSettingsFrame->setIcon(KIcon("services"));
77 connect(servicesSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
78
79 // Trash
80 TrashSettingsPage* trashSettingsPage = new TrashSettingsPage(this);
81 KPageWidgetItem* trashSettingsFrame = addPage(trashSettingsPage,
82 i18nc("@title:group", "Trash"));
83 trashSettingsFrame->setIcon(KIcon("user-trash"));
84 connect(trashSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
85
86 // General
87 GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
88 KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
89 i18nc("@title:group General settings", "General"));
90 generalSettingsFrame->setIcon(KIcon("system-run"));
91 connect(generalSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
92
93 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
94 restoreDialogSize(dialogConfig);
95
96 m_pages.append(startupSettingsPage);
97 m_pages.append(viewSettingsPage);
98 m_pages.append(navigationSettingsPage);
99 m_pages.append(servicesSettingsPage);
100 m_pages.append(trashSettingsPage);
101 m_pages.append(generalSettingsPage);
102 }
103
104 DolphinSettingsDialog::~DolphinSettingsDialog()
105 {
106 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
107 saveDialogSize(dialogConfig);
108 }
109
110 void DolphinSettingsDialog::slotButtonClicked(int button)
111 {
112 if ((button == Ok) || (button == Apply)) {
113 applySettings();
114 } else if (button == Default) {
115 restoreDefaults();
116 }
117
118 KPageDialog::slotButtonClicked(button);
119 }
120
121 void DolphinSettingsDialog::enableApply()
122 {
123 enableButtonApply(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->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"