Commit 366ec1b2 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Disable KCMs while downloading file

When dropping or choosing a remote file, it is downloaded to a temporary location for installation.
Disable the KCM while this is in progress to avoid confusion as to what is happening.
A job is spawned in notification area which is why no additional busy indicator is added to the KCM UI.

Differential Revision: https://phabricator.kde.org/D18497
parent 57946a0f
......@@ -185,6 +185,11 @@ int CursorThemeConfig::selectedSizeRow() const
return m_selectedSizeRow;
}
bool CursorThemeConfig::downloadingFile() const
{
return m_tempCopyJob;
}
QAbstractItemModel *CursorThemeConfig::cursorsModel()
......@@ -469,6 +474,10 @@ void CursorThemeConfig::installThemeFromFile(const QUrl &url)
return;
}
if (m_tempCopyJob) {
return;
}
m_tempInstallFile.reset(new QTemporaryFile());
if (!m_tempInstallFile->open()) {
emit showErrorMessage(i18n("Unable to create a temporary file."));
......@@ -476,11 +485,12 @@ void CursorThemeConfig::installThemeFromFile(const QUrl &url)
return;
}
KIO::FileCopyJob *job = KIO::file_copy(url,QUrl::fromLocalFile(m_tempInstallFile->fileName()),
m_tempCopyJob = KIO::file_copy(url,QUrl::fromLocalFile(m_tempInstallFile->fileName()),
-1, KIO::Overwrite);
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
m_tempCopyJob->uiDelegate()->setAutoErrorHandlingEnabled(true);
emit downloadingFileChanged();
connect(job, &KIO::FileCopyJob::result, this, [this, url](KJob *job) {
connect(m_tempCopyJob, &KIO::FileCopyJob::result, this, [this, url](KJob *job) {
if (job->error() != KJob::NoError) {
emit showErrorMessage(i18n("Unable to download the icon theme archive: %1", job->errorText()));
return;
......@@ -489,6 +499,7 @@ void CursorThemeConfig::installThemeFromFile(const QUrl &url)
installThemeFile(m_tempInstallFile->fileName());
m_tempInstallFile.reset();
});
connect(m_tempCopyJob, &QObject::destroyed, this, &CursorThemeConfig::downloadingFileChanged);
}
void CursorThemeConfig::installThemeFile(const QString &path)
......
......@@ -29,6 +29,11 @@ class CursorThemeModel;
class SortProxyModel;
class CursorTheme;
namespace KIO
{
class FileCopyJob;
}
class CursorThemeConfig : public KQuickAddons::ConfigModule
{
Q_OBJECT
......@@ -40,6 +45,8 @@ class CursorThemeConfig : public KQuickAddons::ConfigModule
Q_PROPERTY(int selectedThemeRow READ selectedThemeRow WRITE setSelectedThemeRow NOTIFY selectedThemeRowChanged)
Q_PROPERTY(int selectedSizeRow READ selectedSizeRow WRITE setSelectedSizeRow NOTIFY selectedSizeRowChanged)
Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged)
public:
CursorThemeConfig(QObject *parent, const QVariantList &);
~CursorThemeConfig() override;
......@@ -65,6 +72,8 @@ public:
int selectedSizeRow() const;
void setSelectedSizeRow(int row);
bool downloadingFile() const;
QAbstractItemModel *cursorsModel();
QAbstractItemModel *sizesModel();
......@@ -74,6 +83,7 @@ Q_SIGNALS:
void canConfigureChanged();
void selectedThemeRowChanged();
void selectedSizeRowChanged();
void downloadingFileChanged();
void showSuccessMessage(const QString &message);
void showInfoMessage(const QString &message);
......@@ -134,6 +144,7 @@ private:
bool m_canConfigure;
QScopedPointer<QTemporaryFile> m_tempInstallFile;
QPointer<KIO::FileCopyJob> m_tempCopyJob;
};
#endif
......@@ -37,6 +37,8 @@ KCM.GridViewKCM {
view.positionViewAtIndex(view.currentIndex, view.GridView.Beginning);
}
enabled: !kcm.downloadingFile
DropArea {
anchors.fill: parent
onEntered: {
......
......@@ -121,6 +121,11 @@ QStringList IconModule::iconGroups() const
return m_iconGroups;
}
bool IconModule::downloadingFile() const
{
return m_tempCopyJob;
}
int IconModule::iconSize(int group) const
{
return m_iconSizes[group];
......@@ -306,6 +311,10 @@ void IconModule::installThemeFromFile(const QUrl &url)
return;
}
if (m_tempCopyJob) {
return;
}
m_tempInstallFile.reset(new QTemporaryFile());
if (!m_tempInstallFile->open()) {
emit showErrorMessage(i18n("Unable to create a temporary file."));
......@@ -313,11 +322,12 @@ void IconModule::installThemeFromFile(const QUrl &url)
return;
}
KIO::FileCopyJob *job = KIO::file_copy(url,QUrl::fromLocalFile(m_tempInstallFile->fileName()),
m_tempCopyJob = KIO::file_copy(url,QUrl::fromLocalFile(m_tempInstallFile->fileName()),
-1, KIO::Overwrite);
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
m_tempCopyJob->uiDelegate()->setAutoErrorHandlingEnabled(true);
emit downloadingFileChanged();
connect(job, &KIO::FileCopyJob::result, this, [this, url](KJob *job) {
connect(m_tempCopyJob, &KIO::FileCopyJob::result, this, [this, url](KJob *job) {
if (job->error() != KJob::NoError) {
emit showErrorMessage(i18n("Unable to download the icon theme archive: %1", job->errorText()));
return;
......@@ -326,6 +336,7 @@ void IconModule::installThemeFromFile(const QUrl &url)
installThemeFile(m_tempInstallFile->fileName());
m_tempInstallFile.reset();
});
connect(m_tempCopyJob, &QObject::destroyed, this, &IconModule::downloadingFileChanged);
}
void IconModule::installThemeFile(const QString &path)
......
......@@ -36,6 +36,11 @@ class KIconTheme;
class QQuickItem;
class QTemporaryFile;
namespace KIO
{
class FileCopyJob;
}
class IconsModel;
class IconModule : public KQuickAddons::ConfigModule
......@@ -46,6 +51,8 @@ class IconModule : public KQuickAddons::ConfigModule
Q_PROPERTY(QStringList iconGroups READ iconGroups CONSTANT)
Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged)
public:
IconModule(QObject *parent, const QVariantList &args);
~IconModule() override;
......@@ -61,6 +68,8 @@ public:
QStringList iconGroups() const;
bool downloadingFile() const;
void load() override;
void save() override;
void defaults() override;
......@@ -77,6 +86,7 @@ public:
signals:
void iconSizesChanged();
void downloadingFileChanged();
void showSuccessMessage(const QString &message);
void showErrorMessage(const QString &message);
......@@ -110,6 +120,7 @@ private:
QStringList m_iconGroups;
QScopedPointer<QTemporaryFile> m_tempInstallFile;
QPointer<KIO::FileCopyJob> m_tempCopyJob;
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
......
......@@ -36,6 +36,8 @@ KCM.GridViewKCM {
view.model: kcm.iconsModel
view.currentIndex: kcm.iconsModel.selectedThemeIndex
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