]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/progress.h
we break the ABI, so let use increase the ABI number :)
[apt.git] / apt-pkg / contrib / progress.h
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 using std::string;
29
30 class Configuration;
31 class OpProgress
32 {
33 unsigned long Current;
34 unsigned long Total;
35 unsigned long Size;
36 unsigned long SubTotal;
37 float LastPercent;
38
39 // Change reduction code
40 struct timeval LastTime;
41 string LastOp;
42 string LastSubOp;
43
44 protected:
45
46 string Op;
47 string SubOp;
48 float Percent;
49
50 bool MajorChange;
51
52 bool CheckChange(float Interval = 0.7);
53 virtual void Update() {};
54
55 public:
56
57 void Progress(unsigned long Current);
58 void SubProgress(unsigned long SubTotal);
59 void SubProgress(unsigned long SubTotal,const string &Op);
60 void OverallProgress(unsigned long Current,unsigned long Total,
61 unsigned long Size,const string &Op);
62 virtual void Done() {};
63
64 OpProgress();
65 virtual ~OpProgress() {};
66 };
67
68 class OpTextProgress : public OpProgress
69 {
70 protected:
71
72 string OldOp;
73 bool NoUpdate;
74 bool NoDisplay;
75 unsigned long LastLen;
76 virtual void Update();
77 void Write(const char *S);
78
79 public:
80
81 virtual void Done();
82
83 OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
84 NoDisplay(false), LastLen(0) {};
85 OpTextProgress(Configuration &Config);
86 virtual ~OpTextProgress() {Done();};
87 };
88
89 #endif