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_globalViewProps
= new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"));
52 m_localViewProps
= new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"));
53 m_localViewProps
->setToolTip(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for."));
55 QButtonGroup
* viewGroup
= new QButtonGroup(this);
56 viewGroup
->addButton(m_globalViewProps
);
57 viewGroup
->addButton(m_localViewProps
);
58 topLayout
->addRow(i18nc("@title:group", "View: "), m_globalViewProps
);
59 topLayout
->addRow(QString(), m_localViewProps
);
62 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
66 m_naturalSorting
= new QRadioButton(i18nc("option:radio", "Natural"));
67 m_caseInsensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical, case insensitive"));
68 m_caseSensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical, case sensitive"));
70 QButtonGroup
* sortingModeGroup
= new QButtonGroup(this);
71 sortingModeGroup
->addButton(m_naturalSorting
);
72 sortingModeGroup
->addButton(m_caseInsensitiveSorting
);
73 sortingModeGroup
->addButton(m_caseSensitiveSorting
);
74 topLayout
->addRow(i18nc("@title:group", "Sorting mode: "), m_naturalSorting
);
75 topLayout
->addRow(QString(), m_caseInsensitiveSorting
);
76 topLayout
->addRow(QString(), m_caseSensitiveSorting
);
79 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
84 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"));
85 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips
);
88 // 'Show selection marker'
89 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"));
91 topLayout
->addRow(QString(), m_showSelectionToggle
);
93 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle
);
96 // 'Inline renaming of items'
97 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename inline"));
98 topLayout
->addRow(QString(), m_renameInline
);
100 // 'Switch between panes of split views with tab key'
101 m_useTabForSplitViewSwitch
= new QCheckBox(i18nc("option:check", "Switch between split views panes with tab key"));
102 topLayout
->addRow(QString(), m_useTabForSplitViewSwitch
);
104 // 'Close active pane when turning off split view'
105 m_closeActiveSplitView
= new QCheckBox(i18nc("option:check", "Turning off split view closes active pane"));
106 topLayout
->addRow(QString(), m_closeActiveSplitView
);
107 m_closeActiveSplitView
->setToolTip(i18n("When deactivated, turning off split view will close the inactive pane"));
111 connect(m_localViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
112 connect(m_globalViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
114 connect(m_showToolTips
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
116 connect(m_showSelectionToggle
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
117 connect(m_naturalSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
118 connect(m_caseInsensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
119 connect(m_caseSensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
120 connect(m_renameInline
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
121 connect(m_useTabForSplitViewSwitch
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
122 connect(m_closeActiveSplitView
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
125 BehaviorSettingsPage::~BehaviorSettingsPage()
129 void BehaviorSettingsPage::applySettings()
131 GeneralSettings
* settings
= GeneralSettings::self();
132 ViewProperties
props(m_url
); // read current view properties
134 const bool useGlobalViewProps
= m_globalViewProps
->isChecked();
135 settings
->setGlobalViewProps(useGlobalViewProps
);
137 settings
->setShowToolTips(m_showToolTips
->isChecked());
139 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
140 setSortingChoiceValue(settings
);
141 settings
->setRenameInline(m_renameInline
->isChecked());
142 settings
->setUseTabForSwitchingSplitView(m_useTabForSplitViewSwitch
->isChecked());
143 settings
->setCloseActiveSplitView(m_closeActiveSplitView
->isChecked());
146 if (useGlobalViewProps
) {
147 // Remember the global view properties by applying the current view properties.
148 // It is important that GeneralSettings::globalViewProps() is set before
149 // the class ViewProperties is used, as ViewProperties uses this setting
150 // to find the destination folder for storing the view properties.
151 ViewProperties
globalProps(m_url
);
152 globalProps
.setDirProperties(props
);
156 void BehaviorSettingsPage::restoreDefaults()
158 GeneralSettings
* settings
= GeneralSettings::self();
159 settings
->useDefaults(true);
161 settings
->useDefaults(false);
164 void BehaviorSettingsPage::loadSettings()
166 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
167 m_localViewProps
->setChecked(!useGlobalViewProps
);
168 m_globalViewProps
->setChecked(useGlobalViewProps
);
171 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
173 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
174 m_renameInline
->setChecked(GeneralSettings::renameInline());
175 m_useTabForSplitViewSwitch
->setChecked(GeneralSettings::useTabForSwitchingSplitView());
176 m_closeActiveSplitView
->setChecked(GeneralSettings::closeActiveSplitView());
178 loadSortingChoiceSettings();
181 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings
*settings
)
183 using Choice
= GeneralSettings::EnumSortingChoice
;
184 if (m_naturalSorting
->isChecked()) {
185 settings
->setSortingChoice(Choice::NaturalSorting
);
186 } else if (m_caseInsensitiveSorting
->isChecked()) {
187 settings
->setSortingChoice(Choice::CaseInsensitiveSorting
);
188 } else if (m_caseSensitiveSorting
->isChecked()) {
189 settings
->setSortingChoice(Choice::CaseSensitiveSorting
);
193 void BehaviorSettingsPage::loadSortingChoiceSettings()
195 using Choice
= GeneralSettings::EnumSortingChoice
;
196 switch (GeneralSettings::sortingChoice()) {
197 case Choice::NaturalSorting
:
198 m_naturalSorting
->setChecked(true);
200 case Choice::CaseInsensitiveSorting
:
201 m_caseInsensitiveSorting
->setChecked(true);
203 case Choice::CaseSensitiveSorting
:
204 m_caseSensitiveSorting
->setChecked(true);