Changeset View
Changeset View
Standalone View
Standalone View
src/kpackage/private/packagejob.cpp
Show All 19 Lines | |||||
20 | #include "packagejob_p.h" | 20 | #include "packagejob_p.h" | ||
21 | #include "packagejobthread_p.h" | 21 | #include "packagejobthread_p.h" | ||
22 | #include "config-package.h" | 22 | #include "config-package.h" | ||
23 | 23 | | |||
24 | #include "package_p.h" | 24 | #include "package_p.h" | ||
25 | 25 | | |||
26 | #include "kpackage_debug.h" | 26 | #include "kpackage_debug.h" | ||
27 | 27 | | |||
28 | #include <QDBusConnection> | ||||
29 | #include <QDBusMessage> | ||||
30 | | ||||
28 | namespace KPackage | 31 | namespace KPackage | ||
29 | { | 32 | { | ||
30 | class PackageJobPrivate | 33 | class PackageJobPrivate | ||
31 | { | 34 | { | ||
32 | public: | 35 | public: | ||
33 | PackageJobThread *thread; | 36 | PackageJobThread *thread; | ||
34 | Package *package; | 37 | Package *package; | ||
35 | QString installPath; | 38 | QString installPath; | ||
36 | }; | 39 | }; | ||
37 | 40 | | |||
38 | PackageJob::PackageJob(Package *package, QObject *parent) : | 41 | PackageJob::PackageJob(Package *package, QObject *parent) : | ||
39 | KJob(parent) | 42 | KJob(parent) | ||
40 | { | 43 | { | ||
41 | d = new PackageJobPrivate; | 44 | d = new PackageJobPrivate; | ||
42 | d->thread = new PackageJobThread(this); | 45 | d->thread = new PackageJobThread(this); | ||
43 | d->package = package; | 46 | d->package = package; | ||
44 | 47 | | |||
45 | connect(PackageDeletionNotifier::self(), &PackageDeletionNotifier::packageDeleted, this, [this](Package *package) { | 48 | connect(PackageDeletionNotifier::self(), &PackageDeletionNotifier::packageDeleted, this, [this](Package *package) { | ||
46 | if (package == d->package) { | 49 | if (package == d->package) { | ||
47 | d->package = nullptr; | 50 | d->package = nullptr; | ||
48 | } | 51 | } | ||
49 | }); | 52 | }); | ||
50 | 53 | | |||
51 | connect(d->thread, SIGNAL(finished(bool,QString)), | | |||
52 | SLOT(slotFinished(bool,QString)), Qt::QueuedConnection); | | |||
53 | connect(d->thread, &PackageJobThread::installPathChanged, this, | 54 | connect(d->thread, &PackageJobThread::installPathChanged, this, | ||
54 | [this](const QString &installPath) { | 55 | [this](const QString &installPath) { | ||
55 | if (d->package) { | 56 | if (d->package) { | ||
56 | d->package->setPath(installPath); | 57 | d->package->setPath(installPath); | ||
57 | } | 58 | } | ||
58 | emit installPathChanged(installPath); | 59 | emit installPathChanged(installPath); | ||
59 | }, Qt::QueuedConnection); | 60 | }, Qt::QueuedConnection); | ||
60 | } | 61 | } | ||
Show All 17 Lines | |||||
78 | 79 | | |||
79 | void PackageJob::start() | 80 | void PackageJob::start() | ||
80 | { | 81 | { | ||
81 | d->thread->start(); | 82 | d->thread->start(); | ||
82 | } | 83 | } | ||
83 | 84 | | |||
84 | void PackageJob::install(const QString &src, const QString &dest) | 85 | void PackageJob::install(const QString &src, const QString &dest) | ||
85 | { | 86 | { | ||
87 | | ||||
88 | connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { | ||||
89 | if (ok) { | ||||
90 | const QString pluginId = d->package->metadata().pluginId(); | ||||
broulik: Can this be invalid or does `install` already check for validity? | |||||
bool PackageJobThread::installPackage(const QString &src, const QString &dest, OperationType operation) ... if (!meta.isValid()) { qCDebug(KPACKAGE_LOG) << "No metadata file in package" << src << path; d->errorMessage = i18n("No metadata file in package: %1", src); d->errorCode = Package::JobError::MetadataFileMissingError; return false; } davidedmundson: bool PackageJobThread::installPackage(const QString &src, const QString &dest, OperationType… | |||||
91 | const QStringList serviceTypes = d->package->metadata().serviceTypes(); | ||||
92 | for (auto packageType: serviceTypes) { | ||||
93 | auto msg = QDBusMessage::createSignal(QStringLiteral("/KPackage/") + packageType, QStringLiteral("org.kde.plasma.kpackage"), QStringLiteral("packageInstalled")); | ||||
broulik: Can `packageType` contain characters not allowed in DBus? | |||||
Technically, yes, it's a string in the metadata of the package type so could. By convention format X-KDE-ServiceTypes is always in the format Foo/Blah and generally we control the package structures. davidedmundson: Technically, yes, it's a string in the metadata of the package type so could.
By convention… | |||||
94 | msg.setArguments({pluginId}); | ||||
95 | QDBusConnection::sessionBus().send(msg); | ||||
96 | } | ||||
97 | } | ||||
98 | slotFinished(ok, error); | ||||
99 | }, Qt::QueuedConnection); | ||||
86 | d->thread->install(src, dest); | 100 | d->thread->install(src, dest); | ||
87 | } | 101 | } | ||
88 | 102 | | |||
89 | void PackageJob::update(const QString &src, const QString &dest) | 103 | void PackageJob::update(const QString &src, const QString &dest) | ||
90 | { | 104 | { | ||
105 | connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { | ||||
106 | slotFinished(ok, error); | ||||
107 | }, Qt::QueuedConnection); | ||||
91 | d->thread->update(src, dest); | 108 | d->thread->update(src, dest); | ||
92 | } | 109 | } | ||
93 | 110 | | |||
94 | void PackageJob::uninstall(const QString &installationPath) | 111 | void PackageJob::uninstall(const QString &installationPath) | ||
95 | { | 112 | { | ||
113 | //capture first as uninstalling wipes d->package | ||||
114 | const QString pluginId = d->package->metadata().pluginId(); | ||||
115 | const QStringList serviceTypes = d->package->metadata().serviceTypes(); | ||||
116 | connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { | ||||
117 | if (ok) { | ||||
118 | for (auto packageType: serviceTypes) { | ||||
119 | auto msg = QDBusMessage::createSignal(QStringLiteral("/KPackage/") + packageType, QStringLiteral("org.kde.plasma.kpackage"), QStringLiteral("packageUninstalled")); | ||||
120 | msg.setArguments({pluginId}); | ||||
121 | QDBusConnection::sessionBus().send(msg); | ||||
122 | } | ||||
123 | } | ||||
124 | slotFinished(ok, error); | ||||
125 | }, Qt::QueuedConnection); | ||||
96 | d->thread->uninstall(installationPath); | 126 | d->thread->uninstall(installationPath); | ||
97 | } | 127 | } | ||
98 | 128 | | |||
99 | } // namespace KPackage | 129 | } // namespace KPackage | ||
100 | 130 | | |||
101 | #include "moc_packagejob_p.cpp" | 131 | #include "moc_packagejob_p.cpp" |
Can this be invalid or does install already check for validity?