Changeset View
Changeset View
Standalone View
Standalone View
kcms/desktoptheme/kcm.cpp
Show All 21 Lines | |||||
22 | #include "kcm.h" | 22 | #include "kcm.h" | ||
23 | 23 | | |||
24 | #include <KPluginFactory> | 24 | #include <KPluginFactory> | ||
25 | #include <KAboutData> | 25 | #include <KAboutData> | ||
26 | #include <KSharedConfig> | 26 | #include <KSharedConfig> | ||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | #include <KDesktopFile> | 28 | #include <KDesktopFile> | ||
29 | 29 | | |||
30 | #include <KIO/FileCopyJob> | ||||
31 | #include <KIO/JobUiDelegate> | ||||
32 | | ||||
30 | #include <Plasma/Theme> | 33 | #include <Plasma/Theme> | ||
31 | #include <Plasma/Svg> | 34 | #include <Plasma/Svg> | ||
32 | 35 | | |||
33 | #include <QDebug> | 36 | #include <QDebug> | ||
34 | #include <QProcess> | 37 | #include <QProcess> | ||
35 | #include <QQuickItem> | 38 | #include <QQuickItem> | ||
36 | #include <QQuickWindow> | 39 | #include <QQuickWindow> | ||
37 | #include <QStandardPaths> | 40 | #include <QStandardPaths> | ||
38 | #include <QStandardItemModel> | 41 | #include <QStandardItemModel> | ||
42 | #include <QTemporaryFile> | ||||
39 | 43 | | |||
40 | #include <KNewStuff3/KNS3/DownloadDialog> | 44 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
41 | 45 | | |||
42 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | 46 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | ||
43 | 47 | | |||
44 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | 48 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | ||
45 | 49 | | |||
46 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | 50 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 106 | { | |||
103 | const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, m_selectedPlugin); | 107 | const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, m_selectedPlugin); | ||
104 | if (results.count() == 1) { | 108 | if (results.count() == 1) { | ||
105 | return results.first().row(); | 109 | return results.first().row(); | ||
106 | } | 110 | } | ||
107 | 111 | | |||
108 | return -1; | 112 | return -1; | ||
109 | } | 113 | } | ||
110 | 114 | | |||
115 | bool KCMDesktopTheme::downloadingFile() const | ||||
116 | { | ||||
117 | return m_tempCopyJob; | ||||
118 | } | ||||
119 | | ||||
111 | void KCMDesktopTheme::setPendingDeletion(int index, bool pending) | 120 | void KCMDesktopTheme::setPendingDeletion(int index, bool pending) | ||
112 | { | 121 | { | ||
113 | QModelIndex idx = m_model->index(index, 0); | 122 | QModelIndex idx = m_model->index(index, 0); | ||
114 | 123 | | |||
115 | m_model->setData(idx, pending, PendingDeletionRole); | 124 | m_model->setData(idx, pending, PendingDeletionRole); | ||
116 | 125 | | |||
117 | if (pending && selectedPluginIndex() == index) { | 126 | if (pending && selectedPluginIndex() == index) { | ||
118 | // move to the next non-pending theme | 127 | // move to the next non-pending theme | ||
Show All 16 Lines | 136 | { | |||
135 | 144 | | |||
136 | if (ctx && ctx->window()) { | 145 | if (ctx && ctx->window()) { | ||
137 | m_newStuffDialog->windowHandle()->setTransientParent(ctx->window()); | 146 | m_newStuffDialog->windowHandle()->setTransientParent(ctx->window()); | ||
138 | } | 147 | } | ||
139 | 148 | | |||
140 | m_newStuffDialog.data()->show(); | 149 | m_newStuffDialog.data()->show(); | ||
141 | } | 150 | } | ||
142 | 151 | | |||
143 | void KCMDesktopTheme::installThemeFromFile(const QUrl &file) | 152 | void KCMDesktopTheme::installThemeFromFile(const QUrl &url) | ||
153 | { | ||||
154 | if (url.isLocalFile()) { | ||||
155 | installTheme(url.toLocalFile()); | ||||
156 | return; | ||||
157 | } | ||||
158 | | ||||
159 | if (m_tempCopyJob) { | ||||
160 | return; | ||||
161 | } | ||||
162 | | ||||
163 | m_tempInstallFile.reset(new QTemporaryFile()); | ||||
164 | if (!m_tempInstallFile->open()) { | ||||
165 | emit showErrorMessage(i18n("Unable to create a temporary file.")); | ||||
166 | m_tempInstallFile.reset(); | ||||
167 | return; | ||||
168 | } | ||||
169 | | ||||
170 | m_tempCopyJob = KIO::file_copy(url, QUrl::fromLocalFile(m_tempInstallFile->fileName()), | ||||
171 | -1, KIO::Overwrite); | ||||
172 | m_tempCopyJob->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||||
173 | emit downloadingFileChanged(); | ||||
174 | | ||||
175 | connect(m_tempCopyJob, &KIO::FileCopyJob::result, this, [this, url](KJob *job) { | ||||
176 | if (job->error() != KJob::NoError) { | ||||
177 | emit showErrorMessage(i18n("Unable to download the theme: %1", job->errorText())); | ||||
178 | return; | ||||
179 | } | ||||
180 | | ||||
181 | installTheme(m_tempInstallFile->fileName()); | ||||
182 | m_tempInstallFile.reset(); | ||||
183 | }); | ||||
184 | connect(m_tempCopyJob, &QObject::destroyed, this, &KCMDesktopTheme::downloadingFileChanged); | ||||
185 | } | ||||
186 | | ||||
187 | void KCMDesktopTheme::installTheme(const QString &path) | ||||
144 | { | 188 | { | ||
145 | qCDebug(KCM_DESKTOP_THEME) << "Installing ... " << file; | 189 | qCDebug(KCM_DESKTOP_THEME) << "Installing ... " << path; | ||
146 | 190 | | |||
147 | const QString program = QStringLiteral("kpackagetool5"); | 191 | const QString program = QStringLiteral("kpackagetool5"); | ||
148 | const QStringList arguments = { QStringLiteral("--type"), QStringLiteral("Plasma/Theme"), QStringLiteral("--install"), file.toLocalFile()}; | 192 | const QStringList arguments = { QStringLiteral("--type"), QStringLiteral("Plasma/Theme"), QStringLiteral("--install"), path}; | ||
149 | 193 | | |||
150 | qCDebug(KCM_DESKTOP_THEME) << program << arguments.join(QStringLiteral(" ")); | 194 | qCDebug(KCM_DESKTOP_THEME) << program << arguments.join(QStringLiteral(" ")); | ||
151 | QProcess *myProcess = new QProcess(this); | 195 | QProcess *myProcess = new QProcess(this); | ||
152 | connect(myProcess, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), | 196 | connect(myProcess, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), | ||
153 | this, [this, myProcess](int exitCode, QProcess::ExitStatus exitStatus) { | 197 | this, [this, myProcess](int exitCode, QProcess::ExitStatus exitStatus) { | ||
154 | Q_UNUSED(exitStatus); | 198 | Q_UNUSED(exitStatus); | ||
155 | if (exitCode == 0) { | 199 | if (exitCode == 0) { | ||
156 | emit showSuccessMessage(i18n("Theme installed successfully.")); | 200 | emit showSuccessMessage(i18n("Theme installed successfully.")); | ||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |