diff --git a/ChangeLog b/ChangeLog index aef62c24..257af727 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-08-21 Bart Hakvoort + + * include/Utils.h, + src/Utils.cc: added format_time() + * include/OperationDetail.h, + src/OperationDetail.cc: keep track of elapsed time between + STATUS_EXECUTE and STATUS_[ERROR|SUCCES] + * include/Dialog_Progress.h, + src/Dialog_Progress.cc: show elapsed time in the details per (sub) + process + * src/GParted_Core.cc: use Utils::format_time() + 2006-08-21 Bart Hakvoort * src/FileSystem.cc: added nice -n 19, so that all extensive diff --git a/include/Dialog_Progress.h b/include/Dialog_Progress.h index 16a2c074..38e5a9e7 100644 --- a/include/Dialog_Progress.h +++ b/include/Dialog_Progress.h @@ -75,16 +75,14 @@ private: struct treeview_operations_Columns : public Gtk::TreeModelColumnRecord { Gtk::TreeModelColumn operation_description; - Gtk::TreeModelColumn< Glib::RefPtr > operation_icon; + Gtk::TreeModelColumn elapsed_time ; Gtk::TreeModelColumn< Glib::RefPtr > status_icon; - Gtk::TreeModelColumn hidden_status ; treeview_operations_Columns() { add( operation_description ); - add( operation_icon ); + add( elapsed_time ); add( status_icon ) ; - add( hidden_status ) ; } }; treeview_operations_Columns treeview_operations_columns; diff --git a/include/OperationDetail.h b/include/OperationDetail.h index 6c45e72d..3570faab 100644 --- a/include/OperationDetail.h +++ b/include/OperationDetail.h @@ -55,6 +55,7 @@ public: OperationDetailStatus get_status() const ; void set_treepath( const Glib::ustring & treepath ) ; Glib::ustring get_treepath() const ; + Glib::ustring get_elapsed_time() const ; void add_child( const OperationDetail & operationdetail ) ; std::vector & get_childs() ; @@ -75,6 +76,7 @@ private: Glib::ustring treepath ; std::vector sub_details ; + std::time_t time_start, time_elapsed ; }; } //GParted diff --git a/include/Utils.h b/include/Utils.h index 84d36dc1..eddcc203 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -124,6 +124,7 @@ public: static Glib::RefPtr get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ; static Glib::ustring get_filesystem_string( FILESYSTEM filesystem ) ; static Glib::ustring format_size( Sector size ) ; + static Glib::ustring format_time( std::time_t seconds ) ; static double sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) ; static int execute_command( const Glib::ustring & command ) ; static int execute_command( const Glib::ustring & command, diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc index b5fe3a3f..c356bdf5 100644 --- a/src/Dialog_Progress.cc +++ b/src/Dialog_Progress.cc @@ -71,11 +71,16 @@ Dialog_Progress::Dialog_Progress( const std::vector & operations ) treestore_operations = Gtk::TreeStore::create( treeview_operations_columns ); treeview_operations .set_model( treestore_operations ); treeview_operations .set_headers_visible( false ); - treeview_operations .append_column( "", treeview_operations_columns .operation_icon ); - treeview_operations .append_column( "", treeview_operations_columns .operation_description ); - treeview_operations .append_column( "", treeview_operations_columns .status_icon ); - treeview_operations .set_size_request( 500, 250 ) ; treeview_operations .set_rules_hint( true ) ; + treeview_operations .set_size_request( 500, 250 ) ; + treeview_operations .append_column( "", treeview_operations_columns .operation_description ); + treeview_operations .append_column( "", treeview_operations_columns .elapsed_time ); + treeview_operations .append_column( "", treeview_operations_columns .status_icon ); + + treeview_operations .get_column( 0 ) ->set_expand( true ) ; + treeview_operations .get_column( 0 ) ->set_cell_data_func( + * ( treeview_operations .get_column( 0 ) ->get_first_cell_renderer() ), + sigc::mem_fun(*this, &Dialog_Progress::on_cell_data_description) ) ; //fill 'er up for ( unsigned int t = 0 ; t < operations .size() ; t++ ) @@ -84,17 +89,10 @@ Dialog_Progress::Dialog_Progress( const std::vector & operations ) this ->operations[ t ] ->operation_detail .set_treepath( Utils::num_to_str( t ) ) ; treerow = *( treestore_operations ->append() ); - treerow[ treeview_operations_columns .operation_icon ] = operations[ t ] ->icon ; treerow[ treeview_operations_columns .operation_description ] = this ->operations[ t ] ->operation_detail .get_description() ; - treerow[ treeview_operations_columns .hidden_status ] = STATUS_NONE ; } - treeview_operations .get_column( 1 ) ->set_expand( true ) ; - treeview_operations .get_column( 1 ) ->set_cell_data_func( - * ( treeview_operations .get_column( 1 ) ->get_first_cell_renderer() ), - sigc::mem_fun(*this, &Dialog_Progress::on_cell_data_description) ) ; - scrolledwindow .set_shadow_type( Gtk::SHADOW_ETCHED_IN ) ; scrolledwindow .set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ) ; scrolledwindow .add( treeview_operations ) ; @@ -123,6 +121,7 @@ void Dialog_Progress::on_signal_update( const OperationDetail & operationdetail Gtk::TreeRow treerow = *iter ; treerow[ treeview_operations_columns .operation_description ] = operationdetail .get_description() ; + treerow[ treeview_operations_columns .elapsed_time ] = operationdetail .get_elapsed_time() ; switch ( operationdetail .get_status() ) { @@ -161,11 +160,10 @@ void Dialog_Progress::on_signal_update( const OperationDetail & operationdetail { unsigned int pos = operationdetail .get_treepath() .rfind( ":" ) ; if ( pos >= 0 && pos < operationdetail .get_treepath() .length() ) - iter= treestore_operations ->get_iter( - operationdetail .get_treepath() .substr( 0, - operationdetail .get_treepath() .rfind( ":" ) ) ) ; + iter = treestore_operations ->get_iter( operationdetail .get_treepath() + .substr( 0, operationdetail .get_treepath() .rfind( ":" ) ) ) ; else - iter= treestore_operations ->get_iter( operationdetail .get_treepath() ) ; + iter = treestore_operations ->get_iter( operationdetail .get_treepath() ) ; if ( iter) { @@ -361,6 +359,8 @@ void Dialog_Progress::echo_operation_details( const OperationDetail & operationd out << "" << std::endl ; out << "" << std::endl ; out << temp ; + if ( ! operationdetail .get_elapsed_time() .empty() ) + out << "  " << operationdetail .get_elapsed_time() ; //show status... if ( operationdetail .get_status() != STATUS_NONE ) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 0b43e3db..af86ac37 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -1639,29 +1639,10 @@ void GParted_Core::set_progress_info( Sector total, std::time_t time_remaining = Utils::round( (1.0 - operationdetail .fraction) * sec_per_frac ) ; - //format it a bit.. - Glib::ustring time ; - - int unit = static_cast( time_remaining / 3600 ) ; - if ( unit < 10 ) - time += "0" ; - time += Utils::num_to_str( unit ) + ":" ; - time_remaining %= 3600 ; - - unit = static_cast( time_remaining / 60 ) ; - if ( unit < 10 ) - time += "0" ; - time += Utils::num_to_str( unit ) + ":" ; - time_remaining %= 60 ; - - if ( time_remaining < 10 ) - time += "0" ; - time += Utils::num_to_str( time_remaining ) ; - operationdetail .progress_text = String::ucompose( _("%1 of %2 copied (%3 remaining)"), Utils::format_size( done ), Utils::format_size( total ), - time ) ; + Utils::format_time( time_remaining) ) ; operationdetail .set_description( String::ucompose( _("%1 of %2 copied"), done, total ), FONT_ITALIC ) ; } diff --git a/src/OperationDetail.cc b/src/OperationDetail.cc index f3706f4d..a0f883dc 100644 --- a/src/OperationDetail.cc +++ b/src/OperationDetail.cc @@ -24,16 +24,18 @@ namespace GParted OperationDetail::OperationDetail() { - status = STATUS_NONE ; + set_status( STATUS_NONE ) ; fraction = -1 ; + time_elapsed = -1 ; } OperationDetail::OperationDetail( const Glib::ustring & description, OperationDetailStatus status, Font font ) { set_description( description, font ) ; - this ->status = status ; + set_status( status ) ; fraction = -1 ; + time_elapsed = -1 ; } void OperationDetail::set_description( const Glib::ustring & description, Font font ) @@ -54,8 +56,7 @@ void OperationDetail::set_description( const Glib::ustring & description, Font f break ; } - if ( ! treepath .empty() ) - on_update( *this ) ; + on_update( *this ) ; } Glib::ustring OperationDetail::get_description() const @@ -64,9 +65,24 @@ Glib::ustring OperationDetail::get_description() const } void OperationDetail::set_status( OperationDetailStatus status ) -{ +{ if ( this ->status != STATUS_ERROR ) { + switch ( status ) + { + case STATUS_EXECUTE: + time_elapsed = -1 ; + time_start = std::time( NULL ) ; + break ; + case STATUS_ERROR: + case STATUS_SUCCES: + time_elapsed = std::time( NULL ) - time_start ; + break ; + + default: + break ; + } + this ->status = status ; on_update( *this ) ; } @@ -86,6 +102,14 @@ Glib::ustring OperationDetail::get_treepath() const { return treepath ; } + +Glib::ustring OperationDetail::get_elapsed_time() const +{ + if ( time_elapsed >= 0 ) + return Utils::format_time( time_elapsed ) ; + + return "" ; +} void OperationDetail::add_child( const OperationDetail & operationdetail ) { @@ -118,7 +142,8 @@ OperationDetail & OperationDetail::get_last_child() void OperationDetail::on_update( const OperationDetail & operationdetail ) { - signal_update .emit( operationdetail ) ; + if ( ! treepath .empty() ) + signal_update .emit( operationdetail ) ; } } //GParted diff --git a/src/Utils.cc b/src/Utils.cc index 28154e7d..ccbf4909 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -163,6 +163,32 @@ Glib::ustring Utils::format_size( Sector size ) return String::ucompose( _("%1 TiB"), ss .str() ) ; } } + +Glib::ustring Utils::format_time( std::time_t seconds ) +{ + Glib::ustring time ; + + int unit = static_cast( seconds / 3600 ) ; + if ( unit > 0 ) + { + if ( unit < 10 ) + time += "0" ; + time += num_to_str( unit ) + ":" ; + seconds %= 3600 ; + } + + unit = static_cast( seconds / 60 ) ; + if ( unit < 10 ) + time += "0" ; + time += num_to_str( unit ) + ":" ; + seconds %= 60 ; + + if ( seconds < 10 ) + time += "0" ; + time += num_to_str( seconds ) ; + + return time ; +} double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) {