]> git.saurik.com Git - apt.git/commitdiff
move common code into PackageManager::StatusChanged()
authorMichael Vogt <mvo@debian.org>
Fri, 11 Oct 2013 20:48:22 +0000 (22:48 +0200)
committerMichael Vogt <mvo@debian.org>
Fri, 11 Oct 2013 20:48:22 +0000 (22:48 +0200)
apt-pkg/deb/dpkgpm.cc
apt-pkg/iprogress.cc
apt-pkg/iprogress.h

index cd4f5c31ec68af130e0752ef54109843319eaa5c..35adb91f693642a5065d95fb1fa9dafcaf12f788 100644 (file)
@@ -58,9 +58,10 @@ public:
                         last_reported_progress(0.0)
    {
       dpkgbuf[0] = '\0';
                         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();
          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();
          progress = new APT::Progress::PackageManagerText();
       else
          progress = new APT::Progress::PackageManager();
index 68a2c720741f3d81227371c1365ec9f21fc40835..3980590511f9140bb67e6e3fa1257f1834e91ec4 100644 (file)
@@ -1,5 +1,6 @@
 #include <apt-pkg/iprogress.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/iprogress.h>
 #include <apt-pkg/strutl.h>
+#include <apti18n.h>
 
 #include <termios.h>
 #include <sys/ioctl.h>
 
 #include <termios.h>
 #include <sys/ioctl.h>
@@ -7,6 +8,20 @@
 namespace APT {
 namespace Progress {
 
 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
 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)
 {
                                         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;
 
 
    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;
              << 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)
 {
                                        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;
 
    std::cout << progress_str << "\r\n";
    std::flush(std::cout);
                    
    last_reported_progress = percentage;
+
+   return true;
 }
 
 
 }
 
 
index f097e09432b271d9daa79f35d72e2ab4f8184ff5..5f1655ab970c524c1b2b4e129c1a9cdfad08e4ac 100644 (file)
@@ -14,21 +14,26 @@ namespace Progress {
     /** \brief dpointer placeholder */
     void *d;
 
     /** \brief dpointer placeholder */
     void *d;
 
+ protected:
+    std::string progress_str;
+    float percentage;
+    int last_reported_progress;
+
  public:
  public:
+    PackageManager() : percentage(0.0), last_reported_progress(0) {};
     virtual ~PackageManager() {};
 
     virtual void Started() {};
     virtual void Finished() {};
     
     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 StepsDone,
-                               unsigned int TotalSteps) {};
+                               unsigned int TotalSteps);
  };
 
  class PackageManagerFancy : public PackageManager
  {
  protected:
  };
 
  class PackageManagerFancy : public PackageManager
  {
  protected:
-    int last_reported_progress;
     int nr_terminal_rows;
     void SetupTerminalScrollArea(int nr_rows);
 
     int nr_terminal_rows;
     void SetupTerminalScrollArea(int nr_rows);
 
@@ -36,19 +41,15 @@ namespace Progress {
     PackageManagerFancy();
     virtual void Started();
     virtual void Finished();
     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
  {
                                unsigned int StepsDone,
                                unsigned int TotalSteps);
  };
 
  class PackageManagerText : public PackageManager
  {
- protected:
-    int last_reported_progress;
-
  public:
  public:
-    PackageManagerText() : last_reported_progress(0) {};
-    virtual void StatusChanged(std::string PackageName, 
+    virtual bool StatusChanged(std::string PackageName, 
                                unsigned int StepsDone,
                                unsigned int TotalSteps);
 
                                unsigned int StepsDone,
                                unsigned int TotalSteps);