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



commit ac949e30030a4a9461594856beaed1a5932ff508
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Jan 13 17:19:06 2016 +0000

    Update ext2 create progress tracker to use the new ProgressBar (#760709)
    
    Adapt the ext2 create file system progress tracker to used the new
    ProgressBar class.  Also make it track when the text progress indicator
    completes 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

 src/ext2.cc |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/src/ext2.cc b/src/ext2.cc
index 2bcc099..e3b0b52 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -325,16 +325,22 @@ void ext2::resize_progress( OperationDetail *operationdetail )
 
 void ext2::create_progress( OperationDetail *operationdetail )
 {
-       Glib::ustring ss;
-       size_t p = output.find_last_of('\n');
-       // looks like "Writing inode tables: xx/yy"
-       if ( p == output.npos )
-               return;
-       ss = output.substr( p );
-       int x, y;
-       if ( sscanf( ss.c_str(), "\nWriting inode tables: %d/%d", &x, &y ) == 2 )
+       ProgressBar & progressbar = operationdetail->get_progressbar();
+       Glib::ustring line = Utils::last_line( output );
+       // Text progress on the LAST LINE looks like "Writing inode tables:  105/1600"
+       long long progress, target;
+       if ( sscanf( line.c_str(), "Writing inode tables: %Ld/%Ld", &progress, &target ) == 2 )
        {
-               operationdetail->fraction = (double)x / y;
+               if ( ! progressbar.running() )
+                       progressbar.start( (double)target );
+               progressbar.update( (double)progress );
+               operationdetail->signal_update( *operationdetail );
+       }
+       // Or when finished, on any line, ...
+       else if ( output.find( "Writing inode tables: done" ) != output.npos )
+       {
+               if ( progressbar.running() )
+                       progressbar.stop();
                operationdetail->signal_update( *operationdetail );
        }
 }


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