File indexing completed on 2024-05-12 17:18:55
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Peter Penz (peter.penz@gmx.at) and Patrice Tremblay 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "generalviewsettingspage.h" 0008 #include "dolphin_generalsettings.h" 0009 #include "dolphinmainwindow.h" 0010 #include "views/viewproperties.h" 0011 0012 #include <KLocalizedString> 0013 0014 #include <QButtonGroup> 0015 #include <QCheckBox> 0016 #include <QFormLayout> 0017 #include <QMimeDatabase> 0018 #include <QVBoxLayout> 0019 0020 GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *parent) 0021 : SettingsPageBase(parent) 0022 , m_url(url) 0023 { 0024 QFormLayout *topLayout = new QFormLayout(this); 0025 0026 // Display style 0027 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common display style for all folders")); 0028 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember display style for each folder")); 0029 m_localViewProps->setToolTip(i18nc("@info", "Dolphin will create a hidden .directory file in each folder you change view properties for.")); 0030 0031 QButtonGroup *viewGroup = new QButtonGroup(this); 0032 viewGroup->addButton(m_globalViewProps); 0033 viewGroup->addButton(m_localViewProps); 0034 topLayout->addRow(i18nc("@title:group", "Display style: "), m_globalViewProps); 0035 topLayout->addRow(QString(), m_localViewProps); 0036 0037 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); 0038 0039 // Browsing 0040 m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder")); 0041 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations")); 0042 topLayout->addRow(i18nc("@title:group", "Browsing: "), m_openArchivesAsFolder); 0043 topLayout->addRow(QString(), m_autoExpandFolders); 0044 0045 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); 0046 0047 #if HAVE_BALOO 0048 // 'Show tooltips' 0049 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips")); 0050 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips); 0051 #endif 0052 0053 // 'Show selection marker' 0054 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker")); 0055 #if HAVE_BALOO 0056 topLayout->addRow(QString(), m_showSelectionToggle); 0057 #else 0058 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showSelectionToggle); 0059 #endif 0060 0061 // 'Inline renaming of items' 0062 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline")); 0063 topLayout->addRow(QString(), m_renameInline); 0064 0065 m_hideXtrashFiles = new QCheckBox(i18nc("option:check", "Also hide backup files while hiding hidden files")); 0066 QMimeDatabase db; 0067 QMimeType mime = db.mimeTypeForName(QStringLiteral("application/x-trash")); 0068 m_hideXtrashFiles->setToolTip(i18nc("@info:tooltip %1 are the file patterns for mimetype application/x-trash", 0069 "Backup files are the files whose mime-type is application/x-trash, patterns: %1", 0070 (mime.globPatterns().join(", ")))); 0071 topLayout->addRow(QString(), m_hideXtrashFiles); 0072 0073 loadSettings(); 0074 0075 connect(m_localViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed); 0076 connect(m_globalViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed); 0077 0078 connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0079 connect(m_autoExpandFolders, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0080 #if HAVE_BALOO 0081 connect(m_showToolTips, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0082 #endif 0083 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0084 connect(m_renameInline, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0085 connect(m_hideXtrashFiles, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed); 0086 } 0087 0088 GeneralViewSettingsPage::~GeneralViewSettingsPage() 0089 { 0090 } 0091 0092 void GeneralViewSettingsPage::applySettings() 0093 { 0094 GeneralSettings *settings = GeneralSettings::self(); 0095 ViewProperties props(m_url); // read current view properties 0096 const bool useGlobalViewProps = m_globalViewProps->isChecked(); 0097 settings->setGlobalViewProps(useGlobalViewProps); 0098 #if HAVE_BALOO 0099 settings->setShowToolTips(m_showToolTips->isChecked()); 0100 #endif 0101 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked()); 0102 settings->setRenameInline(m_renameInline->isChecked()); 0103 settings->setHideXTrashFile(m_hideXtrashFiles->isChecked()); 0104 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked()); 0105 settings->save(); 0106 if (useGlobalViewProps) { 0107 // Remember the global view properties by applying the current view properties. 0108 // It is important that GeneralSettings::globalViewProps() is set before 0109 // the class ViewProperties is used, as ViewProperties uses this setting 0110 // to find the destination folder for storing the view properties. 0111 ViewProperties globalProps(m_url); 0112 globalProps.setDirProperties(props); 0113 } 0114 } 0115 0116 void GeneralViewSettingsPage::restoreDefaults() 0117 { 0118 GeneralSettings *settings = GeneralSettings::self(); 0119 settings->useDefaults(true); 0120 loadSettings(); 0121 settings->useDefaults(false); 0122 } 0123 0124 void GeneralViewSettingsPage::loadSettings() 0125 { 0126 const bool useGlobalViewProps = GeneralSettings::globalViewProps(); 0127 m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives()); 0128 m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders()); 0129 #if HAVE_BALOO 0130 m_showToolTips->setChecked(GeneralSettings::showToolTips()); 0131 #endif 0132 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle()); 0133 m_renameInline->setChecked(GeneralSettings::renameInline()); 0134 m_hideXtrashFiles->setChecked(GeneralSettings::hideXTrashFile()); 0135 0136 m_localViewProps->setChecked(!useGlobalViewProps); 0137 m_globalViewProps->setChecked(useGlobalViewProps); 0138 } 0139 0140 #include "moc_generalviewsettingspage.cpp"