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:
00173 bool kill( KillVerbosity verbosity = Quietly );
00174
00181 bool suspend();
00182
00188 bool resume();
00189
00190 protected:
00197 virtual bool doKill();
00198
00204 virtual bool doSuspend();
00205
00211 virtual bool doResume();
00212
00219 void setCapabilities( Capabilities capabilities );
00220
00221 public:
00227 bool exec();
00228
00229 enum
00230 {
00231 NoError = 0,
00232 KilledJobError = 1,
00233 UserDefinedError = 100
00234 };
00235
00236
00243 int error() const;
00244
00253 QString errorText() const;
00254
00271 virtual QString errorString() const;
00272
00273
00280 qulonglong processedAmount(Unit unit) const;
00281
00288 qulonglong totalAmount(Unit unit) const;
00289
00295 unsigned long percent() const;
00296
00306 void setAutoDelete( bool autodelete );
00307
00315 bool isAutoDelete() const;
00316
00317 Q_SIGNALS:
00318 #ifndef Q_MOC_RUN
00319 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00320 private:
00321 #endif
00322 #endif
00323
00336 void finished(KJob *job);
00337
00346 void suspended(KJob *job);
00347
00356 void resumed(KJob *job);
00357
00372 void result(KJob *job);
00373
00374 Q_SIGNALS:
00388 void description(KJob *job, const QString &title,
00389 const QPair<QString, QString> &field1 = qMakePair(QString(), QString()),
00390 const QPair<QString, QString> &field2 = qMakePair(QString(), QString()));
00391
00400 void infoMessage( KJob *job, const QString &plain, const QString &rich = QString() );
00401
00409 void warning( KJob *job, const QString &plain, const QString &rich = QString() );
00410
00411
00412 Q_SIGNALS:
00413 #ifndef Q_MOC_RUN
00414 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00415 private:
00416 #endif
00417 #endif
00418
00430 void totalAmount(KJob *job, KJob::Unit unit, qulonglong amount);
00431
00444 void processedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
00445
00456 void totalSize(KJob *job, qulonglong size);
00457
00468 void processedSize(KJob *job, qulonglong size);
00469
00483 void percent( KJob *job, unsigned long percent );
00484
00494 void speed(KJob *job, unsigned long speed);
00495
00496 protected:
00504 void setError( int errorCode );
00505
00513 void setErrorText( const QString &errorText );
00514
00515
00524 void setProcessedAmount(Unit unit, qulonglong amount);
00525
00534 void setTotalAmount(Unit unit, qulonglong amount);
00535
00542 void setPercent( unsigned long percentage );
00543
00544
00555 void emitResult();
00556
00566 void emitPercent( qulonglong processedAmount, qulonglong totalAmount );
00567
00574 void emitSpeed(unsigned long speed);
00575
00576 protected:
00577 KJobPrivate *const d_ptr;
00578 KJob(KJobPrivate &dd, QObject *parent);
00579
00580 private:
00581 Q_PRIVATE_SLOT(d_func(), void _k_speedTimeout())
00582 Q_DECLARE_PRIVATE(KJob)
00583 };
00584
00585 Q_DECLARE_OPERATORS_FOR_FLAGS( KJob::Capabilities )
00586
00587 #endif