apt @VERSION@
progress.h
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 using std::string;
00029 
00030 class Configuration;
00031 class OpProgress
00032 {
00033    unsigned long Current;
00034    unsigned long Total;
00035    unsigned long Size;
00036    unsigned long SubTotal;
00037    float LastPercent;
00038    
00039    // Change reduction code
00040    struct timeval LastTime;
00041    string LastOp;
00042    string LastSubOp;
00043    
00044    protected:
00045    
00046    string Op;
00047    string SubOp;
00048    float Percent;
00049    
00050    bool MajorChange;
00051    
00052    bool CheckChange(float Interval = 0.7);                  
00053    virtual void Update() {};
00054    
00055    public:
00056    
00057    void Progress(unsigned long Current);
00058    void SubProgress(unsigned long SubTotal, const string &Op = "", float const Percent = -1);
00059    void OverallProgress(unsigned long Current,unsigned long Total,
00060                         unsigned long Size,const string &Op);
00061    virtual void Done() {};
00062    
00063    OpProgress();
00064    virtual ~OpProgress() {};
00065 };
00066 
00067 class OpTextProgress : public OpProgress
00068 {
00069    protected:
00070    
00071    string OldOp;
00072    bool NoUpdate;
00073    bool NoDisplay;
00074    unsigned long LastLen;
00075    virtual void Update();
00076    void Write(const char *S);
00077    
00078    public:
00079 
00080    virtual void Done();
00081    
00082    OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), 
00083                 NoDisplay(false), LastLen(0) {};
00084    OpTextProgress(Configuration &Config);
00085    virtual ~OpTextProgress() {Done();};
00086 };
00087 
00088 #endif