mirror of
https://gitlab.gnome.org/GNOME/gparted
synced 2024-08-27 03:30:17 +00:00
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
This commit is contained in:
parent
b0d9d2de7e
commit
608060f82d
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
||||
|
|
11
src/Utils.cc
11
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"
|
||||
|
|
64
src/ext2.cc
64
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 )
|
||||
|
|
Loading…
Reference in a new issue