]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/dolphinsettingsdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphinsettingsdialog.h"
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"
32 #include <KWindowConfig>
33 #include <KLocalizedString>
36 #include <QPushButton>
37 #include <QDialogButtonBox>
39 DolphinSettingsDialog::DolphinSettingsDialog(const QUrl
& url
, QWidget
* parent
) :
44 const QSize minSize
= minimumSize();
45 setMinimumSize(QSize(512, minSize
.height()));
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);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
108 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
109 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig
);
112 DolphinSettingsDialog::~DolphinSettingsDialog()
114 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "SettingsDialog");
115 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig
);
118 void DolphinSettingsDialog::enableApply()
120 buttonBox()->button(QDialogButtonBox::Apply
)->setEnabled(true);
123 void DolphinSettingsDialog::applySettings()
125 foreach (SettingsPageBase
* page
, m_pages
) {
126 page
->applySettings();
129 emit
settingsChanged();
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);
138 buttonBox()->button(QDialogButtonBox::Apply
)->setEnabled(false);
141 void DolphinSettingsDialog::restoreDefaults()
143 foreach (SettingsPageBase
* page
, m_pages
) {
144 page
->restoreDefaults();