]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/generalviewsettingspage.cpp
a81d46dd2616caa8596590c2cb9673ff260a3dd7
[dolphin.git] / src / settings / viewmodes / generalviewsettingspage.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz (peter.penz@gmx.at) and Patrice Tremblay
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "generalviewsettingspage.h"
8 #include "dolphin_generalsettings.h"
9 #include "dolphinmainwindow.h"
10 #include "views/viewproperties.h"
11
12 #include <KLocalizedString>
13
14 #include <QButtonGroup>
15 #include <QCheckBox>
16 #include <QFormLayout>
17 #include <QVBoxLayout>
18
19 GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *parent)
20 : SettingsPageBase(parent)
21 , m_url(url)
22 {
23 QFormLayout *topLayout = new QFormLayout(this);
24
25 // Display style
26 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common display style for all folders"));
27 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember display style for each folder"));
28 m_localViewProps->setToolTip(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for."));
29
30 QButtonGroup *viewGroup = new QButtonGroup(this);
31 viewGroup->addButton(m_globalViewProps);
32 viewGroup->addButton(m_localViewProps);
33 topLayout->addRow(i18nc("@title:group", "Display style: "), m_globalViewProps);
34 topLayout->addRow(QString(), m_localViewProps);
35
36 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
37
38 // Browsing
39 m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"));
40 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"));
41 topLayout->addRow(i18nc("@title:group", "Browsing: "), m_openArchivesAsFolder);
42 topLayout->addRow(QString(), m_autoExpandFolders);
43
44 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
45
46 #if HAVE_BALOO
47 // 'Show tooltips'
48 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"));
49 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips);
50 #endif
51
52 // 'Show selection marker'
53 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"));
54 #if HAVE_BALOO
55 topLayout->addRow(QString(), m_showSelectionToggle);
56 #else
57 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle);
58 #endif
59
60 // 'Inline renaming of items'
61 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"));
62 topLayout->addRow(QString(), m_renameInline);
63
64 loadSettings();
65
66 connect(m_localViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed);
67 connect(m_globalViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed);
68
69 connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
70 connect(m_autoExpandFolders, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
71 #if HAVE_BALOO
72 connect(m_showToolTips, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
73 #endif
74 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
75 connect(m_renameInline, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
76 }
77
78 GeneralViewSettingsPage::~GeneralViewSettingsPage()
79 {
80 }
81
82 void GeneralViewSettingsPage::applySettings()
83 {
84 GeneralSettings *settings = GeneralSettings::self();
85 ViewProperties props(m_url); // read current view properties
86 const bool useGlobalViewProps = m_globalViewProps->isChecked();
87 settings->setGlobalViewProps(useGlobalViewProps);
88 #if HAVE_BALOO
89 settings->setShowToolTips(m_showToolTips->isChecked());
90 #endif
91 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
92 settings->setRenameInline(m_renameInline->isChecked());
93 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
94 settings->save();
95 if (useGlobalViewProps) {
96 // Remember the global view properties by applying the current view properties.
97 // It is important that GeneralSettings::globalViewProps() is set before
98 // the class ViewProperties is used, as ViewProperties uses this setting
99 // to find the destination folder for storing the view properties.
100 ViewProperties globalProps(m_url);
101 globalProps.setDirProperties(props);
102 }
103 }
104
105 void GeneralViewSettingsPage::restoreDefaults()
106 {
107 GeneralSettings *settings = GeneralSettings::self();
108 settings->useDefaults(true);
109 loadSettings();
110 settings->useDefaults(false);
111 }
112
113 void GeneralViewSettingsPage::loadSettings()
114 {
115 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
116 m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
117 m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
118 #if HAVE_BALOO
119 m_showToolTips->setChecked(GeneralSettings::showToolTips());
120 #endif
121 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
122 m_renameInline->setChecked(GeneralSettings::renameInline());
123
124 m_localViewProps->setChecked(!useGlobalViewProps);
125 m_globalViewProps->setChecked(useGlobalViewProps);
126 }
127
128 #include "moc_generalviewsettingspage.cpp"