Changeset View
Changeset View
Standalone View
Standalone View
src/kuiserverjobtracker.cpp
Show All 36 Lines | |||||
37 | public: | 37 | public: | ||
38 | Private(KUiServerJobTracker *parent) | 38 | Private(KUiServerJobTracker *parent) | ||
39 | : q(parent) | 39 | : q(parent) | ||
40 | { | 40 | { | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | KUiServerJobTracker *const q; | 43 | KUiServerJobTracker *const q; | ||
44 | 44 | | |||
45 | void _k_killJob(); | | |||
46 | | ||||
47 | static void updateDestUrl(KJob *job, org::kde::JobViewV2 *jobView); | 45 | static void updateDestUrl(KJob *job, org::kde::JobViewV2 *jobView); | ||
48 | 46 | | |||
49 | QHash<KJob *, org::kde::JobViewV2 *> progressJobView; | 47 | QHash<KJob *, org::kde::JobViewV2 *> progressJobView; | ||
50 | 48 | | |||
51 | QMetaObject::Connection serverRegisteredConnection; | 49 | QMetaObject::Connection serverRegisteredConnection; | ||
52 | }; | 50 | }; | ||
53 | 51 | | |||
54 | void KUiServerJobTracker::Private::_k_killJob() | | |||
55 | { | | |||
56 | org::kde::JobViewV2 *jobView = qobject_cast<org::kde::JobViewV2 *>(q->sender()); | | |||
57 | | ||||
58 | if (jobView) { | | |||
59 | KJob *job = progressJobView.key(jobView); | | |||
60 | | ||||
61 | if (job) { | | |||
62 | job->kill(KJob::EmitResult); | | |||
63 | } | | |||
64 | } | | |||
65 | } | | |||
66 | | ||||
67 | void KUiServerJobTracker::Private::updateDestUrl(KJob *job, org::kde::JobViewV2 *jobView) | 52 | void KUiServerJobTracker::Private::updateDestUrl(KJob *job, org::kde::JobViewV2 *jobView) | ||
68 | { | 53 | { | ||
69 | const QVariant destUrl = job->property("destUrl"); | 54 | const QVariant destUrl = job->property("destUrl"); | ||
70 | if (destUrl.isValid()) { | 55 | if (destUrl.isValid()) { | ||
71 | jobView->setDestUrl(QDBusVariant(destUrl)); | 56 | jobView->setDestUrl(QDBusVariant(destUrl)); | ||
72 | } | 57 | } | ||
73 | } | 58 | } | ||
74 | 59 | | |||
Show All 39 Lines | 77 | { | |||
114 | // This will only work if main() used QIcon::fromTheme. | 99 | // This will only work if main() used QIcon::fromTheme. | ||
115 | QString programIconName = QApplication::windowIcon().name(); | 100 | QString programIconName = QApplication::windowIcon().name(); | ||
116 | 101 | | |||
117 | if (programIconName.isEmpty()) { | 102 | if (programIconName.isEmpty()) { | ||
118 | programIconName = appName; | 103 | programIconName = appName; | ||
119 | } | 104 | } | ||
120 | 105 | | |||
121 | QPointer<KJob> jobWatch = job; | 106 | QPointer<KJob> jobWatch = job; | ||
122 | QDBusReply<QDBusObjectPath> reply = serverProxy()->uiserver().requestView(appName, | 107 | QDBusPendingReply<QDBusObjectPath> reply = serverProxy()->uiserver().requestView(appName, | ||
123 | programIconName, | 108 | programIconName, | ||
124 | job->capabilities()); | 109 | job->capabilities()); | ||
110 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||||
111 | connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, jobWatch](QDBusPendingCallWatcher *watcher) { | ||||
112 | QDBusPendingReply<QDBusObjectPath> reply = *watcher; | ||||
113 | watcher->deleteLater(); | ||||
125 | 114 | | |||
126 | // If we got a valid reply, register the interface for later usage. | 115 | if (reply.isError()) { | ||
127 | if (reply.isValid()) { | | |||
128 | org::kde::JobViewV2 *jobView = new org::kde::JobViewV2(QStringLiteral("org.kde.JobViewServer"), | | |||
129 | reply.value().path(), | | |||
130 | QDBusConnection::sessionBus()); | | |||
131 | if (!jobWatch) { | | |||
132 | //qCDebug(KJOBWIDGETS) << "deleted out from under us when asking the server proxy for the view"; | | |||
133 | jobView->terminate(QString()); | | |||
134 | delete jobView; | | |||
135 | return; | 116 | return; | ||
136 | } | 117 | } | ||
137 | 118 | | |||
138 | QObject::connect(jobView, SIGNAL(cancelRequested()), | 119 | org::kde::JobViewV2 *jobView = new org::kde::JobViewV2( | ||
139 | this, SLOT(_k_killJob())); | 120 | QStringLiteral("org.kde.JobViewServer"), | ||
140 | QObject::connect(jobView, &org::kde::JobViewV2::suspendRequested, | 121 | reply.value().path(), | ||
141 | job, &KJob::suspend); | 122 | QDBusConnection::sessionBus() | ||
142 | QObject::connect(jobView, &org::kde::JobViewV2::resumeRequested, | 123 | ); | ||
143 | job, &KJob::resume); | | |||
144 | | ||||
145 | d->updateDestUrl(job, jobView); | | |||
146 | 124 | | |||
147 | if (!jobWatch) { | 125 | if (!jobWatch) { | ||
148 | //qCDebug(KJOBWIDGETS) << "deleted out from under us when creating the dbus interface"; | 126 | // if the reply took a while, terminate the job now to not leave one lingering around | ||
149 | jobView->terminate(QString()); | 127 | jobView->terminate(QString()); | ||
150 | delete jobView; | 128 | delete jobView; | ||
151 | return; | 129 | return; | ||
152 | } | 130 | } | ||
153 | 131 | | |||
132 | KJob *job = jobWatch.data(); | ||||
133 | connect(jobView, &OrgKdeJobViewV2Interface::cancelRequested, job, [job]() { | ||||
134 | job->kill(KJob::EmitResult); | ||||
135 | }); | ||||
136 | connect(jobView, &org::kde::JobViewV2::suspendRequested, job , &KJob::suspend); | ||||
137 | connect(jobView, &org::kde::JobViewV2::resumeRequested, job, &KJob::resume); | ||||
138 | | ||||
139 | d->updateDestUrl(job, jobView); | ||||
140 | | ||||
154 | d->progressJobView.insert(job, jobView); | 141 | d->progressJobView.insert(job, jobView); | ||
155 | } else if (!jobWatch) { | 142 | }); | ||
156 | qWarning() << "Uh-oh...KUiServerJobTracker was trying to forward a job, but it was deleted from under us." | | |||
157 | << "kuiserver *may* have a stranded job. we can't do anything about it because the returned objectPath is invalid."; | | |||
158 | return; | | |||
159 | } | | |||
160 | 143 | | |||
161 | KJobTrackerInterface::registerJob(job); | 144 | KJobTrackerInterface::registerJob(job); | ||
162 | } | 145 | } | ||
163 | 146 | | |||
164 | void KUiServerJobTracker::unregisterJob(KJob *job) | 147 | void KUiServerJobTracker::unregisterJob(KJob *job) | ||
165 | { | 148 | { | ||
166 | KJobTrackerInterface::unregisterJob(job); | 149 | KJobTrackerInterface::unregisterJob(job); | ||
167 | 150 | | |||
▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines |