diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/progressmanager.h | |
download | tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip |
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/progressmanager.h')
-rw-r--r-- | src/progressmanager.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/progressmanager.h b/src/progressmanager.h new file mode 100644 index 0000000..5eaac3b --- /dev/null +++ b/src/progressmanager.h @@ -0,0 +1,127 @@ +/*************************************************************************** + copyright : (C) 2005-2006 by Robby Stephenson + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +// much of this code is adapted from libkdepim +// which is GPL licensed, Copyright (c) 2004 Till Adam + +#ifndef TELLICO_PROGRESSMANAGER_H +#define TELLICO_PROGRESSMANAGER_H + +#include <qobject.h> +#include <qmap.h> +#include <qguardedptr.h> + +namespace Tellico { + +class ProgressManager; + +/** + * @author Robby Stephenson + */ +class ProgressItem : public QObject { +Q_OBJECT + +friend class ProgressManager; + +public: + class Done { + public: + Done(const QObject* obj) : m_object(obj) {} + ~Done(); + private: + const QObject* m_object; + }; + + bool canCancel() const { return m_canCancel; } + const QString& label() const { return m_label; } + void setLabel(const QString& label); + +// uint progress() const { return m_total ? (100*m_completed/m_total) : 0; } + uint progress() const { return m_progress; } + void setProgress(uint steps); + uint totalSteps() const { return m_total; } + void setTotalSteps(uint steps); + void setDone(); + + void cancel(); + +signals: + void signalProgress(ProgressItem* item); + void signalDone(ProgressItem* item); + void signalCancelled(ProgressItem* item); + void signalTotalSteps(ProgressItem* item); + +protected: + /* Only to be used by the ProgressManager */ + ProgressItem(const QString& label, bool canCancel); + virtual ~ProgressItem(); + +private: + QString m_label; + bool m_canCancel; + uint m_progress; + uint m_total; + bool m_cancelled; +}; + +/** + * @author Robby Stephenson + */ +class ProgressManager : public QObject { +Q_OBJECT + +public: + virtual ~ProgressManager() {} + + static ProgressManager* self() { if(!s_self) s_self = new ProgressManager(); return s_self; } + + ProgressItem& newProgressItem(const QObject* owner, const QString& label, bool canCancel = false) { + return newProgressItemImpl(owner, label, canCancel); + } + + void setProgress(const QObject* owner, uint steps); + void setTotalSteps(const QObject* owner, uint steps); + void setDone(const QObject* owner); + + bool anyCanBeCancelled() const; + +signals: +// void signalItemAdded(ProgressItem* item); +// void signalItemProgress(ProgressItem* item); +// void signalItemDone(ProgressItem* item); +// void signalItemCancelled(ProgressItem* item); + void signalTotalProgress(uint progress); + +public slots: + void slotCancelAll(); + +private slots: + void slotItemDone(ProgressItem* item); + void slotUpdateTotalProgress(); + +private: + ProgressManager(); + ProgressManager(const ProgressManager&); // no copies + + ProgressItem& newProgressItemImpl(const QObject* owner, const QString& label, bool canCancel); + void setDone(ProgressItem* item); + + typedef QMap<QGuardedPtr<const QObject>, QGuardedPtr<ProgressItem> > ProgressMap; + ProgressMap m_items; + + static ProgressManager* s_self; +}; + +} // end namespace + +#endif |