00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#ifndef __KPIM_PROGRESSMANAGER_H__
00025
#define __KPIM_PROGRESSMANAGER_H__
00026
00027
#include <qobject.h>
00028
#include <qdict.h>
00029
#include <qstring.h>
00030
00031
namespace KPIM {
00032
00033
class ProgressItem;
00034
class ProgressManager;
00035
typedef QMap<ProgressItem*, bool> ProgressItemMap;
00036
00037
class ProgressItem :
public QObject
00038 {
00039 Q_OBJECT;
00040
friend class ProgressManager;
00041
friend class QDict< ProgressItem >;
00042
00043
public:
00044
00049
const QString& id()
const {
return mId; }
00050
00054 ProgressItem *parent()
const {
return mParent; }
00055
00059
const QString& label()
const {
return mLabel; }
00060
00064
void setLabel(
const QString& v );
00065
00069
const QString& status()
const {
return mStatus; }
00074
void setStatus(
const QString& v );
00075
00079
bool canBeCanceled()
const {
return mCanBeCanceled; }
00080
00085
bool usesCrypto()
const {
return mUsesCrypto; }
00086
00092
void setUsesCrypto(
bool v );
00093
00097
unsigned int progress()
const {
return mProgress; }
00098
00103
void setProgress(
unsigned int v );
00104
00112
void setComplete();
00113
00118
void reset() { setProgress( 0 ); setStatus( QString::null ); mCompleted = 0; }
00119
00120
void cancel();
00121
00122
00123
void setTotalItems(
unsigned int v ) { mTotal = v; }
00124
unsigned int totalItems() const;
00125
void setCompletedItems(
unsigned int v ) { mCompleted = v; }
00126
void incCompletedItems(
unsigned int v = 1 ) { mCompleted += v; }
00127
unsigned int completedItems() const;
00128
00132
void updateProgress() { setProgress( mTotal? mCompleted*100/mTotal: 0 ); };
00133
00134
void addChild( ProgressItem *kiddo );
00135
void removeChild( ProgressItem *kiddo );
00136
00137
bool canceled()
const {
return mCanceled; }
00138
00139 signals:
00144
void progressItemAdded( ProgressItem* );
00150
void progressItemProgress( ProgressItem*,
unsigned int );
00157
void progressItemCompleted( ProgressItem* );
00168
void progressItemCanceled( ProgressItem* );
00175
void progressItemStatus( ProgressItem*,
const QString& );
00182
void progressItemLabel( ProgressItem*,
const QString& );
00189
void progressItemUsesCrypto( ProgressItem*,
bool );
00190
00191
00192
protected:
00193
00194 ProgressItem( ProgressItem* parent,
00195
const QString&
id,
00196
const QString& label,
00197
const QString& status,
00198
bool isCancellable,
00199
bool usesCrypto );
00200
virtual ~ProgressItem();
00201
00202
00203
private:
00204
QString mId;
00205
QString mLabel;
00206
QString mStatus;
00207 ProgressItem* mParent;
00208
bool mCanBeCanceled;
00209
unsigned int mProgress;
00210 ProgressItemMap mChildren;
00211
unsigned int mTotal;
00212
unsigned int mCompleted;
00213
bool mWaitingForKids;
00214
bool mCanceled;
00215
bool mUsesCrypto;
00216 };
00217
00239 class ProgressManager :
public QObject
00240 {
00241
00242 Q_OBJECT;
00243
00244
public:
00245
virtual ~
ProgressManager();
00246
00250
static ProgressManager *
instance();
00251
00258 static QString getUniqueID() {
return QString::number( ++uID ); };
00259
00265 static ProgressItem *
createProgressItem(
const QString &label ) {
00266
return instance()->
createProgressItemImpl( 0,
getUniqueID(), label,
00267 QString::null,
true,
false );
00268 }
00269
00284 static ProgressItem * createProgressItem( ProgressItem* parent,
00285
const QString&
id,
00286
const QString& label,
00287
const QString& status = QString::null,
00288
bool canBeCanceled =
true,
00289
bool usesCrypto =
false ) {
00290
return instance()->
createProgressItemImpl( parent,
id, label, status,
00291 canBeCanceled, usesCrypto );
00292 }
00293
00298 static ProgressItem * createProgressItem(
const QString& parent,
00299
const QString&
id,
00300
const QString& label,
00301
const QString& status = QString::null,
00302
bool canBeCanceled =
true,
00303
bool usesCrypto =
false ) {
00304
return instance()->
createProgressItemImpl( parent,
id, label,
00305 status, canBeCanceled, usesCrypto );
00306 }
00307
00311 static ProgressItem * createProgressItem(
const QString&
id,
00312
const QString& label,
00313
const QString& status = QString::null,
00314
bool canBeCanceled =
true,
00315
bool usesCrypto =
false ) {
00316
return instance()->
createProgressItemImpl( 0,
id, label, status,
00317 canBeCanceled, usesCrypto );
00318 }
00319
00320
00324 bool isEmpty()
const {
return mTransactions.isEmpty(); }
00325
00330 ProgressItem*
singleItem() const;
00331
00336 static
void emitShowProgressDialog() {
00337
instance()->
emitShowProgressDialogImpl();
00338 }
00339
00340 signals:
00342
void progressItemAdded( ProgressItem* );
00344
void progressItemProgress( ProgressItem*,
unsigned int );
00346
void progressItemCompleted( ProgressItem* );
00348
void progressItemCanceled( ProgressItem* );
00350
void progressItemStatus( ProgressItem*,
const QString& );
00352
void progressItemLabel( ProgressItem*,
const QString& );
00354
void progressItemUsesCrypto( ProgressItem*,
bool );
00355
00360
void showProgressDialog();
00361
public slots:
00362
00368
void slotStandardCancelHandler( ProgressItem* item );
00369
00373
void slotAbortAll();
00374
00375
private slots:
00376
void slotTransactionCompleted( ProgressItem *item );
00377
00378
private:
00379
ProgressManager();
00380
00381
ProgressManager(
const ProgressManager& );
00382
00383
virtual ProgressItem* createProgressItemImpl(
00384 ProgressItem* parent,
const QString&
id,
00385
const QString& label,
const QString& status,
00386
bool cancellable,
bool usesCrypto );
00387
virtual ProgressItem* createProgressItemImpl(
00388
const QString& parent,
const QString&
id,
00389
const QString& label,
const QString& status,
00390
bool cancellable,
bool usesCrypto );
00391
void emitShowProgressDialogImpl();
00392
00393
QDict< ProgressItem > mTransactions;
00394
static ProgressManager *mInstance;
00395
static unsigned int uID;
00396 };
00397
00398 }
00399
00400
#endif // __KPIM_PROGRESSMANAGER_H__