1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "behaviorsettingspage.h"
24 #include "views/viewproperties.h"
26 #include <KLocalizedString>
28 #include <QButtonGroup>
30 #include <QFormLayout>
31 #include <QRadioButton>
32 #include <QSpacerItem>
34 BehaviorSettingsPage::BehaviorSettingsPage(const QUrl
& url
, QWidget
* parent
) :
35 SettingsPageBase(parent
),
37 m_localViewProps(nullptr),
38 m_globalViewProps(nullptr),
39 m_showToolTips(nullptr),
40 m_showSelectionToggle(nullptr),
41 m_naturalSorting(nullptr),
42 m_caseSensitiveSorting(nullptr),
43 m_caseInsensitiveSorting(nullptr),
44 m_renameInline(nullptr),
45 m_useTabForSplitViewSwitch(nullptr)
47 QFormLayout
* topLayout
= new QFormLayout(this);
51 m_localViewProps
= new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"));
52 m_globalViewProps
= new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"));
54 QButtonGroup
* viewGroup
= new QButtonGroup(this);
55 viewGroup
->addButton(m_localViewProps
);
56 viewGroup
->addButton(m_globalViewProps
);
57 topLayout
->addRow(i18nc("@title:group", "View: "), m_localViewProps
);
58 topLayout
->addRow(QString(), m_globalViewProps
);
61 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
65 m_naturalSorting
= new QRadioButton(i18nc("option:radio", "Natural"));
66 m_caseInsensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical, case insensitive"));
67 m_caseSensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical, case sensitive"));
69 QButtonGroup
* sortingModeGroup
= new QButtonGroup(this);
70 sortingModeGroup
->addButton(m_naturalSorting
);
71 sortingModeGroup
->addButton(m_caseInsensitiveSorting
);
72 sortingModeGroup
->addButton(m_caseSensitiveSorting
);
73 topLayout
->addRow(i18nc("@title:group", "Sorting mode: "), m_naturalSorting
);
74 topLayout
->addRow(QString(), m_caseInsensitiveSorting
);
75 topLayout
->addRow(QString(), m_caseSensitiveSorting
);
78 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
83 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"));
84 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips
);
87 // 'Show selection marker'
88 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"));
90 topLayout
->addRow(QString(), m_showSelectionToggle
);
92 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle
);
95 // 'Inline renaming of items'
96 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename inline"));
97 topLayout
->addRow(QString(), m_renameInline
);
99 // 'Switch between split views with tab key'
100 m_useTabForSplitViewSwitch
= new QCheckBox(i18nc("option:check", "Switch between split views with tab key"));
101 topLayout
->addRow(QString(), m_useTabForSplitViewSwitch
);
103 // 'Close active view when turning off split view'
104 m_closeActiveSplitView
= new QCheckBox(i18nc("option:check", "Turning off split view closes active pane"));
105 topLayout
->addRow(QString(), m_closeActiveSplitView
);
106 m_closeActiveSplitView
->setToolTip(i18n("When deactivated, turning off split view will close the inactive pane"));
110 connect(m_localViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
111 connect(m_globalViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
113 connect(m_showToolTips
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
115 connect(m_showSelectionToggle
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
116 connect(m_naturalSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
117 connect(m_caseInsensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
118 connect(m_caseSensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
119 connect(m_renameInline
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
120 connect(m_useTabForSplitViewSwitch
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
121 connect(m_closeActiveSplitView
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
124 BehaviorSettingsPage::~BehaviorSettingsPage()
128 void BehaviorSettingsPage::applySettings()
130 GeneralSettings
* settings
= GeneralSettings::self();
131 ViewProperties
props(m_url
); // read current view properties
133 const bool useGlobalViewProps
= m_globalViewProps
->isChecked();
134 settings
->setGlobalViewProps(useGlobalViewProps
);
136 settings
->setShowToolTips(m_showToolTips
->isChecked());
138 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
139 setSortingChoiceValue(settings
);
140 settings
->setRenameInline(m_renameInline
->isChecked());
141 settings
->setUseTabForSwitchingSplitView(m_useTabForSplitViewSwitch
->isChecked());
142 settings
->setCloseActiveSplitView(m_closeActiveSplitView
->isChecked());
145 if (useGlobalViewProps
) {
146 // Remember the global view properties by applying the current view properties.
147 // It is important that GeneralSettings::globalViewProps() is set before
148 // the class ViewProperties is used, as ViewProperties uses this setting
149 // to find the destination folder for storing the view properties.
150 ViewProperties
globalProps(m_url
);
151 globalProps
.setDirProperties(props
);
155 void BehaviorSettingsPage::restoreDefaults()
157 GeneralSettings
* settings
= GeneralSettings::self();
158 settings
->useDefaults(true);
160 settings
->useDefaults(false);
163 void BehaviorSettingsPage::loadSettings()
165 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
166 m_localViewProps
->setChecked(!useGlobalViewProps
);
167 m_globalViewProps
->setChecked(useGlobalViewProps
);
170 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
172 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
173 m_renameInline
->setChecked(GeneralSettings::renameInline());
174 m_useTabForSplitViewSwitch
->setChecked(GeneralSettings::useTabForSwitchingSplitView());
175 m_closeActiveSplitView
->setChecked(GeneralSettings::closeActiveSplitView());
177 loadSortingChoiceSettings();
180 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings
*settings
)
182 using Choice
= GeneralSettings::EnumSortingChoice
;
183 if (m_naturalSorting
->isChecked()) {
184 settings
->setSortingChoice(Choice::NaturalSorting
);
185 } else if (m_caseInsensitiveSorting
->isChecked()) {
186 settings
->setSortingChoice(Choice::CaseInsensitiveSorting
);
187 } else if (m_caseSensitiveSorting
->isChecked()) {
188 settings
->setSortingChoice(Choice::CaseSensitiveSorting
);
192 void BehaviorSettingsPage::loadSortingChoiceSettings()
194 using Choice
= GeneralSettings::EnumSortingChoice
;
195 switch (GeneralSettings::sortingChoice()) {
196 case Choice::NaturalSorting
:
197 m_naturalSorting
->setChecked(true);
199 case Choice::CaseInsensitiveSorting
:
200 m_caseInsensitiveSorting
->setChecked(true);
202 case Choice::CaseSensitiveSorting
:
203 m_caseSensitiveSorting
->setChecked(true);