Commit 6359240e authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

ksplash kcm: Only update necessary parts on KNewStuff events

CCBUG: 431568
parent 846a9636
......@@ -26,6 +26,7 @@ target_link_libraries(kcm_splashscreen
KF5::I18n
KF5::Plasma
KF5::PlasmaQuick
KF5::NewStuff
Qt::DBus
Qt::Widgets
......
......@@ -63,7 +63,9 @@ KCMSplashScreen::KCMSplashScreen(QObject *parent, const QVariantList &args)
m_sortModel = new QSortFilterProxyModel(this);
m_sortModel->setSourceModel(m_model);
m_sortModel->setSortLocaleAware(true);
m_sortModel->setSortRole(Qt::DisplayRole);
m_sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_sortModel->setDynamicSortFilter(true);
connect(m_model, &QAbstractItemModel::dataChanged, this, [this] {
bool hasPendingDeletions = !pendingDeletions().isEmpty();
......@@ -100,36 +102,58 @@ SplashScreenSettings *KCMSplashScreen::splashScreenSettings() const
return m_data->settings();
}
QAbstractProxyModel *KCMSplashScreen::splashModel() const
QAbstractProxyModel *KCMSplashScreen::splashSortedModel() const
{
return m_sortModel;
}
void KCMSplashScreen::ghnsEntriesChanged(const QQmlListReference &changedEntries)
void KCMSplashScreen::ghnsEntryChanged(KNSCore::EntryWrapper *wrapper)
{
if (changedEntries.count() > 0) {
load();
auto removeItemFromModel = [this](const QStringList &files) {
if (!files.isEmpty()) {
const QString guessedPluginId = QFileInfo(files.constFirst()).fileName();
const int index = pluginIndex(guessedPluginId);
if (index != -1) {
m_model->removeRows(index, 1);
}
}
};
const KNSCore::EntryInternal entry = wrapper->entry();
if (entry.status() == KNS3::Entry::Deleted) {
removeItemFromModel(entry.uninstalledFiles());
} else if (entry.status() == KNS3::Entry::Installed) {
removeItemFromModel(entry.installedFiles());
KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
pkg.setPath(entry.installedFiles().constFirst());
addKPackageToModel(pkg);
m_sortModel->sort(Qt::DisplayRole);
}
}
void KCMSplashScreen::addKPackageToModel(const KPackage::Package &pkg)
{
const static QString writableLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
QStandardItem *row = new QStandardItem(pkg.metadata().name());
row->setData(pkg.metadata().pluginId(), PluginNameRole);
row->setData(pkg.filePath("previews", QStringLiteral("splash.png")), ScreenshotRole);
row->setData(pkg.metadata().description(), DescriptionRole);
row->setData(pkg.path().startsWith(writableLocation), UninstallableRole);
row->setData(false, PendingDeletionRole);
m_packageRoot = writableLocation + QLatin1Char('/') + pkg.defaultPackageRoot();
m_model->appendRow(row);
}
void KCMSplashScreen::load()
{
m_data->settings()->load();
m_model->clear();
const QList<KPackage::Package> pkgs = availablePackages(QStringLiteral("splashmainscript"));
const QString writableLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
for (const KPackage::Package &pkg : pkgs) {
QStandardItem *row = new QStandardItem(pkg.metadata().name());
row->setData(pkg.metadata().pluginId(), PluginNameRole);
row->setData(pkg.filePath("previews", QStringLiteral("splash.png")), ScreenshotRole);
row->setData(pkg.metadata().description(), DescriptionRole);
row->setData(pkg.path().startsWith(writableLocation), UninstallableRole);
row->setData(false, PendingDeletionRole);
m_packageRoot = writableLocation + QLatin1Char('/') + pkg.defaultPackageRoot();
m_model->appendRow(row);
addKPackageToModel(pkg);
}
m_sortModel->sort(PluginNameRole);
m_sortModel->sort(Qt::DisplayRole);
QStandardItem *row = new QStandardItem(i18n("None"));
row->setData("None", PluginNameRole);
......
......@@ -21,6 +21,7 @@
#ifndef _KCM_SEARCH_H
#define _KCM_SEARCH_H
#include <KNSCore/EntryWrapper>
#include <KPackage/Package>
#include <KQuickAddons/ManagedConfigModule>
......@@ -33,7 +34,7 @@ class KCMSplashScreen : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(SplashScreenSettings *splashScreenSettings READ splashScreenSettings CONSTANT)
Q_PROPERTY(QAbstractProxyModel *splashModel READ splashModel CONSTANT)
Q_PROPERTY(QAbstractProxyModel *splashSortedModel READ splashSortedModel CONSTANT)
Q_PROPERTY(bool testing READ testing NOTIFY testingChanged)
public:
......@@ -48,14 +49,14 @@ public:
KCMSplashScreen(QObject *parent, const QVariantList &args);
SplashScreenSettings *splashScreenSettings() const;
QAbstractProxyModel *splashModel() const;
QAbstractProxyModel *splashSortedModel() const;
bool testing() const;
Q_INVOKABLE int sortModelPluginIndex(const QString &pluginName) const;
Q_INVOKABLE void ghnsEntryChanged(KNSCore::EntryWrapper *wrapper);
QStringList pendingDeletions();
public Q_SLOTS:
void ghnsEntriesChanged(const QQmlListReference &changedEntries);
void save() override;
void load() override;
void defaults() override;
......@@ -69,6 +70,7 @@ Q_SIGNALS:
private:
QList<KPackage::Package> availablePackages(const QString &component);
int pluginIndex(const QString &pluginName) const;
void addKPackageToModel(const KPackage::Package &pkg);
SplashScreenData *m_data;
QStandardItemModel *m_model;
......
......@@ -34,7 +34,7 @@ KCM.GridViewKCM {
extraEnabledConditions: !kcm.testing
}
view.model: kcm.splashModel
view.model: kcm.splashSortedModel
//NOTE: pay attention to never break this binding
view.currentIndex: kcm.sortModelPluginIndex(kcm.splashScreenSettings.theme)
......@@ -106,7 +106,12 @@ KCM.GridViewKCM {
text: i18n("&Get New Splash Screens...")
configFile: "ksplash.knsrc"
viewMode: NewStuff.Page.ViewMode.Preview
onChangedEntriesChanged: kcm.ghnsEntriesChanged(newStuffButton.changedEntries);
onChangedEntriesChanged: {
var length = newStuffButton.changedEntries.length;
if (length > 0) {
kcm.ghnsEntryChanged(newStuffButton.changedEntries[length - 1]);
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment