1 /*
2     SPDX-FileCopyrightText: 2008 Aaron Seigo <aseigo@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "servicejob.h"
8 
9 #include <QDebug>
10 
11 #include "private/servicejob_p.h"
12 
13 namespace Plasma
14 {
ServiceJobPrivate(ServiceJob * owner,const QString & dest,const QString & op,const QVariantMap & params)15 ServiceJobPrivate::ServiceJobPrivate(ServiceJob *owner, const QString &dest, const QString &op, const QVariantMap &params)
16     : q(owner)
17     , destination(dest)
18     , operation(op)
19     , parameters(params)
20     , m_allowAutoStart(true)
21 {
22 }
23 
preventAutoStart()24 void ServiceJobPrivate::preventAutoStart()
25 {
26     m_allowAutoStart = false;
27 }
28 
autoStart()29 void ServiceJobPrivate::autoStart()
30 {
31     if (m_allowAutoStart) {
32         m_allowAutoStart = false;
33 
34         if (q->isAutoDelete()) {
35             // by checking for isAutoDelete, we prevent autostarting when
36             // exec() is called or when the job owner has "taken control"
37             // of the job by requesting it not be autodeleted
38             q->start();
39         }
40     }
41 }
42 
ServiceJob(const QString & destination,const QString & operation,const QVariantMap & parameters,QObject * parent)43 ServiceJob::ServiceJob(const QString &destination, const QString &operation, const QVariantMap &parameters, QObject *parent)
44     : KJob(parent)
45     , d(new ServiceJobPrivate(this, destination, operation, parameters))
46 {
47     connect(this, SIGNAL(finished(KJob *)), this, SLOT(preventAutoStart()));
48 }
49 
~ServiceJob()50 ServiceJob::~ServiceJob()
51 {
52     delete d;
53 }
54 
destination() const55 QString ServiceJob::destination() const
56 {
57     return d->destination;
58 }
59 
operationName() const60 QString ServiceJob::operationName() const
61 {
62     return d->operation;
63 }
64 
parameters() const65 QVariantMap ServiceJob::parameters() const
66 {
67     return d->parameters;
68 }
69 
result() const70 QVariant ServiceJob::result() const
71 {
72     return d->result;
73 }
74 
setResult(const QVariant & result)75 void ServiceJob::setResult(const QVariant &result)
76 {
77     d->result = result;
78     emitResult();
79 }
80 
start()81 void ServiceJob::start()
82 {
83     setResult(false);
84 }
85 
86 } // namespace Plasma
87 
88 #include "moc_servicejob.cpp"
89