File indexing completed on 2024-05-05 05:50:42
0001 /* 0002 SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 SPDX-License-Identifier: BSD-2-Clause 0005 */ 0006 0007 #include "pluginsettingspage.h" 0008 #include "ark_debug.h" 0009 0010 #include <QTreeWidget> 0011 0012 namespace Kerfuffle 0013 { 0014 PluginSettingsPage::PluginSettingsPage(QWidget *parent, const QString &name, const QString &iconName) 0015 : SettingsPage(parent, name, iconName) 0016 { 0017 setupUi(this); 0018 0019 const auto installedPlugins = m_pluginManager.installedPlugins(); 0020 for (const auto plugin : installedPlugins) { 0021 const auto metaData = plugin->metaData(); 0022 auto item = new QTreeWidgetItem(kcfg_disabledPlugins); 0023 item->setData(0, Qt::UserRole, QVariant::fromValue(plugin)); 0024 item->setText(0, metaData.name()); 0025 item->setText(1, metaData.description()); 0026 item->setCheckState(0, plugin->isEnabled() ? Qt::Checked : Qt::Unchecked); 0027 if (!plugin->isEnabled()) { 0028 m_toBeDisabled << metaData.pluginId(); 0029 } 0030 if (!plugin->hasRequiredExecutables()) { 0031 item->setDisabled(true); 0032 for (int i : {0, 1}) { 0033 item->setToolTip(i, i18n("The plugin cannot be used because one or more required executables are missing. Check your installation.")); 0034 } 0035 } 0036 } 0037 0038 for (int i : {0, 1}) { 0039 kcfg_disabledPlugins->resizeColumnToContents(i); 0040 } 0041 kcfg_disabledPlugins->sortItems(0, Qt::AscendingOrder); 0042 connect(kcfg_disabledPlugins, &QTreeWidget::itemChanged, this, &PluginSettingsPage::slotItemChanged); 0043 0044 // Set the custom property that KConfigDialogManager will use to update the settings. 0045 kcfg_disabledPlugins->setProperty("kcfg_property", QByteArray("disabledPlugins")); 0046 // Set the custom property that KConfigDialogManager will use to monitor signals for changes. 0047 kcfg_disabledPlugins->setProperty("kcfg_propertyNotify", QByteArray(SIGNAL(itemChanged(QTreeWidgetItem *, int)))); 0048 } 0049 0050 void PluginSettingsPage::slotSettingsChanged() 0051 { 0052 m_toBeDisabled.clear(); 0053 } 0054 0055 void PluginSettingsPage::slotDefaultsButtonClicked() 0056 { 0057 // KConfigDialogManager doesn't know how to reset the QTreeWidget, we need to do it manually. 0058 QTreeWidgetItemIterator iterator(kcfg_disabledPlugins); 0059 while (*iterator) { 0060 auto item = *iterator; 0061 // By default every plugin is enabled. 0062 item->setCheckState(0, Qt::Checked); 0063 iterator++; 0064 } 0065 } 0066 0067 void PluginSettingsPage::slotItemChanged(QTreeWidgetItem *item) 0068 { 0069 auto plugin = item->data(0, Qt::UserRole).value<Plugin *>(); 0070 if (!plugin) { 0071 return; 0072 } 0073 0074 const auto pluginId = plugin->metaData().pluginId(); 0075 plugin->setEnabled(item->checkState(0) == Qt::Checked); 0076 // If unchecked, add to the list of plugins that will be disabled. 0077 m_toBeDisabled.removeAll(pluginId); 0078 if (!plugin->isEnabled()) { 0079 m_toBeDisabled << pluginId; 0080 } 0081 // Enable the Apply button by setting the property. 0082 qCDebug(ARK) << "Going to disable the following plugins:" << m_toBeDisabled; 0083 kcfg_disabledPlugins->setProperty("disabledPlugins", m_toBeDisabled); 0084 } 0085 0086 } 0087 0088 #include "moc_pluginsettingspage.cpp"