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",
44 "Dolphin will add file system metadata to folders you change view properties for. If that is not possible, "
45 "a hidden .directory file is created instead."));
46 localViewPropsLabel
->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont
));
47 localViewPropsLabel
->setWordWrap(true);
48 localViewPropsLabel
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Preferred
);
50 QButtonGroup
*viewGroup
= new QButtonGroup(this);
51 viewGroup
->addButton(m_globalViewProps
);
52 viewGroup
->addButton(m_localViewProps
);
53 topLayout
->addRow(i18nc("@title:group", "Display style: "), m_globalViewProps
);
54 topLayout
->addRow(QString(), globalViewPropsLabel
);
55 topLayout
->addRow(QString(), m_localViewProps
);
56 topLayout
->addRow(QString(), localViewPropsLabel
);
58 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
61 m_openArchivesAsFolder
= new QCheckBox(i18nc("@option:check", "Open archives as folder"));
62 m_autoExpandFolders
= new QCheckBox(i18nc("option:check", "Open folders during drag operations"));
63 topLayout
->addRow(i18nc("@title:group", "Browsing: "), m_openArchivesAsFolder
);
64 topLayout
->addRow(QString(), m_autoExpandFolders
);
66 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
70 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show item information on hover"));
71 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips
);
74 // 'Show selection marker'
75 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"));
77 topLayout
->addRow(QString(), m_showSelectionToggle
);
79 topLayout
->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle
);
82 // 'Inline renaming of items'
83 m_renameInline
= new QCheckBox(i18nc("option:check", "Rename single items inline"));
84 m_renameInline
->setToolTip(i18n("Renaming multiple items is always done with a dialog window."));
85 topLayout
->addRow(QString(), m_renameInline
);
87 m_hideXtrashFiles
= new QCheckBox(i18nc("option:check", "Also hide backup files while hiding hidden files"));
89 QMimeType mime
= db
.mimeTypeForName(QStringLiteral("application/x-trash"));
90 m_hideXtrashFiles
->setToolTip(i18nc("@info:tooltip %1 are the file patterns for mimetype application/x-trash",
91 "Backup files are the files whose mime-type is application/x-trash, patterns: %1",
92 (mime
.globPatterns().join(", "))));
93 topLayout
->addRow(QString(), m_hideXtrashFiles
);
95 // --------------------- //
96 // START double click view background
98 // list of actions allowed to be triggered by double click
99 // actions were selected based on their usefulness of being triggered with the mouse
100 QStringList allowedActions
{"new_tab",
103 "show_information_panel",
104 "show_folders_panel",
105 "show_terminal_panel",
113 "toggle_selection_mode",
121 // create actions combo-box and add actions
122 m_doubleClickViewComboBox
= new QComboBox();
123 m_doubleClickViewComboBox
->setAccessibleDescription(i18nc("Accessible description for combobox with actions of double click view background setting",
124 "Action to trigger when double clicking view background"));
125 // i18n: Completes the sentence "Double-click triggers [Nothing]".
126 m_doubleClickViewComboBox
->addItem(QIcon::fromTheme("empty"), i18nc("@item:inlistbox", "Nothing"), QStringLiteral("none"));
127 m_doubleClickViewComboBox
->addItem(QIcon::fromTheme("list-add"), i18nc("@item:inlistbox", "Custom Command"), customCommand
);
128 m_doubleClickViewComboBox
->insertSeparator(2);
130 DolphinMainWindow
*mainWindow
= qobject_cast
<DolphinMainWindow
*>(QApplication::activeWindow());
132 if (mainWindow
!= nullptr) {
133 KActionCollection
*actions
= mainWindow
->actionCollection();
134 // get the allowed actions from actionCollection and add them to the combobox
135 for (const QString
&actionName
: allowedActions
) {
136 QAction
*action
= actions
->action(actionName
);
137 if (action
== nullptr) {
138 qCWarning(DolphinDebug
) << QStringLiteral("Double click view: action `%1` was not found").arg(actionName
);
142 QString actionText
= action
->text();
143 // remove ampersand used to define the action's shortcut
144 actionText
.remove(QLatin1Char('&'));
145 m_doubleClickViewComboBox
->addItem(action
->icon(), actionText
, action
->objectName());
148 // i18n: This sentence is incomplete because the user can choose an action that is triggered in a combobox that will appear directly after "triggers".
149 // (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.)
150 // 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.
151 // There can be many possible actions in the combobox. The default is "Nothing". Other actions are "New Tab", "Create Folder", "Show Hidden Files", …
152 QLabel
*doubleClickViewLabel
{new QLabel(i18nc("@info", "Double-click triggers"))};
153 QHBoxLayout
*doubleClickViewHLayout
{new QHBoxLayout()};
154 QWidget
*doubleClickViewWidget
{new QWidget()};
155 doubleClickViewWidget
->setLayout(doubleClickViewHLayout
);
156 doubleClickViewHLayout
->addWidget(doubleClickViewLabel
);
157 doubleClickViewHLayout
->setContentsMargins(0, 0, 0, 0);
158 doubleClickViewHLayout
->addWidget(m_doubleClickViewComboBox
);
159 topLayout
->addRow(i18nc("@title:group", "Background: "), doubleClickViewWidget
);
161 m_doubleClickViewCustomAction
= new QLineEdit();
162 m_doubleClickViewCustomAction
->setAccessibleDescription(
163 i18nc("Accessible description for custom command text field of double click view background setting",
164 "Enter custom command to trigger when double clicking view background"));
165 m_doubleClickViewCustomAction
->setPlaceholderText(i18nc("@info:placeholder for terminal command", "Command…"));
166 topLayout
->addRow(QString(), m_doubleClickViewCustomAction
);
168 m_doubleClickViewCustomActionInfo
= new QLabel(i18nc("@label",
169 "Use {path} to get the path of the current folder. "
170 "Example: dolphin {path}"));
171 m_doubleClickViewCustomActionInfo
->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont
));
172 m_doubleClickViewCustomActionInfo
->setWordWrap(true);
173 m_doubleClickViewCustomActionInfo
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Preferred
);
174 m_doubleClickViewCustomActionInfo
->hide();
175 m_doubleClickViewCustomActionInfo
->setTextInteractionFlags(Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard
176 | Qt::LinksAccessibleByKeyboard
); // for accessibility
177 topLayout
->addRow(QString(), m_doubleClickViewCustomActionInfo
);
178 // END double click view background
179 // --------------------- //
183 connect(m_localViewProps
, &QRadioButton::toggled
, this, &GeneralViewSettingsPage::changed
);
184 connect(m_globalViewProps
, &QRadioButton::toggled
, this, &GeneralViewSettingsPage::changed
);
186 connect(m_openArchivesAsFolder
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
187 connect(m_autoExpandFolders
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
189 connect(m_showToolTips
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
191 connect(m_showSelectionToggle
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
192 connect(m_renameInline
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
193 connect(m_hideXtrashFiles
, &QCheckBox::toggled
, this, &GeneralViewSettingsPage::changed
);
194 connect(m_doubleClickViewCustomAction
, &QLineEdit::textChanged
, this, &GeneralViewSettingsPage::changed
);
195 connect(m_doubleClickViewComboBox
, qOverload
<int>(&QComboBox::currentIndexChanged
), this, &GeneralViewSettingsPage::changed
);
196 connect(m_doubleClickViewComboBox
, qOverload
<int>(&QComboBox::currentIndexChanged
), this, &GeneralViewSettingsPage::updateCustomActionVisibility
);
199 GeneralViewSettingsPage::~GeneralViewSettingsPage()
203 void GeneralViewSettingsPage::applySettings()
205 GeneralSettings
*settings
= GeneralSettings::self();
206 ViewProperties
props(m_url
); // read current view properties
207 const bool useGlobalViewProps
= m_globalViewProps
->isChecked();
208 settings
->setGlobalViewProps(useGlobalViewProps
);
210 settings
->setShowToolTips(m_showToolTips
->isChecked());
212 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
213 settings
->setRenameInline(m_renameInline
->isChecked());
214 settings
->setHideXTrashFile(m_hideXtrashFiles
->isChecked());
215 settings
->setAutoExpandFolders(m_autoExpandFolders
->isChecked());
216 settings
->setBrowseThroughArchives(m_openArchivesAsFolder
->isChecked());
217 settings
->setDoubleClickViewCustomAction(m_doubleClickViewCustomAction
->text());
218 settings
->setDoubleClickViewAction(m_doubleClickViewComboBox
->currentData().toString());
220 if (useGlobalViewProps
) {
221 // Remember the global view properties by applying the current view properties.
222 // It is important that GeneralSettings::globalViewProps() is set before
223 // the class ViewProperties is used, as ViewProperties uses this setting
224 // to find the destination folder for storing the view properties.
225 ViewProperties
globalProps(m_url
);
226 globalProps
.setDirProperties(props
);
230 void GeneralViewSettingsPage::restoreDefaults()
232 GeneralSettings
*settings
= GeneralSettings::self();
233 settings
->useDefaults(true);
235 settings
->useDefaults(false);
238 void GeneralViewSettingsPage::loadSettings()
240 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
241 m_openArchivesAsFolder
->setChecked(GeneralSettings::browseThroughArchives());
242 m_autoExpandFolders
->setChecked(GeneralSettings::autoExpandFolders());
244 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
246 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
247 m_renameInline
->setChecked(GeneralSettings::renameInline());
248 m_hideXtrashFiles
->setChecked(GeneralSettings::hideXTrashFile());
250 m_localViewProps
->setChecked(!useGlobalViewProps
);
251 m_globalViewProps
->setChecked(useGlobalViewProps
);
252 int index
= m_doubleClickViewComboBox
->findData(GeneralSettings::doubleClickViewAction());
253 m_doubleClickViewComboBox
->setCurrentIndex((index
== -1) ? 0 : index
);
254 m_doubleClickViewCustomAction
->setText(GeneralSettings::doubleClickViewCustomAction());
255 updateCustomActionVisibility(m_doubleClickViewComboBox
->currentIndex());
258 void GeneralViewSettingsPage::updateCustomActionVisibility(int doubleClickViewComboBoxCurrentIndex
)
260 auto data
= m_doubleClickViewComboBox
->itemData(doubleClickViewComboBoxCurrentIndex
, Qt::UserRole
);
261 m_doubleClickViewCustomAction
->setVisible(data
== customCommand
);
262 m_doubleClickViewCustomActionInfo
->setVisible(data
== customCommand
);
265 #include "moc_generalviewsettingspage.cpp"