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.
This commit is contained in:
Bart Hakvoort 2004-10-21 11:13:37 +00:00
parent 641c4504bf
commit 32cd2f2548
3 changed files with 54 additions and 40 deletions

View File

@ -1,3 +1,8 @@
2004-10-21 Bart Hakvoort <gparted@users.sf.net>
* 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 <gparted@users.sf.net>
* src/Dialog_Base_Partition.cc (Get_New_Partition): Tweaked resizingbehaviour a bit. This solved some minor annoyances.

View File

@ -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 <Partition> & partitions ) ;
private:
void Resize_Move_Normal( const std::vector <Partition> & partitions ) ;
void Resize_Move_Extended( const std::vector <Partition> & partitions ) ;
short BUF ; //added to the min. size a filesystem can be..( safety reasons )
};

View File

@ -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 <Partition> & 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 <Partition> & partitions )
@ -86,52 +87,58 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector <Partit
Sector previous, next ;
previous = next = 0 ;
//also check the partitions filesystem ( if this is ext2/3 or reiserfs then previous should be 0 )
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 )
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 <Part
MB_PER_PIXEL = (double) TOTAL_MB / 500 ;
//calculate proportional length of partition ( in pixels )
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_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 <Part
}
}
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) ) ) ;
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 ) ) ;