]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: progress.h,v 1.6 2001/05/07 05:06:52 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | OpProgress - Operation Progress | |
7 | ||
8 | This class allows lengthy operations to communicate their progress | |
9 | to the GUI. The progress model is simple and is not designed to handle | |
10 | the complex case of the multi-activity aquire class. | |
11 | ||
12 | The model is based on the concept of an overall operation consisting | |
13 | of a series of small sub operations. Each sub operation has it's own | |
14 | completion status and the overall operation has it's completion status. | |
15 | The units of the two are not mixed and are completely independent. | |
16 | ||
17 | The UI is expected to subclass this to provide the visuals to the user. | |
18 | ||
19 | ##################################################################### */ | |
20 | /*}}}*/ | |
21 | #ifndef PKGLIB_PROGRESS_H | |
22 | #define PKGLIB_PROGRESS_H | |
23 | ||
24 | ||
25 | #include <string> | |
26 | #include <sys/time.h> | |
27 | ||
28 | class Configuration; | |
29 | class OpProgress | |
30 | { | |
31 | unsigned long long Current; | |
32 | unsigned long long Total; | |
33 | unsigned long long Size; | |
34 | unsigned long long SubTotal; | |
35 | float LastPercent; | |
36 | ||
37 | // Change reduction code | |
38 | struct timeval LastTime; | |
39 | std::string LastOp; | |
40 | std::string LastSubOp; | |
41 | ||
42 | protected: | |
43 | ||
44 | std::string Op; | |
45 | std::string SubOp; | |
46 | float Percent; | |
47 | ||
48 | bool MajorChange; | |
49 | ||
50 | bool CheckChange(float Interval = 0.7); | |
51 | virtual void Update() {}; | |
52 | ||
53 | public: | |
54 | ||
55 | void Progress(unsigned long long Current); | |
56 | void SubProgress(unsigned long long SubTotal, const std::string &Op = "", float const Percent = -1); | |
57 | void OverallProgress(unsigned long long Current,unsigned long long Total, | |
58 | unsigned long long Size,const std::string &Op); | |
59 | virtual void Done() {}; | |
60 | ||
61 | OpProgress(); | |
62 | virtual ~OpProgress() {}; | |
63 | }; | |
64 | ||
65 | class OpTextProgress : public OpProgress | |
66 | { | |
67 | protected: | |
68 | ||
69 | std::string OldOp; | |
70 | bool NoUpdate; | |
71 | bool NoDisplay; | |
72 | unsigned long LastLen; | |
73 | virtual void Update(); | |
74 | void Write(const char *S); | |
75 | ||
76 | public: | |
77 | ||
78 | virtual void Done(); | |
79 | ||
80 | OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), | |
81 | NoDisplay(false), LastLen(0) {}; | |
82 | OpTextProgress(Configuration &Config); | |
83 | virtual ~OpTextProgress() {Done();}; | |
84 | }; | |
85 | ||
86 | #endif |