diff options
author | Michael Vogt <mvo@debian.org> | 2013-10-11 22:48:22 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2013-10-11 22:48:22 +0200 |
commit | 6c5ae8ed079e01082f606614641b19b7c08893ad (patch) | |
tree | 30d168e66eed72236853fe8ce99e4d7bcae2bcb0 /apt-pkg | |
parent | db78c60c6a726ed70fa8b0984090b80840444016 (diff) |
move common code into PackageManager::StatusChanged()
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 5 | ||||
-rw-r--r-- | apt-pkg/iprogress.cc | 43 | ||||
-rw-r--r-- | apt-pkg/iprogress.h | 19 |
3 files changed, 38 insertions, 29 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index cd4f5c31e..35adb91f6 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -58,9 +58,10 @@ public: last_reported_progress(0.0) { dpkgbuf[0] = '\0'; - if(_config->FindB("DpkgPM::Progress-Fancy", false) == true) + if(_config->FindB("Dpkg::Progress-Fancy", false) == true) progress = new APT::Progress::PackageManagerFancy(); - else if (_config->FindB("DpkgPM::Progress", false) == true) + else if (_config->FindB("Dpkg::Progress", + _config->FindB("DpkgPM::Progress", false)) == true) progress = new APT::Progress::PackageManagerText(); else progress = new APT::Progress::PackageManager(); diff --git a/apt-pkg/iprogress.cc b/apt-pkg/iprogress.cc index 68a2c7207..398059051 100644 --- a/apt-pkg/iprogress.cc +++ b/apt-pkg/iprogress.cc @@ -1,5 +1,6 @@ #include <apt-pkg/iprogress.h> #include <apt-pkg/strutl.h> +#include <apti18n.h> #include <termios.h> #include <sys/ioctl.h> @@ -7,6 +8,20 @@ namespace APT { namespace Progress { +bool PackageManager::StatusChanged(std::string PackageName, + unsigned int StepsDone, + unsigned int TotalSteps) +{ + int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); + percentage = StepsDone/(float)TotalSteps * 100.0; + strprintf(progress_str, _("Progress: [%3i%%]"), (int)percentage); + + if(percentage < (last_reported_progress + reporting_steps)) + return false; + + return true; +} + void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows) { // scroll down a bit to avoid visual glitch when the screen @@ -55,18 +70,12 @@ void PackageManagerFancy::Finished() } } -void PackageManagerFancy::StatusChanged(std::string PackageName, +bool PackageManagerFancy::StatusChanged(std::string PackageName, unsigned int StepsDone, unsigned int TotalSteps) { - int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); - float percentage = StepsDone/(float)TotalSteps * 100.0; - - if(percentage < (last_reported_progress + reporting_steps)) - return; - - std::string progress_str; - strprintf(progress_str, "Progress: [%3i%%]", (int)percentage); + if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps)) + return false; int row = nr_terminal_rows; @@ -90,25 +99,23 @@ void PackageManagerFancy::StatusChanged(std::string PackageName, << restore_fg; std::flush(std::cout); last_reported_progress = percentage; + + return true; } -void PackageManagerText::StatusChanged(std::string PackageName, +bool PackageManagerText::StatusChanged(std::string PackageName, unsigned int StepsDone, unsigned int TotalSteps) { - int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); - float percentage = StepsDone/(float)TotalSteps * 100.0; - - if(percentage < (last_reported_progress + reporting_steps)) - return; - - std::string progress_str; - strprintf(progress_str, "Progress: [%3i%%]", (int)percentage); + if (!PackageManager::StatusChanged(PackageName, StepsDone, TotalSteps)) + return false; std::cout << progress_str << "\r\n"; std::flush(std::cout); last_reported_progress = percentage; + + return true; } diff --git a/apt-pkg/iprogress.h b/apt-pkg/iprogress.h index f097e0943..5f1655ab9 100644 --- a/apt-pkg/iprogress.h +++ b/apt-pkg/iprogress.h @@ -14,21 +14,26 @@ namespace Progress { /** \brief dpointer placeholder */ void *d; + protected: + std::string progress_str; + float percentage; + int last_reported_progress; + public: + PackageManager() : percentage(0.0), last_reported_progress(0) {}; virtual ~PackageManager() {}; virtual void Started() {}; virtual void Finished() {}; - virtual void StatusChanged(std::string PackageName, + virtual bool StatusChanged(std::string PackageName, unsigned int StepsDone, - unsigned int TotalSteps) {}; + unsigned int TotalSteps); }; class PackageManagerFancy : public PackageManager { protected: - int last_reported_progress; int nr_terminal_rows; void SetupTerminalScrollArea(int nr_rows); @@ -36,19 +41,15 @@ namespace Progress { PackageManagerFancy(); virtual void Started(); virtual void Finished(); - virtual void StatusChanged(std::string PackageName, + virtual bool StatusChanged(std::string PackageName, unsigned int StepsDone, unsigned int TotalSteps); }; class PackageManagerText : public PackageManager { - protected: - int last_reported_progress; - public: - PackageManagerText() : last_reported_progress(0) {}; - virtual void StatusChanged(std::string PackageName, + virtual bool StatusChanged(std::string PackageName, unsigned int StepsDone, unsigned int TotalSteps); |