KDECore
kjob.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KJOB_H
00023 #define KJOB_H
00024
00025 #include <kdecore_export.h>
00026 #include <QtCore/QObject>
00027 #include <QtCore/QPair>
00028
00029 class KJobUiDelegate;
00030
00031 class KJobPrivate;
00079 class KDECORE_EXPORT KJob : public QObject
00080 {
00081 Q_OBJECT
00082 Q_ENUMS( KillVerbosity Capability Unit )
00083 Q_FLAGS( Capabilities )
00084
00085 public:
00086 enum Unit { Bytes, Files, Directories };
00087
00088 enum Capability { NoCapabilities = 0x0000,
00089 Killable = 0x0001,
00090 Suspendable = 0x0002 };
00091
00092 Q_DECLARE_FLAGS( Capabilities, Capability )
00093
00094
00099 explicit KJob( QObject *parent = 0 );
00100
00104 virtual ~KJob();
00105
00115 void setUiDelegate( KJobUiDelegate *delegate );
00116
00122 KJobUiDelegate *uiDelegate() const;
00123
00130 Capabilities capabilities() const;
00131
00138 bool isSuspended() const;
00139
00156 virtual void start() = 0;
00157
00158 enum KillVerbosity { Quietly, EmitResult };
00159
00160 public Q_SLOTS:
00172 bool kill( KillVerbosity verbosity = Quietly );
00173
00180 bool suspend();
00181
00187 bool resume();
00188
00189 protected:
00196 virtual bool doKill();
00197
00203 virtual bool doSuspend();
00204
00210 virtual bool doResume();
00211
00218 void setCapabilities( Capabilities capabilities );
00219
00220 public:
00226 bool exec();
00227
00228 enum
00229 {
00230 NoError = 0,
00231 KilledJobError = 1,
00232 UserDefinedError = 100
00233 };
00234
00235
00242 int error() const;
00243
00252 QString errorText() const;
00253
00270 virtual QString errorString() const;
00271
00272
00279 qulonglong processedAmount(Unit unit) const;
00280
00287 qulonglong totalAmount(Unit unit) const;
00288
00294 unsigned long percent() const;
00295
00305 void setAutoDelete( bool autodelete );
00306
00314 bool isAutoDelete() const;
00315
00316 Q_SIGNALS:
00317 #ifndef Q_MOC_RUN
00318 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00319 private:
00320 #endif
00321 #endif
00322
00332 void finished(KJob *job);
00333
00342 void suspended(KJob *job);
00343
00352 void resumed(KJob *job);
00353
00363 void result(KJob *job);
00364
00365 Q_SIGNALS:
00379 void description(KJob *job, const QString &title,
00380 const QPair<QString, QString> &field1 = qMakePair(QString(), QString()),
00381 const QPair<QString, QString> &field2 = qMakePair(QString(), QString()));
00382
00391 void infoMessage( KJob *job, const QString &plain, const QString &rich = QString() );
00392
00400 void warning( KJob *job, const QString &plain, const QString &rich = QString() );
00401
00402
00403 Q_SIGNALS:
00404 #ifndef Q_MOC_RUN
00405 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00406 private:
00407 #endif
00408 #endif
00409
00421 void totalAmount(KJob *job, KJob::Unit unit, qulonglong amount);
00422
00435 void processedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
00436
00447 void totalSize(KJob *job, qulonglong size);
00448
00459 void processedSize(KJob *job, qulonglong size);
00460
00474 void percent( KJob *job, unsigned long percent );
00475
00485 void speed(KJob *job, unsigned long speed);
00486
00487 protected:
00495 void setError( int errorCode );
00496
00504 void setErrorText( const QString &errorText );
00505
00506
00515 void setProcessedAmount(Unit unit, qulonglong amount);
00516
00525 void setTotalAmount(Unit unit, qulonglong amount);
00526
00533 void setPercent( unsigned long percentage );
00534
00535
00546 void emitResult();
00547
00557 void emitPercent( qulonglong processedAmount, qulonglong totalAmount );
00558
00565 void emitSpeed(unsigned long speed);
00566
00567 protected:
00568 KJobPrivate *const d_ptr;
00569 KJob(KJobPrivate &dd, QObject *parent);
00570
00571 private:
00572 Q_PRIVATE_SLOT(d_func(), void _k_speedTimeout())
00573 Q_DECLARE_PRIVATE(KJob)
00574 };
00575
00576 Q_DECLARE_OPERATORS_FOR_FLAGS( KJob::Capabilities )
00577
00578 #endif