]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
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
),
40 m_showSelectionToggle(0),
42 m_caseSensitiveSorting(0),
43 m_caseInsensitiveSorting(0),
46 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
49 QGroupBox
* viewPropsBox
= new QGroupBox(i18nc("@title:group", "View"), this);
50 viewPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
52 m_localViewProps
= new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"), viewPropsBox
);
53 m_globalViewProps
= new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"), viewPropsBox
);
55 QVBoxLayout
* viewPropsLayout
= new QVBoxLayout(viewPropsBox
);
56 viewPropsLayout
->addWidget(m_localViewProps
);
57 viewPropsLayout
->addWidget(m_globalViewProps
);
60 QGroupBox
* sortingPropsBox
= new QGroupBox(i18nc("@title:group", "Sorting Mode"), this);
61 sortingPropsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
63 m_naturalSorting
= new QRadioButton(i18nc("option:radio", "Natural sorting"), sortingPropsBox
);
64 m_caseInsensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical sorting, case insensitive"), sortingPropsBox
);
65 m_caseSensitiveSorting
= new QRadioButton(i18nc("option:radio", "Alphabetical sorting, case sensitive"), sortingPropsBox
);
67 QVBoxLayout
* sortingPropsLayout
= new QVBoxLayout(sortingPropsBox
);
68 sortingPropsLayout
->addWidget(m_naturalSorting
);
69 sortingPropsLayout
->addWidget(m_caseInsensitiveSorting
);
70 sortingPropsLayout
->addWidget(m_caseSensitiveSorting
);
73 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
75 // 'Show selection marker'
76 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
78 // 'Inline renaming of items'
79 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename inline"), this);
81 topLayout
->addWidget(viewPropsBox
);
82 topLayout
->addWidget(sortingPropsBox
);
83 topLayout
->addWidget(m_showToolTips
);
84 topLayout
->addWidget(m_showSelectionToggle
);
85 topLayout
->addWidget(m_renameInline
);
86 topLayout
->addStretch();
90 connect(m_localViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
91 connect(m_globalViewProps
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
92 connect(m_showToolTips
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
93 connect(m_showSelectionToggle
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
94 connect(m_naturalSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
95 connect(m_caseInsensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
96 connect(m_caseSensitiveSorting
, &QRadioButton::toggled
, this, &BehaviorSettingsPage::changed
);
97 connect(m_renameInline
, &QCheckBox::toggled
, this, &BehaviorSettingsPage::changed
);
100 BehaviorSettingsPage::~BehaviorSettingsPage()
104 void BehaviorSettingsPage::applySettings()
106 GeneralSettings
* settings
= GeneralSettings::self();
107 ViewProperties
props(m_url
); // read current view properties
109 const bool useGlobalViewProps
= m_globalViewProps
->isChecked();
110 settings
->setGlobalViewProps(useGlobalViewProps
);
111 settings
->setShowToolTips(m_showToolTips
->isChecked());
112 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
113 setSortingChoiceValue(settings
);
114 settings
->setRenameInline(m_renameInline
->isChecked());
117 if (useGlobalViewProps
) {
118 // Remember the global view properties by applying the current view properties.
119 // It is important that GeneralSettings::globalViewProps() is set before
120 // the class ViewProperties is used, as ViewProperties uses this setting
121 // to find the destination folder for storing the view properties.
122 ViewProperties
globalProps(m_url
);
123 globalProps
.setDirProperties(props
);
127 void BehaviorSettingsPage::restoreDefaults()
129 GeneralSettings
* settings
= GeneralSettings::self();
130 settings
->useDefaults(true);
132 settings
->useDefaults(false);
135 void BehaviorSettingsPage::loadSettings()
137 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
138 m_localViewProps
->setChecked(!useGlobalViewProps
);
139 m_globalViewProps
->setChecked(useGlobalViewProps
);
141 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
142 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
143 m_renameInline
->setChecked(GeneralSettings::renameInline());
145 loadSortingChoiceSettings();
148 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings
*settings
)
150 using Choice
= GeneralSettings::EnumSortingChoice
;
151 if (m_naturalSorting
->isChecked()) {
152 settings
->setSortingChoice(Choice::NaturalSorting
);
153 } else if (m_caseInsensitiveSorting
->isChecked()) {
154 settings
->setSortingChoice(Choice::CaseInsensitiveSorting
);
155 } else if (m_caseSensitiveSorting
->isChecked()) {
156 settings
->setSortingChoice(Choice::CaseSensitiveSorting
);
160 void BehaviorSettingsPage::loadSortingChoiceSettings()
162 using Choice
= GeneralSettings::EnumSortingChoice
;
163 switch (GeneralSettings::sortingChoice()) {
164 case Choice::NaturalSorting
:
165 m_naturalSorting
->setChecked(true);
167 case Choice::CaseInsensitiveSorting
:
168 m_caseInsensitiveSorting
->setChecked(true);
170 case Choice::CaseSensitiveSorting
:
171 m_caseSensitiveSorting
->setChecked(true);