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);
00059    void SubProgress(unsigned long SubTotal,const string &Op);
00060    void OverallProgress(unsigned long Current,unsigned long Total,
00061                         unsigned long Size,const string &Op);
00062    virtual void Done() {};
00063    
00064    OpProgress();
00065    virtual ~OpProgress() {};
00066 };
00067 
00068 class OpTextProgress : public OpProgress
00069 {
00070    protected:
00071    
00072    string OldOp;
00073    bool NoUpdate;
00074    bool NoDisplay;
00075    unsigned long LastLen;
00076    virtual void Update();
00077    void Write(const char *S);
00078    
00079    public:
00080 
00081    virtual void Done();
00082    
00083    OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), 
00084                 NoDisplay(false), LastLen(0) {};
00085    OpTextProgress(Configuration &Config);
00086    virtual ~OpTextProgress() {Done();};
00087 };
00088 
00089 #endif