Progress Pile   version 0.0.1
Progress pile.
progress.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_PROGRESS_H_INCLUDE
11 #define GUARD_PROGRESS_H_INCLUDE
12 
13 #include <progress/progress-config.h>
14 #include <QList>
15 #include <QString>
16 #include <stdint.h>
17 
19 class PROGRESS_EXPORT Progress {
20  //
21  //
22  //
23  //
24  /* DEFINITIONS ----------------------------------------------------- */
25 
27  struct Portion {
28  int64_t offset_in_parent_;
29  int64_t size_in_parent_;
30 
31  int64_t tot_size_;
32  int64_t progress_;
33 
34  void * user_data_;
35 
36  QString current_status_;
37  };
38 
40  typedef bool (*KbSignal) (
41  int64_t total_size,
42  int64_t progress,
43  const QString & status,
44  void * level_data,
45  void * global_data);
46 
48  typedef bool (*KbSignalSimple) (
49  int64_t total_size,
50  int64_t progress);
51 
52 public:
53 
54  /* DEFINITIONS ===================================================== */
55  //
56  //
57  //
58  //
59  /* DATA ------------------------------------------------------------ */
60 
61 private:
62 
63  QList<Portion> stack_;
65  int cutoff_level_;
67  int64_t granularity_;
69  int64_t prev_prog_;
71  bool b_should_stop_;
72  QString current_status_;
73  void * user_data_;
74 
75  KbSignalSimple kb_simple_signal_;
76  KbSignal kb_full_signal_;
77 
78  /* DATA ============================================================ */
79  //
80  //
81  //
82  //
83  /* FUNCTIONS ------------------------------------------------------- */
84 
85 
86 public:
87 
89  explicit Progress ();
90 
92  virtual
93  ~Progress ();
94 
95 
97  bool
98  init (
99  const QString & title = QString (),
100  int64_t total_size = 100);
101 
103  void
104  end ();
105 
107  inline bool
108  isInitialized () const {
109  return !stack_.isEmpty ();
110  }
111 
112 
114  void
115  enter (
116  int64_t parent_size,
117  const QString &label = QString (),
118  int64_t total_size = 100,
119  int64_t parent_offset = -1,
120  void * portion_data = NULL);
121 
122 
124  void
125  finish (
126  bool update_parent = true);
127 
128 
130  inline const QString &
131  currentStatus () const {
132  return current_status_;
133  }
134 
135 
137  inline int
138  cutoffLevel () const {
139  return cutoff_level_;
140  }
141 
143  inline void
145  int value) {
146  cutoff_level_ = value;
147  }
148 
149 
151  inline int64_t
152  granularity () const {
153  return granularity_;
154  }
155 
157  inline void
158  setGranularity (int64_t value) {
159  granularity_ = value;
160  }
161 
162 
164  inline void *
165  userData () const {
166  return user_data_;
167  }
168 
170  inline void
171  setUserData (void * value) {
172  user_data_ = value;
173  }
174 
175 
177  inline KbSignalSimple
178  simpleCallback () const {
179  return kb_simple_signal_;
180  }
181 
183  inline void
184  setSimpleCallback (KbSignalSimple value) {
185  kb_simple_signal_ = value;
186  }
187 
188 
190  inline KbSignal
191  callback () const {
192  return kb_full_signal_;
193  }
194 
196  inline void
197  setCallback (KbSignal value) {
198  kb_full_signal_ = value;
199  }
200 
201 
203  bool
204  step (
205  int64_t chunk_size = 1,
206  int64_t offset = -1);
207 
209  inline void
210  setStop () {
211  b_should_stop_ = true;
212  }
213 
215  inline void
217  b_should_stop_ = false;
218  }
219 
221  inline bool
222  shouldStop () const {
223  return b_should_stop_;
224  }
225 
227  inline bool
228  emitSigal ();
229 
231  inline void
232  setLevelCharact (
233  int64_t total_size,
234  int64_t progress = 0);
235 
236 
237 private:
238 
240  QString
241  searchCurrentLabel ();
242 
244  void
245  signalChange (
246  bool b_bypass_checks = false);
247 
248 
249 }; // class Progress
250 
251 
252 #endif // GUARD_PROGRESS_H_INCLUDE
int cutoffLevel() const
Size of the active portion of the stack.
Definition: progress.h:138
Report progress.
Definition: progress.h:19
const QString & currentStatus() const
Tell the label for current operation.
Definition: progress.h:131
void * userData() const
User data associated with the instance.
Definition: progress.h:165
void setCutoffLevel(int value)
Size of the active portion of the stack.
Definition: progress.h:144
void setStop()
Sets the internal state to signal the process should terminate.
Definition: progress.h:210
bool isInitialized() const
Teell if the instance was initialized (init() was called).
Definition: progress.h:108
void setSimpleCallback(KbSignalSimple value)
Simple callback to be used when progress changes.
Definition: progress.h:184
void setGranularity(int64_t value)
Emit signals when progress advances by at least this much.
Definition: progress.h:158
void setUserData(void *value)
User data associated with the instance.
Definition: progress.h:171
void setCallback(KbSignal value)
Callback to be used when progress changes.
Definition: progress.h:197
void resetStop()
Resets the internal state to signal the process should terminate.
Definition: progress.h:216
KbSignal callback() const
Callback to be used when progress changes.
Definition: progress.h:191
KbSignalSimple simpleCallback() const
Simple callback to be used when progress changes.
Definition: progress.h:178
int64_t granularity() const
Emit signals when progress advances by at least this much.
Definition: progress.h:152
bool shouldStop() const
Tell if the process / operation should stop.
Definition: progress.h:222