2008-05-18 06:27:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_SERVICEJOB_H
|
|
|
|
#define PLASMA_SERVICEJOB_H
|
|
|
|
|
2008-05-19 01:18:59 +02:00
|
|
|
#include <QtCore/QVariant>
|
2008-07-15 08:38:20 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2008-05-19 01:18:59 +02:00
|
|
|
#include <KDE/KJob>
|
|
|
|
#include <KDE/KService>
|
2008-05-18 06:27:54 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class ServiceJobPrivate;
|
|
|
|
|
2008-05-18 06:27:54 +02:00
|
|
|
/**
|
|
|
|
* @brief This class provides jobs for use with Plasma::Service
|
2008-08-03 00:29:19 +02:00
|
|
|
*
|
|
|
|
* Unlike KJob, you can do the work in start(), since Plasma::Service already
|
|
|
|
* delays the call to start() until the event loop is reached.
|
|
|
|
*
|
|
|
|
* If the job is quick enough that it is not worth reporting the progress,
|
|
|
|
* you just need to implement start() to do the task, then call emitResult()
|
|
|
|
* at the end of it. If the task does not complete successfully, you should
|
|
|
|
* set a non-zero error code with setError(int) and an error message with
|
|
|
|
* setErrorText(QString).
|
|
|
|
*
|
|
|
|
* If the job is longer (involving network access, for instance), you should
|
|
|
|
* report the progress at regular intervals. See the KJob documentation for
|
|
|
|
* information on how to do this.
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
2008-07-15 08:38:20 +02:00
|
|
|
class PLASMA_EXPORT ServiceJob : public KJob
|
2008-05-18 06:27:54 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*
|
2008-08-03 00:29:19 +02:00
|
|
|
* @arg destination the subject that the job is acting on
|
|
|
|
* @arg operation the action that the job is performing on the @p destination
|
|
|
|
* @arg parameters the parameters of the @p action
|
|
|
|
* @arg parent the parent object for this service
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
|
|
|
ServiceJob(const QString &destination, const QString &operation,
|
|
|
|
const QMap<QString, QVariant> ¶meters, QObject *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~ServiceJob();
|
|
|
|
|
|
|
|
/**
|
2008-08-03 00:29:19 +02:00
|
|
|
* @return the subject that the job is acting on
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
|
|
|
QString destination() const;
|
|
|
|
|
|
|
|
/**
|
2008-08-03 00:29:19 +02:00
|
|
|
* @return the operation the job is performing on the destination
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
|
|
|
QString operationName() const;
|
|
|
|
|
|
|
|
/**
|
2008-08-03 00:29:19 +02:00
|
|
|
* @return the parameters for the operation
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
|
|
|
QMap<QString, QVariant> parameters() const;
|
|
|
|
|
|
|
|
/**
|
2008-08-03 00:29:19 +02:00
|
|
|
* Returns the result of the operation
|
|
|
|
*
|
|
|
|
* The result will be invalid if the job has not completed yet, or
|
|
|
|
* if the job does not have a meaningful result.
|
|
|
|
*
|
|
|
|
* Note that this should not be used to find out whether the operation
|
|
|
|
* was successful. Instead, you should check the value of error().
|
|
|
|
*
|
|
|
|
* @return the result of the operation
|
2008-05-18 06:27:54 +02:00
|
|
|
*/
|
|
|
|
QVariant result() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Sets the result for an operation.
|
|
|
|
*/
|
|
|
|
void setResult(const QVariant &result);
|
|
|
|
|
|
|
|
private:
|
2008-08-03 00:29:19 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void slotStart())
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
ServiceJobPrivate * const d;
|
2008-05-18 06:27:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|
|
|
|
|