[gparted] Display progress during resize (#467925)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Display progress during resize (#467925)
- Date: Fri, 18 Dec 2015 16:30:20 +0000 (UTC)
commit 57b028bb8e7c9fa5e750624f405cc268dfa3b4af
Author: Phillip Susi <psusi ubuntu com>
Date: Sat Mar 2 10:14:51 2013 -0500
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
include/FileSystem.h | 4 +++-
include/ext2.h | 3 +++
include/ntfs.h | 3 +++
src/FileSystem.cc | 7 +++++++
src/ext2.cc | 36 +++++++++++++++++++++++++++++++++++-
src/ntfs.cc | 19 +++++++++++++++++++
6 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/include/FileSystem.h b/include/FileSystem.h
index 1e45907..b9e74b4 100644
--- a/include/FileSystem.h
+++ b/include/FileSystem.h
@@ -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;
diff --git a/include/ext2.h b/include/ext2.h
index 7860d7c..96df48e 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -52,6 +52,9 @@ public:
bool copy( const Partition & partition_new,
Partition & partition_old,
OperationDetail & operationdetail );
+
+private:
+ void resize_progress( OperationDetail *operationdetail );
};
} //GParted
diff --git a/include/ntfs.h b/include/ntfs.h
index 2a4170c..602b5e6 100644
--- a/include/ntfs.h
+++ b/include/ntfs.h
@@ -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
diff --git a/src/FileSystem.cc b/src/FileSystem.cc
index 2915f8f..fe7eb3f 100644
--- a/src/FileSystem.cc
+++ b/src/FileSystem.cc
@@ -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 );
diff --git a/src/ext2.cc b/src/ext2.cc
index 7405d65..bf653dd 100644
--- a/src/ext2.cc
+++ b/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
diff --git a/src/ntfs.cc b/src/ntfs.cc
index d48b5a0..0d66cf5 100644
--- a/src/ntfs.cc
+++ b/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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]