]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
Now when you click the button "Defaults" in the settings dialog, it will push the...
[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 "generalsettingspage.h"
26 #include "navigationsettingspage.h"
27 #include "servicessettingspage.h"
28 #include "startupsettingspage.h"
29 #include "viewsettingspage.h"
30
31 #include <klocale.h>
32 #include <kmessagebox.h>
33 #include <kicon.h>
34
35 DolphinSettingsDialog::DolphinSettingsDialog(const KUrl& url, QWidget* parent) :
36 KPageDialog(parent),
37 m_pages()
38
39 {
40 const QSize minSize = minimumSize();
41 setMinimumSize(QSize(512, minSize.height()));
42
43 setFaceType(List);
44 setCaption(i18nc("@title:window", "Dolphin Preferences"));
45 setButtons(Ok | Apply | Cancel | Default);
46 enableButtonApply(false);
47 setDefaultButton(Ok);
48
49 // Startup
50 StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
51 KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
52 i18nc("@title:group", "Startup"));
53 startupSettingsFrame->setIcon(KIcon("go-home"));
54 connect(startupSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
55
56 // View Modes
57 ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(this);
58 KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage,
59 i18nc("@title:group", "View Modes"));
60 viewSettingsFrame->setIcon(KIcon("view-choose"));
61 connect(viewSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
62
63 // Navigation
64 NavigationSettingsPage* navigationSettingsPage = new NavigationSettingsPage(this);
65 KPageWidgetItem* navigationSettingsFrame = addPage(navigationSettingsPage,
66 i18nc("@title:group", "Navigation"));
67 navigationSettingsFrame->setIcon(KIcon("input-mouse"));
68 connect(navigationSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
69
70 // Services
71 ServicesSettingsPage* servicesSettingsPage = new ServicesSettingsPage(this);
72 KPageWidgetItem* servicesSettingsFrame = addPage(servicesSettingsPage,
73 i18nc("@title:group", "Services"));
74 servicesSettingsFrame->setIcon(KIcon("services"));
75 connect(servicesSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
76
77 // General
78 GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
79 KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
80 i18nc("@title:group General settings", "General"));
81 generalSettingsFrame->setIcon(KIcon("system-run"));
82 connect(generalSettingsPage, SIGNAL(changed()), this, SLOT(enableApply()));
83
84 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
85 restoreDialogSize(dialogConfig);
86
87 m_pages.append(startupSettingsPage);
88 m_pages.append(viewSettingsPage);
89 m_pages.append(navigationSettingsPage);
90 m_pages.append(servicesSettingsPage);
91 m_pages.append(generalSettingsPage);
92 }
93
94 DolphinSettingsDialog::~DolphinSettingsDialog()
95 {
96 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
97 saveDialogSize(dialogConfig);
98 }
99
100 void DolphinSettingsDialog::slotButtonClicked(int button)
101 {
102 if ((button == Ok) || (button == Apply)) {
103 applySettings();
104 } else if (button == Default) {
105 restoreDefaults();
106 }
107
108 KPageDialog::slotButtonClicked(button);
109 }
110
111 void DolphinSettingsDialog::enableApply()
112 {
113 enableButtonApply(true);
114 }
115
116 void DolphinSettingsDialog::applySettings()
117 {
118 foreach (SettingsPageBase* page, m_pages) {
119 page->applySettings();
120 }
121 DolphinApplication::app()->refreshMainWindows();
122 enableButtonApply(false);
123 }
124
125 void DolphinSettingsDialog::restoreDefaults()
126 {
127 foreach (SettingsPageBase* page, m_pages) {
128 page->restoreDefaults();
129 }
130 }
131
132 #include "dolphinsettingsdialog.moc"