]>
Commit | Line | Data |
---|---|---|
404ec98e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
233b185f | 3 | // $Id: progress.h,v 1.6 2001/05/07 05:06:52 jgg Exp $ |
404ec98e AL |
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 | /*}}}*/ | |
404ec98e AL |
21 | #ifndef PKGLIB_PROGRESS_H |
22 | #define PKGLIB_PROGRESS_H | |
23 | ||
24 | #ifdef __GNUG__ | |
25 | #pragma interface "apt-pkg/progress.h" | |
26 | #endif | |
27 | ||
28 | #include <string> | |
29 | #include <sys/time.h> | |
30 | ||
233b185f AL |
31 | using std::string; |
32 | ||
0a8e3465 | 33 | class Configuration; |
404ec98e AL |
34 | class OpProgress |
35 | { | |
36 | unsigned long Current; | |
37 | unsigned long Total; | |
38 | unsigned long Size; | |
39 | unsigned long SubTotal; | |
40 | float LastPercent; | |
41 | ||
42 | // Change reduction code | |
43 | struct timeval LastTime; | |
44 | string LastOp; | |
1a7c9eba | 45 | string LastSubOp; |
404ec98e AL |
46 | |
47 | protected: | |
48 | ||
49 | string Op; | |
50 | string SubOp; | |
51 | float Percent; | |
52 | ||
53 | bool MajorChange; | |
54 | ||
55 | bool CheckChange(float Interval = 0.7); | |
56 | virtual void Update() {}; | |
57 | ||
58 | public: | |
59 | ||
60 | void Progress(unsigned long Current); | |
8ce4327b | 61 | void SubProgress(unsigned long SubTotal); |
404ec98e AL |
62 | void SubProgress(unsigned long SubTotal,string Op); |
63 | void OverallProgress(unsigned long Current,unsigned long Total, | |
64 | unsigned long Size,string Op); | |
1a7c9eba AL |
65 | virtual void Done() {}; |
66 | ||
404ec98e AL |
67 | OpProgress(); |
68 | virtual ~OpProgress() {}; | |
69 | }; | |
70 | ||
71 | class OpTextProgress : public OpProgress | |
72 | { | |
73 | protected: | |
74 | ||
75 | string OldOp; | |
76 | bool NoUpdate; | |
0a8e3465 | 77 | bool NoDisplay; |
404ec98e AL |
78 | unsigned long LastLen; |
79 | virtual void Update(); | |
80 | void Write(const char *S); | |
81 | ||
82 | public: | |
83 | ||
1a7c9eba | 84 | virtual void Done(); |
404ec98e | 85 | |
0a8e3465 AL |
86 | OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), |
87 | NoDisplay(false), LastLen(0) {}; | |
88 | OpTextProgress(Configuration &Config); | |
404ec98e AL |
89 | virtual ~OpTextProgress() {Done();}; |
90 | }; | |
91 | ||
92 | #endif |