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