File indexing completed on 2024-04-28 17:03:14
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dolphinsettingsdialog.h" 0008 0009 #include "config-dolphin.h" 0010 #include "contextmenu/contextmenusettingspage.h" 0011 #include "dolphin_generalsettings.h" 0012 #include "dolphinmainwindow.h" 0013 #include "interface/interfacesettingspage.h" 0014 #include "trash/trashsettingspage.h" 0015 #include "viewmodes/viewsettingspage.h" 0016 #if HAVE_KUSERFEEDBACK 0017 #include "userfeedback/dolphinfeedbackprovider.h" 0018 #include "userfeedback/userfeedbacksettingspage.h" 0019 #endif 0020 0021 #include <KAuthorized> 0022 #include <KLocalizedString> 0023 #include <KMessageBox> 0024 #include <KWindowConfig> 0025 0026 #include <kwidgetsaddons_version.h> 0027 0028 #include <QCloseEvent> 0029 #include <QPushButton> 0030 0031 DolphinSettingsDialog::DolphinSettingsDialog(const QUrl &url, QWidget *parent, KActionCollection *actions) 0032 : KPageDialog(parent) 0033 , m_pages() 0034 , m_unsavedChanges(false) 0035 0036 { 0037 const QSize minSize = minimumSize(); 0038 setMinimumSize(QSize(540, minSize.height())); 0039 0040 setFaceType(List); 0041 setWindowTitle(i18nc("@title:window", "Configure")); 0042 QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults); 0043 box->button(QDialogButtonBox::Apply)->setEnabled(false); 0044 box->button(QDialogButtonBox::Ok)->setDefault(true); 0045 setButtonBox(box); 0046 0047 connect(box->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings); 0048 connect(box->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings); 0049 connect(box->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &DolphinSettingsDialog::restoreDefaults); 0050 0051 // Interface 0052 InterfaceSettingsPage *interfaceSettingsPage = new InterfaceSettingsPage(this); 0053 KPageWidgetItem *interfaceSettingsFrame = addPage(interfaceSettingsPage, i18nc("@title:group Interface settings", "Interface")); 0054 interfaceSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"))); 0055 connect(interfaceSettingsPage, &InterfaceSettingsPage::changed, this, &DolphinSettingsDialog::enableApply); 0056 0057 // View 0058 ViewSettingsPage *viewSettingsPage = new ViewSettingsPage(url, this); 0059 KPageWidgetItem *viewSettingsFrame = addPage(viewSettingsPage, i18nc("@title:group", "View")); 0060 viewSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-icons"))); 0061 connect(viewSettingsPage, &ViewSettingsPage::changed, this, &DolphinSettingsDialog::enableApply); 0062 0063 // Context Menu 0064 auto contextMenuSettingsPage = new ContextMenuSettingsPage(this, 0065 actions, 0066 {QStringLiteral("add_to_places"), 0067 QStringLiteral("sort"), 0068 QStringLiteral("view_mode"), 0069 QStringLiteral("open_in_new_tab"), 0070 QStringLiteral("open_in_new_window"), 0071 QStringLiteral("open_in_split_view"), 0072 QStringLiteral("copy_location"), 0073 QStringLiteral("duplicate"), 0074 QStringLiteral("open_terminal_here"), 0075 QStringLiteral("copy_to_inactive_split_view"), 0076 QStringLiteral("move_to_inactive_split_view")}); 0077 KPageWidgetItem *contextMenuSettingsFrame = addPage(contextMenuSettingsPage, i18nc("@title:group", "Context Menu")); 0078 contextMenuSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-menu-edit"))); 0079 connect(contextMenuSettingsPage, &ContextMenuSettingsPage::changed, this, &DolphinSettingsDialog::enableApply); 0080 0081 // Trash 0082 SettingsPageBase *trashSettingsPage = nullptr; 0083 #ifndef Q_OS_WIN 0084 trashSettingsPage = createTrashSettingsPage(this); 0085 #endif 0086 if (trashSettingsPage) { 0087 trashSettings = addPage(trashSettingsPage, i18nc("@title:group", "Trash")); 0088 trashSettings->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); 0089 connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply); 0090 } 0091 0092 #if HAVE_KUSERFEEDBACK 0093 // User Feedback 0094 UserFeedbackSettingsPage *feedbackSettingsPage = nullptr; 0095 if (DolphinFeedbackProvider::instance()->isEnabled()) { 0096 feedbackSettingsPage = new UserFeedbackSettingsPage(this); 0097 auto feedbackSettingsFrame = addPage(feedbackSettingsPage, i18nc("@title:group", "User Feedback")); 0098 feedbackSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-locale"))); 0099 connect(feedbackSettingsPage, &UserFeedbackSettingsPage::changed, this, &DolphinSettingsDialog::enableApply); 0100 } 0101 #endif 0102 0103 m_pages.append(interfaceSettingsPage); 0104 m_pages.append(viewSettingsPage); 0105 m_pages.append(contextMenuSettingsPage); 0106 if (trashSettingsPage) { 0107 m_pages.append(trashSettingsPage); 0108 } 0109 #if HAVE_KUSERFEEDBACK 0110 if (feedbackSettingsPage) { 0111 m_pages.append(feedbackSettingsPage); 0112 } 0113 #endif 0114 0115 const KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), QStringLiteral("SettingsDialog")); 0116 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig); 0117 } 0118 0119 DolphinSettingsDialog::~DolphinSettingsDialog() 0120 { 0121 KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), QStringLiteral("SettingsDialog")); 0122 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig); 0123 } 0124 0125 void DolphinSettingsDialog::enableApply() 0126 { 0127 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true); 0128 m_unsavedChanges = true; 0129 } 0130 0131 void DolphinSettingsDialog::applySettings() 0132 { 0133 for (SettingsPageBase *page : std::as_const(m_pages)) { 0134 page->applySettings(); 0135 } 0136 0137 Q_EMIT settingsChanged(); 0138 0139 GeneralSettings *settings = GeneralSettings::self(); 0140 if (settings->modifiedStartupSettings()) { 0141 // Reset the modified startup settings hint. The changed startup settings 0142 // have been applied already due to emitting settingsChanged(). 0143 settings->setModifiedStartupSettings(false); 0144 settings->save(); 0145 } 0146 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false); 0147 m_unsavedChanges = false; 0148 } 0149 0150 void DolphinSettingsDialog::restoreDefaults() 0151 { 0152 for (SettingsPageBase *page : std::as_const(m_pages)) { 0153 page->restoreDefaults(); 0154 } 0155 } 0156 0157 void DolphinSettingsDialog::closeEvent(QCloseEvent *event) 0158 { 0159 if (!m_unsavedChanges) { 0160 event->accept(); 0161 return; 0162 } 0163 0164 const auto response = KMessageBox::warningTwoActionsCancel(this, 0165 i18n("You have unsaved changes. Do you want to apply the changes or discard them?"), 0166 i18n("Warning"), 0167 KStandardGuiItem::save(), 0168 KStandardGuiItem::discard(), 0169 KStandardGuiItem::cancel()); 0170 switch (response) { 0171 case KMessageBox::PrimaryAction: 0172 applySettings(); 0173 Q_FALLTHROUGH(); 0174 case KMessageBox::SecondaryAction: 0175 event->accept(); 0176 break; 0177 case KMessageBox::Cancel: 0178 event->ignore(); 0179 break; 0180 default: 0181 break; 0182 } 0183 } 0184 0185 SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent) 0186 { 0187 if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) { 0188 return nullptr; 0189 } 0190 0191 return new TrashSettingsPage(parent); 0192 } 0193 0194 #include "moc_dolphinsettingsdialog.cpp"