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