[gparted] Update ext2 resize progress tracker to use the new ProgressBar (#760709)



commit 608060f82dae66cca0a8be2590bdd12ddcdf8be7
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Jan 11 16:17:39 2016 +0000

    Update ext2 resize progress tracker to use the new ProgressBar (#760709)
    
    Adapt the ext2 resize progress tracker to the new ProgressBar class.
    Also update the progress function to track when text progress bars have
    completely passed in the output so that the progress bar can be stopped
    as well as started when needed.
    
    Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
                 copy methods

 include/Utils.h |    1 +
 include/ext2.h  |    3 ++
 src/Utils.cc    |   11 +++++++++
 src/ext2.cc     |   64 +++++++++++++++++++++++++++++++++---------------------
 4 files changed, 54 insertions(+), 25 deletions(-)
---
diff --git a/include/Utils.h b/include/Utils.h
index f2ae5fe..2256788 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -197,6 +197,7 @@ public:
                                         , const Glib::ustring & pattern
                                         ) ;
        static Glib::ustring trim( const Glib::ustring & src, const Glib::ustring & c = " \t\r\n" ) ;
+       static Glib::ustring last_line( const Glib::ustring & src );
        static Glib::ustring get_lang() ;
        static void tokenize( const Glib::ustring& str,
                              std::vector<Glib::ustring>& tokens,
diff --git a/include/ext2.h b/include/ext2.h
index 95fbbde..edad76f 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -20,8 +20,11 @@
 #define GPARTED_EXT2_H
 
 #include "../include/FileSystem.h"
+#include "../include/OperationDetail.h"
 #include "../include/Partition.h"
 
+#include <glibmm/ustring.h>
+
 namespace GParted
 {
 
diff --git a/src/Utils.cc b/src/Utils.cc
index 8a02276..c4707c9 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -31,6 +31,7 @@
 #include <uuid/uuid.h>
 #include <cerrno>
 #include <sys/statvfs.h>
+#include <glibmm/ustring.h>
 #include <gtkmm/main.h>
 #include <fcntl.h>
 #include <sys/types.h>
@@ -670,6 +671,16 @@ Glib::ustring Utils::trim( const Glib::ustring & src, const Glib::ustring & c /*
        return src.substr(p1, (p2-p1)+1);
 }
 
+// Return portion of string after the last carriage return character or
+// the whole string when there is no carriage return character.
+Glib::ustring Utils::last_line( const Glib::ustring & src )
+{
+       Glib::ustring::size_type p = src.find_last_of( '\n' );
+       if ( p == Glib::ustring::npos )
+               return src;
+       return src.substr( p+1 );
+}
+
 Glib::ustring Utils::get_lang()
 {
        //Extract base language from string that may look like "en_CA.UTF-8"
diff --git a/src/ext2.cc b/src/ext2.cc
index 0b74341..2bcc099 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -16,7 +16,12 @@
  */
  
 #include "../include/ext2.h"
+#include "../include/OperationDetail.h"
 #include "../include/Partition.h"
+#include "../include/ProgressBar.h"
+#include "../include/Utils.h"
+
+#include <glibmm/ustring.h>
 
 namespace GParted
 {
@@ -282,31 +287,40 @@ bool ext2::copy( const Partition & src_part,
 
 void ext2::resize_progress( OperationDetail *operationdetail )
 {
-       Glib::ustring ss;
-       size_t p = output.find_last_of('\n');
-       // looks like "Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXX------------"
-       if ( p == output.npos )
-               return;
-       ss = output.substr( p );
-       if ( ss.empty() )
-               return;
-       size_t sslen = ss.length();
-       if ( ss[sslen-1] != 'X' && ss[sslen-1] != '-' )
-               return;
-       // p = Start of progress bar
-       p = ss.find_last_not_of( "X-" );
-       if ( p == ss.npos )
-               p = 0;
-       else
-               p++;
-       size_t barlen = sslen - p;
-       // q = First dash in progress bar or end of string
-       size_t q = ss.find( '-', p );
-       if ( q == ss.npos )
-               q = sslen;
-       size_t xlen = q - p;
-       operationdetail->fraction = (double)xlen / barlen;
-       operationdetail->signal_update( *operationdetail );
+       ProgressBar & progressbar = operationdetail->get_progressbar();
+       Glib::ustring line = Utils::last_line( output );
+       size_t llen = line.length();
+       // There may be multiple text progress bars on subsequent last lines which look
+       // like: "Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXX------------"
+       if ( llen > 0 && ( line[llen-1] == 'X' || line[llen-1] == '-' ) )
+       {
+               // p = Start of progress bar
+               size_t p = line.find_last_not_of( "X-" );
+               if ( p == line.npos )
+                       p = 0;
+               else
+                       p++;
+               size_t barlen = llen - p;
+
+               // q = First dash in progress bar or end of string
+               size_t q = line.find( '-', p );
+               if ( q == line.npos )
+                       q = llen;
+               size_t xlen = q - p;
+
+               if ( ! progressbar.running() )
+                       progressbar.start( (double)barlen );
+               progressbar.update( (double)xlen );
+               operationdetail->signal_update( *operationdetail );
+       }
+       // Ending summary line looks like:
+       // "The filesystem on /dev/sdb3 is now 256000 block long."
+       else if ( output.find( " is now " ) != output.npos )
+       {
+               if ( progressbar.running() )
+                       progressbar.stop();
+               operationdetail->signal_update( *operationdetail );
+       }
 }
 
 void ext2::create_progress( OperationDetail *operationdetail )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]