KDECore
kjob.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 Stephan Kulow <coolo@kde.org> 00003 David Faure <faure@kde.org> 00004 Copyright (C) 2006 Kevin Ottens <ervin@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 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 00160 virtual void start() = 0; 00161 00162 enum KillVerbosity { Quietly, EmitResult }; 00163 00164 public Q_SLOTS: 00177 bool kill( KillVerbosity verbosity = Quietly ); 00178 00185 bool suspend(); 00186 00192 bool resume(); 00193 00194 protected: 00201 virtual bool doKill(); 00202 00208 virtual bool doSuspend(); 00209 00215 virtual bool doResume(); 00216 00223 void setCapabilities( Capabilities capabilities ); 00224 00225 public: 00244 bool exec(); 00245 00246 enum 00247 { 00248 NoError = 0, 00249 KilledJobError = 1, 00250 UserDefinedError = 100 00251 }; 00252 00253 00260 int error() const; 00261 00270 QString errorText() const; 00271 00288 virtual QString errorString() const; 00289 00290 00297 qulonglong processedAmount(Unit unit) const; 00298 00305 qulonglong totalAmount(Unit unit) const; 00306 00312 unsigned long percent() const; 00313 00323 void setAutoDelete( bool autodelete ); 00324 00332 bool isAutoDelete() const; 00333 00334 Q_SIGNALS: 00335 #if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER) 00336 private: // don't tell moc, doxygen or kdevelop, but those signals are in fact private 00337 #endif 00338 00356 void finished(KJob *job); 00357 00366 void suspended(KJob *job); 00367 00376 void resumed(KJob *job); 00377 00392 void result(KJob *job); 00393 00394 Q_SIGNALS: 00408 void description(KJob *job, const QString &title, 00409 const QPair<QString, QString> &field1 = qMakePair(QString(), QString()), 00410 const QPair<QString, QString> &field2 = qMakePair(QString(), QString())); 00411 00420 void infoMessage( KJob *job, const QString &plain, const QString &rich = QString() ); 00421 00429 void warning( KJob *job, const QString &plain, const QString &rich = QString() ); 00430 00431 00432 Q_SIGNALS: 00433 #if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER) 00434 private: // don't tell moc, doxygen or kdevelop, but those signals are in fact private 00435 #endif 00436 00448 void totalAmount(KJob *job, KJob::Unit unit, qulonglong amount); 00449 00462 void processedAmount(KJob *job, KJob::Unit unit, qulonglong amount); 00463 00474 void totalSize(KJob *job, qulonglong size); 00475 00486 void processedSize(KJob *job, qulonglong size); 00487 00501 void percent( KJob *job, unsigned long percent ); 00502 00512 void speed(KJob *job, unsigned long speed); 00513 00514 protected: 00522 void setError( int errorCode ); 00523 00531 void setErrorText( const QString &errorText ); 00532 00533 00542 void setProcessedAmount(Unit unit, qulonglong amount); 00543 00552 void setTotalAmount(Unit unit, qulonglong amount); 00553 00560 void setPercent( unsigned long percentage ); 00561 00562 00573 void emitResult(); 00574 00584 void emitPercent( qulonglong processedAmount, qulonglong totalAmount ); 00585 00592 void emitSpeed(unsigned long speed); 00593 00594 protected: 00595 KJobPrivate *const d_ptr; 00596 KJob(KJobPrivate &dd, QObject *parent); 00597 00598 private: 00599 Q_PRIVATE_SLOT(d_func(), void _k_speedTimeout()) 00600 Q_DECLARE_PRIVATE(KJob) 00601 }; 00602 00603 Q_DECLARE_OPERATORS_FOR_FLAGS( KJob::Capabilities ) 00604 00605 #endif
KDE 4.6 API Reference