]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
4e78447c7d726d8ea86b3c79e024dfed33abd613
[dolphin.git] / src / settings / general / behaviorsettingspage.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz (peter.penz@gmx.at) and Patrice Tremblay
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "behaviorsettingspage.h"
8
9 #include "global.h"
10 #include "views/viewproperties.h"
11
12 #include <KLocalizedString>
13
14 #include <QButtonGroup>
15 #include <QCheckBox>
16 #include <QFormLayout>
17 #include <QRadioButton>
18 #include <QSpacerItem>
19
20 BehaviorSettingsPage::BehaviorSettingsPage(const QUrl& url, QWidget* parent) :
21 SettingsPageBase(parent),
22 m_url(url),
23 m_localViewProps(nullptr),
24 m_globalViewProps(nullptr),
25 m_showToolTips(nullptr),
26 m_showSelectionToggle(nullptr),
27 m_naturalSorting(nullptr),
28 m_caseSensitiveSorting(nullptr),
29 m_caseInsensitiveSorting(nullptr),
30 m_renameInline(nullptr),
31 m_useTabForSplitViewSwitch(nullptr)
32 {
33 QFormLayout* topLayout = new QFormLayout(this);
34
35
36 // View properties
37 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common display style for all folders"));
38 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember display style for each folder"));
39 m_localViewProps->setToolTip(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for."));
40
41 QButtonGroup* viewGroup = new QButtonGroup(this);
42 viewGroup->addButton(m_globalViewProps);
43 viewGroup->addButton(m_localViewProps);
44 topLayout->addRow(i18nc("@title:group", "View: "), m_globalViewProps);
45 topLayout->addRow(QString(), m_localViewProps);
46
47
48 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
49
50
51 // Sorting properties
52 m_naturalSorting = new QRadioButton(i18nc("option:radio", "Natural"));
53 m_caseInsensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical, case insensitive"));
54 m_caseSensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical, case sensitive"));
55
56 QButtonGroup* sortingModeGroup = new QButtonGroup(this);
57 sortingModeGroup->addButton(m_naturalSorting);
58 sortingModeGroup->addButton(m_caseInsensitiveSorting);
59 sortingModeGroup->addButton(m_caseSensitiveSorting);
60 topLayout->addRow(i18nc("@title:group", "Sorting mode: "), m_naturalSorting);
61 topLayout->addRow(QString(), m_caseInsensitiveSorting);
62 topLayout->addRow(QString(), m_caseSensitiveSorting);
63
64
65 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
66
67
68 #if HAVE_BALOO
69 // 'Show tooltips'
70 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"));
71 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips);
72 #endif
73
74 // 'Show selection marker'
75 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"));
76 #if HAVE_BALOO
77 topLayout->addRow(QString(), m_showSelectionToggle);
78 #else
79 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle);
80 #endif
81
82 // 'Inline renaming of items'
83 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"));
84 topLayout->addRow(QString(), m_renameInline);
85
86 // 'Switch between panes of split views with tab key'
87 m_useTabForSplitViewSwitch = new QCheckBox(i18nc("option:check", "Switch between split views panes with tab key"));
88 topLayout->addRow(QString(), m_useTabForSplitViewSwitch);
89
90 // 'Close active pane when turning off split view'
91 m_closeActiveSplitView = new QCheckBox(i18nc("option:check", "Turning off split view closes active pane"));
92 topLayout->addRow(QString(), m_closeActiveSplitView);
93 m_closeActiveSplitView->setToolTip(i18n("When deactivated, turning off split view will close the inactive pane"));
94
95 loadSettings();
96
97 connect(m_localViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
98 connect(m_globalViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
99 #if HAVE_BALOO
100 connect(m_showToolTips, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
101 #endif
102 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
103 connect(m_naturalSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
104 connect(m_caseInsensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
105 connect(m_caseSensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
106 connect(m_renameInline, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
107 connect(m_useTabForSplitViewSwitch, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
108 connect(m_closeActiveSplitView, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
109 }
110
111 BehaviorSettingsPage::~BehaviorSettingsPage()
112 {
113 }
114
115 void BehaviorSettingsPage::applySettings()
116 {
117 GeneralSettings* settings = GeneralSettings::self();
118 ViewProperties props(m_url); // read current view properties
119
120 const bool useGlobalViewProps = m_globalViewProps->isChecked();
121 settings->setGlobalViewProps(useGlobalViewProps);
122 #if HAVE_BALOO
123 settings->setShowToolTips(m_showToolTips->isChecked());
124 #endif
125 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
126 setSortingChoiceValue(settings);
127 settings->setRenameInline(m_renameInline->isChecked());
128 settings->setUseTabForSwitchingSplitView(m_useTabForSplitViewSwitch->isChecked());
129 settings->setCloseActiveSplitView(m_closeActiveSplitView->isChecked());
130 settings->save();
131
132 if (useGlobalViewProps) {
133 // Remember the global view properties by applying the current view properties.
134 // It is important that GeneralSettings::globalViewProps() is set before
135 // the class ViewProperties is used, as ViewProperties uses this setting
136 // to find the destination folder for storing the view properties.
137 ViewProperties globalProps(m_url);
138 globalProps.setDirProperties(props);
139 }
140 }
141
142 void BehaviorSettingsPage::restoreDefaults()
143 {
144 GeneralSettings* settings = GeneralSettings::self();
145 settings->useDefaults(true);
146 loadSettings();
147 settings->useDefaults(false);
148 }
149
150 void BehaviorSettingsPage::loadSettings()
151 {
152 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
153 m_localViewProps->setChecked(!useGlobalViewProps);
154 m_globalViewProps->setChecked(useGlobalViewProps);
155
156 #if HAVE_BALOO
157 m_showToolTips->setChecked(GeneralSettings::showToolTips());
158 #endif
159 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
160 m_renameInline->setChecked(GeneralSettings::renameInline());
161 m_useTabForSplitViewSwitch->setChecked(GeneralSettings::useTabForSwitchingSplitView());
162 m_closeActiveSplitView->setChecked(GeneralSettings::closeActiveSplitView());
163
164 loadSortingChoiceSettings();
165 }
166
167 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings *settings)
168 {
169 using Choice = GeneralSettings::EnumSortingChoice;
170 if (m_naturalSorting->isChecked()) {
171 settings->setSortingChoice(Choice::NaturalSorting);
172 } else if (m_caseInsensitiveSorting->isChecked()) {
173 settings->setSortingChoice(Choice::CaseInsensitiveSorting);
174 } else if (m_caseSensitiveSorting->isChecked()) {
175 settings->setSortingChoice(Choice::CaseSensitiveSorting);
176 }
177 }
178
179 void BehaviorSettingsPage::loadSortingChoiceSettings()
180 {
181 using Choice = GeneralSettings::EnumSortingChoice;
182 switch (GeneralSettings::sortingChoice()) {
183 case Choice::NaturalSorting:
184 m_naturalSorting->setChecked(true);
185 break;
186 case Choice::CaseInsensitiveSorting:
187 m_caseInsensitiveSorting->setChecked(true);
188 break;
189 case Choice::CaseSensitiveSorting:
190 m_caseSensitiveSorting->setChecked(true);
191 break;
192 default:
193 Q_UNREACHABLE();
194 }
195 }