2 * SPDX-FileCopyrightText: 2006 Peter Penz (peter.penz@gmx.at) and Patrice Tremblay
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "generalviewsettingspage.h"
8 #include "dolphin_generalsettings.h"
9 #include "dolphindebug.h"
10 #include "dolphinmainwindow.h"
11 #include "views/viewproperties.h"
13 #include <KActionCollection>
14 #include <KLocalizedString>
16 #include <QApplication>
17 #include <QButtonGroup>
20 #include <QFontDatabase>
21 #include <QFormLayout>
24 #include <QMimeDatabase>
25 #include <QVBoxLayout>
27 GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl
&url
, QWidget
*parent
)
28 : SettingsPageBase(parent
)
31 QFormLayout
*topLayout
= new QFormLayout(this);
34 m_globalViewProps
= new QRadioButton(i18nc("@option:radio", "Use common display style for all folders"));
35 // i18n: The information in this sentence contradicts the preceding sentence. That's what the word "still" is communicating.
36 // The previous sentence is "Use common display style for all folders".
37 QLabel
*globalViewPropsLabel
= new QLabel(i18nc("@info", "Some special views like search, recent files, or trash will still use a custom display style."));
38 globalViewPropsLabel
->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont
));
39 globalViewPropsLabel
->setWordWrap(true);
40 globalViewPropsLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Preferred
);
42 m_localViewProps
= new QRadioButton(i18nc("@option:radio", "Remember display style for each folder"));
43 QLabel
*localViewPropsLabel
= new QLabel(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for."));
44 localViewPropsLabel
->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont
));
45 localViewPropsLabel
->setWordWrap(true);
46 localViewPropsLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Preferred
);
48 QButtonGroup
*viewGroup
= new QButtonGroup(this);
49 viewGroup
->addButton(m_globalViewProps
);
50 viewGroup
->addButton(m_localViewProps
);
51 topLayout
->addRow(i18nc("@title:group", "Display style: "), m_globalViewProps
);
52 topLayout
->addRow(QString(), globalViewPropsLabel
);
53 topLayout
->addRow(QString(), m_localViewProps
);
54 topLayout
->addRow(QString(), localViewPropsLabel
);
56 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
59 m_openArchivesAsFolder
= new QCheckBox(i18nc("@option:check", "Open archives as folder"));
60 m_autoExpandFolders
= new QCheckBox(i18nc("option:check", "Open folders during drag operations"));
61 topLayout
->addRow(i18nc("@title:group", "Browsing: "), m_openArchivesAsFolder
);
62 topLayout
->addRow(QString(), m_autoExpandFolders
);
64 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
68 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show item information on hover"));
69 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips
);
72 // 'Show selection marker'
73 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"));
75 topLayout
->addRow(QString(), m_showSelectionToggle
);
77 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle
);
80 // 'Inline renaming of items'
81 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename single items inline"));
82 m_renameInline
->setToolTip(i18n("Renaming multiple items is always done with a dialog window."));
83 topLayout
->addRow(QString(), m_renameInline
);
85 m_hideXtrashFiles
= new QCheckBox(i18nc("option:check", "Also hide backup files while hiding hidden files"));
87 QMimeType mime
= db
.mimeTypeForName(QStringLiteral("application/x-trash"));
88 m_hideXtrashFiles
->setToolTip(i18nc("@info:tooltip %1 are the file patterns for mimetype application/x-trash",
89 "Backup files are the files whose mime-type is application/x-trash, patterns: %1",
90 (mime
.globPatterns().join(", "))));
91 topLayout
->addRow(QString(), m_hideXtrashFiles
);
93 // --------------------- //
94 // START double click view background
96 // list of actions allowed to be triggered by double click
97 // actions were selected based on their usefulness of being triggered with the mouse
98 QStringList allowedActions
{"new_tab",
101 "show_information_panel",
102 "show_folders_panel",
103 "show_terminal_panel",
111 "toggle_selection_mode",
118 // create actions combo-box and add actions
119 m_doubleClickViewComboBox
= new QComboBox();
120 m_doubleClickViewComboBox
->setAccessibleDescription(i18nc("Accessible description for combobox with actions of double click view background setting",
121 "Action to trigger when double clicking view background"));
122 // i18n: Completes the sentence "Double-click triggers [Nothing]".
123 m_doubleClickViewComboBox
->addItem(QIcon::fromTheme("empty"), i18nc("@item:inlistbox", "Nothing"), QStringLiteral("none"));
124 m_doubleClickViewComboBox
->addItem(QIcon::fromTheme("list-add"), i18nc("@item:inlistbox", "Custom Command"), customCommand
);
125 m_doubleClickViewComboBox
->insertSeparator(2);
127 DolphinMainWindow
*mainWindow
= static_cast<DolphinMainWindow
*>(QApplication::activeWindow());
128 if (mainWindow
!= nullptr) {
129 KActionCollection
*actions
= mainWindow
->actionCollection();
130 // get the allowed actions from actionCollection and add them to the combobox
131 for (const QString
&actionName
: allowedActions
) {
132 QAction
*action
= actions
->action(actionName
);
133 if (action
== nullptr) {
134 qCWarning(DolphinDebug
) << QStringLiteral("Double click view: action `%1` was not found").arg(actionName
);
138 QString actionText
= action
->text();
139 // remove ampersand used to define the action's shortcut
140 actionText
.remove(QLatin1Char('&'));
141 m_doubleClickViewComboBox
->addItem(action
->icon(), actionText
, action
->objectName());
144 // i18n: This sentence is incomplete because the user can choose an action that is triggered in a combobox that will appear directly after "triggers".
145 // (While using a left-to-right language it will be to the right of "triggers", in a right-to-left layout it will be to the left.)
146 // So please try to keep this translation in a way that it is a complete sentence when reading the content of the combobox as part of the sentence.
147 // There can be many possible actions in the combobox. The default is "Nothing". Other actions are "New Tab", "Create Folder", "Show Hidden Files", …
148 QLabel
*doubleClickViewLabel
{new QLabel(i18nc("@info", "Double-click triggers"))};
149 QHBoxLayout
*doubleClickViewHLayout
{new QHBoxLayout()};
150 QWidget
*doubleClickViewWidget
{new QWidget()};
151 doubleClickViewWidget
->setLayout(doubleClickViewHLayout
);
152 doubleClickViewHLayout
->addWidget(doubleClickViewLabel
);
153 doubleClickViewHLayout
->setContentsMargins(0, 0, 0, 0);
154 doubleClickViewHLayout
->addWidget(m_doubleClickViewComboBox
);
155 topLayout
->addRow(i18nc("@title:group", "Background: "), doubleClickViewWidget
);
157 m_doubleClickViewCustomAction
= new QLineEdit();
158 m_doubleClickViewCustomAction
->setAccessibleDescription(
159 i18nc("Accessible description for custom command text field of double click view background setting",
160 "Enter custom command to trigger when double clicking view background"));
161 m_doubleClickViewCustomAction
->setPlaceholderText(i18nc("@info:placeholder for terminal command", "Command…"));
162 topLayout
->addRow(QString(), m_doubleClickViewCustomAction
);
164 m_doubleClickViewCustomActionInfo
= new QLabel(i18nc("@label",
165 "Use {path} to get the path of the current folder. "
166 "Example: dolphin {path}"));
167 m_doubleClickViewCustomActionInfo
->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont
));
168 m_doubleClickViewCustomActionInfo
->setWordWrap(true);
169 m_doubleClickViewCustomActionInfo
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Preferred
);
170 m_doubleClickViewCustomActionInfo
->hide();
171 m_doubleClickViewCustomActionInfo
->setTextInteractionFlags(Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard
172 | Qt::LinksAccessibleByKeyboard
); // for accessibility
173 topLayout
->addRow(QString(), m_doubleClickViewCustomActionInfo
);
174 // END double click view background
175 // --------------------- //
179 connect(m_localViewProps
, &QRadioButton::toggled
, this, &GeneralViewSettingsPage::changed
);
180 connect(m_globalViewProps
, &QRadioButton::toggled
, this, &GeneralViewSettingsPage::changed
);
182 connect(m_openArchivesAsFolder
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
183 connect(m_autoExpandFolders
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
185 connect(m_showToolTips
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
187 connect(m_showSelectionToggle
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
188 connect(m_renameInline
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
189 connect(m_hideXtrashFiles
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
190 connect(m_doubleClickViewCustomAction
, &QLineEdit::textChanged
, this, &GeneralViewSettingsPage::changed
);
191 connect(m_doubleClickViewComboBox
, qOverload
<int>(&QComboBox::currentIndexChanged
), this, &GeneralViewSettingsPage::changed
);
192 connect(m_doubleClickViewComboBox
, qOverload
<int>(&QComboBox::currentIndexChanged
), this, &GeneralViewSettingsPage::updateCustomActionVisibility
);
195 GeneralViewSettingsPage::~GeneralViewSettingsPage()
199 void GeneralViewSettingsPage::applySettings()
201 GeneralSettings
*settings
= GeneralSettings::self();
202 ViewProperties
props(m_url
); // read current view properties
203 const bool useGlobalViewProps
= m_globalViewProps
->isChecked();
204 settings
->setGlobalViewProps(useGlobalViewProps
);
206 settings
->setShowToolTips(m_showToolTips
->isChecked());
208 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
209 settings
->setRenameInline(m_renameInline
->isChecked());
210 settings
->setHideXTrashFile(m_hideXtrashFiles
->isChecked());
211 settings
->setAutoExpandFolders(m_autoExpandFolders
->isChecked());
212 settings
->setBrowseThroughArchives(m_openArchivesAsFolder
->isChecked());
213 settings
->setDoubleClickViewCustomAction(m_doubleClickViewCustomAction
->text());
214 settings
->setDoubleClickViewAction(m_doubleClickViewComboBox
->currentData().toString());
216 if (useGlobalViewProps
) {
217 // Remember the global view properties by applying the current view properties.
218 // It is important that GeneralSettings::globalViewProps() is set before
219 // the class ViewProperties is used, as ViewProperties uses this setting
220 // to find the destination folder for storing the view properties.
221 ViewProperties
globalProps(m_url
);
222 globalProps
.setDirProperties(props
);
226 void GeneralViewSettingsPage::restoreDefaults()
228 GeneralSettings
*settings
= GeneralSettings::self();
229 settings
->useDefaults(true);
231 settings
->useDefaults(false);
234 void GeneralViewSettingsPage::loadSettings()
236 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
237 m_openArchivesAsFolder
->setChecked(GeneralSettings::browseThroughArchives());
238 m_autoExpandFolders
->setChecked(GeneralSettings::autoExpandFolders());
240 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
242 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
243 m_renameInline
->setChecked(GeneralSettings::renameInline());
244 m_hideXtrashFiles
->setChecked(GeneralSettings::hideXTrashFile());
246 m_localViewProps
->setChecked(!useGlobalViewProps
);
247 m_globalViewProps
->setChecked(useGlobalViewProps
);
248 int index
= m_doubleClickViewComboBox
->findData(GeneralSettings::doubleClickViewAction());
249 m_doubleClickViewComboBox
->setCurrentIndex((index
== -1) ? 0 : index
);
250 m_doubleClickViewCustomAction
->setText(GeneralSettings::doubleClickViewCustomAction());
251 updateCustomActionVisibility(m_doubleClickViewComboBox
->currentIndex());
254 void GeneralViewSettingsPage::updateCustomActionVisibility(int doubleClickViewComboBoxCurrentIndex
)
256 auto data
= m_doubleClickViewComboBox
->itemData(doubleClickViewComboBoxCurrentIndex
, Qt::UserRole
);
257 m_doubleClickViewCustomAction
->setVisible(data
== customCommand
);
258 m_doubleClickViewCustomActionInfo
->setVisible(data
== customCommand
);
261 #include "moc_generalviewsettingspage.cpp"