From 32cd2f2548c09c1c029d9343d74756e75d68255c Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 21 Oct 2004 11:13:37 +0000 Subject: [PATCH] fixed some bugs with minimum size of resizable partition + some * include/Dialog_Partition_Resize_Move.h, src/Dialog_Partition_Resize_Move.cc: fixed some bugs with minimum size of resizable partition + some codecleanups. --- ChangeLog | 5 ++ include/Dialog_Partition_Resize_Move.h | 4 +- src/Dialog_Partition_Resize_Move.cc | 85 ++++++++++++++------------ 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1c7d3f7..99d41223 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-10-21 Bart Hakvoort + + * include/Dialog_Partition_Resize_Move.h, + src/Dialog_Partition_Resize_Move.cc: fixed some bugs with minimum size of resizable partition + some codecleanups. + 2004-10-20 Bart Hakvoort * src/Dialog_Base_Partition.cc (Get_New_Partition): Tweaked resizingbehaviour a bit. This solved some minor annoyances. diff --git a/include/Dialog_Partition_Resize_Move.h b/include/Dialog_Partition_Resize_Move.h index 2920fa21..637809c9 100644 --- a/include/Dialog_Partition_Resize_Move.h +++ b/include/Dialog_Partition_Resize_Move.h @@ -26,12 +26,14 @@ namespace GParted class Dialog_Partition_Resize_Move : public Dialog_Base_Partition { public: - Dialog_Partition_Resize_Move( ) ; + Dialog_Partition_Resize_Move( ) ; void Set_Data( const Partition & selected_partition, const std::vector & partitions ) ; private: void Resize_Move_Normal( const std::vector & partitions ) ; void Resize_Move_Extended( const std::vector & partitions ) ; + + short BUF ; //added to the min. size a filesystem can be..( safety reasons ) }; diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index d73e47ef..acade8c8 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -20,8 +20,9 @@ namespace GParted { -Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( ) +Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( ) { + BUF = 5 ; } void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partition, const std::vector & partitions ) @@ -45,18 +46,18 @@ void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partitio frame_resizer_base ->set_rgb_partition_color( selected_partition .color ) ; //set some initial values... ( i believe i only use these for fat16 checks.. *sigh* ) - this ->x_start = frame_resizer_base ->get_x_start() ; - this ->x_end = frame_resizer_base ->get_x_end() ; + this ->x_start = frame_resizer_base ->get_x_start( ) ; + this ->x_end = frame_resizer_base ->get_x_end( ) ; //store the original values - ORIG_BEFORE = spinbutton_before .get_value_as_int() ; - ORIG_SIZE = spinbutton_size .get_value_as_int() ; - ORIG_AFTER = spinbutton_after .get_value_as_int() ; + ORIG_BEFORE = spinbutton_before .get_value_as_int( ) ; + ORIG_SIZE = spinbutton_size .get_value_as_int( ) ; + ORIG_AFTER = spinbutton_after .get_value_as_int( ) ; GRIP = false ; Set_Confirm_Button( RESIZE_MOVE ) ; - this ->show_all_children() ; + this ->show_all_children( ) ; } void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector & partitions ) @@ -86,52 +87,58 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector = 1 && partitions[t -1].type == GParted::UNALLOCATED && selected_partition.filesystem != "ext2" && selected_partition.filesystem != "ext3" && selected_partition.filesystem != "reiserfs" && partitions[t -1] .inside_extended == selected_partition.inside_extended ) + if ( t >= 1 && partitions[t -1].type == GParted::UNALLOCATED && selected_partition.filesystem != "ext2" && selected_partition.filesystem != "ext3" && selected_partition.filesystem != "reiserfs" && partitions[t -1] .inside_extended == selected_partition.inside_extended ) { - previous = partitions[t -1].sector_end - partitions[t -1].sector_start ; - START = partitions[t -1].sector_start ; + previous = partitions[t -1] .sector_end - partitions[t -1] .sector_start ; + START = partitions[t -1] .sector_start ; } else - START = selected_partition.sector_start ; + START = selected_partition .sector_start ; - if ( t +1 < partitions.size() && partitions[t +1].type == GParted::UNALLOCATED && partitions[t +1] .inside_extended == selected_partition.inside_extended ) + if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::UNALLOCATED && partitions[t +1] .inside_extended == selected_partition .inside_extended ) next = partitions[t +1].sector_end - partitions[t +1].sector_start ; total_length = previous + (selected_partition.sector_end - selected_partition.sector_start) + next; TOTAL_MB = Sector_To_MB( total_length ) ; - MB_PER_PIXEL = (double) TOTAL_MB / 500 ; + MB_PER_PIXEL = (double) TOTAL_MB / 500 ; //now calculate proportional length of partition - frame_resizer_base ->set_x_start( Round( (double) previous / ( (double)total_length/500) ) ) ; - frame_resizer_base ->set_x_end( ( Round( (double) (selected_partition.sector_end - selected_partition.sector_start) / ( (double)total_length/500) )) + frame_resizer_base ->get_x_start() ) ; - frame_resizer_base ->set_used( Round( (double) selected_partition.sectors_used / ( (double)total_length/500) ) ) ; + frame_resizer_base ->set_x_start( Round( (double) previous / ( (double)total_length/500) ) ) ; + frame_resizer_base ->set_x_end( ( Round( (double) (selected_partition.sector_end - selected_partition.sector_start) / ( (double)total_length/500) )) + frame_resizer_base ->get_x_start() ) ; + frame_resizer_base ->set_used( Round( (double) selected_partition.sectors_used / ( (double)total_length/500) ) ) ; - //set values of spinbutton_before - if ( ! fixed_start ) - { - spinbutton_before .set_range( 0, Sector_To_MB(total_length - selected_partition.sectors_used) -1 ) ;//mind the -1 !! - spinbutton_before .set_value( Sector_To_MB( previous ) ) ; - } - //set values of spinbutton_size //since some filesystems have upper and lower limits we need to check for this long LOWER, UPPER; if ( selected_partition.filesystem == "fat16" && selected_partition .Get_Used_MB() < 32 ) - LOWER = 32 +1 ; + LOWER = 32 +BUF ; else if ( selected_partition.filesystem == "fat32" && selected_partition .Get_Used_MB() < 256 ) - LOWER = 256 +1; //when shrinking to 256 the filesystem converts to fat16, thats why i added the 1 + LOWER = 256 +BUF; else if ( selected_partition.filesystem == "reiserfs" && selected_partition .Get_Used_MB() < 40 ) LOWER = 40 ; else - LOWER = selected_partition .Get_Used_MB() +1; + LOWER = selected_partition .Get_Used_MB() +BUF; + + //in certain (rare) case LOWER is a bit too high... + if ( LOWER > selected_partition .Get_Length_MB( ) ) + LOWER = selected_partition .Get_Length_MB( ) ; if ( selected_partition.filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) UPPER = 1023 ; else UPPER = Sector_To_MB( total_length ) ; - spinbutton_size .set_range( LOWER , UPPER ) ; + + //set values of spinbutton_before + if ( ! fixed_start ) + { + spinbutton_before .set_range( 0, Sector_To_MB( total_length ) - LOWER ) ; + spinbutton_before .set_value( Sector_To_MB( previous ) ) ; + } + + //set values of spinbutton_size + spinbutton_size .set_range( LOWER, UPPER ) ; spinbutton_size .set_value( selected_partition .Get_Length_MB() ) ; //set values of spinbutton_after @@ -181,8 +188,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector set_x_start( Round( (double) previous / ( (double)total_length/500) ) ) ; - frame_resizer_base ->set_x_end( ( Round( (double) (selected_partition.sector_end - selected_partition.sector_start) / ( (double)total_length/500) )) + frame_resizer_base ->get_x_start() ) ; + frame_resizer_base ->set_x_start( Round( (double) previous / ( (double)total_length/500) ) ) ; + frame_resizer_base ->set_x_end( ( Round( (double) (selected_partition.sector_end - selected_partition.sector_start) / ( (double)total_length/500) ) ) + 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 ; @@ -197,32 +204,32 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector set_used_start( Round( (double) (first - START) / ( (double)total_length/500) ) ) ; - frame_resizer_base ->set_used( Round( (double) used / ( (double)total_length/500) ) ) ; + frame_resizer_base ->set_used_start( Round( (double) (first - START) / ( (double)total_length/500) ) ) ; + frame_resizer_base ->set_used( Round( (double) used / ( (double)total_length/500) ) ) ; //set values of spinbutton_before (we assume there is no fixed start.) if ( first == 0 ) //no logicals - spinbutton_before .set_range( 0, TOTAL_MB - 1) ; + spinbutton_before .set_range( 0, TOTAL_MB - 1 ) ; else spinbutton_before .set_range( 0, Sector_To_MB (first - START) ) ; - spinbutton_before .set_value( Sector_To_MB ( previous ) ) ; + spinbutton_before .set_value( Sector_To_MB ( previous ) ) ; //set values of spinbutton_size if ( first == 0 ) //no logicals - spinbutton_size .set_range( 1 , TOTAL_MB ) ; + spinbutton_size .set_range( 1, TOTAL_MB ) ; else - spinbutton_size .set_range( Sector_To_MB( used ) , TOTAL_MB ) ; + spinbutton_size .set_range( Sector_To_MB( used ), TOTAL_MB ) ; - spinbutton_size .set_value( selected_partition .Get_Length_MB() ) ; + spinbutton_size .set_value( selected_partition .Get_Length_MB() ) ; //set values of spinbutton_after if ( first == 0 ) //no logicals - spinbutton_after .set_range( 0, TOTAL_MB -1 ) ; + spinbutton_after .set_range( 0, TOTAL_MB -1 ) ; else - spinbutton_after .set_range( 0, Sector_To_MB( total_length + START - first - used) ) ; + spinbutton_after .set_range( 0, Sector_To_MB( total_length + START - first - used) ) ; - spinbutton_after .set_value( Sector_To_MB( next ) ) ; + spinbutton_after .set_value( Sector_To_MB( next ) ) ; //set contents of label_minmax Set_MinMax_Text( Sector_To_MB( used ) +1, Sector_To_MB( total_length ) ) ;