]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/generalviewsettingspage.cpp
DolphinMainWindowTest: Add unit test for autosave session feature
[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 <QMimeDatabase>
18 #include <QVBoxLayout>
19
20 GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *parent)
21 : SettingsPageBase(parent)
22 , m_url(url)
23 {
24 QFormLayout *topLayout = new QFormLayout(this);
25
26 // Display style
27 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common display style for all folders"));
28 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember display style for each folder"));
29 m_localViewProps->setToolTip(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for."));
30
31 QButtonGroup *viewGroup = new QButtonGroup(this);
32 viewGroup->addButton(m_globalViewProps);
33 viewGroup->addButton(m_localViewProps);
34 topLayout->addRow(i18nc("@title:group", "Display style: "), m_globalViewProps);
35 topLayout->addRow(QString(), m_localViewProps);
36
37 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
38
39 // Browsing
40 m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"));
41 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"));
42 topLayout->addRow(i18nc("@title:group", "Browsing: "), m_openArchivesAsFolder);
43 topLayout->addRow(QString(), m_autoExpandFolders);
44
45 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
46
47 #if HAVE_BALOO
48 // 'Show tooltips'
49 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"));
50 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips);
51 #endif
52
53 // 'Show selection marker'
54 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"));
55 #if HAVE_BALOO
56 topLayout->addRow(QString(), m_showSelectionToggle);
57 #else
58 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle);
59 #endif
60
61 // 'Inline renaming of items'
62 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"));
63 topLayout->addRow(QString(), m_renameInline);
64
65 m_hideXtrashFiles = new QCheckBox(i18nc("option:check", "Also hide backup files while hiding hidden files"));
66 QMimeDatabase db;
67 QMimeType mime = db.mimeTypeForName(QStringLiteral("application/x-trash"));
68 m_hideXtrashFiles->setToolTip(i18nc("@info:tooltip %1 are the file patterns for mimetype application/x-trash",
69 "Backup files are the files whose mime-type is application/x-trash, patterns: %1",
70 (mime.globPatterns().join(", "))));
71 topLayout->addRow(QString(), m_hideXtrashFiles);
72
73 loadSettings();
74
75 connect(m_localViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed);
76 connect(m_globalViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed);
77
78 connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
79 connect(m_autoExpandFolders, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
80 #if HAVE_BALOO
81 connect(m_showToolTips, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
82 #endif
83 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
84 connect(m_renameInline, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
85 connect(m_hideXtrashFiles, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
86 }
87
88 GeneralViewSettingsPage::~GeneralViewSettingsPage()
89 {
90 }
91
92 void GeneralViewSettingsPage::applySettings()
93 {
94 GeneralSettings *settings = GeneralSettings::self();
95 ViewProperties props(m_url); // read current view properties
96 const bool useGlobalViewProps = m_globalViewProps->isChecked();
97 settings->setGlobalViewProps(useGlobalViewProps);
98 #if HAVE_BALOO
99 settings->setShowToolTips(m_showToolTips->isChecked());
100 #endif
101 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
102 settings->setRenameInline(m_renameInline->isChecked());
103 settings->setHideXTrashFile(m_hideXtrashFiles->isChecked());
104 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
105 settings->save();
106 if (useGlobalViewProps) {
107 // Remember the global view properties by applying the current view properties.
108 // It is important that GeneralSettings::globalViewProps() is set before
109 // the class ViewProperties is used, as ViewProperties uses this setting
110 // to find the destination folder for storing the view properties.
111 ViewProperties globalProps(m_url);
112 globalProps.setDirProperties(props);
113 }
114 }
115
116 void GeneralViewSettingsPage::restoreDefaults()
117 {
118 GeneralSettings *settings = GeneralSettings::self();
119 settings->useDefaults(true);
120 loadSettings();
121 settings->useDefaults(false);
122 }
123
124 void GeneralViewSettingsPage::loadSettings()
125 {
126 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
127 m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
128 m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
129 #if HAVE_BALOO
130 m_showToolTips->setChecked(GeneralSettings::showToolTips());
131 #endif
132 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
133 m_renameInline->setChecked(GeneralSettings::renameInline());
134 m_hideXtrashFiles->setChecked(GeneralSettings::hideXTrashFile());
135
136 m_localViewProps->setChecked(!useGlobalViewProps);
137 m_globalViewProps->setChecked(useGlobalViewProps);
138 }
139
140 #include "moc_generalviewsettingspage.cpp"