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