Display progress during resize (#467925)
Capture and parse the progress reports of ntfsresize and resize2fs and update the dialog progress bar. Bug 467925 - gparted: add progress bar during operation
This commit is contained in:
parent
5b0465e9a3
commit
57b028bb8e
|
@ -88,8 +88,10 @@ protected:
|
|||
Sector T, N, S ; //File system [T]otal num of blocks, [N]um of free (or used) blocks, block [S]ize
|
||||
int exit_status ;
|
||||
unsigned int index ;
|
||||
sigc::signal<void, OperationDetail *> signal_progress;
|
||||
|
||||
private:
|
||||
void update_command_progress( OperationDetail *operationdetail );
|
||||
void store_exit_status( GPid pid, int status );
|
||||
bool running;
|
||||
int pipecount;
|
||||
|
|
|
@ -52,6 +52,9 @@ public:
|
|||
bool copy( const Partition & partition_new,
|
||||
Partition & partition_old,
|
||||
OperationDetail & operationdetail );
|
||||
|
||||
private:
|
||||
void resize_progress( OperationDetail *operationdetail );
|
||||
};
|
||||
|
||||
} //GParted
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
|
||||
|
||||
static const Glib::ustring Change_UUID_Warning [] ;
|
||||
|
||||
private:
|
||||
void resize_progress( OperationDetail *operationdetail );
|
||||
};
|
||||
|
||||
} //GParted
|
||||
|
|
|
@ -125,6 +125,8 @@ int FileSystem::execute_command( const Glib::ustring & command, OperationDetail
|
|||
errorcapture.signal_update.connect( sigc::bind( sigc::ptr_fun( update_command_output ),
|
||||
children[children.size() - 1],
|
||||
&error ) );
|
||||
outputcapture.signal_update.connect( sigc::bind( sigc::mem_fun( *this, &FileSystem::update_command_progress ),
|
||||
&operationdetail ) );
|
||||
outputcapture.connect_signal();
|
||||
errorcapture.connect_signal();
|
||||
|
||||
|
@ -147,6 +149,11 @@ int FileSystem::execute_command( const Glib::ustring & command, OperationDetail
|
|||
return exit_status;
|
||||
}
|
||||
|
||||
void FileSystem::update_command_progress( OperationDetail *operationdetail )
|
||||
{
|
||||
signal_progress.emit( operationdetail );
|
||||
}
|
||||
|
||||
void FileSystem::set_status( OperationDetail & operationdetail, bool success )
|
||||
{
|
||||
operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
|
||||
|
|
36
src/ext2.cc
36
src/ext2.cc
|
@ -233,7 +233,10 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd
|
|||
str_temp += " " + Utils::num_to_str( floor( Utils::sector_to_unit(
|
||||
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K";
|
||||
|
||||
return ! execute_command( str_temp, operationdetail, EXEC_CHECK_STATUS );
|
||||
sigc::connection c = signal_progress.connect( sigc::mem_fun( *this, &ext2::resize_progress ) );
|
||||
bool ret = ! execute_command( str_temp, operationdetail, EXEC_CHECK_STATUS );
|
||||
c.disconnect();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ext2::check_repair( const Partition & partition, OperationDetail & operationdetail )
|
||||
|
@ -270,4 +273,35 @@ bool ext2::copy( const Partition & src_part,
|
|||
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
|
||||
}
|
||||
|
||||
//Private methods
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
} //GParted
|
||||
|
|
19
src/ntfs.cc
19
src/ntfs.cc
|
@ -223,6 +223,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
|
|||
//real resize
|
||||
operationdetail .add_child( OperationDetail( _("real resize") ) ) ;
|
||||
|
||||
sigc::connection c = signal_progress.connect( sigc::mem_fun( *this, &ntfs::resize_progress ) );
|
||||
if ( ! execute_command( cmd + " " + partition_new.get_path(),
|
||||
operationdetail.get_last_child(), EXEC_CHECK_STATUS ) )
|
||||
{
|
||||
|
@ -233,6 +234,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
|
|||
{
|
||||
operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
|
||||
}
|
||||
c.disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -256,4 +258,21 @@ bool ntfs::check_repair( const Partition & partition, OperationDetail & operatio
|
|||
return ! execute_command( "ntfsresize -i -f -v " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS );
|
||||
}
|
||||
|
||||
//Private methods
|
||||
|
||||
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 )
|
||||
{
|
||||
operationdetail->fraction = frac / 100;
|
||||
operationdetail->signal_update( *operationdetail );
|
||||
}
|
||||
}
|
||||
|
||||
} //GParted
|
||||
|
|
Loading…
Reference in New Issue