From 808b777019d61a4244bdabf866606e3463b0b9cf Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Tue, 13 Dec 2005 21:30:13 +0000 Subject: [PATCH] replaced the inline Utils functions with static functions. This shaves a * replaced the inline Utils functions with static functions. This shaves a few kbytes (24 in fact) off the binary and is a bit cleaner code-wise (imho). --- ChangeLog | 6 ++ include/Utils.h | 103 +++--------------------- po/.cvsignore | 1 + po/POTFILES.in | 2 +- src/Dialog_Base_Partition.cc | 16 ++-- src/Dialog_Disklabel.cc | 10 +-- src/Dialog_Filesystems.cc | 2 +- src/Dialog_Partition_Copy.cc | 6 +- src/Dialog_Partition_Info.cc | 60 +++++++------- src/Dialog_Partition_New.cc | 10 +-- src/Dialog_Partition_Resize_Move.cc | 36 ++++----- src/Dialog_Progress.cc | 4 +- src/GParted_Core.cc | 8 +- src/Makefile.am | 1 + src/Operation.cc | 14 ++-- src/Partition.cc | 10 +-- src/TreeView_Detail.cc | 10 +-- src/Utils.cc | 117 ++++++++++++++++++++++++++++ src/VBox_VisualDisk.cc | 26 +++---- src/Win_GParted.cc | 66 ++++++++-------- src/ext2.cc | 2 +- src/ext3.cc | 2 +- src/ntfs.cc | 2 +- src/reiserfs.cc | 2 +- 24 files changed, 279 insertions(+), 237 deletions(-) create mode 100644 src/Utils.cc diff --git a/ChangeLog b/ChangeLog index 51c7b399..ffc0159c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-12-13 Bart Hakvoort + + * replaced the inline Utils functions with static functions. + This shaves a few kbytes (24 in fact) off the binary and is a bit + cleaner code-wise (imho). + 2005-12-12 Bart Hakvoort * src/GParted_Core.cc: don't use wait_for_node() if resizing an diff --git a/include/Utils.h b/include/Utils.h index 081fd486..f590fd86 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -29,8 +29,7 @@ #include #include -#include -#include +#include namespace GParted { @@ -88,98 +87,18 @@ struct FS } }; - -//globally used convenience functions -inline long Round( double double_value ) + +class Utils { - return static_cast( double_value + 0.5 ) ; -} - -inline long Sector_To_MB( Sector sectors ) -{ - return Round( sectors * 0.000488281250 ) ; // that's what 512/1024/1024 gives you :) -} - -inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false, const Glib::ustring & text_color = "black" ) -{ - Gtk::Label * label = manage( new Gtk::Label( text ) ) ; +public: + static long Round( double double_value ) ; + static long Sector_To_MB( Sector sectors ) ; + static Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false, const Glib::ustring & text_color = "black" ) ; + static Glib::ustring num_to_str( Sector number, bool use_C_locale = false ) ; + static Glib::ustring Get_Color( FILESYSTEM filesystem ) ; + static Glib::ustring Get_Filesystem_String( FILESYSTEM filesystem ) ; +}; - label ->set_use_markup( use_markup ) ; - - if ( align_left ) - label ->set_alignment( Gtk::ALIGN_LEFT ) ; - - label ->set_line_wrap( wrap ) ; - - if ( text_color != "black" ) - { - Gdk::Color color( text_color ) ; - label ->modify_fg( label ->get_state( ), color ) ; - } - - return label ; -} - -inline Glib::ustring num_to_str( Sector number, bool use_C_locale = false ) -{ - std::stringstream ss ; - //ss.imbue( std::locale( use_C_locale ? "C" : "" ) ) ; see #157871 - ss << number ; - return ss .str( ) ; -} - -//use http://developer.gnome.org/projects/gup/hig/2.0/design.html#Palette as a starting point.. -inline Glib::ustring Get_Color( FILESYSTEM filesystem ) -{ - switch( filesystem ) - { - case FS_UNALLOCATED : return "darkgrey" ; - case FS_UNKNOWN : return "black" ; - case FS_UNFORMATTED : return "black" ; - case FS_EXTENDED : return "#7DFCFE" ; - case FS_EXT2 : return "#9DB8D2" ; - case FS_EXT3 : return "#7590AE" ; - case FS_LINUX_SWAP : return "#C1665A" ; - case FS_FAT16 : return "green" ; - case FS_FAT32 : return "#18D918" ; - case FS_NTFS : return "#42E5AC" ; - case FS_REISERFS : return "#ADA7C8" ; - case FS_REISER4 : return "#887FA3" ; - case FS_XFS : return "#EED680" ; - case FS_JFS : return "#E0C39E" ; - case FS_HFS : return "#E0B6AF" ; - case FS_HFSPLUS : return "#C0A39E" ; - case FS_UFS : return "#D1940C" ; - - default : return "black" ; - } -} - -inline Glib::ustring Get_Filesystem_String( FILESYSTEM filesystem ) -{ - switch( filesystem ) - { - case FS_UNALLOCATED : return _("unallocated") ; - case FS_UNKNOWN : return _("unknown") ; - case FS_UNFORMATTED : return _("unformatted") ; - case FS_EXTENDED : return "extended" ; - case FS_EXT2 : return "ext2" ; - case FS_EXT3 : return "ext3" ; - case FS_LINUX_SWAP : return "linux-swap" ; - case FS_FAT16 : return "fat16" ; - case FS_FAT32 : return "fat32" ; - case FS_NTFS : return "ntfs" ; - case FS_REISERFS : return "reiserfs" ; - case FS_REISER4 : return "reiser4" ; - case FS_XFS : return "xfs" ; - case FS_JFS : return "jfs" ; - case FS_HFS : return "hfs" ; - case FS_HFSPLUS : return "hfs+" ; - case FS_UFS : return "ufs" ; - - default : return "" ; - } -} }//GParted diff --git a/po/.cvsignore b/po/.cvsignore index 6f6605a7..903c515e 100644 --- a/po/.cvsignore +++ b/po/.cvsignore @@ -1,6 +1,7 @@ *.gmo *.mo *.pot +*.swp Makefile Makefile.in Makefile.in.in diff --git a/po/POTFILES.in b/po/POTFILES.in index b5bd9903..f439e897 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,7 +1,6 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. gparted.desktop.in -include/Utils.h src/Dialog_Base_Partition.cc src/Dialog_Disklabel.cc src/Dialog_Filesystems.cc @@ -14,6 +13,7 @@ src/GParted_Core.cc src/Operation.cc src/Partition.cc src/TreeView_Detail.cc +src/Utils.cc src/VBox_VisualDisk.cc src/Win_GParted.cc src/main.cc diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc index 30400cdc..f89b16cb 100644 --- a/src/Dialog_Base_Partition.cc +++ b/src/Dialog_Base_Partition.cc @@ -51,21 +51,21 @@ Dialog_Base_Partition::Dialog_Base_Partition( ) vbox_resize_move .pack_start( hbox_table, Gtk::PACK_SHRINK ); //add spinbutton_before - table_resize.attach( * mk_label( (Glib::ustring) _( "Free Space Preceding (MB):") + " \t" ), 0, 1, 0, 1, Gtk::SHRINK ); + table_resize.attach( * Utils::mk_label( (Glib::ustring) _( "Free Space Preceding (MB):") + " \t" ), 0, 1, 0, 1, Gtk::SHRINK ); spinbutton_before .set_numeric( true ); spinbutton_before .set_increments( 1, 100 ); table_resize.attach( spinbutton_before, 1, 2, 0, 1, Gtk::FILL ); //add spinbutton_size - table_resize.attach( * mk_label( _( "New Size (MB):" ) ), 0, 1, 1, 2 ); + table_resize.attach( * Utils::mk_label( _( "New Size (MB):" ) ), 0, 1, 1, 2 ); spinbutton_size .set_numeric( true ); spinbutton_size .set_increments( 1, 100 ); table_resize.attach( spinbutton_size, 1, 2, 1, 2, Gtk::FILL ); //add spinbutton_after - table_resize.attach( * mk_label( _( "Free Space Following (MB):") ), 0, 1, 2, 3 ) ; + table_resize.attach( * Utils::mk_label( _( "Free Space Following (MB):") ), 0, 1, 2, 3 ) ; spinbutton_after .set_numeric( true ); spinbutton_after .set_increments( 1, 100 ); @@ -82,9 +82,9 @@ Dialog_Base_Partition::Dialog_Base_Partition( ) spinbutton_after .signal_value_changed( ) .connect( sigc::bind( sigc::mem_fun( *this, &Dialog_Base_Partition::on_spinbutton_value_changed), AFTER) ) ; //pack warning about small differences in values.. - this ->get_vbox( ) ->pack_start( * mk_label( "\n " + (Glib::ustring) _( "NOTE: values on disk may differ slightly from the values entered here.") + "" ), Gtk::PACK_SHRINK ); + this ->get_vbox( ) ->pack_start( * Utils::mk_label( "\n " + (Glib::ustring) _( "NOTE: values on disk may differ slightly from the values entered here.") + "" ), Gtk::PACK_SHRINK ); - this ->get_vbox( ) ->pack_start( * mk_label( "" ), Gtk::PACK_SHRINK ); //filler :-P + this ->get_vbox( ) ->pack_start( * Utils::mk_label( "" ), Gtk::PACK_SHRINK ); //filler :-P this->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL ); this ->show_all_children( ) ; @@ -146,7 +146,7 @@ void Dialog_Base_Partition::Set_Confirm_Button( CONFIRMBUTTON button_type ) break ; case RESIZE_MOVE: image_temp = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_BUTTON ) ); hbox_resize_move .pack_start( *image_temp, Gtk::PACK_EXPAND_PADDING ) ; - hbox_resize_move .pack_start( * mk_label( fixed_start ? _("Resize") : _("Resize/Move") ), Gtk::PACK_EXPAND_PADDING ) ; + hbox_resize_move .pack_start( * Utils::mk_label( fixed_start ? _("Resize") : _("Resize/Move") ), Gtk::PACK_EXPAND_PADDING ) ; button_resize_move .add( hbox_resize_move ) ; this ->add_action_widget ( button_resize_move, Gtk::RESPONSE_OK ) ; @@ -247,9 +247,9 @@ void Dialog_Base_Partition::on_spinbutton_value_changed( SPINBUTTON spinbutton ) //And apply the changes to the visual view... if ( ! fixed_start ) - frame_resizer_base ->set_x_start( Round( spinbutton_before .get_value( ) / MB_PER_PIXEL ) ) ; + frame_resizer_base ->set_x_start( Utils::Round( spinbutton_before .get_value( ) / MB_PER_PIXEL ) ) ; - frame_resizer_base ->set_x_end( 500 - Round( spinbutton_after .get_value( ) / MB_PER_PIXEL ) ) ; + frame_resizer_base ->set_x_end( 500 - Utils::Round( spinbutton_after .get_value( ) / MB_PER_PIXEL ) ) ; frame_resizer_base ->Draw_Partition( ) ; diff --git a/src/Dialog_Disklabel.cc b/src/Dialog_Disklabel.cc index ee1723f2..879607bf 100644 --- a/src/Dialog_Disklabel.cc +++ b/src/Dialog_Disklabel.cc @@ -43,7 +43,7 @@ Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std str_temp = "" ; str_temp += String::ucompose( _("Set Disklabel on %1"), device_path ) ; str_temp += "\n" ; - vbox ->pack_start( * mk_label( str_temp ), Gtk::PACK_SHRINK ); + vbox ->pack_start( * Utils::mk_label( str_temp ), Gtk::PACK_SHRINK ); str_temp = _("A disklabel is a piece of data stored at a well known place on the disk, that indicates where each partition begins and how many sectors it occupies.") ; str_temp += "\n" ; @@ -51,7 +51,7 @@ Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std str_temp += "\n\n" ; str_temp += _("By default GParted creates an msdos disklabel.") ; str_temp += "\n" ; - vbox ->pack_start( * mk_label( str_temp, true, true, true ), Gtk::PACK_SHRINK ); + vbox ->pack_start( * Utils::mk_label( str_temp, true, true, true ), Gtk::PACK_SHRINK ); //advanced str_temp = "" ; @@ -65,7 +65,7 @@ Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std hbox ->set_border_width( 5 ) ; str_temp = _("Select new labeltype:") ; str_temp += "\t" ; - hbox ->pack_start( * mk_label( str_temp ), Gtk::PACK_SHRINK ); + hbox ->pack_start( * Utils::mk_label( str_temp ), Gtk::PACK_SHRINK ); expander_advanced .add( *hbox ) ; //create and add optionmenu @@ -82,7 +82,7 @@ Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std str_temp += String::ucompose( _("WARNING: Creating a new disklabel will erase all data on %1!"), device_path ) ; str_temp += "\n"; - this ->get_vbox( ) ->pack_start( * mk_label( str_temp ), Gtk::PACK_SHRINK ); + this ->get_vbox( ) ->pack_start( * Utils::mk_label( str_temp ), Gtk::PACK_SHRINK ); this ->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL ); this ->add_button( _("Create"), Gtk::RESPONSE_OK ); @@ -95,6 +95,4 @@ Glib::ustring Dialog_Disklabel::Get_Disklabel( ) return labeltypes[ optionmenu_labeltypes .get_history( ) ] ; } - - }//GParted diff --git a/src/Dialog_Filesystems.cc b/src/Dialog_Filesystems.cc index 6f385f61..77802ea0 100644 --- a/src/Dialog_Filesystems.cc +++ b/src/Dialog_Filesystems.cc @@ -54,7 +54,7 @@ void Dialog_Filesystems::Load_Filesystems( const std::vector< FS > & FILESYSTEMS void Dialog_Filesystems::Show_Filesystem( const FS & fs ) { treerow = *( liststore_filesystems ->append( ) ); - treerow[ treeview_filesystems_columns .filesystem ] = Get_Filesystem_String( fs .filesystem ) ; + treerow[ treeview_filesystems_columns .filesystem ] = Utils::Get_Filesystem_String( fs .filesystem ) ; treerow[ treeview_filesystems_columns .create ] = render_icon( fs .create ? Gtk::Stock::APPLY : Gtk::Stock::CANCEL, Gtk::ICON_SIZE_LARGE_TOOLBAR); diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index 85f1e5c3..55dc7d4e 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -47,9 +47,9 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons //now calculate proportional length of partition frame_resizer_base ->set_x_start( 0 ) ; - int x_end = Round( COPIED_LENGTH_MB / ( TOTAL_MB/500.00 ) ) ; //> 500 px only possible with xfs... + int x_end = Utils::Round( COPIED_LENGTH_MB / ( TOTAL_MB/500.00 ) ) ; //> 500 px only possible with xfs... frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ; - frame_resizer_base ->set_used( Round( copied_partition .Get_Used_MB( ) / ( TOTAL_MB/500.00) ) ) ; + frame_resizer_base ->set_used( Utils::Round( copied_partition .Get_Used_MB( ) / ( TOTAL_MB/500.00) ) ) ; fs .MAX = ( ! fs .MAX || fs .MAX > TOTAL_MB ) ? TOTAL_MB : fs .MAX -= BUF ; @@ -72,7 +72,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ; GRIP = false ; - frame_resizer_base ->set_size_limits( Round(fs .MIN / MB_PER_PIXEL), Round(fs .MAX / MB_PER_PIXEL) +1 ) ; + frame_resizer_base ->set_size_limits( Utils::Round(fs .MIN / MB_PER_PIXEL), Utils::Round(fs .MAX / MB_PER_PIXEL) +1 ) ; //set contents of label_minmax Set_MinMax_Text( fs .MIN, fs .MAX ) ; diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index db5abcc4..0bac8873 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -44,10 +44,10 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) hbox = manage( new Gtk::HBox( ) ); hbox ->pack_start( *image, Gtk::PACK_SHRINK ) ; - hbox ->pack_start( * mk_label( " " + (Glib::ustring) _( "Warning:" ) + " " ), Gtk::PACK_SHRINK ) ; + hbox ->pack_start( * Utils::mk_label( " " + (Glib::ustring) _( "Warning:" ) + " " ), Gtk::PACK_SHRINK ) ; frame ->set_label_widget( *hbox ) ; - frame ->add( * mk_label( "" + partition.error + "", true, true, true ) ) ; + frame ->add( * Utils::mk_label( "" + partition.error + "", true, true, true ) ) ; this ->get_vbox() ->pack_start( *frame, Gtk::PACK_SHRINK ) ; } @@ -103,7 +103,7 @@ void Dialog_Partition_Info::init_drawingarea( ) //calculate proportional width of used and unused used = unused = 0 ; - used = Round( (375 - BORDER *2) / ( static_cast (partition .sector_end - partition .sector_start) / partition .sectors_used ) ) ; + used = Utils::Round( (375 - BORDER *2) / ( static_cast (partition .sector_end - partition .sector_start) / partition .sectors_used ) ) ; unused = 375 - used - BORDER *2 ; //allocate some colors @@ -129,44 +129,44 @@ void Dialog_Partition_Info::Display_Info( ) this ->get_vbox( ) ->pack_start( *table, Gtk::PACK_SHRINK ) ; //filesystem - table ->attach( * mk_label( "" + (Glib::ustring) _( "Filesystem:" ) + "" ) , 0, 1, top, bottom, Gtk::FILL ); - table ->attach( * mk_label( Get_Filesystem_String( partition .filesystem ) ), 1, 2, top++, bottom++, Gtk::FILL ); + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Filesystem:" ) + "" ) , 0, 1, top, bottom, Gtk::FILL ); + table ->attach( * Utils::mk_label( Utils::Get_Filesystem_String( partition .filesystem ) ), 1, 2, top++, bottom++, Gtk::FILL ); //size - table ->attach( * mk_label( "" + (Glib::ustring) _( "Size:" ) + "" ), 0,1,top, bottom,Gtk::FILL); - table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Length_MB( ) ) ), 1, 2, top++, bottom++,Gtk::FILL ); + 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 ); if ( partition.sectors_used != -1 ) { //calculate relative diskusage - int percent_used = 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( * mk_label( "" + (Glib::ustring) _( "Used:" ) + "" ), 0,1, top, bottom,Gtk::FILL ) ; - table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Used_MB( ) ) ), 1, 2, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( "\t\t\t( " + num_to_str( percent_used ) + "% )"), 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( String::ucompose( _("%1 MB"), this ->partition .Get_Used_MB( ) ) ), 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( * mk_label( "" + (Glib::ustring) _( "Unused:" ) + "" ), 0,1, top, bottom,Gtk::FILL); - table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Unused_MB( ) ) ), 1, 2, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( "\t\t\t( " + num_to_str( 100 - percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; + 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( "\t\t\t( " + Utils::num_to_str( 100 - percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; } //flags if ( partition.type != GParted::TYPE_UNALLOCATED ) { - table ->attach( * mk_label( "" + (Glib::ustring) _( "Flags:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( partition .flags ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Flags:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( partition .flags ), 1, 2, top++, bottom++, Gtk::FILL ) ; } //one blank line - table ->attach( * mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW ) { //path - table ->attach( * mk_label( "" + (Glib::ustring) _( "Path:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( partition .partition ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Path:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( partition .partition ), 1, 2, top++, bottom++, Gtk::FILL ) ; //realpath (this sucks) char real_path[4096] ; @@ -175,13 +175,13 @@ void Dialog_Partition_Info::Display_Info( ) //only show realpath if it's diffent from the short path... if ( partition.partition != real_path ) { - table ->attach( * mk_label( "" + (Glib::ustring) _( "Real Path:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( real_path ), 1,2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Real Path:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( real_path ), 1,2, top++, bottom++, Gtk::FILL ) ; } //status Glib::ustring str_temp ; - table ->attach( * mk_label( "" + (Glib::ustring) _( "Status:" ) + "" ), 0,1, top, bottom, Gtk::FILL) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Status:" ) + "" ), 0,1, top, bottom, Gtk::FILL) ; if ( partition.busy ) { if ( partition .type == GParted::TYPE_EXTENDED ) @@ -198,23 +198,23 @@ void Dialog_Partition_Info::Display_Info( ) else str_temp = _("Not mounted" ) ; - table ->attach( * mk_label( str_temp ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( str_temp ), 1, 2, top++, bottom++, Gtk::FILL ) ; } //one blank line - table ->attach( * mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; //first sector - table ->attach( * mk_label( "" + (Glib::ustring) _( "First Sector:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( num_to_str( partition.sector_start ) ), 1,2, top++, bottom++,Gtk::FILL); + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "First Sector:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( Utils::num_to_str( partition.sector_start ) ), 1,2, top++, bottom++,Gtk::FILL); //last sector - table ->attach( * mk_label( "" + (Glib::ustring) _( "Last Sector:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( num_to_str( partition.sector_end ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Last Sector:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( Utils::num_to_str( partition.sector_end ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; //total sectors - table ->attach( * mk_label( "" + (Glib::ustring) _( "Total Sectors:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; - table ->attach( * mk_label( num_to_str( partition .sector_end - partition .sector_start ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( "" + (Glib::ustring) _( "Total Sectors:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ) ; + table ->attach( * Utils::mk_label( Utils::num_to_str( partition .sector_end - partition .sector_start ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; } Dialog_Partition_Info::~Dialog_Partition_Info( ) diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index dc3dfa82..46afd656 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -50,7 +50,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten hbox_main .pack_start( table_create, Gtk::PACK_SHRINK ); /*TO TRANSLATORS: used as label for a list of choices. Create as: */ - table_create.attach( * mk_label( (Glib::ustring) _("Create as:") + "\t" ), 0, 1, 0, 1, Gtk::FILL); + table_create.attach( * Utils::mk_label( (Glib::ustring) _("Create as:") + "\t" ), 0, 1, 0, 1, Gtk::FILL); //fill partitiontype menu menu_type .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("Primary Partition") ) ) ; @@ -77,7 +77,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten table_create .attach( optionmenu_type, 1, 2, 0, 1, Gtk::FILL ); //filesystems to choose from - table_create.attach( * mk_label( (Glib::ustring) _("Filesystem:") + "\t" ), 0, 1, 1, 2, Gtk::FILL ); + table_create.attach( * Utils::mk_label( (Glib::ustring) _("Filesystem:") + "\t" ), 0, 1, 1, 2, Gtk::FILL ); Build_Filesystems_Menu( only_unformatted ) ; @@ -163,7 +163,7 @@ void Dialog_Partition_New::optionmenu_changed( bool type ) { if ( optionmenu_type .get_history( ) == GParted::TYPE_EXTENDED && menu_filesystem .items( ) .size( ) < FILESYSTEMS .size( ) ) { - menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( Get_Filesystem_String( GParted::FS_EXTENDED ) ) ) ; + menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( Utils::Get_Filesystem_String( GParted::FS_EXTENDED ) ) ) ; optionmenu_filesystem .set_history( menu_filesystem .items( ) .size( ) -1 ) ; optionmenu_filesystem .set_sensitive( false ) ; } @@ -204,7 +204,7 @@ void Dialog_Partition_New::optionmenu_changed( bool type ) frame_resizer_base ->override_default_rgb_unused_color( color_temp ); //partitioncolor.. - color_temp .set( Get_Color( fs .filesystem ) ) ; + color_temp .set( Utils::Get_Color( fs .filesystem ) ) ; frame_resizer_base ->set_rgb_partition_color( color_temp ) ; frame_resizer_base ->Draw_Partition( ) ; @@ -215,7 +215,7 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted ) //fill the filesystem menu with the filesystems (except for extended) for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) -1 ; t++ ) { - menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( Get_Filesystem_String( FILESYSTEMS[ t ] .filesystem ) ) ) ; + menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( Utils::Get_Filesystem_String( FILESYSTEMS[ t ] .filesystem ) ) ) ; menu_filesystem .items( )[ t ] .set_sensitive( ! only_unformatted && FILESYSTEMS[ t ] .create && this ->selected_partition .Get_Length_MB() >= FILESYSTEMS[ t ] .MIN ) ; } diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index 5c0cdda7..b5a8accf 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -99,14 +99,14 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector set_x_start( Round( previous / ( total_length / 500.00 ) ) ) ; - frame_resizer_base ->set_x_end( Round( (selected_partition .sector_end - selected_partition .sector_start) / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start( ) ) ; - frame_resizer_base ->set_used( Round( selected_partition.sectors_used / ( total_length / 500.00 ) ) ) ; + frame_resizer_base ->set_x_start( Utils::Round( previous / ( total_length / 500.00 ) ) ) ; + frame_resizer_base ->set_x_end( Utils::Round( (selected_partition .sector_end - selected_partition .sector_start) / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start( ) ) ; + frame_resizer_base ->set_used( Utils::Round( selected_partition.sectors_used / ( total_length / 500.00 ) ) ) ; if ( fs .shrink ) { @@ -130,7 +130,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector set_size_limits( Round( fs .MIN / MB_PER_PIXEL ), Round( fs .MAX / MB_PER_PIXEL ) +1 ) ; + frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / MB_PER_PIXEL ), Utils::Round( fs .MAX / MB_PER_PIXEL ) +1 ) ; //set contents of label_minmax Set_MinMax_Text( fs .MIN, fs .MAX ) ; @@ -171,12 +171,12 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector set_x_start( Round( previous / ( total_length / 500.00 ) ) ) ; - frame_resizer_base ->set_x_end( Round( (selected_partition .sector_end - selected_partition .sector_start) / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start( ) ) ; + frame_resizer_base ->set_x_start( Utils::Round( previous / ( total_length / 500.00 ) ) ) ; + frame_resizer_base ->set_x_end( Utils::Round( (selected_partition .sector_end - selected_partition .sector_start) / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start( ) ) ; //used is a bit different here... we consider start of first logical to end last logical as used space Sector first =0, used =0 ; @@ -191,22 +191,22 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector set_used_start( Round( (first - START) / ( total_length / 500.00 ) ) ) ; - frame_resizer_base ->set_used( Round( used / ( total_length / 500.00 ) ) ) ; + frame_resizer_base ->set_used_start( Utils::Round( (first - START) / ( total_length / 500.00 ) ) ) ; + frame_resizer_base ->set_used( Utils::Round( used / ( total_length / 500.00 ) ) ) ; //set values of spinbutton_before (we assume there is no fixed start.) if ( first == 0 ) //no logicals spinbutton_before .set_range( 0, TOTAL_MB - BUF/2 ) ; else - spinbutton_before .set_range( 0, Sector_To_MB (first - START) ) ; + spinbutton_before .set_range( 0, Utils::Sector_To_MB (first - START) ) ; - spinbutton_before .set_value( Sector_To_MB ( previous ) ) ; + spinbutton_before .set_value( Utils::Sector_To_MB ( previous ) ) ; //set values of spinbutton_size if ( first == 0 ) //no logicals spinbutton_size .set_range( BUF/2, TOTAL_MB ) ; else - spinbutton_size .set_range( Sector_To_MB( used ), TOTAL_MB ) ; + spinbutton_size .set_range( Utils::Sector_To_MB( used ), TOTAL_MB ) ; spinbutton_size .set_value( selected_partition .Get_Length_MB( ) ) ; @@ -214,12 +214,12 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector get_vbox( ) ->pack_start( * mk_label( str_temp ), Gtk::PACK_SHRINK ); + this ->get_vbox( ) ->pack_start( * Utils::mk_label( str_temp ), Gtk::PACK_SHRINK ); progressbar_current .set_pulse_step( 0.01 ) ; progressbar_current .set_size_request( 500, -1 ) ; @@ -58,7 +58,7 @@ Dialog_Progress::Dialog_Progress( int count_operations, Glib::RefPtrget_vbox( ) ->pack_start( scrolledwindow, Gtk::PACK_SHRINK ); - this ->get_vbox( ) ->pack_start( * mk_label( "\n" + static_cast( _( "Completed Operations" ) ) + ":" ), Gtk::PACK_SHRINK ); + this ->get_vbox( ) ->pack_start( * Utils::mk_label( "\n" + static_cast( _( "Completed Operations" ) ) + ":" ), Gtk::PACK_SHRINK ); this ->get_vbox( ) ->pack_start( progressbar_all, Gtk::PACK_SHRINK ); this ->get_vbox( ) ->set_spacing( 5 ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 0f65390f..8b2eb5d0 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -108,7 +108,7 @@ void GParted_Core::get_devices( std::vector & devices ) temp_device .sectors = lp_device ->bios_geom .sectors ; temp_device .cylinders = lp_device ->bios_geom .cylinders ; temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ; - temp_device .cylsize = Sector_To_MB( temp_device .heads * temp_device .sectors ) ; + temp_device .cylsize = Utils::Sector_To_MB( temp_device .heads * temp_device .sectors ) ; //make sure cylsize is at least 1 MB if ( temp_device .cylsize < 1 ) @@ -222,7 +222,7 @@ void GParted_Core::set_device_partitions( Device & device ) case PED_PARTITION_NORMAL: case PED_PARTITION_LOGICAL: partition_temp .Set( device .path, - device .path + num_to_str( lp_partition ->num ), + device .path + Utils::num_to_str( lp_partition ->num ), lp_partition ->num, lp_partition ->type == 0 ? GParted::TYPE_PRIMARY : GParted::TYPE_LOGICAL, Get_Filesystem( ), lp_partition ->geom .start, @@ -239,7 +239,7 @@ void GParted_Core::set_device_partitions( Device & device ) case PED_PARTITION_EXTENDED: partition_temp.Set( device .path, - device .path + num_to_str( lp_partition ->num ), + device .path + Utils::num_to_str( lp_partition ->num ), lp_partition ->num , GParted::TYPE_EXTENDED , GParted::FS_EXTENDED , @@ -882,7 +882,7 @@ bool GParted_Core::set_partition_type( const Partition & partition ) if ( open_device_and_disk( partition .device_path ) ) { - PedFileSystemType * fs_type = ped_file_system_type_get( Get_Filesystem_String( partition .filesystem ) .c_str() ) ; + PedFileSystemType * fs_type = ped_file_system_type_get( Utils::Get_Filesystem_String( partition .filesystem ) .c_str() ) ; //default is Linux (83) if ( ! fs_type ) diff --git a/src/Makefile.am b/src/Makefile.am index d73f3561..40ccd790 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ gparted_SOURCES = \ Operation.cc\ Partition.cc\ TreeView_Detail.cc\ + Utils.cc\ VBox_VisualDisk.cc\ Win_GParted.cc\ ext2.cc\ diff --git a/src/Operation.cc b/src/Operation.cc index 2de26a47..aa805acd 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -51,7 +51,7 @@ Glib::ustring Operation::Get_String( ) /*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 2345 MB) from /dev/hda */ return String::ucompose( _("Delete %1 (%2, %3 MB) from %4"), temp, - Get_Filesystem_String( partition_original .filesystem ), + Utils::Get_Filesystem_String( partition_original .filesystem ), partition_original .Get_Length_MB( ), device .path ) ; @@ -75,7 +75,7 @@ Glib::ustring Operation::Get_String( ) return String::ucompose( _("Create %1 #%2 (%3, %4 MB) on %5"), temp, partition_new.partition_number, - Get_Filesystem_String( partition_new.filesystem ), + Utils::Get_Filesystem_String( partition_new.filesystem ), partition_new .Get_Length_MB( ), device .path ) ; @@ -85,9 +85,9 @@ Glib::ustring Operation::Get_String( ) if ( diff >= MEGABYTE ) { if ( partition_new .sector_start > partition_original .sector_start ) - temp = String::ucompose( _("Move %1 forward by %2 MB"), partition_new.partition, Sector_To_MB( diff ) ) ; + temp = String::ucompose( _("Move %1 forward by %2 MB"), partition_new.partition, Utils::Sector_To_MB( diff ) ) ; else - temp = String::ucompose( _("Move %1 backward by %2 MB"), partition_new.partition, Sector_To_MB( diff ) ) ; + temp = String::ucompose( _("Move %1 backward by %2 MB"), partition_new.partition, Utils::Sector_To_MB( diff ) ) ; } //check if size has changed ( we only consider changes >= 1 MB ) @@ -116,15 +116,15 @@ Glib::ustring Operation::Get_String( ) /*TO TRANSLATORS: looks like Convert /dev/hda4 from ntfs to linux-swap */ return String::ucompose( _( "Convert %1 from %2 to %3"), partition_original .partition, - Get_Filesystem_String( partition_original .filesystem ), - Get_Filesystem_String( partition_new .filesystem ) ) ; + Utils::Get_Filesystem_String( partition_original .filesystem ), + Utils::Get_Filesystem_String( partition_new .filesystem ) ) ; case COPY : /*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 2500 MB) */ return String::ucompose( _("Copy %1 to %2 (start at %3 MB)"), partition_new .partition, device .path, - Sector_To_MB( partition_new .sector_start ) ) ; + Utils::Sector_To_MB( partition_new .sector_start ) ) ; default : return ""; diff --git a/src/Partition.cc b/src/Partition.cc index c2476f24..52bf7fa2 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -54,7 +54,7 @@ void Partition::Set( const Glib::ustring & device_path, this ->filesystem = filesystem; this ->sector_start = sector_start; this ->sector_end = sector_end; - this ->color.set( Get_Color( filesystem ) ); + this ->color.set( Utils::Get_Color( filesystem ) ); this ->inside_extended = inside_extended; this ->busy = busy; } @@ -70,7 +70,7 @@ void Partition::Set_Unused( Sector sectors_unused ) void Partition::Set_Unallocated( const Glib::ustring & device_path, Sector sector_start, Sector sector_end, bool inside_extended ) { - this ->Set( device_path, Get_Filesystem_String( GParted::FS_UNALLOCATED ), -1, GParted::TYPE_UNALLOCATED, GParted::FS_UNALLOCATED, sector_start, sector_end, inside_extended, false ); + this ->Set( device_path, Utils::Get_Filesystem_String( GParted::FS_UNALLOCATED ), -1, GParted::TYPE_UNALLOCATED, GParted::FS_UNALLOCATED, sector_start, sector_end, inside_extended, false ); this ->error = this ->flags = "" ; this ->status = GParted::STAT_REAL ; } @@ -79,17 +79,17 @@ void Partition::Update_Number( int new_number ) { //of course this fails when we have devicenames with numbers over 99 partition = partition .substr( 0, partition .length( ) - ( partition_number >= 10 ? 2 : 1 ) ) ; this ->partition_number = new_number; - this ->partition += num_to_str( partition_number ) ; + this ->partition += Utils::num_to_str( partition_number ) ; } const long Partition::Get_Length_MB( ) const { - return Sector_To_MB( sector_end - sector_start ) ; + return Utils::Sector_To_MB( sector_end - sector_start ) ; } const long Partition::Get_Used_MB( ) const { - return Sector_To_MB( this ->sectors_used ) ; + return Utils::Sector_To_MB( this ->sectors_used ) ; } const long Partition::Get_Unused_MB( ) const diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index deaac9ac..c4792d1f 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -144,24 +144,24 @@ void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, const Partition treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON ); treerow[ treeview_detail_columns .partition ] = partition .partition; - treerow[ treeview_detail_columns .color ] = Get_Color( partition .filesystem ) ; + treerow[ treeview_detail_columns .color ] = Utils::Get_Color( partition .filesystem ) ; treerow[ treeview_detail_columns .text_color ] = ( partition .type == GParted::TYPE_UNALLOCATED ) ? "darkgrey" : "black" ; - treerow[ treeview_detail_columns .type ] = Get_Filesystem_String( partition .filesystem ) ; + treerow[ treeview_detail_columns .type ] = Utils::Get_Filesystem_String( partition .filesystem ) ; treerow[ treeview_detail_columns .type_square ] = "██" ; //size - treerow[ treeview_detail_columns .size ] = num_to_str( partition .Get_Length_MB( ) ) ; + treerow[ treeview_detail_columns .size ] = Utils::num_to_str( partition .Get_Length_MB( ) ) ; //used if ( partition .sectors_used != -1 ) - treerow[ treeview_detail_columns .used ] = num_to_str( partition .Get_Used_MB( ) ) ; + treerow[ treeview_detail_columns .used ] = Utils::num_to_str( partition .Get_Used_MB( ) ) ; else treerow[ treeview_detail_columns .used ] = "---" ; //unused if ( partition .sectors_unused != -1 ) - treerow[ treeview_detail_columns .unused ] = num_to_str( partition .Get_Unused_MB( ) ) ; + treerow[ treeview_detail_columns .unused ] = Utils::num_to_str( partition .Get_Unused_MB( ) ) ; else treerow[ treeview_detail_columns .unused ] = "---" ; diff --git a/src/Utils.cc b/src/Utils.cc new file mode 100644 index 00000000..eb499087 --- /dev/null +++ b/src/Utils.cc @@ -0,0 +1,117 @@ +/* Copyright (C) 2004 Bart 'plors' Hakvoort + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "../include/Utils.h" + +#include +//#include + +namespace GParted +{ + +long Utils::Round( double double_value ) +{ + return static_cast( double_value + 0.5 ) ; +} + +long Utils::Sector_To_MB( Sector sectors ) +{ + return Round( sectors * 0.000488281250 ) ; // that's what 512/1024/1024 gives you :) +} + +Gtk::Label * Utils::mk_label( const Glib::ustring & text, bool use_markup, bool align_left, bool wrap, const Glib::ustring & text_color ) +{ + Gtk::Label * label = manage( new Gtk::Label( text ) ) ; + + label ->set_use_markup( use_markup ) ; + + if ( align_left ) + label ->set_alignment( Gtk::ALIGN_LEFT ) ; + + label ->set_line_wrap( wrap ) ; + + if ( text_color != "black" ) + { + Gdk::Color color( text_color ) ; + label ->modify_fg( label ->get_state( ), color ) ; + } + + return label ; +} + +Glib::ustring Utils::num_to_str( Sector number, bool use_C_locale ) +{ + std::stringstream ss ; + //ss.imbue( std::locale( use_C_locale ? "C" : "" ) ) ; see #157871 + ss << number ; + return ss .str( ) ; +} + +//use http://developer.gnome.org/projects/gup/hig/2.0/design.html#Palette as a starting point.. +Glib::ustring Utils::Get_Color( FILESYSTEM filesystem ) +{ + switch( filesystem ) + { + case FS_UNALLOCATED : return "darkgrey" ; + case FS_UNKNOWN : return "black" ; + case FS_UNFORMATTED : return "black" ; + case FS_EXTENDED : return "#7DFCFE" ; + case FS_EXT2 : return "#9DB8D2" ; + case FS_EXT3 : return "#7590AE" ; + case FS_LINUX_SWAP : return "#C1665A" ; + case FS_FAT16 : return "green" ; + case FS_FAT32 : return "#18D918" ; + case FS_NTFS : return "#42E5AC" ; + case FS_REISERFS : return "#ADA7C8" ; + case FS_REISER4 : return "#887FA3" ; + case FS_XFS : return "#EED680" ; + case FS_JFS : return "#E0C39E" ; + case FS_HFS : return "#E0B6AF" ; + case FS_HFSPLUS : return "#C0A39E" ; + case FS_UFS : return "#D1940C" ; + + default : return "black" ; + } +} + +Glib::ustring Utils::Get_Filesystem_String( FILESYSTEM filesystem ) +{ + switch( filesystem ) + { + case FS_UNALLOCATED : return _("unallocated") ; + case FS_UNKNOWN : return _("unknown") ; + case FS_UNFORMATTED : return _("unformatted") ; + case FS_EXTENDED : return "extended" ; + case FS_EXT2 : return "ext2" ; + case FS_EXT3 : return "ext3" ; + case FS_LINUX_SWAP : return "linux-swap" ; + case FS_FAT16 : return "fat16" ; + case FS_FAT32 : return "fat32" ; + case FS_NTFS : return "ntfs" ; + case FS_REISERFS : return "reiserfs" ; + case FS_REISER4 : return "reiser4" ; + case FS_XFS : return "xfs" ; + case FS_JFS : return "jfs" ; + case FS_HFS : return "hfs" ; + case FS_HFSPLUS : return "hfs+" ; + case FS_UFS : return "ufs" ; + + default : return "" ; + } +} + +} //GParted.. diff --git a/src/VBox_VisualDisk.cc b/src/VBox_VisualDisk.cc index a7aa1d45..cb58f820 100644 --- a/src/VBox_VisualDisk.cc +++ b/src/VBox_VisualDisk.cc @@ -46,7 +46,7 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con //since disksegments have minimal sizes ( unallocated 15 and partitions 20 pixels ) i do some checking to prevent the visual disk from growing to much - Sector sectors_per_pixel = Round( device_length / 750.00 ) ; + Sector sectors_per_pixel = Utils::Round( device_length / 750.00 ) ; double extra_pixels = 0 ; @@ -61,7 +61,7 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con } //draw visual disk and its legend - this ->SCREEN_WIDTH = 750 - Round( extra_pixels ) ; + this ->SCREEN_WIDTH = 750 - Utils::Round( extra_pixels ) ; Build_Visual_Disk( ) ; Build_Legend( ) ; @@ -167,7 +167,7 @@ void VBox_VisualDisk::Create_Visual_Partition( const Partition & partition ) //tooltip str_temp = "" ; if ( partition .type != GParted::TYPE_UNALLOCATED ) - str_temp = Get_Filesystem_String( partition .filesystem ) + "\n" ; + str_temp = Utils::Get_Filesystem_String( partition .filesystem ) + "\n" ; str_temp += partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB( ) ) ; tooltips .set_tip( *( visual_partitions.back( ) ->drawingarea ), str_temp ) ; @@ -206,19 +206,19 @@ void VBox_VisualDisk::Build_Legend( ) hide_used_unused = false ; if ( t ) - hbox_legend ->pack_start( * mk_label( " " ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK ); else - hbox_legend ->pack_start( * mk_label( " " ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK ); - hbox_legend ->pack_start( * mk_label( "██ ", false, false, false, Get_Color( legend[ t ] ) ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( "██ ", false, false, false, Utils::Get_Color( legend[ t ] ) ), Gtk::PACK_SHRINK ); if ( legend[ t ] == GParted::FS_UNALLOCATED ) { - str_temp = Get_Filesystem_String( GParted::FS_UNALLOCATED ) ;//_("unallocated") ; - hbox_legend ->pack_start( * mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); + str_temp = Utils::Get_Filesystem_String( GParted::FS_UNALLOCATED ) ;//_("unallocated") ; + hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); } else - hbox_legend ->pack_start( * mk_label( Get_Filesystem_String( legend[ t ] ) + " " ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( legend[ t ] ) + " " ), Gtk::PACK_SHRINK ); } //if there are any partitions add used/unused @@ -231,12 +231,12 @@ void VBox_VisualDisk::Build_Legend( ) hbox_legend ->set_border_width( 2 ) ; frame_disk_legend ->add( *hbox_legend ); - hbox_legend ->pack_start( * mk_label( " ██ ", false, false, false, "#F8F8BA" ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( " ██ ", false, false, false, "#F8F8BA" ), Gtk::PACK_SHRINK ); str_temp = _("used") ; - hbox_legend ->pack_start( * mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); - hbox_legend ->pack_start( * mk_label( "██ ", false, false, false, "white" ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( "██ ", false, false, false, "white" ), Gtk::PACK_SHRINK ); str_temp = _("unused") ; - hbox_legend ->pack_start( * mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); + hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK ); } } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index d9f5d6aa..1f6aa3de 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -197,7 +197,7 @@ void Win_GParted::init_convert_menu() { for ( unsigned int t=0; t < gparted_core .get_filesystems( ) .size( ) -1 ; t++ ) { - color .set( Get_Color( gparted_core .get_filesystems( )[ t ] .filesystem ) ); + color .set( Utils::Get_Color( gparted_core .get_filesystems( )[ t ] .filesystem ) ); hbox = manage( new Gtk::HBox( ) ); //the colored square @@ -208,7 +208,7 @@ void Win_GParted::init_convert_menu() hbox ->pack_start( *entry, Gtk::PACK_SHRINK ); //the label... - hbox ->pack_start( * mk_label( " " + Get_Filesystem_String( gparted_core .get_filesystems( )[ t ] .filesystem ) ), Gtk::PACK_SHRINK ); + hbox ->pack_start( * Utils::mk_label( " " + Utils::Get_Filesystem_String( gparted_core .get_filesystems( )[ t ] .filesystem ) ), Gtk::PACK_SHRINK ); menu_item = manage( new Gtk::MenuItem( *hbox ) ) ; menu_convert.items( ) .push_back( *menu_item ); @@ -224,30 +224,30 @@ void Win_GParted::init_device_info() int top =0, bottom = 1; //title - vbox_info .pack_start( * mk_label( " " + (Glib::ustring) _( "Harddisk Information" ) + ":" ), Gtk::PACK_SHRINK ); + vbox_info .pack_start( * Utils::mk_label( " " + (Glib::ustring) _( "Harddisk Information" ) + ":" ), Gtk::PACK_SHRINK ); //GENERAL DEVICE INFO table = manage( new Gtk::Table() ) ; table ->set_col_spacings( 10 ) ; //model - table ->attach( * mk_label( " " + (Glib::ustring) _( "Model:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Model:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back(), 1,2, top++, bottom++, Gtk::FILL); //size - table ->attach( * mk_label( " " + (Glib::ustring) _( "Size:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Size:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back(), 1,2, top++, bottom++, Gtk::FILL); //path - table ->attach( * mk_label( " " + (Glib::ustring) _( "Path:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Path:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back(), 1,2, top++, bottom++, Gtk::FILL); //real path - table ->attach( * mk_label( " " + (Glib::ustring) _( "Real Path:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Real Path:" ) + "" ) , 0,1,top, bottom ,Gtk::FILL); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back(), 1,2, top++, bottom++, Gtk::FILL); vbox_info .pack_start( *table, Gtk::PACK_SHRINK ); @@ -258,31 +258,31 @@ void Win_GParted::init_device_info() table ->set_col_spacings( 10 ) ; //one blank line - table ->attach( * mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ); + table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ); //disktype - table ->attach( * mk_label( " " + (Glib::ustring) _( "DiskLabelType:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "DiskLabelType:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL ); //heads - table ->attach( * mk_label( " " + (Glib::ustring) _( "Heads:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Heads:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL ); //sectors/track - table ->attach( * mk_label( " " + (Glib::ustring) _( "Sectors/Track:" ) + "" ) , 0, 1, top, bottom, Gtk::FILL ); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Sectors/Track:" ) + "" ) , 0, 1, top, bottom, Gtk::FILL ); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL ); //cylinders - table ->attach( * mk_label( " " + (Glib::ustring) _( "Cylinders:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Cylinders:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL ); //total sectors - table ->attach( * mk_label( " " + (Glib::ustring) _( "Total Sectors:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); - device_info .push_back( mk_label( "" ) ) ; + table ->attach( * Utils::mk_label( " " + (Glib::ustring) _( "Total Sectors:" ) + "" ), 0, 1, top, bottom, Gtk::FILL ); + device_info .push_back( Utils::mk_label( "" ) ) ; table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL ); vbox_info .pack_start( *table, Gtk::PACK_SHRINK ); @@ -365,7 +365,7 @@ void Win_GParted::Refresh_OptionMenu( ) hbox ->pack_start( *image, Gtk::PACK_SHRINK ); //the label... - hbox ->pack_start( *mk_label( " " + devices[ i ] .path + "\t(" + String::ucompose( _("%1 MB"), Sector_To_MB( devices[ i ] .length ) ) + ")" ), Gtk::PACK_SHRINK ); + hbox ->pack_start( *Utils::mk_label( " " + devices[ i ] .path + "\t(" + String::ucompose( _("%1 MB"), Utils::Sector_To_MB( devices[ i ] .length ) ) + ")" ), Gtk::PACK_SHRINK ); menu_item = manage( new Gtk::MenuItem( *hbox ) ) ; optionmenu_devices .get_menu( ) ->items( ) .push_back( *menu_item ); @@ -422,16 +422,16 @@ 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"), Sector_To_MB( devices[ current_device ] .length ) ) ) ; + device_info[ t++ ] ->set_text( String::ucompose( _("%1 MB"), Utils::Sector_To_MB( devices[ current_device ] .length ) ) ) ; device_info[ t++ ] ->set_text( devices[ current_device ] .path ) ; device_info[ t++ ] ->set_text( devices[ current_device ] .realpath ) ; //detailed info device_info[ t++ ] ->set_text( devices[ current_device ] .disktype ) ; - device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .heads ) ); - device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .sectors ) ); - device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .cylinders ) ); - device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .length ) ); + device_info[ t++ ] ->set_text( Utils::num_to_str( devices[ current_device ] .heads ) ); + device_info[ t++ ] ->set_text( Utils::num_to_str( devices[ current_device ] .sectors ) ); + device_info[ t++ ] ->set_text( Utils::num_to_str( devices[ current_device ] .cylinders ) ); + device_info[ t++ ] ->set_text( Utils::num_to_str( devices[ current_device ] .length ) ); } } @@ -940,7 +940,7 @@ void Win_GParted::activate_resize( ) image = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_BUTTON ) ); hbox_resize_move .pack_start( *image, Gtk::PACK_SHRINK ) ; - hbox_resize_move .pack_start( * mk_label( _("Resize/Move") ), Gtk::PACK_SHRINK ) ; + hbox_resize_move .pack_start( * Utils::mk_label( _("Resize/Move") ), Gtk::PACK_SHRINK ) ; button_resize_move .add( hbox_resize_move ) ; dialog .add_action_widget( button_resize_move, Gtk::RESPONSE_OK ) ; @@ -1120,7 +1120,7 @@ void Win_GParted::activate_convert( GParted::FILESYSTEM new_fs ) { //standard warning.. str_temp = "" ; - str_temp += String::ucompose( _("Are you sure you want to convert this filesystem to %1?"), Get_Filesystem_String( new_fs ) ) + "\n\n" ; + str_temp += String::ucompose( _("Are you sure you want to convert this filesystem to %1?"), Utils::Get_Filesystem_String( new_fs ) ) + "\n\n" ; str_temp += String::ucompose( _("This operation will destroy all data on %1"), selected_partition .partition ) ; Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_CANCEL, true ); @@ -1139,13 +1139,13 @@ void Win_GParted::activate_convert( GParted::FILESYSTEM new_fs ) if ( selected_partition .Get_Length_MB( ) < fs .MIN || ( fs .MAX && selected_partition .Get_Length_MB( ) > fs .MAX ) ) { str_temp = "" ; - str_temp += String::ucompose( _("Can not convert this filesystem to %1."), Get_Filesystem_String( new_fs ) ) ; + str_temp += String::ucompose( _("Can not convert this filesystem to %1."), Utils::Get_Filesystem_String( new_fs ) ) ; str_temp += "\n\n" ; if ( selected_partition .Get_Length_MB( ) < fs .MIN ) - str_temp += String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MB."), Get_Filesystem_String( new_fs ), fs .MIN ) ; + str_temp += String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MB."), Utils::Get_Filesystem_String( new_fs ), fs .MIN ) ; else - str_temp += String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MB."), Get_Filesystem_String( new_fs ), fs .MAX ) ; + str_temp += String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MB."), Utils::Get_Filesystem_String( new_fs ), fs .MAX ) ; Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true ); diff --git a/src/ext2.cc b/src/ext2.cc index 83e51708..d988c2ca 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -88,7 +88,7 @@ bool ext2::Resize( const Partition & partition_new, bool fill_partition ) Glib::ustring str_temp = "resize2fs " + partition_new .partition ; if ( ! fill_partition ) - str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; + str_temp += " " + Utils::num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; return ! Execute_Command( str_temp ) ; } diff --git a/src/ext3.cc b/src/ext3.cc index c5eaddb9..669679a1 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -88,7 +88,7 @@ bool ext3::Resize( const Partition & partition_new, bool fill_partition ) Glib::ustring str_temp = "resize2fs " + partition_new .partition ; if ( ! fill_partition ) - str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; + str_temp += " " + Utils::num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; return ! Execute_Command( str_temp ) ; } diff --git a/src/ntfs.cc b/src/ntfs.cc index ca19df53..fa3929db 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -84,7 +84,7 @@ bool ntfs::Resize( const Partition & partition_new, bool fill_partition ) Glib::ustring str_temp = "echo y | ntfsresize -f " + partition_new .partition ; if ( ! fill_partition ) - str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; + str_temp += " -s " + Utils::num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; return ! Execute_Command( str_temp ) ; } diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 6b153163..549d45c2 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -92,7 +92,7 @@ bool reiserfs::Resize( const Partition & partition_new, bool fill_partition ) Glib::ustring str_temp = "echo y | resize_reiserfs " + partition_new .partition ; if ( ! fill_partition ) - str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; + str_temp += " -s " + Utils::num_to_str( partition_new .Get_Length_MB( ) - cylinder_size, true ) + "M" ; return ! Execute_Command( str_temp ) ; }