Commit 442c43b3 authored by Dan Leinir Turthra Jensen's avatar Dan Leinir Turthra Jensen 🌈
Browse files

Switch the Plasma Desktop KCMs to using KNewStuffQuick

Summary:
This switches the KCMs which previously used a bit of a hack to show the old Widgets based Get Hot New Stuff dialog from a button in the Qt Quick based KCMs so that they instead use the new KNewStuff Qt Quick submodule. The modules affected by this are:

* Colors
* Cursor Theme
* Desktop Theme
* Icons
* KSplash

Reviewers: mart, ngraham

Reviewed By: mart, ngraham

Subscribers: bcooksley, davidedmundson, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26544
parent 268c5ced
......@@ -23,7 +23,7 @@ target_link_libraries(kcm_colors
KF5::I18n
KF5::KIOCore
KF5::KIOWidgets
KF5::NewStuff
KF5::NewStuffCore
KF5::QuickAddons
KF5::WindowSystem
)
......
......@@ -47,6 +47,11 @@
#include <KIO/DeleteJob>
#include <KIO/JobUiDelegate>
#include <knewstuffcore_version.h>
#if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67
#include <KNSCore/EntryWrapper>
#endif
#include <algorithm>
#include "../krdb/krdb.h"
......@@ -114,25 +119,21 @@ bool KCMColors::downloadingFile() const
return m_tempCopyJob;
}
void KCMColors::getNewStuff(QQuickItem *ctx)
void KCMColors::reloadModel(const QQmlListReference &changedEntries)
{
if (!m_newStuffDialog) {
m_newStuffDialog = new KNS3::DownloadDialog(QStringLiteral("colorschemes.knsrc"));
m_newStuffDialog.data()->setWindowTitle(i18n("Download New Color Schemes"));
m_newStuffDialog->setWindowModality(Qt::WindowModal);
m_newStuffDialog->winId(); // so it creates the windowHandle();
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, [this] {
m_model->load();
m_model->load();
const auto newEntries = m_newStuffDialog->installedEntries();
// If one new theme was installed, select the first color file in it
if (newEntries.count() == 1) {
QStringList installedThemes;
#if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67
// If one new theme was installed, select the first color file in it
if (changedEntries.count() > 1) {
QStringList installedThemes;
const QString suffix = QStringLiteral(".colors");
const QString suffix = QStringLiteral(".colors");
for (const QString &path : newEntries.first().installedFiles()) {
for (int i = 0; i < changedEntries.count(); ++i) {
KNSCore::EntryWrapper* entry = qobject_cast<KNSCore::EntryWrapper*>(changedEntries.at(i));
if (entry && entry->entry().status() == KNS3::Entry::Installed) {
for (const QString &path : entry->entry().installedFiles()) {
const QString fileName = path.section(QLatin1Char('/'), -1, -1);
const int suffixPos = fileName.indexOf(suffix);
......@@ -150,15 +151,12 @@ void KCMColors::getNewStuff(QQuickItem *ctx)
m_model->setSelectedScheme(installedThemes.constFirst());
}
// Only do this for the first newly installed theme we find
break;
}
});
}
if (ctx && ctx->window()) {
m_newStuffDialog->windowHandle()->setTransientParent(ctx->window());
}
}
m_newStuffDialog.data()->show();
#endif
}
void KCMColors::installSchemeFromFile(const QUrl &url)
......
......@@ -23,10 +23,10 @@
#include <QScopedPointer>
#include <QPointer>
#include <QQmlListReference>
#include <KSharedConfig>
#include <KNewStuff3/KNS3/DownloadDialog>
#include <KQuickAddons/ManagedConfigModule>
......@@ -74,7 +74,7 @@ public:
ColorsSettings *colorsSettings() const;
bool downloadingFile() const;
Q_INVOKABLE void getNewStuff(QQuickItem *ctx);
Q_INVOKABLE void reloadModel(const QQmlListReference &changedEntries);
Q_INVOKABLE void installSchemeFromFile(const QUrl &url);
Q_INVOKABLE void editScheme(const QString &schemeName, QQuickItem *ctx);
......@@ -107,8 +107,6 @@ private:
bool m_applyToAlien = true;
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
QProcess *m_editDialogProcess = nullptr;
KSharedConfigPtr m_config;
......
......@@ -24,7 +24,7 @@ import QtQuick.Window 2.2
import QtQuick.Dialogs 1.0 as QtDialogs
import QtQuick.Controls 2.3 as QtControls
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.kcm 1.1 as KCM
import org.kde.private.kcms.colors 1.0 as Private
......@@ -348,11 +348,12 @@ KCM.GridViewKCM {
onClicked: fileDialogLoader.active = true
}
QtControls.Button {
text: i18n("Get New Color Schemes...")
icon.name: "get-hot-new-stuff"
onClicked: kcm.getNewStuff(this)
visible: KAuthorized.authorize("ghns")
NewStuff.Button {
id: newStuffButton
downloadNewWhat: i18n("Color Schemes")
configFile: "colorschemes.knsrc"
viewMode: NewStuff.Page.ViewMode.Tiles
onChangedEntriesChanged: kcm.reloadModel(newStuffButton.changedEntries);
}
}
}
......
......@@ -37,7 +37,7 @@ target_link_libraries(kcm_cursortheme
KF5::KIOCore
KF5::KIOWidgets
KF5::KDELibs4Support
KF5::NewStuff
KF5::NewStuffCore
KF5::QuickAddons
${X11_LIBRARIES}
XCB::XCB
......
......@@ -39,8 +39,12 @@
#include <KTar>
#include <KGlobalSettings>
#include <KNewStuff3/KNS3/DownloadDialog>
#include <knewstuffcore_version.h>
#if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67
#include <KNSCore/EntryWrapper>
#endif
#include <QQmlListReference>
#include <QX11Info>
#include <QStandardItemModel>
......@@ -404,43 +408,42 @@ void CursorThemeConfig::defaults()
m_preferredSize = m_settings->cursorSize();
}
void CursorThemeConfig::getNewClicked()
void CursorThemeConfig::ghnsEntriesChanged(const QQmlListReference &changedEntries)
{
KNS3::DownloadDialog dialog("xcursor.knsrc", nullptr);
if (dialog.exec()) {
KNS3::Entry::List list = dialog.changedEntries();
if (!list.isEmpty()) {
for (const KNS3::Entry& entry : list) {
if (entry.status() == KNS3::Entry::Deleted) {
for (const QString& deleted : entry.uninstalledFiles()) {
QVector<QStringRef> list = deleted.splitRef(QLatin1Char('/'));
if (list.last() == QLatin1Char('*')) {
list.takeLast();
}
QModelIndex idx = m_themeModel->findIndex(list.last().toString());
if (idx.isValid()) {
m_themeModel->removeTheme(idx);
}
#if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MINOR>=67
for (int i = 0; i < changedEntries.count(); ++i) {
KNSCore::EntryWrapper* entry = qobject_cast<KNSCore::EntryWrapper*>(changedEntries.at(i));
if (entry) {
if (entry->entry().status() == KNS3::Entry::Deleted) {
for (const QString& deleted : entry->entry().uninstalledFiles()) {
QVector<QStringRef> list = deleted.splitRef(QLatin1Char('/'));
if (list.last() == QLatin1Char('*')) {
list.takeLast();
}
} else if (entry.status() == KNS3::Entry::Installed) {
for (const QString& created : entry.installedFiles()) {
QStringList list = created.split(QLatin1Char('/'));
if (list.last() == QLatin1Char('*')) {
list.takeLast();
}
// Because we sometimes get some extra slashes in the installed files list
list.removeAll({});
// Because we'll also get the containing folder, if it was not already there
// we need to ignore it.
if (list.last() == QLatin1String(".icons")) {
continue;
}
m_themeModel->addTheme(QStringLiteral("/%1").arg(list.join(QLatin1Char('/'))));
QModelIndex idx = m_themeModel->findIndex(list.last().toString());
if (idx.isValid()) {
m_themeModel->removeTheme(idx);
}
}
} else if (entry->entry().status() == KNS3::Entry::Installed) {
for (const QString& created : entry->entry().installedFiles()) {
QStringList list = created.split(QLatin1Char('/'));
if (list.last() == QLatin1Char('*')) {
list.takeLast();
}
// Because we sometimes get some extra slashes in the installed files list
list.removeAll({});
// Because we'll also get the containing folder, if it was not already there
// we need to ignore it.
if (list.last() == QLatin1String(".icons")) {
continue;
}
m_themeModel->addTheme(list.join(QLatin1Char('/')));
}
}
}
}
#endif
}
void CursorThemeConfig::installThemeFromFile(const QUrl &url)
......
......@@ -23,6 +23,7 @@
#include <KQuickAddons/ManagedConfigModule>
#include <QScopedPointer>
class QQmlListReference;
class QStandardItemModel;
class QTemporaryFile;
......@@ -95,7 +96,7 @@ Q_SIGNALS:
void showErrorMessage(const QString &message);
public Q_SLOTS:
void getNewClicked();
void ghnsEntriesChanged(const QQmlListReference &changedEntries);
void installThemeFromFile(const QUrl &url);
void removeTheme(int row);
......
......@@ -22,7 +22,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2 as QtControls
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.kcm 1.1 as KCM
import org.kde.private.kcm_cursortheme 1.0
......@@ -144,12 +144,13 @@ KCM.GridViewKCM {
onClicked: fileDialogLoader.active = true;
enabled: kcm.canInstall
}
QtControls.Button {
icon.name: "get-hot-new-stuff"
text: i18n("&Get New Cursors...")
onClicked: kcm.getNewClicked();
NewStuff.Button {
id: newStuffButton
enabled: kcm.canInstall
visible: KAuthorized.authorize("ghns")
downloadNewWhat: i18n("Cursors")
configFile: "xcursor.knsrc"
viewMode: NewStuff.Page.ViewMode.Tiles
onChangedEntriesChanged: kcm.ghnsEntriesChanged(newStuffButton.changedEntries);
}
}
}
......
......@@ -20,7 +20,6 @@ target_link_libraries(kcm_desktoptheme
KF5::Plasma
KF5::Declarative
KF5::QuickAddons
KF5::NewStuff
)
kcoreaddons_desktop_to_json(kcm_desktoptheme "kcm_desktoptheme.desktop" SERVICE_TYPES kcmodule.desktop)
......
......@@ -40,8 +40,6 @@
#include <QStandardItemModel>
#include <QTemporaryFile>
#include <KNewStuff3/KNS3/DownloadDialog>
#include "desktopthemesettings.h"
#include "filterproxymodel.h"
#include "themesmodel.h"
......@@ -108,23 +106,6 @@ bool KCMDesktopTheme::downloadingFile() const
return m_tempCopyJob;
}
void KCMDesktopTheme::getNewStuff(QQuickItem *ctx)
{
if (!m_newStuffDialog) {
m_newStuffDialog = new KNS3::DownloadDialog(QStringLiteral("plasma-themes.knsrc"));
m_newStuffDialog.data()->setWindowTitle(i18n("Download New Plasma Styles"));
m_newStuffDialog->setWindowModality(Qt::WindowModal);
m_newStuffDialog->winId(); // so it creates the windowHandle();
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, &KCMDesktopTheme::load);
}
if (ctx && ctx->window()) {
m_newStuffDialog->windowHandle()->setTransientParent(ctx->window());
}
m_newStuffDialog.data()->show();
}
void KCMDesktopTheme::installThemeFromFile(const QUrl &url)
{
if (url.isLocalFile()) {
......
......@@ -25,8 +25,6 @@
#include <KQuickAddons/ManagedConfigModule>
#include <KNewStuff3/KNS3/DownloadDialog>
class QTemporaryFile;
namespace Plasma {
......@@ -66,7 +64,6 @@ public:
bool canEditThemes() const;
Q_INVOKABLE void getNewStuff(QQuickItem *ctx);
Q_INVOKABLE void installThemeFromFile(const QUrl &url);
Q_INVOKABLE void applyPlasmaTheme(QQuickItem *item, const QString &themeName);
......@@ -98,8 +95,6 @@ private:
QHash<QString, Plasma::Theme*> m_themes;
bool m_haveThemeExplorerInstalled;
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
QScopedPointer<QTemporaryFile> m_tempInstallFile;
QPointer<KIO::FileCopyJob> m_tempCopyJob;
};
......
......@@ -24,7 +24,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.0
import QtQuick.Controls 2.3 as QtControls
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.kcm 1.1 as KCM
import org.kde.private.kcms.desktoptheme 1.0 as Private
......@@ -206,11 +206,12 @@ KCM.GridViewKCM {
onClicked: fileDialogLoader.active = true;
}
QtControls.Button {
text: i18n("Get New Plasma Styles...")
icon.name: "get-hot-new-stuff"
onClicked: kcm.getNewStuff(this)
visible: KAuthorized.authorize("ghns")
NewStuff.Button {
id: newStuffButton
downloadNewWhat: i18n("Plasma Styles")
configFile: "plasma-themes.knsrc"
viewMode: NewStuff.Page.ViewMode.Preview
onChangedEntriesChanged: kcm.load();
}
}
}
......
......@@ -14,7 +14,6 @@ target_link_libraries(kcm_icons
KF5::I18n
KF5::IconThemes
KF5::Archive
KF5::NewStuff
KF5::KIOWidgets
KF5::QuickAddons
)
......
......@@ -172,31 +172,16 @@ void IconModule::processPendingDeletions()
m_model->removeItemsPendingDeletion();
}
void IconModule::getNewStuff(QQuickItem *ctx)
void IconModule::ghnsEntriesChanged(const QQmlListReference &changedEntries)
{
if (!m_newStuffDialog) {
m_newStuffDialog = new KNS3::DownloadDialog(QStringLiteral("icons.knsrc"));
m_newStuffDialog->setWindowTitle(i18n("Download New Icon Themes"));
m_newStuffDialog->setWindowModality(Qt::WindowModal);
m_newStuffDialog->winId(); // so it creates the windowHandle();
// TODO would be lovely to scroll to and select the newly installed scheme, if any
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, [this] {
if (m_newStuffDialog->changedEntries().isEmpty()) {
return;
}
// reload the display icontheme items
KIconLoader::global()->newIconLoader();
m_model->load();
QPixmapCache::clear();
});
}
if (ctx && ctx->window()) {
m_newStuffDialog->windowHandle()->setTransientParent(ctx->window());
if (changedEntries.count() == 0) {
return;
}
m_newStuffDialog->show();
// reload the display icontheme items
KIconLoader::global()->newIconLoader();
m_model->load();
QPixmapCache::clear();
}
void IconModule::installThemeFromFile(const QUrl &url)
......
......@@ -28,9 +28,6 @@
#include <KQuickAddons/ManagedConfigModule>
#include <KNS3/DownloadDialog>
#include <KLocalizedString>
#include <QScopedPointer>
#include <QCache>
......@@ -76,7 +73,7 @@ public:
void load() override;
void save() override;
Q_INVOKABLE void getNewStuff(QQuickItem *ctx);
Q_INVOKABLE void ghnsEntriesChanged(const QQmlListReference &changedEntries);
Q_INVOKABLE void installThemeFromFile(const QUrl &url);
Q_INVOKABLE QList<int> availableIconSizes(int group) const;
......@@ -117,5 +114,4 @@ private:
QScopedPointer<QTemporaryFile> m_tempInstallFile;
QPointer<KIO::FileCopyJob> m_tempCopyJob;
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
};
......@@ -25,7 +25,7 @@ import QtQuick.Dialogs 1.0 as QtDialogs
import QtQuick.Controls 2.3 as QtControls
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrolsaddons 2.0 as KQCAddons
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.kcm 1.1 as KCM
import org.kde.private.kcms.icons 1.0 as Private
......@@ -251,12 +251,12 @@ KCM.GridViewKCM {
onClicked: fileDialogLoader.active = true
}
QtControls.Button {
enabled: !kcm.iconsSettings.isImmutable("Theme")
text: i18n("Get New Icons...")
icon.name: "get-hot-new-stuff"
onClicked: kcm.getNewStuff(this)
visible: KAuthorized.authorize("ghns")
NewStuff.Button {
id: newStuffButton
downloadNewWhat: i18n("Icons")
configFile: "icons.knsrc"
viewMode: NewStuff.Page.ViewMode.Preview
onChangedEntriesChanged: kcm.ghnsEntriesChanged(newStuffButton.changedEntries);
}
}
}
......
......@@ -12,11 +12,11 @@ add_library(kcm_splashscreen MODULE ${kcm_splashscreen_SRCS})
target_link_libraries(kcm_splashscreen
KF5::KIOWidgets
KF5::CoreAddons
KF5::ConfigWidgets
KF5::QuickAddons
KF5::I18n
KF5::Plasma
KF5::PlasmaQuick
KF5::NewStuff
Qt5::DBus
Qt5::Widgets
......
......@@ -32,8 +32,6 @@
#include <KPackage/PackageLoader>
#include <KNewStuff3/KNS3/DownloadDialog>
#include "splashscreensettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMSplashScreenFactory, "kcm_splashscreen.json", registerPlugin<KCMSplashScreen>();)
......@@ -93,14 +91,10 @@ QStandardItemModel *KCMSplashScreen::splashModel() const
return m_model;
}
void KCMSplashScreen::getNewClicked()
void KCMSplashScreen::ghnsEntriesChanged(const QQmlListReference &changedEntries)
{
KNS3::DownloadDialog dialog("ksplash.knsrc", nullptr);
if (dialog.exec()) {
KNS3::Entry::List list = dialog.changedEntries();
if (!list.isEmpty()) {
loadModel();
}
if (changedEntries.count() > 0) {
loadModel();
}
}
......
......@@ -50,7 +50,7 @@ public:
Q_INVOKABLE int pluginIndex(const QString &pluginName) const;
public Q_SLOTS:
void getNewClicked();
void ghnsEntriesChanged(const QQmlListReference &changedEntries);
void save() override;
void test(const QString &plugin);
......
......@@ -21,7 +21,7 @@ import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.0 as QtControls
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.kcm 1.1 as KCM
KCM.GridViewKCM {
......@@ -80,11 +80,12 @@ KCM.GridViewKCM {
Item {
Layout.fillWidth: true
}
QtControls.Button {
iconName: "get-hot-new-stuff"
text: i18n("&Get New Splash Screens...")
onClicked: kcm.getNewClicked();
visible: KAuthorized.authorize("ghns")
NewStuff.Button {
id: newStuffButton
downloadNewWhat: i18n("Splash Screens")
configFile: "ksplash.knsrc"
viewMode: NewStuff.Page.ViewMode.Preview
onChangedEntriesChanged: kcm.ghnsEntriesChanged(newStuffButton.changedEntries);
}
}
}
Markdown is supported
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