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