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 "dolphin_generalsettings.h"
25 #include <KLocalizedString>
29 #include <QRadioButton>
30 #include <QVBoxLayout>
32 #include <views/viewproperties.h>
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 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
50 QGroupBox
* viewPropsBox
= new QGroupBox(i18nc("@title:group", "View"), this);
51 viewPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
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
);
56 QVBoxLayout
* viewPropsLayout
= new QVBoxLayout(viewPropsBox
);
57 viewPropsLayout
->addWidget(m_localViewProps
);
58 viewPropsLayout
->addWidget(m_globalViewProps
);
61 QGroupBox
* sortingPropsBox
= new QGroupBox(i18nc("@title:group", "Sorting Mode"), this);
62 sortingPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
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
);
68 QVBoxLayout
* sortingPropsLayout
= new QVBoxLayout(sortingPropsBox
);
69 sortingPropsLayout
->addWidget(m_naturalSorting
);
70 sortingPropsLayout
->addWidget(m_caseInsensitiveSorting
);
71 sortingPropsLayout
->addWidget(m_caseSensitiveSorting
);
74 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
76 // 'Show selection marker'
77 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
79 // 'Inline renaming of items'
80 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename inline"), this);
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);
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();
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
);
106 BehaviorSettingsPage::~BehaviorSettingsPage()
110 void BehaviorSettingsPage::applySettings()
112 GeneralSettings
* settings
= GeneralSettings::self();
113 ViewProperties
props(m_url
); // read current view properties
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());
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
);
134 void BehaviorSettingsPage::restoreDefaults()
136 GeneralSettings
* settings
= GeneralSettings::self();
137 settings
->useDefaults(true);
139 settings
->useDefaults(false);
142 void BehaviorSettingsPage::loadSettings()
144 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
145 m_localViewProps
->setChecked(!useGlobalViewProps
);
146 m_globalViewProps
->setChecked(useGlobalViewProps
);
148 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
149 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
150 m_renameInline
->setChecked(GeneralSettings::renameInline());
151 m_useTabForSplitViewSwitch
->setChecked(GeneralSettings::useTabForSwitchingSplitView());
153 loadSortingChoiceSettings();
156 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings
*settings
)
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
);
168 void BehaviorSettingsPage::loadSortingChoiceSettings()
170 using Choice
= GeneralSettings::EnumSortingChoice
;
171 switch (GeneralSettings::sortingChoice()) {
172 case Choice::NaturalSorting
:
173 m_naturalSorting
->setChecked(true);
175 case Choice::CaseInsensitiveSorting
:
176 m_caseInsensitiveSorting
->setChecked(true);
178 case Choice::CaseSensitiveSorting
:
179 m_caseSensitiveSorting
->setChecked(true);