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