9#include "kdynamicjobtracker_p.h"
10#include "kio_widgets_debug.h"
11#include "kuiserver_interface.h"
13#include <KJobTrackerInterface>
14#include <KUiServerJobTracker>
15#include <KUiServerV2JobTracker>
16#include <KWidgetJobTracker>
17#include <kio/jobtracker.h>
19#include <QApplication>
20#include <QDBusConnection>
21#include <QDBusConnectionInterface>
22#include <QDBusServiceWatcher>
24#include <QXmlStreamReader>
32class KDynamicJobTrackerPrivate
35 KDynamicJobTrackerPrivate()
39 ~KDynamicJobTrackerPrivate()
41 delete kuiserverTracker;
42 delete kuiserverV2Tracker;
46 static bool hasDBusInterface(
const QString &introspectionData,
const QString &interface)
49 while (!xml.atEnd() && !xml.hasError()) {
53 if (xml.attributes().value(
QLatin1String(
"name")) == interface) {
66 enum JobViewServerSupport {
72 JobViewServerSupport jobViewServerSupport = NeedsChecking;
76KDynamicJobTracker::KDynamicJobTracker(
QObject *parent)
78 , d(new KDynamicJobTrackerPrivate)
82KDynamicJobTracker::~KDynamicJobTracker() =
default;
84void KDynamicJobTracker::registerJob(
KJob *job)
86 if (d->trackers.contains(job)) {
94 const bool canHaveWidgets = (qobject_cast<QApplication *>(qApp) !=
nullptr);
98 AllTrackers &trackers = d->trackers[job];
99 trackers.kuiserverTracker =
nullptr;
100 trackers.kuiserverV2Tracker =
nullptr;
101 trackers.widgetTracker =
nullptr;
103 auto useWidgetsFallback = [
this, canHaveWidgets, &trackers, job] {
104 if (canHaveWidgets) {
106 if (!d->widgetTracker) {
110 trackers.widgetTracker = d->widgetTracker;
116#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
117 useWidgetsFallback();
123 useWidgetsFallback();
127 const QString kuiserverService = QStringLiteral(
"org.kde.kuiserver");
129 if (!d->jobViewServerWatcher) {
135 d->jobViewServerSupport = KDynamicJobTrackerPrivate::NeedsChecking;
139 if (d->jobViewServerSupport == KDynamicJobTrackerPrivate::NeedsChecking) {
142 QStringLiteral(
"/JobViewServer"),
143 QStringLiteral(
"org.freedesktop.DBus.Introspectable"),
144 QStringLiteral(
"Introspect"));
147 qCWarning(KIO_WIDGETS) <<
"Failed to check which JobView API is supported" << reply.errorMessage();
148 d->jobViewServerSupport = KDynamicJobTrackerPrivate::Error;
150 const QString introspectionData = reply.arguments().
first().toString();
152 if (KDynamicJobTrackerPrivate::hasDBusInterface(introspectionData, QStringLiteral(
"org.kde.JobViewServerV2"))) {
153 d->jobViewServerSupport = KDynamicJobTrackerPrivate::V2Supported;
155 d->jobViewServerSupport = KDynamicJobTrackerPrivate::V2NotSupported;
162 if (!requiresTrackerReply.
isValid() || requiresTrackerReply.value()) {
163 d->jobViewServerSupport = KDynamicJobTrackerPrivate::Error;
167 QStringLiteral(
"/JobViewServer"),
168 QStringLiteral(
"org.kde.kuiserver"),
169 QStringLiteral(
"requiresJobTrackerChanged"),
171 SLOT(handleRequiresJobTrackerChanged(
bool)));
174 if (d->jobViewServerSupport == KDynamicJobTrackerPrivate::V2Supported) {
175 if (!d->kuiserverV2Tracker) {
179 trackers.kuiserverV2Tracker = d->kuiserverV2Tracker;
185 if (d->jobViewServerSupport != KDynamicJobTrackerPrivate::Error) {
186 if (!d->kuiserverTracker) {
190 trackers.kuiserverTracker = d->kuiserverTracker;
196 if (d->jobViewServerSupport == KDynamicJobTrackerPrivate::Error) {
197 useWidgetsFallback();
201void KDynamicJobTracker::unregisterJob(
KJob *job)
207 if (it == d->trackers.end()) {
208 qCWarning(KIO_WIDGETS) <<
"Tried to unregister a kio job that hasn't been registered.";
212 const AllTrackers &trackers = it.
value();
217 if (kuiserverTracker) {
221 if (kuiserverV2Tracker) {
229 d->trackers.erase(it);
232void KDynamicJobTracker::handleRequiresJobTrackerChanged(
bool req)
235 d->jobViewServerSupport = KDynamicJobTrackerPrivate::Error;
237 d->jobViewServerSupport = KDynamicJobTrackerPrivate::V2Supported;
241Q_GLOBAL_STATIC(KDynamicJobTracker, globalJobTracker)
244static int registerDynamicJobTracker()
251Q_CONSTRUCTOR_FUNCTION(registerDynamicJobTracker)
253#include "moc_kdynamicjobtracker_p.cpp"
void unregisterJob(KJob *job) override
void registerJob(KJob *job) override
void registerJob(KJob *job) override
void unregisterJob(KJob *job) override
KIOCORE_EXPORT void setJobTracker(KJobTrackerInterface *tracker)
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
bool isValid() const const
void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
T value(const Key &key, const T &defaultValue) const const
bool disconnect(const QMetaObject::Connection &connection)
QString first(qsizetype n) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)