]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/progress.h
merged from donkult
[apt.git] / apt-pkg / contrib / progress.h
CommitLineData
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
404ec98e
AL
24
25#include <string>
26#include <sys/time.h>
27
233b185f
AL
28using std::string;
29
0a8e3465 30class Configuration;
404ec98e
AL
31class 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;
1a7c9eba 42 string LastSubOp;
404ec98e
AL
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);
c6660a4b 58 void SubProgress(unsigned long SubTotal, const string &Op = "", float const Percent = -1);
404ec98e 59 void OverallProgress(unsigned long Current,unsigned long Total,
171c75f1 60 unsigned long Size,const string &Op);
1a7c9eba
AL
61 virtual void Done() {};
62
404ec98e
AL
63 OpProgress();
64 virtual ~OpProgress() {};
65};
66
67class OpTextProgress : public OpProgress
68{
69 protected:
70
71 string OldOp;
72 bool NoUpdate;
0a8e3465 73 bool NoDisplay;
404ec98e
AL
74 unsigned long LastLen;
75 virtual void Update();
76 void Write(const char *S);
77
78 public:
79
1a7c9eba 80 virtual void Done();
404ec98e 81
0a8e3465
AL
82 OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
83 NoDisplay(false), LastLen(0) {};
84 OpTextProgress(Configuration &Config);
404ec98e
AL
85 virtual ~OpTextProgress() {Done();};
86};
87
88#endif