progress.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: progress.h,v 1.6 2001/05/07 05:06:52 jgg Exp $
  4. /* ######################################################################
  5. OpProgress - Operation Progress
  6. This class allows lengthy operations to communicate their progress
  7. to the GUI. The progress model is simple and is not designed to handle
  8. the complex case of the multi-activity acquire class.
  9. The model is based on the concept of an overall operation consisting
  10. of a series of small sub operations. Each sub operation has it's own
  11. completion status and the overall operation has it's completion status.
  12. The units of the two are not mixed and are completely independent.
  13. The UI is expected to subclass this to provide the visuals to the user.
  14. ##################################################################### */
  15. /*}}}*/
  16. #ifndef PKGLIB_PROGRESS_H
  17. #define PKGLIB_PROGRESS_H
  18. #include <string>
  19. #include <sys/time.h>
  20. #ifndef APT_8_CLEANER_HEADERS
  21. using std::string;
  22. #endif
  23. class Configuration;
  24. class OpProgress
  25. {
  26. unsigned long long Current;
  27. unsigned long long Total;
  28. unsigned long long Size;
  29. unsigned long long SubTotal;
  30. float LastPercent;
  31. // Change reduction code
  32. struct timeval LastTime;
  33. std::string LastOp;
  34. std::string LastSubOp;
  35. protected:
  36. std::string Op;
  37. std::string SubOp;
  38. float Percent;
  39. bool MajorChange;
  40. bool CheckChange(float Interval = 0.7);
  41. virtual void Update() {};
  42. public:
  43. void Progress(unsigned long long Current);
  44. void SubProgress(unsigned long long SubTotal, const std::string &Op = "", float const Percent = -1);
  45. void OverallProgress(unsigned long long Current,unsigned long long Total,
  46. unsigned long long Size,const std::string &Op);
  47. virtual void Done() {};
  48. OpProgress();
  49. virtual ~OpProgress() {};
  50. };
  51. class OpTextProgress : public OpProgress
  52. {
  53. protected:
  54. std::string OldOp;
  55. bool NoUpdate;
  56. bool NoDisplay;
  57. unsigned long LastLen;
  58. virtual void Update();
  59. void Write(const char *S);
  60. public:
  61. virtual void Done();
  62. OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
  63. NoDisplay(false), LastLen(0) {};
  64. OpTextProgress(Configuration &Config);
  65. virtual ~OpTextProgress() {Done();};
  66. };
  67. #endif