]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
Merge branch 'Applications/15.12'
[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_caseSensitiveSorting(0),
43 m_caseInsensitiveSorting(0),
44 m_renameInline(0)
45 {
46 QVBoxLayout* topLayout = new QVBoxLayout(this);
47
48 // View properties
49 QGroupBox* viewPropsBox = new QGroupBox(i18nc("@title:group", "View"), this);
50 viewPropsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
51
52 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"), viewPropsBox);
53 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"), viewPropsBox);
54
55 QVBoxLayout* viewPropsLayout = new QVBoxLayout(viewPropsBox);
56 viewPropsLayout->addWidget(m_localViewProps);
57 viewPropsLayout->addWidget(m_globalViewProps);
58
59 // Sorting properties
60 QGroupBox* sortingPropsBox = new QGroupBox(i18nc("@title:group", "Sorting Mode"), this);
61 sortingPropsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
62
63 m_naturalSorting = new QRadioButton(i18nc("option:radio", "Natural sorting"), sortingPropsBox);
64 m_caseInsensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical sorting, case insensitive"), sortingPropsBox);
65 m_caseSensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical sorting, case sensitive"), sortingPropsBox);
66
67 QVBoxLayout* sortingPropsLayout = new QVBoxLayout(sortingPropsBox);
68 sortingPropsLayout->addWidget(m_naturalSorting);
69 sortingPropsLayout->addWidget(m_caseInsensitiveSorting);
70 sortingPropsLayout->addWidget(m_caseSensitiveSorting);
71
72 // 'Show tooltips'
73 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
74
75 // 'Show selection marker'
76 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
77
78 // 'Inline renaming of items'
79 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"), this);
80
81 topLayout->addWidget(viewPropsBox);
82 topLayout->addWidget(sortingPropsBox);
83 topLayout->addWidget(m_showToolTips);
84 topLayout->addWidget(m_showSelectionToggle);
85 topLayout->addWidget(m_renameInline);
86 topLayout->addStretch();
87
88 loadSettings();
89
90 connect(m_localViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
91 connect(m_globalViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
92 connect(m_showToolTips, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
93 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
94 connect(m_naturalSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
95 connect(m_caseInsensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
96 connect(m_caseSensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
97 connect(m_renameInline, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
98 }
99
100 BehaviorSettingsPage::~BehaviorSettingsPage()
101 {
102 }
103
104 void BehaviorSettingsPage::applySettings()
105 {
106 GeneralSettings* settings = GeneralSettings::self();
107 ViewProperties props(m_url); // read current view properties
108
109 const bool useGlobalViewProps = m_globalViewProps->isChecked();
110 settings->setGlobalViewProps(useGlobalViewProps);
111 settings->setShowToolTips(m_showToolTips->isChecked());
112 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
113 setSortingChoiceValue(settings);
114 settings->setRenameInline(m_renameInline->isChecked());
115 settings->save();
116
117 if (useGlobalViewProps) {
118 // Remember the global view properties by applying the current view properties.
119 // It is important that GeneralSettings::globalViewProps() is set before
120 // the class ViewProperties is used, as ViewProperties uses this setting
121 // to find the destination folder for storing the view properties.
122 ViewProperties globalProps(m_url);
123 globalProps.setDirProperties(props);
124 }
125 }
126
127 void BehaviorSettingsPage::restoreDefaults()
128 {
129 GeneralSettings* settings = GeneralSettings::self();
130 settings->useDefaults(true);
131 loadSettings();
132 settings->useDefaults(false);
133 }
134
135 void BehaviorSettingsPage::loadSettings()
136 {
137 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
138 m_localViewProps->setChecked(!useGlobalViewProps);
139 m_globalViewProps->setChecked(useGlobalViewProps);
140
141 m_showToolTips->setChecked(GeneralSettings::showToolTips());
142 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
143 m_renameInline->setChecked(GeneralSettings::renameInline());
144
145 loadSortingChoiceSettings();
146 }
147
148 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings *settings)
149 {
150 using Choice = GeneralSettings::EnumSortingChoice;
151 if (m_naturalSorting->isChecked()) {
152 settings->setSortingChoice(Choice::NaturalSorting);
153 } else if (m_caseInsensitiveSorting->isChecked()) {
154 settings->setSortingChoice(Choice::CaseInsensitiveSorting);
155 } else if (m_caseSensitiveSorting->isChecked()) {
156 settings->setSortingChoice(Choice::CaseSensitiveSorting);
157 }
158 }
159
160 void BehaviorSettingsPage::loadSortingChoiceSettings()
161 {
162 using Choice = GeneralSettings::EnumSortingChoice;
163 switch (GeneralSettings::sortingChoice()) {
164 case Choice::NaturalSorting:
165 m_naturalSorting->setChecked(true);
166 break;
167 case Choice::CaseInsensitiveSorting:
168 m_caseInsensitiveSorting->setChecked(true);
169 break;
170 case Choice::CaseSensitiveSorting:
171 m_caseSensitiveSorting->setChecked(true);
172 break;
173 default:
174 Q_UNREACHABLE();
175 }
176 }