progress.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 aquire 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. #ifdef __GNUG__
  19. #endif
  20. #include <string>
  21. #include <sys/time.h>
  22. using std::string;
  23. class Configuration;
  24. class OpProgress
  25. {
  26. unsigned long Current;
  27. unsigned long Total;
  28. unsigned long Size;
  29. unsigned long SubTotal;
  30. float LastPercent;
  31. // Change reduction code
  32. struct timeval LastTime;
  33. string LastOp;
  34. string LastSubOp;
  35. protected:
  36. string Op;
  37. 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 Current);
  44. void SubProgress(unsigned long SubTotal);
  45. void SubProgress(unsigned long SubTotal,const string &Op);
  46. void OverallProgress(unsigned long Current,unsigned long Total,
  47. unsigned long Size,const string &Op);
  48. virtual void Done() {};
  49. OpProgress();
  50. virtual ~OpProgress() {};
  51. };
  52. class OpTextProgress : public OpProgress
  53. {
  54. protected:
  55. string OldOp;
  56. bool NoUpdate;
  57. bool NoDisplay;
  58. unsigned long LastLen;
  59. virtual void Update();
  60. void Write(const char *S);
  61. public:
  62. virtual void Done();
  63. OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
  64. NoDisplay(false), LastLen(0) {};
  65. OpTextProgress(Configuration &Config);
  66. virtual ~OpTextProgress() {Done();};
  67. };
  68. #endif