KCoreAddons

kjob.h
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
5  SPDX-FileCopyrightText: 2000 David Faure <[email protected]>
6  SPDX-FileCopyrightText: 2006 Kevin Ottens <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-only
9 */
10 
11 #ifndef KJOB_H
12 #define KJOB_H
13 
14 #include <kcoreaddons_export.h>
15 #include <QObject>
16 #include <QPair>
17 
18 class KJobUiDelegate;
19 
20 class KJobPrivate;
75 class KCOREADDONS_EXPORT KJob : public QObject
76 {
77  Q_OBJECT
78  Q_PROPERTY(int error READ error NOTIFY result)
79  Q_PROPERTY(QString errorText READ errorText NOTIFY result)
80  Q_PROPERTY(QString errorString READ errorString NOTIFY result)
81  Q_PROPERTY(ulong percent READ percent NOTIFY percent) // KF6 TODO: make "int", is enough
82  Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT)
83 
84 public:
85  enum Unit { Bytes, Files, Directories };
86  Q_ENUM(Unit)
87 
88 
91  enum Capability {
92  NoCapabilities = 0x0000,
93  Killable = 0x0001,
94  Suspendable = 0x0002,
95  };
97 
98 
101  Q_DECLARE_FLAGS(Capabilities, Capability)
102  Q_FLAG(Capabilities)
103 
109  explicit KJob(QObject *parent = nullptr);
110 
114  ~KJob() override;
115 
125  void setUiDelegate(KJobUiDelegate *delegate);
126 
132  KJobUiDelegate *uiDelegate() const;
133 
140  Capabilities capabilities() const;
141 
148  bool isSuspended() const;
149 
171  Q_SCRIPTABLE virtual void start() = 0;
172 
173  enum KillVerbosity { Quietly, EmitResult };
174  Q_ENUM(KillVerbosity)
175 
176 public Q_SLOTS:
190  bool kill(KillVerbosity verbosity = Quietly);
191 
198  bool suspend();
199 
205  bool resume();
206 
207 protected:
215  virtual bool doKill();
216 
222  virtual bool doSuspend();
223 
229  virtual bool doResume();
230 
237  void setCapabilities(Capabilities capabilities);
238 
239 public:
258  bool exec();
259 
260  enum {
261  /*** Indicates there is no error */
262  NoError = 0,
263  /*** Indicates the job was killed */
264  KilledJobError = 1,
265  /*** Subclasses should define error codes starting at this value */
266  UserDefinedError = 100
267  };
268 
276  int error() const;
277 
289  QString errorText() const;
290 
308  virtual QString errorString() const;
309 
316  Q_SCRIPTABLE qulonglong processedAmount(Unit unit) const;
317 
324  Q_SCRIPTABLE qulonglong totalAmount(Unit unit) const;
325 
331  unsigned long percent() const;
332 
342  void setAutoDelete(bool autodelete);
343 
351  bool isAutoDelete() const;
352 
353 Q_SIGNALS:
371  void finished(KJob *job
372 #if !defined(K_DOXYGEN)
373  , QPrivateSignal
374 #endif
375  );
376 
385  void suspended(KJob *job
386 #if !defined(K_DOXYGEN)
387  , QPrivateSignal
388 #endif
389  );
390 
399  void resumed(KJob *job
400 #if !defined(K_DOXYGEN)
401  , QPrivateSignal
402 #endif
403  );
404 
419  void result(KJob *job
420 #if !defined(K_DOXYGEN)
421  , QPrivateSignal
422 #endif
423  );
424 
438  void description(KJob *job, const QString &title,
449  void infoMessage(KJob *job, const QString &plain, const QString &rich = QString());
450 
458  void warning(KJob *job, const QString &plain, const QString &rich = QString());
459 
460 Q_SIGNALS:
461  // These signals must be connected from KIO::KCoreDirLister (among others),
462  // therefore they must be public.
475  void totalAmount(KJob *job, KJob::Unit unit, qulonglong amount);
476 
489  void processedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
490 
501  void totalSize(KJob *job, qulonglong size);
502 
513  void processedSize(KJob *job, qulonglong size);
514 
528  void percent(KJob *job, unsigned long percent);
529 
539  void speed(KJob *job, unsigned long speed);
540 
541 protected:
561  void setError(int errorCode);
562 
576  void setErrorText(const QString &errorText);
577 
586  void setProcessedAmount(Unit unit, qulonglong amount);
587 
596  void setTotalAmount(Unit unit, qulonglong amount);
597 
604  void setPercent(unsigned long percentage);
605 
616  void emitResult();
617 
627  void emitPercent(qulonglong processedAmount, qulonglong totalAmount);
628 
635  void emitSpeed(unsigned long speed);
636 
637 protected:
638  KJobPrivate *const d_ptr;
639  KJob(KJobPrivate &dd, QObject *parent);
640 
641 private:
642  void finishJob(bool emitResult);
643 
644  Q_PRIVATE_SLOT(d_func(), void _k_speedTimeout())
645  Q_DECLARE_PRIVATE(KJob)
646 };
647 
648 Q_DECLARE_METATYPE(KJob::Unit)
649 Q_DECLARE_OPERATORS_FOR_FLAGS(KJob::Capabilities)
650 
651 #endif
Q_ENUM(...)
Capability
Definition: kjob.h:91
The base class for all KJob UI delegate.
Q_PROPERTY(...)
The base class for all jobs.
Definition: kjob.h:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri May 29 2020 23:04:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.