diff --git a/src/kcmutilsgeneratemoduledata.cpp.in b/src/kcmutilsgeneratemoduledata.cpp.in index b4109faab9f42183ca72d1702583fc6ea7cbb67f..632eb8bc3be43c401233e30107fa87279c74183c 100644 --- a/src/kcmutilsgeneratemoduledata.cpp.in +++ b/src/kcmutilsgeneratemoduledata.cpp.in @@ -2,8 +2,6 @@ #include "@HEADER_NAME@" -#include - @INCLUDES_SETTINGS@ @OPEN_NAMESPACE@ diff --git a/src/kpluginselector.cpp b/src/kpluginselector.cpp index fb7ef14c57d4303480fb6c87df1726707fe2b3b1..74d7e1a7f57ae99ff46caa05e4867ef5294fa5d8 100644 --- a/src/kpluginselector.cpp +++ b/src/kpluginselector.cpp @@ -45,7 +45,9 @@ KPluginSelector::Private::Private(KPluginSelector *parent) , parent(parent) , listView(nullptr) , categoryDrawer(nullptr) + , pluginDelegate(nullptr) , showIcons(false) + , showDefaultIndicator(false) { } @@ -271,6 +273,7 @@ KPluginSelector::KPluginSelector(QWidget *parent) connect(d->lineEdit, &QLineEdit::textChanged, d->proxyModel, &QSortFilterProxyModel::invalidate); connect(pluginDelegate, &Private::PluginDelegate::changed, this, &KPluginSelector::changed); connect(pluginDelegate, &Private::PluginDelegate::configCommitted, this, &KPluginSelector::configCommitted); + connect(this, &KPluginSelector::defaultsIndicatorsVisible, pluginDelegate, &Private::PluginDelegate::slotResetModel); connect(this, &KPluginSelector::changed, [this]{ emit defaulted(isDefault()); }); @@ -371,6 +374,19 @@ void KPluginSelector::save() emit changed(false); } +bool KPluginSelector::isSaveNeeded() const +{ + for (int i = 0; i < d->pluginModel->rowCount(); i++) { + const QModelIndex index = d->pluginModel->index(i, 0); + PluginEntry *pluginEntry = static_cast(index.internalPointer()); + if (d->pluginModel->data(index, Qt::CheckStateRole).toBool() != pluginEntry->pluginInfo.isPluginEnabled()) { + return true; + } + } + + return false; +} + void KPluginSelector::defaults() { bool isChanged = false; @@ -450,6 +466,14 @@ void KPluginSelector::setAdditionalButtonHandler(std::function(d->listView->itemDelegate())->setHandler(handler); } +void KPluginSelector::setDefaultsIndicatorsVisible(bool isVisible) +{ + if (isVisible != d->showDefaultIndicator) { + d->showDefaultIndicator = isVisible; + emit defaultsIndicatorsVisible(); + } +} + KPluginSelector::Private::PluginModel::PluginModel(KPluginSelector::Private *pluginSelector_d, QObject *parent) : QAbstractListModel(parent) , pluginSelector_d(pluginSelector_d) @@ -819,6 +843,10 @@ void KPluginSelector::Private::PluginDelegate::updateItemWidgets(const QListsetVisible(false); } } else { + PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value(); + bool isDefault = pluginEntry->pluginInfo.isPluginEnabledByDefault() == index.model()->data(index, Qt::CheckStateRole).toBool(); + checkBox->setProperty("_kde_highlight_neutral", pluginSelector_d->showDefaultIndicator && !isDefault); + checkBox->setChecked(index.model()->data(index, Qt::CheckStateRole).toBool()); checkBox->setEnabled(index.model()->data(index, IsCheckableRole).toBool()); configurePushButton->setVisible(index.model()->data(index, ServicesCountRole).toBool()); @@ -846,6 +874,7 @@ void KPluginSelector::Private::PluginDelegate::emitChanged(bool state) { const QModelIndex index = focusedIndex(); PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value(); + if (pluginEntry->pluginInfo.isPluginEnabled() != state) { changedEntries << pluginEntry; } else { @@ -968,6 +997,11 @@ void KPluginSelector::Private::PluginDelegate::slotDefaultClicked() } } +void KPluginSelector::Private::PluginDelegate::slotResetModel() +{ + resetModel(); +} + QFont KPluginSelector::Private::PluginDelegate::titleFont(const QFont &baseFont) const { QFont retFont(baseFont); diff --git a/src/kpluginselector.h b/src/kpluginselector.h index f0a1609c350e62889151ed08fb002807e5fffbc3..097ed40dfae64ee382211a2d3146e416e4b2940f 100644 --- a/src/kpluginselector.h +++ b/src/kpluginselector.h @@ -158,6 +158,13 @@ public: */ void save(); + /** + * Returns true if the plugin selector has any changes that are not yet saved to configuration. + * @see save() + * @since 5.78 + */ + bool isSaveNeeded() const; + /** * Change to applications defaults * @see isDefault() @@ -219,6 +226,13 @@ public: */ void setAdditionalButtonHandler(std::function handler); + /** + * Show an indicator when a plugin status is different from default + * + * @since 5.78 + */ + void setDefaultsIndicatorsVisible(bool isVisible); + Q_SIGNALS: /** * Tells you whether the configuration is changed or not. @@ -238,6 +252,14 @@ Q_SIGNALS: */ void defaulted(bool isDefault); + /** + * Emitted when show defaults indicators changed + * @see setDefaultsIndicatorsVisible + * + * @since 5.78 + */ + void defaultsIndicatorsVisible(); + private: class Private; Private *const d; diff --git a/src/kpluginselector_p.h b/src/kpluginselector_p.h index daa4cfeb041cc17428255cb35a623b0a1ba24d0f..b468c9da83e99cac3fbbae32fa0e34fcc55ba983 100644 --- a/src/kpluginselector_p.h +++ b/src/kpluginselector_p.h @@ -70,6 +70,7 @@ public: DependenciesWidget *dependenciesWidget; bool showIcons; QStringList kcmArguments; + bool showDefaultIndicator; }; class PluginEntry @@ -183,6 +184,9 @@ public: inline void addChangedEntry(PluginEntry *entry) { changedEntries << entry; }; void setHandler(std::function handler); +public Q_SLOTS: + void slotResetModel(); + Q_SIGNALS: void changed(bool hasChanged); void configCommitted(const QByteArray &componentName);