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