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"
23 #include <KLocalizedString>
27 #include <QRadioButton>
28 #include <QVBoxLayout>
30 #include <views/viewproperties.h>
32 BehaviorSettingsPage::BehaviorSettingsPage(const QUrl
& url
, QWidget
* parent
) :
33 SettingsPageBase(parent
),
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)
45 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
48 QGroupBox
* viewPropsBox
= new QGroupBox(i18nc("@title:group", "View"), this);
49 viewPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
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
);
54 QVBoxLayout
* viewPropsLayout
= new QVBoxLayout(viewPropsBox
);
55 viewPropsLayout
->addWidget(m_localViewProps
);
56 viewPropsLayout
->addWidget(m_globalViewProps
);
59 QGroupBox
* sortingPropsBox
= new QGroupBox(i18nc("@title:group", "Sorting Mode"), this);
60 sortingPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
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
);
66 QVBoxLayout
* sortingPropsLayout
= new QVBoxLayout(sortingPropsBox
);
67 sortingPropsLayout
->addWidget(m_naturalSorting
);
68 sortingPropsLayout
->addWidget(m_caseInsensitiveSorting
);
69 sortingPropsLayout
->addWidget(m_caseSensitiveSorting
);
72 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
74 // 'Show selection marker'
75 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
77 // 'Inline renaming of items'
78 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename inline"), this);
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);
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();
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
);
104 BehaviorSettingsPage::~BehaviorSettingsPage()
108 void BehaviorSettingsPage::applySettings()
110 GeneralSettings
* settings
= GeneralSettings::self();
111 ViewProperties
props(m_url
); // read current view properties
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());
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
);
132 void BehaviorSettingsPage::restoreDefaults()
134 GeneralSettings
* settings
= GeneralSettings::self();
135 settings
->useDefaults(true);
137 settings
->useDefaults(false);
140 void BehaviorSettingsPage::loadSettings()
142 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
143 m_localViewProps
->setChecked(!useGlobalViewProps
);
144 m_globalViewProps
->setChecked(useGlobalViewProps
);
146 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
147 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
148 m_renameInline
->setChecked(GeneralSettings::renameInline());
149 m_useTabForSplitViewSwitch
->setChecked(GeneralSettings::useTabForSwitchingSplitView());
151 loadSortingChoiceSettings();
154 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings
*settings
)
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
);
166 void BehaviorSettingsPage::loadSortingChoiceSettings()
168 using Choice
= GeneralSettings::EnumSortingChoice
;
169 switch (GeneralSettings::sortingChoice()) {
170 case Choice::NaturalSorting
:
171 m_naturalSorting
->setChecked(true);
173 case Choice::CaseInsensitiveSorting
:
174 m_caseInsensitiveSorting
->setChecked(true);
176 case Choice::CaseSensitiveSorting
:
177 m_caseSensitiveSorting
->setChecked(true);