From 2a972b06b8cbf098490db5f241da30aa98e2c01c Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Wed, 4 Jan 2006 18:54:46 +0000 Subject: [PATCH] added get_length() from now on values >=1024MB are displayed in GB's * include/Partition.h, src/Partition.cc: added get_length() * include/Utils.h, src/Utils.cc, src/Dialog_Partition_Info.cc, src/Operation.cc, src/TreeView_Detail.cc, src/VBox_VisualDisk.cc, src/Win_GParted.cc: from now on values >=1024MB are displayed in GB's (#319840) --- ChangeLog | 13 +++++++++++++ include/Partition.h | 6 +----- include/Utils.h | 1 + src/Dialog_Partition_Info.cc | 11 ++++++----- src/Operation.cc | 9 ++++++--- src/Partition.cc | 12 +++++++++--- src/TreeView_Detail.cc | 32 +++++++++++++++++++++----------- src/Utils.cc | 20 ++++++++++++++++++++ src/VBox_VisualDisk.cc | 2 +- src/Win_GParted.cc | 5 ++--- 10 files changed, 80 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6774b175..7538ba8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-01-04 Bart Hakvoort + + * include/Partition.h, + src/Partition.cc: added get_length() + * include/Utils.h, + src/Utils.cc, + src/Dialog_Partition_Info.cc, + src/Operation.cc, + src/TreeView_Detail.cc, + src/VBox_VisualDisk.cc, + src/Win_GParted.cc: from now on values >=1024MB are displayed in + GB's (#319840) + 2006-01-03 Bart Hakvoort * src/Win_GParted.cc: replaced 'can not' with 'cannot' (#325570) diff --git a/include/Partition.h b/include/Partition.h index 8df8be8f..ef5567f8 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -25,11 +25,6 @@ #include "../include/Utils.h" -#include - -#include -#include - namespace GParted { @@ -77,6 +72,7 @@ public: long Get_Length_MB() const ; long Get_Used_MB() const ; long Get_Unused_MB() const ; + Sector get_length() const ; bool operator==( const Partition & partition ) const ; diff --git a/include/Utils.h b/include/Utils.h index ddfcefd4..aff5a68f 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -114,6 +114,7 @@ public: unsigned long flags = 0, const Glib::ustring & data = "" ) ; static bool unmount( const Glib::ustring & node, const Glib::ustring & mountpoint, Glib::ustring & error ) ; + static Glib::ustring format_size( Sector size ) ; }; diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index 0bac8873..fbc20807 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -134,21 +134,22 @@ void Dialog_Partition_Info::Display_Info( ) //size table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Size:" ) + "" ), 0,1,top, bottom,Gtk::FILL); - table ->attach( * Utils::mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Length_MB( ) ) ), 1, 2, top++, bottom++,Gtk::FILL ); + table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .get_length() ) ), 1, 2, top++, bottom++,Gtk::FILL ); if ( partition.sectors_used != -1 ) { //calculate relative diskusage - int percent_used = Utils::Round( static_cast(partition .Get_Used_MB( ) ) / partition .Get_Length_MB( ) *100 ) ; + int percent_used = + Utils::Round( static_cast(partition .Get_Used_MB() ) / partition .Get_Length_MB() *100 ) ; //used - table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Used:" ) + "" ), 0,1, top, bottom,Gtk::FILL ) ; - table ->attach( * Utils::mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Used_MB( ) ) ), 1, 2, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Used:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .sectors_used ) ), 1, 2, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; //unused table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Unused:" ) + "" ), 0,1, top, bottom,Gtk::FILL); - table ->attach( * Utils::mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Unused_MB( ) ) ), 1, 2, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .sectors_unused ) ), 1, 2, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( 100 - percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; } diff --git a/src/Operation.cc b/src/Operation.cc index a7a392f8..a340cfd4 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -135,11 +135,14 @@ void Operation::Apply_Operation_To_Visual( std::vector & partitions ) { switch ( operationtype ) { - case DELETE : Apply_Delete_To_Visual( partitions ) ; break ; - case RESIZE_MOVE: Apply_Resize_Move_To_Visual( partitions ); break ; + case DELETE : Apply_Delete_To_Visual( partitions ) ; + break ; + case RESIZE_MOVE: Apply_Resize_Move_To_Visual( partitions ) ; + break ; case CREATE : case FORMAT : - case COPY : Apply_Create_To_Visual( partitions ); break ; + case COPY : Apply_Create_To_Visual( partitions ) ; + break ; } } diff --git a/src/Partition.cc b/src/Partition.cc index 3c8a7a4c..cdf399a1 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -54,17 +54,18 @@ void Partition::Set( const Glib::ustring & device_path, this ->filesystem = filesystem; this ->sector_start = sector_start; this ->sector_end = sector_end; - this ->color.set( Utils::Get_Color( filesystem ) ); this ->inside_extended = inside_extended; this ->busy = busy; + + this ->color.set( Utils::Get_Color( filesystem ) ); } void Partition::Set_Unused( Sector sectors_unused ) { - if ( sectors_unused < ( sector_end - sector_start ) ) + if ( sectors_unused < get_length() ) { this ->sectors_unused = sectors_unused ; - this ->sectors_used = ( sectors_unused == -1 ) ? -1 : ( sector_end - sector_start) - sectors_unused ; + this ->sectors_used = ( sectors_unused == -1 ) ? -1 : get_length() - sectors_unused ; } } @@ -105,6 +106,11 @@ long Partition::Get_Unused_MB() const return Get_Length_MB() - Get_Used_MB( ) ; } +Sector Partition::get_length() const +{ + return sector_end - sector_start + 1 ; +} + bool Partition::operator==( const Partition & partition ) const { return this ->partition_number == partition .partition_number && diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index 2eed7d21..187852e8 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -15,8 +15,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "../include/TreeView_Detail.h" - +#include "../include/TreeView_Detail.h" + namespace GParted { @@ -33,9 +33,9 @@ TreeView_Detail::TreeView_Detail( ) //append columns append_column( _("Partition"), treeview_detail_columns .partition ); append_column( _("Filesystem"), treeview_detail_columns .color ); - append_column( _("Size(MB)"), treeview_detail_columns .size ); - append_column( _("Used(MB)"), treeview_detail_columns .used ); - append_column( _("Unused(MB)"), treeview_detail_columns .unused ); + append_column( _("Size"), treeview_detail_columns .size ); + append_column( _("Used"), treeview_detail_columns .used ); + append_column( _("Unused"), treeview_detail_columns .unused ); append_column( _("Flags"), treeview_detail_columns .flags ); //status_icon @@ -63,6 +63,13 @@ TreeView_Detail::TreeView_Detail( ) //set alignment of numeric columns to right for( short t = 2 ; t < 5 ; t++ ) get_column_cell_renderer( t ) ->property_xalign() = 1 ; + + //expand columns and centeralign the headertext + for( short t = 2 ; t < 6 ; t++ ) + { + get_column( t ) ->set_expand( true ) ; + get_column( t ) ->set_alignment( 0.5 ) ; + } } void TreeView_Detail::load_partitions( const std::vector & partitions ) @@ -133,19 +140,22 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition treerow[ treeview_detail_columns .partition ] = partition .partition; treerow[ treeview_detail_columns .color ] = Utils::get_color_as_pixbuf( partition .filesystem, 16, 16 ) ; - treerow[ treeview_detail_columns .text_color ] = partition .type == GParted::TYPE_UNALLOCATED ? "darkgrey" : "black" ; - treerow[ treeview_detail_columns .filesystem ] = Utils::Get_Filesystem_String( partition .filesystem ) ; + treerow[ treeview_detail_columns .text_color ] = + partition .type == GParted::TYPE_UNALLOCATED ? "darkgrey" : "black" ; + + treerow[ treeview_detail_columns .filesystem ] = + Utils::Get_Filesystem_String( partition .filesystem ) ; //size - treerow[ treeview_detail_columns .size ] = Utils::num_to_str( partition .Get_Length_MB() ) ; - + treerow[ treeview_detail_columns .size ] = Utils::format_size( partition .get_length() ) ; + //used treerow[ treeview_detail_columns .used ] = - partition .sectors_used == -1 ? "---" : Utils::num_to_str( partition .Get_Used_MB() ) ; + partition .sectors_used == -1 ? "---" : Utils::format_size( partition .sectors_used ) ; //unused treerow[ treeview_detail_columns .unused ] = - partition .sectors_unused == -1 ? "---" : Utils::num_to_str( partition .Get_Unused_MB() ) ; + partition .sectors_unused == -1 ? "---" : Utils::format_size( partition .sectors_unused ) ; //flags treerow[ treeview_detail_columns .flags ] = " " + partition .flags ; diff --git a/src/Utils.cc b/src/Utils.cc index d3e2439a..df0e5ad3 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -20,6 +20,7 @@ #include #include #include +#include namespace GParted @@ -238,4 +239,23 @@ bool Utils::unmount( const Glib::ustring & node, const Glib::ustring & mountpoin return false ; } +Glib::ustring Utils::format_size( Sector size ) +{ + size *= 512 ; + std::stringstream ss ; + ss .imbue( std::locale( "" ) ) ; + ss << std::setiosflags( std::ios::fixed ) << std::setprecision( 2 ) ; + + if ( size < 1073741824 ) + { + ss << static_cast( size / 1048567.0 ) ; + return String::ucompose( _("%1 MB"), ss .str() ) ; + } + else + { + ss << static_cast( size / 1073741824.0 ) ; + return String::ucompose( _("%1 GB"), ss .str() ) ; + } +} + } //GParted.. diff --git a/src/VBox_VisualDisk.cc b/src/VBox_VisualDisk.cc index 2f56ecb9..9fd3ec20 100644 --- a/src/VBox_VisualDisk.cc +++ b/src/VBox_VisualDisk.cc @@ -125,7 +125,7 @@ void VBox_VisualDisk::set_static_data( const std::vector & partitions partitions[ t ] .sector_end - partitions[ t ] .sector_start ) ; else visual_partitions .back() .pango_layout = drawingarea .create_pango_layout( - partitions[ t ] .partition + "\n" + String::ucompose( _("%1 MB"), partitions[ t ] .Get_Length_MB() ) ) ; + partitions[ t ] .partition + "\n" + Utils::format_size( partitions[ t ] .get_length() ) ) ; } } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 30654280..a8c9eaed 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -414,8 +414,7 @@ void Win_GParted::refresh_combo_devices() treerow[ treeview_devices_columns .icon ] = render_icon( Gtk::Stock::HARDDISK, Gtk::ICON_SIZE_LARGE_TOOLBAR ) ; treerow[ treeview_devices_columns .device ] = devices[ i ] .path ; - treerow[ treeview_devices_columns .size ] = - "(" + String::ucompose( _("%1 MB"), Utils::Sector_To_MB( devices[ i ] .length ) ) + ")" ; + treerow[ treeview_devices_columns .size ] = "(" + Utils::format_size( devices[ i ] .length ) + ")" ; } combo_devices .set_active( current_device ) ; @@ -471,7 +470,7 @@ void Win_GParted::Fill_Label_Device_Info( bool clear ) //global info... device_info[ t++ ] ->set_text( devices[ current_device ] .model ) ; - device_info[ t++ ] ->set_text( String::ucompose( _("%1 MB"), Utils::Sector_To_MB( devices[ current_device ] .length ) ) ) ; + device_info[ t++ ] ->set_text( Utils::format_size( devices[ current_device ] .length ) ) ; device_info[ t++ ] ->set_text( devices[ current_device ] .path ) ; device_info[ t++ ] ->set_text( devices[ current_device ] .realpath ) ;