apt
@VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: progress.h,v 1.6 2001/05/07 05:06:52 jgg Exp $ 00004 /* ###################################################################### 00005 00006 OpProgress - Operation Progress 00007 00008 This class allows lengthy operations to communicate their progress 00009 to the GUI. The progress model is simple and is not designed to handle 00010 the complex case of the multi-activity aquire class. 00011 00012 The model is based on the concept of an overall operation consisting 00013 of a series of small sub operations. Each sub operation has it's own 00014 completion status and the overall operation has it's completion status. 00015 The units of the two are not mixed and are completely independent. 00016 00017 The UI is expected to subclass this to provide the visuals to the user. 00018 00019 ##################################################################### */ 00020 /*}}}*/ 00021 #ifndef PKGLIB_PROGRESS_H 00022 #define PKGLIB_PROGRESS_H 00023 00024 00025 #include <string> 00026 #include <sys/time.h> 00027 00028 #ifndef APT_8_CLEANER_HEADERS 00029 using std::string; 00030 #endif 00031 00032 class Configuration; 00033 class OpProgress 00034 { 00035 unsigned long long Current; 00036 unsigned long long Total; 00037 unsigned long long Size; 00038 unsigned long long SubTotal; 00039 float LastPercent; 00040 00041 // Change reduction code 00042 struct timeval LastTime; 00043 std::string LastOp; 00044 std::string LastSubOp; 00045 00046 protected: 00047 00048 std::string Op; 00049 std::string SubOp; 00050 float Percent; 00051 00052 bool MajorChange; 00053 00054 bool CheckChange(float Interval = 0.7); 00055 virtual void Update() {}; 00056 00057 public: 00058 00059 void Progress(unsigned long long Current); 00060 void SubProgress(unsigned long long SubTotal, const std::string &Op = "", float const Percent = -1); 00061 void OverallProgress(unsigned long long Current,unsigned long long Total, 00062 unsigned long long Size,const std::string &Op); 00063 virtual void Done() {}; 00064 00065 OpProgress(); 00066 virtual ~OpProgress() {}; 00067 }; 00068 00069 class OpTextProgress : public OpProgress 00070 { 00071 protected: 00072 00073 std::string OldOp; 00074 bool NoUpdate; 00075 bool NoDisplay; 00076 unsigned long LastLen; 00077 virtual void Update(); 00078 void Write(const char *S); 00079 00080 public: 00081 00082 virtual void Done(); 00083 00084 OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), 00085 NoDisplay(false), LastLen(0) {}; 00086 OpTextProgress(Configuration &Config); 00087 virtual ~OpTextProgress() {Done();}; 00088 }; 00089 00090 #endif