]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
port Dolphin from KUrl to QUrl
[dolphin.git] / src / settings / general / behaviorsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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 "behaviorsettingspage.h"
22
23 #include "dolphin_generalsettings.h"
24
25 #include <KLocalizedString>
26
27 #include <QCheckBox>
28 #include <QGroupBox>
29 #include <QRadioButton>
30 #include <QVBoxLayout>
31
32 #include <views/viewproperties.h>
33
34 BehaviorSettingsPage::BehaviorSettingsPage(const QUrl& url, QWidget* parent) :
35 SettingsPageBase(parent),
36 m_url(url),
37 m_localViewProps(0),
38 m_globalViewProps(0),
39 m_showToolTips(0),
40 m_showSelectionToggle(0),
41 m_naturalSorting(0),
42 m_renameInline(0)
43 {
44 QVBoxLayout* topLayout = new QVBoxLayout(this);
45
46 // View properties
47 QGroupBox* viewPropsBox = new QGroupBox(i18nc("@title:group", "View"), this);
48 viewPropsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
49
50 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"), viewPropsBox);
51 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"), viewPropsBox);
52
53 QVBoxLayout* viewPropsLayout = new QVBoxLayout(viewPropsBox);
54 viewPropsLayout->addWidget(m_localViewProps);
55 viewPropsLayout->addWidget(m_globalViewProps);
56
57 // 'Show tooltips'
58 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
59
60 // 'Show selection marker'
61 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
62
63 // 'Natural sorting of items'
64 m_naturalSorting = new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
65
66 // 'Inline renaming of items'
67 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"), this);
68
69 topLayout->addWidget(viewPropsBox);
70 topLayout->addWidget(m_showToolTips);
71 topLayout->addWidget(m_showSelectionToggle);
72 topLayout->addWidget(m_naturalSorting);
73 topLayout->addWidget(m_renameInline);
74 topLayout->addStretch();
75
76 loadSettings();
77
78 connect(m_localViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
79 connect(m_globalViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
80 connect(m_showToolTips, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
81 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
82 connect(m_naturalSorting, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
83 connect(m_renameInline, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
84 }
85
86 BehaviorSettingsPage::~BehaviorSettingsPage()
87 {
88 }
89
90 void BehaviorSettingsPage::applySettings()
91 {
92 GeneralSettings* settings = GeneralSettings::self();
93 ViewProperties props(m_url); // read current view properties
94
95 const bool useGlobalViewProps = m_globalViewProps->isChecked();
96 settings->setGlobalViewProps(useGlobalViewProps);
97
98 settings->setShowToolTips(m_showToolTips->isChecked());
99 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
100 settings->setRenameInline(m_renameInline->isChecked());
101 settings->writeConfig();
102
103 if (useGlobalViewProps) {
104 // Remember the global view properties by applying the current view properties.
105 // It is important that GeneralSettings::globalViewProps() is set before
106 // the class ViewProperties is used, as ViewProperties uses this setting
107 // to find the destination folder for storing the view properties.
108 ViewProperties globalProps(m_url);
109 globalProps.setDirProperties(props);
110 }
111
112 const bool naturalSorting = m_naturalSorting->isChecked();
113 if (KGlobalSettings::naturalSorting() != naturalSorting) {
114 KConfigGroup group(KSharedConfig::openConfig(), "KDE");
115 group.writeEntry("NaturalSorting", naturalSorting, KConfig::Persistent | KConfig::Global);
116 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged);
117 }
118 }
119
120 void BehaviorSettingsPage::restoreDefaults()
121 {
122 GeneralSettings* settings = GeneralSettings::self();
123 settings->useDefaults(true);
124 loadSettings();
125 settings->useDefaults(false);
126 }
127
128 void BehaviorSettingsPage::loadSettings()
129 {
130 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
131 m_localViewProps->setChecked(!useGlobalViewProps);
132 m_globalViewProps->setChecked(useGlobalViewProps);
133
134 m_showToolTips->setChecked(GeneralSettings::showToolTips());
135 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
136 m_naturalSorting->setChecked(KGlobalSettings::naturalSorting());
137 m_renameInline->setChecked(GeneralSettings::renameInline());
138 }
139