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



commit 9f7a38e6b3498a66a465a691fb99a577edb05814
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Jan 14 14:18:03 2016 +0000

    Update ntfs resize progress tracker to use the new ProgressBar (#760709)
    
    Adapt the ntfs resize progress tracker to use the new ProgressBar class.
    Also make it track when the text progress indicator has 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

 src/ntfs.cc |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/ntfs.cc b/src/ntfs.cc
index 1fb4c4a..d701eec 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -17,7 +17,12 @@
  
  
 #include "../include/ntfs.h"
+#include "../include/OperationDetail.h"
 #include "../include/Partition.h"
+#include "../include/ProgressBar.h"
+#include "../include/Utils.h"
+
+#include <glibmm/ustring.h>
 
 namespace GParted
 {
@@ -262,15 +267,22 @@ bool ntfs::check_repair( const Partition & partition, OperationDetail & operatio
 
 void ntfs::resize_progress( OperationDetail *operationdetail )
 {
-       size_t p = output.find_last_of('\n');
-       if ( p == output.npos )
-               return;
-       Glib::ustring ss = output.substr( p );
-       // looks like "12.34 percent completed"
-       float frac;
-       if ( sscanf( ss.c_str(), "%f percent completed", &frac ) == 1 )
+       ProgressBar & progressbar = operationdetail->get_progressbar();
+       Glib::ustring line = Utils::last_line( output );
+       // Text progress on the LAST LINE looks like " 15.24 percent completed"
+       float percent;
+       if ( sscanf( line.c_str(), "%f percent completed", &percent ) == 1 )
+       {
+               if ( ! progressbar.running() )
+                       progressbar.start( 100.0 );
+               progressbar.update( percent );
+               operationdetail->signal_update( *operationdetail );
+       }
+       // Or when finished, on any line, ...
+       else if ( output.find( "Successfully resized NTFS on device" ) != output.npos )
        {
-               operationdetail->fraction = frac / 100;
+               if ( progressbar.running() )
+                       progressbar.stop();
                operationdetail->signal_update( *operationdetail );
        }
 }


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