diff --git a/kcms/cursortheme/kcmcursortheme.h b/kcms/cursortheme/kcmcursortheme.h --- a/kcms/cursortheme/kcmcursortheme.h +++ b/kcms/cursortheme/kcmcursortheme.h @@ -29,6 +29,11 @@ class SortProxyModel; class CursorTheme; +namespace KIO +{ + class FileCopyJob; +} + class CursorThemeConfig : public KQuickAddons::ConfigModule { Q_OBJECT @@ -40,6 +45,8 @@ 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 @@ int selectedSizeRow() const; void setSelectedSizeRow(int row); + bool downloadingFile() const; + QAbstractItemModel *cursorsModel(); QAbstractItemModel *sizesModel(); @@ -74,6 +83,7 @@ void canConfigureChanged(); void selectedThemeRowChanged(); void selectedSizeRowChanged(); + void downloadingFileChanged(); void showSuccessMessage(const QString &message); void showInfoMessage(const QString &message); @@ -134,6 +144,7 @@ bool m_canConfigure; QScopedPointer m_tempInstallFile; + QPointer m_tempCopyJob; }; #endif diff --git a/kcms/cursortheme/kcmcursortheme.cpp b/kcms/cursortheme/kcmcursortheme.cpp --- a/kcms/cursortheme/kcmcursortheme.cpp +++ b/kcms/cursortheme/kcmcursortheme.cpp @@ -185,6 +185,11 @@ return m_selectedSizeRow; } +bool CursorThemeConfig::downloadingFile() const +{ + return m_tempCopyJob; +} + QAbstractItemModel *CursorThemeConfig::cursorsModel() @@ -469,26 +474,32 @@ 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; } - 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; } installThemeFile(m_tempInstallFile->fileName()); m_tempInstallFile.reset(); }); + connect(m_tempCopyJob, &QObject::destroyed, this, &CursorThemeConfig::downloadingFileChanged); } void CursorThemeConfig::installThemeFile(const QString &path) diff --git a/kcms/cursortheme/package/contents/ui/main.qml b/kcms/cursortheme/package/contents/ui/main.qml --- a/kcms/cursortheme/package/contents/ui/main.qml +++ b/kcms/cursortheme/package/contents/ui/main.qml @@ -37,6 +37,8 @@ view.positionViewAtIndex(view.currentIndex, view.GridView.Beginning); } + enabled: !kcm.downloadingFile + DropArea { anchors.fill: parent onEntered: { diff --git a/kcms/icons/main.h b/kcms/icons/main.h --- a/kcms/icons/main.h +++ b/kcms/icons/main.h @@ -36,6 +36,11 @@ class QQuickItem; class QTemporaryFile; +namespace KIO +{ +class FileCopyJob; +} + class IconsModel; class IconModule : public KQuickAddons::ConfigModule @@ -46,6 +51,8 @@ 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 @@ QStringList iconGroups() const; + bool downloadingFile() const; + void load() override; void save() override; void defaults() override; @@ -77,6 +86,7 @@ signals: void iconSizesChanged(); + void downloadingFileChanged(); void showSuccessMessage(const QString &message); void showErrorMessage(const QString &message); @@ -110,6 +120,7 @@ QStringList m_iconGroups; QScopedPointer m_tempInstallFile; + QPointer m_tempCopyJob; QPointer m_newStuffDialog; diff --git a/kcms/icons/main.cpp b/kcms/icons/main.cpp --- a/kcms/icons/main.cpp +++ b/kcms/icons/main.cpp @@ -121,6 +121,11 @@ return m_iconGroups; } +bool IconModule::downloadingFile() const +{ + return m_tempCopyJob; +} + int IconModule::iconSize(int group) const { return m_iconSizes[group]; @@ -306,26 +311,32 @@ 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; } - 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; } installThemeFile(m_tempInstallFile->fileName()); m_tempInstallFile.reset(); }); + connect(m_tempCopyJob, &QObject::destroyed, this, &IconModule::downloadingFileChanged); } void IconModule::installThemeFile(const QString &path) diff --git a/kcms/icons/package/contents/ui/main.qml b/kcms/icons/package/contents/ui/main.qml --- a/kcms/icons/package/contents/ui/main.qml +++ b/kcms/icons/package/contents/ui/main.qml @@ -36,6 +36,8 @@ view.model: kcm.iconsModel view.currentIndex: kcm.iconsModel.selectedThemeIndex + enabled: !kcm.downloadingFile + DropArea { anchors.fill: parent onEntered: {