libkdepim Library API Documentation

progressmanager.h

00001 /*
00002   progressmanager.h
00003 
00004   This file is part of KDEPIM.
00005 
00006   Author: Till Adam <adam@kde.org> (C) 2004
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Library General Public
00010   License as published by the Free Software Foundation; either
00011   version 2 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Library General Public License for more details.
00017 
00018   You should have received a copy of the GNU Library General Public License
00019   along with this library; see the file COPYING.LIB.  If not, write to
00020   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021   Boston, MA 02111-1307, USA.
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 >; // so it can be deleted from dicts
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     // Often needed values for calculating progress.
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     /* Only to be used by our good friend the ProgressManager */
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      // prevent unsolicited copies
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__
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:20:06 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003