blob: 31e2360a0aead8fcd586c446822d1397b74ce227 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/***************************************************************************
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 libtdepim
// which is GPL licensed, Copyright (c) 2004 Till Adam
#ifndef TELLICO_PROGRESSMANAGER_H
#define TELLICO_PROGRESSMANAGER_H
#include <tqobject.h>
#include <tqmap.h>
#include <tqguardedptr.h>
namespace Tellico {
class ProgressManager;
/**
* @author Robby Stephenson
*/
class ProgressItem : public TQObject {
TQ_OBJECT
friend class ProgressManager;
public:
class Done {
public:
Done(const TQObject* obj) : m_object(obj) {}
~Done();
private:
const TQObject* m_object;
};
bool canCancel() const { return m_canCancel; }
const TQString& label() const { return m_label; }
void setLabel(const TQString& 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 TQString& label, bool canCancel);
virtual ~ProgressItem();
private:
TQString m_label;
bool m_canCancel;
uint m_progress;
uint m_total;
bool m_cancelled;
};
/**
* @author Robby Stephenson
*/
class ProgressManager : public TQObject {
TQ_OBJECT
public:
virtual ~ProgressManager() {}
static ProgressManager* self() { if(!s_self) s_self = new ProgressManager(); return s_self; }
ProgressItem& newProgressItem(const TQObject* owner, const TQString& label, bool canCancel = false) {
return newProgressItemImpl(owner, label, canCancel);
}
void setProgress(const TQObject* owner, uint steps);
void setTotalSteps(const TQObject* owner, uint steps);
void setDone(const TQObject* 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 TQObject* owner, const TQString& label, bool canCancel);
void setDone(ProgressItem* item);
typedef TQMap<TQGuardedPtr<const TQObject>, TQGuardedPtr<ProgressItem> > ProgressMap;
ProgressMap m_items;
static ProgressManager* s_self;
};
} // end namespace
#endif
|