Commit 12f4d353 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Desktop Theme KCM] Support installing from remote locations

Uses KIO to copy the file into temp folder for installation.
The same as the other KCMs do.

Differential Revision: https://phabricator.kde.org/D18498
parent b52c0ceb
......@@ -10,6 +10,8 @@ add_library(kcm_desktoptheme MODULE ${kcm_desktoptheme_SRCS})
target_link_libraries(kcm_desktoptheme
KF5::CoreAddons
KF5::KCMUtils
KF5::KIOCore
KF5::KIOWidgets
KF5::I18n
KF5::Plasma
KF5::Declarative
......
......@@ -27,6 +27,9 @@
#include <KLocalizedString>
#include <KDesktopFile>
#include <KIO/FileCopyJob>
#include <KIO/JobUiDelegate>
#include <Plasma/Theme>
#include <Plasma/Svg>
......@@ -36,6 +39,7 @@
#include <QQuickWindow>
#include <QStandardPaths>
#include <QStandardItemModel>
#include <QTemporaryFile>
#include <KNewStuff3/KNS3/DownloadDialog>
......@@ -108,6 +112,11 @@ int KCMDesktopTheme::selectedPluginIndex() const
return -1;
}
bool KCMDesktopTheme::downloadingFile() const
{
return m_tempCopyJob;
}
void KCMDesktopTheme::setPendingDeletion(int index, bool pending)
{
QModelIndex idx = m_model->index(index, 0);
......@@ -140,12 +149,47 @@ void KCMDesktopTheme::getNewStuff(QQuickItem *ctx)
m_newStuffDialog.data()->show();
}
void KCMDesktopTheme::installThemeFromFile(const QUrl &file)
void KCMDesktopTheme::installThemeFromFile(const QUrl &url)
{
if (url.isLocalFile()) {
installTheme(url.toLocalFile());
return;
}
if (m_tempCopyJob) {
return;
}
m_tempInstallFile.reset(new QTemporaryFile());
if (!m_tempInstallFile->open()) {
emit showErrorMessage(i18n("Unable to create a temporary file."));
m_tempInstallFile.reset();
return;
}
m_tempCopyJob = KIO::file_copy(url, QUrl::fromLocalFile(m_tempInstallFile->fileName()),
-1, KIO::Overwrite);
m_tempCopyJob->uiDelegate()->setAutoErrorHandlingEnabled(true);
emit downloadingFileChanged();
connect(m_tempCopyJob, &KIO::FileCopyJob::result, this, [this, url](KJob *job) {
if (job->error() != KJob::NoError) {
emit showErrorMessage(i18n("Unable to download the theme: %1", job->errorText()));
return;
}
installTheme(m_tempInstallFile->fileName());
m_tempInstallFile.reset();
});
connect(m_tempCopyJob, &QObject::destroyed, this, &KCMDesktopTheme::downloadingFileChanged);
}
void KCMDesktopTheme::installTheme(const QString &path)
{
qCDebug(KCM_DESKTOP_THEME) << "Installing ... " << file;
qCDebug(KCM_DESKTOP_THEME) << "Installing ... " << path;
const QString program = QStringLiteral("kpackagetool5");
const QStringList arguments = { QStringLiteral("--type"), QStringLiteral("Plasma/Theme"), QStringLiteral("--install"), file.toLocalFile()};
const QStringList arguments = { QStringLiteral("--type"), QStringLiteral("Plasma/Theme"), QStringLiteral("--install"), path};
qCDebug(KCM_DESKTOP_THEME) << program << arguments.join(QStringLiteral(" "));
QProcess *myProcess = new QProcess(this);
......
......@@ -26,11 +26,18 @@
#include <KNewStuff3/KNS3/DownloadDialog>
class QTemporaryFile;
namespace Plasma {
class Svg;
class Theme;
}
namespace KIO
{
class FileCopyJob;
}
class QQuickItem;
class QStandardItemModel;
......@@ -40,6 +47,7 @@ class KCMDesktopTheme : public KQuickAddons::ConfigModule
Q_PROPERTY(QStandardItemModel *desktopThemeModel READ desktopThemeModel CONSTANT)
Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged)
Q_PROPERTY(int selectedPluginIndex READ selectedPluginIndex NOTIFY selectedPluginIndexChanged)
Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged)
Q_PROPERTY(bool canEditThemes READ canEditThemes CONSTANT)
public:
......@@ -61,10 +69,12 @@ public:
void setSelectedPlugin(const QString &plugin);
int selectedPluginIndex() const;
bool downloadingFile() const;
bool canEditThemes() const;
Q_INVOKABLE void getNewStuff(QQuickItem *ctx);
Q_INVOKABLE void installThemeFromFile(const QUrl &file);
Q_INVOKABLE void installThemeFromFile(const QUrl &url);
Q_INVOKABLE void setPendingDeletion(int index, bool pending);
......@@ -75,6 +85,8 @@ public:
Q_SIGNALS:
void selectedPluginChanged(const QString &plugin);
void selectedPluginIndexChanged();
void downloadingFileChanged();
void showSuccessMessage(const QString &message);
void showErrorMessage(const QString &message);
......@@ -88,6 +100,8 @@ private:
void processPendingDeletions();
void installTheme(const QString &path);
QStandardItemModel *m_model;
QString m_selectedPlugin;
QStringList m_pendingRemoval;
......@@ -96,6 +110,9 @@ private:
bool m_haveThemeExplorerInstalled;
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
QScopedPointer<QTemporaryFile> m_tempInstallFile;
QPointer<KIO::FileCopyJob> m_tempCopyJob;
};
Q_DECLARE_LOGGING_CATEGORY(KCM_DESKTOP_THEME)
......
......@@ -32,6 +32,8 @@ KCM.GridViewKCM {
view.model: kcm.desktopThemeModel
view.currentIndex: kcm.selectedPluginIndex
enabled: !kcm.downloadingFile
DropArea {
anchors.fill: parent
onEntered: {
......
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