in some places i still used MiB's instead of sectors to store sizes. this

* in some places i still used MiB's instead of sectors to store sizes.
  this has been fixed everywhere. Only the spinbuttons still use
  MiB's. I have a few ideas on how to solve this, but i'll take it up
  with #usability first.
This commit is contained in:
Bart Hakvoort 2006-02-25 10:09:30 +00:00
parent a1ad7dea33
commit 391ca32a2b
23 changed files with 219 additions and 182 deletions

View File

@ -1,3 +1,10 @@
2006-02-25 Bart Hakvoort <hakvoort@cvs.gnome.org>
* in some places i still used MiB's instead of sectors to store sizes.
this has been fixed everywhere. Only the spinbuttons still use
MiB's. I have a few ideas on how to solve this, but i'll take it up
with #usability first.
2006-02-22 Bart Hakvoort <hakvoort@cvs.gnome.org>
* configure.in: bumped to gparted-0.2.2

View File

@ -37,7 +37,7 @@ public:
long heads ;
long sectors ;
long cylinders ;
long cylsize ;//FIXME we should store this one as a Sector
Sector cylsize ;
Glib::ustring model;
Glib::ustring path;
Glib::ustring realpath;

View File

@ -26,7 +26,7 @@ namespace GParted
class Dialog_Partition_Copy : public Dialog_Base_Partition
{
public:
Dialog_Partition_Copy( const FS & fs, long cylinder_size ) ;
Dialog_Partition_Copy( const FS & fs, Sector cylinder_size ) ;
void Set_Data( const Partition & selected_partition, const Partition & copied_partition );
Partition Get_New_Partition( ) ;

View File

@ -30,7 +30,12 @@ class Dialog_Partition_New : public Dialog_Base_Partition
{
public:
Dialog_Partition_New() ;
void Set_Data( const Partition & partition, bool any_extended, unsigned short new_count, const std::vector<FS> & FILESYSTEMS, bool only_unformatted, int cylinder_size );
void Set_Data( const Partition & partition,
bool any_extended,
unsigned short new_count,
const std::vector<FS> & FILESYSTEMS,
bool only_unformatted,
Sector cylinder_size );
Partition Get_New_Partition() ;//overridden function
private:

View File

@ -26,7 +26,7 @@ namespace GParted
class Dialog_Partition_Resize_Move : public Dialog_Base_Partition
{
public:
Dialog_Partition_Resize_Move( const FS & fs, long cylinder_size ) ;
Dialog_Partition_Resize_Move( const FS & fs, Sector cylinder_size ) ;
void Set_Data( const Partition & selected_partition, const std::vector <Partition> & partitions ) ;
private:

View File

@ -69,10 +69,6 @@ public:
//update partition number (used when a logical partition is deleted)
void Update_Number( int new_number );
//FIXME the 3 *MB function are obsolete and should be replaced by Utils::sector_to_unit()
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 ;

View File

@ -97,9 +97,8 @@ struct FS
Support check ; //some checktool available?
Support copy ;
//FIXME: these 2 should hold 'Sectors' instead if MiB's
int MIN ;
int MAX ;
Sector MIN ;
Sector MAX ;
FS()
{

View File

@ -28,8 +28,8 @@ Device::Device()
void Device::Reset()
{
partitions .clear() ;
length = 0 ;
heads = sectors = cylinders = cylsize = 0 ;
length = cylsize = 0 ;
heads = sectors = cylinders = 0 ;
model = path = realpath = disktype = "" ;
max_prims = highest_busy = 0 ;
readonly = false ;

View File

@ -20,7 +20,7 @@
namespace GParted
{
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, long cylinder_size )
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, Sector cylinder_size )
{
this ->fs = fs ;
@ -40,42 +40,49 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
//set some widely used values...
START = selected_partition .sector_start ;
total_length = selected_partition .sector_end - selected_partition .sector_start ;
TOTAL_MB = selected_partition .Get_Length_MB( ) ;
TOTAL_MB = Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
long COPIED_LENGTH_MB = copied_partition .Get_Length_MB( ) ;
long COPIED_LENGTH_MB = Utils::Round( Utils::sector_to_unit( copied_partition .get_length(), GParted::UNIT_MIB ) ) ;
//now calculate proportional length of partition
frame_resizer_base ->set_x_start( 0 ) ;
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( Utils::Round( copied_partition .Get_Used_MB( ) / ( TOTAL_MB/500.00) ) ) ;
frame_resizer_base ->set_used(
Utils::Round( Utils::sector_to_unit(
copied_partition .sectors_used, GParted::UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
fs .MAX = ( ! fs .MAX || fs .MAX > TOTAL_MB ) ? TOTAL_MB : fs .MAX -= BUF ;
fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) ? (TOTAL_MB * MEBIBYTE) : fs .MAX -= BUF ;
if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
fs .MIN = copied_partition .Get_Used_MB( ) + (BUF * 2) ;
fs .MIN = copied_partition .sectors_used + (BUF * 2) ;
else
fs .MIN = COPIED_LENGTH_MB +1 ;
fs .MIN = (COPIED_LENGTH_MB +1) * MEBIBYTE ;
GRIP = true ;
//set values of spinbutton_before
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( 0 ) ;
//set values of spinbutton_size
spinbutton_size .set_range( fs .MIN, fs .MAX ) ;
spinbutton_size .set_range(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value( COPIED_LENGTH_MB ) ;
//set values of spinbutton_after
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ;
GRIP = false ;
frame_resizer_base ->set_size_limits( Utils::Round(fs .MIN / MB_PER_PIXEL), Utils::Round(fs .MAX / MB_PER_PIXEL) +1 ) ;
frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ;
Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
//set global selected_partition (see Dialog_Base_Partition::Get_New_Partition )
this ->selected_partition = copied_partition ;
@ -83,10 +90,10 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
this ->selected_partition .type = selected_partition .inside_extended ? GParted::TYPE_LOGICAL : GParted::TYPE_PRIMARY ;
}
Partition Dialog_Partition_Copy::Get_New_Partition( )
Partition Dialog_Partition_Copy::Get_New_Partition()
{
//first call baseclass to get the correct new partition
selected_partition = Dialog_Base_Partition::Get_New_Partition( ) ;
selected_partition = Dialog_Base_Partition::Get_New_Partition() ;
//set proper name and status for partition
selected_partition .status = GParted::STAT_COPY ;

View File

@ -144,7 +144,7 @@ void Dialog_Partition_Info::Display_Info( )
{
//calculate relative diskusage
int percent_used =
Utils::Round( static_cast<double>(partition .Get_Used_MB() ) / partition .Get_Length_MB() *100 ) ;
Utils::Round( partition .sectors_used / static_cast<double>( partition .get_length() ) * 100 ) ;
//used
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Used:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ;

View File

@ -20,7 +20,7 @@
namespace GParted
{
Dialog_Partition_New::Dialog_Partition_New( )
Dialog_Partition_New::Dialog_Partition_New()
{
/*TO TRANSLATORS: dialogtitle */
this ->set_title( _("Create new Partition") ) ;
@ -39,14 +39,19 @@ Dialog_Partition_New::Dialog_Partition_New( )
this ->get_vbox() ->pack_start( checkbutton_round_to_cylinders, Gtk::PACK_SHRINK ) ;
}
void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_extended, unsigned short new_count, const std::vector<FS> & FILESYSTEMS, bool only_unformatted, int cylinder_size )
void Dialog_Partition_New::Set_Data( const Partition & partition,
bool any_extended,
unsigned short new_count,
const std::vector<FS> & FILESYSTEMS,
bool only_unformatted,
Sector cylinder_size )
{
this ->new_count = new_count;
this ->selected_partition = partition;
this ->cylinder_size = cylinder_size ;
this ->FILESYSTEMS = FILESYSTEMS ;
this ->FILESYSTEMS .back( ) .filesystem = GParted::FS_UNFORMATTED ;
this ->FILESYSTEMS .back( ) .create = GParted::FS::LIBPARTED ;
this ->FILESYSTEMS .back() .filesystem = GParted::FS_UNFORMATTED ;
this ->FILESYSTEMS .back() .create = GParted::FS::LIBPARTED ;
FS fs_tmp ;
fs_tmp .filesystem = GParted::FS_EXTENDED ;
@ -58,45 +63,55 @@ 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: <optionmenu with choices> */
table_create.attach( * Utils::mk_label( (Glib::ustring) _("Create as:") + "\t" ), 0, 1, 0, 1, Gtk::FILL);
table_create .attach( * Utils::mk_label( static_cast<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") ) ) ;
menu_type .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("Logical Partition") ) ) ;
menu_type .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("Extended Partition") ) ) ;
menu_type .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Primary Partition") ) ) ;
menu_type .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Logical Partition") ) ) ;
menu_type .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Extended Partition") ) ) ;
//determine which PartitionType is allowed
if ( partition .inside_extended )
{
menu_type .items( )[ 0 ] .set_sensitive( false );
menu_type .items( )[ 2 ] .set_sensitive( false );
menu_type .items()[ 0 ] .set_sensitive( false );
menu_type .items()[ 2 ] .set_sensitive( false );
menu_type .set_active( 1 );
}
else
{
menu_type .items( )[ 1 ] .set_sensitive( false );
menu_type .items()[ 1 ] .set_sensitive( false );
if ( any_extended )
menu_type .items( )[ 2 ] .set_sensitive( false );
menu_type .items()[ 2 ] .set_sensitive( false );
}
optionmenu_type .set_menu( menu_type );
optionmenu_type .set_size_request( 160, -1 ); //160 is the ideal width for this table column, (when one widget is set, the rest wil take this width as well)
optionmenu_type .signal_changed( ) .connect( sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), true ) );
//160 is the ideal width for this table column.
//(when one widget is set, the rest wil take this width as well)
optionmenu_type .set_size_request( 160, -1 );
optionmenu_type .signal_changed() .connect(
sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), true ) );
table_create .attach( optionmenu_type, 1, 2, 0, 1, Gtk::FILL );
//filesystems to choose from
table_create.attach( * Utils::mk_label( (Glib::ustring) _("Filesystem:") + "\t" ), 0, 1, 1, 2, Gtk::FILL );
table_create .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Filesystem:") ) + "\t" ),
0, 1, 1, 2,
Gtk::FILL );
Build_Filesystems_Menu( only_unformatted ) ;
optionmenu_filesystem .set_menu( menu_filesystem );
optionmenu_filesystem .signal_changed( ) .connect( sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) );
optionmenu_filesystem .signal_changed() .connect(
sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) );
table_create .attach( optionmenu_filesystem, 1, 2, 1, 2, Gtk::FILL );
//set some widely used values...
START = partition.sector_start ;
total_length = partition.sector_end - partition.sector_start ;
TOTAL_MB = this ->selected_partition .Get_Length_MB( ) ;
TOTAL_MB = Utils::Round( Utils::sector_to_unit( this ->selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
//set first enabled filesystem
@ -105,14 +120,14 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten
//set spinbuttons initial values
spinbutton_after .set_value( 0 ) ;
spinbutton_size .set_value( fs .MAX ) ;
spinbutton_size .set_value( Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( 0 ) ;
//euhrm, this wil only happen when there's a very small free space (usually the effect of a bad partitionmanager)
if ( TOTAL_MB < cylinder_size )
if ( TOTAL_MB * MEBIBYTE < this ->cylinder_size )
frame_resizer_base ->set_sensitive( false ) ;
this ->show_all_children( ) ;
this ->show_all_children() ;
}
Partition Dialog_Partition_New::Get_New_Partition()
@ -121,7 +136,7 @@ Partition Dialog_Partition_New::Get_New_Partition()
PartitionType part_type ;
Sector new_start, new_end;
switch ( optionmenu_type .get_history( ) )
switch ( optionmenu_type .get_history() )
{
case 0 : part_type = GParted::TYPE_PRIMARY; break;
case 1 : part_type = GParted::TYPE_LOGICAL; break;
@ -130,8 +145,8 @@ Partition Dialog_Partition_New::Get_New_Partition()
default : part_type = GParted::TYPE_UNALLOCATED ;
}
new_start = START + (Sector) (spinbutton_before .get_value( ) * MEBIBYTE) ;
new_end = new_start + (Sector) (spinbutton_size .get_value( ) * MEBIBYTE) ;
new_start = START + (spinbutton_before .get_value_as_int() * MEBIBYTE) ;
new_end = new_start + (spinbutton_size .get_value_as_int() * MEBIBYTE) ;
/* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new
* partition thinks it's bigger then it can be. Here we try to solve this.*/
@ -144,9 +159,9 @@ Partition Dialog_Partition_New::Get_New_Partition()
part_temp .Set( selected_partition .device_path,
String::ucompose( _("New Partition #%1"), new_count ),
new_count, part_type,
FILESYSTEMS[ optionmenu_filesystem .get_history( ) ] .filesystem,
FILESYSTEMS[ optionmenu_filesystem .get_history() ] .filesystem,
new_start, new_end,
selected_partition .inside_extended, false) ;
selected_partition .inside_extended, false ) ;
//grow new partition a bit if freespaces are < 1 MiB
if ( (part_temp.sector_start - selected_partition.sector_start) < MEBIBYTE )
@ -158,7 +173,10 @@ Partition Dialog_Partition_New::Get_New_Partition()
if ( part_temp .type == GParted::TYPE_EXTENDED )
{
Partition UNALLOCATED ;
UNALLOCATED .Set_Unallocated( part_temp .device_path, part_temp .sector_start, part_temp .sector_end, true ) ;
UNALLOCATED .Set_Unallocated( part_temp .device_path,
part_temp .sector_start,
part_temp .sector_end,
true ) ;
part_temp .logicals .push_back( UNALLOCATED ) ;
}
@ -172,15 +190,18 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
//optionmenu_type
if ( type )
{
if ( optionmenu_type .get_history( ) == GParted::TYPE_EXTENDED && menu_filesystem .items( ) .size( ) < FILESYSTEMS .size( ) )
if ( optionmenu_type .get_history() == GParted::TYPE_EXTENDED &&
menu_filesystem .items() .size() < FILESYSTEMS .size() )
{
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 ) ;
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 ) ;
}
else if ( optionmenu_type .get_history( ) != GParted::TYPE_EXTENDED && menu_filesystem .items( ) .size( ) == FILESYSTEMS .size( ) )
else if ( optionmenu_type .get_history() != GParted::TYPE_EXTENDED &&
menu_filesystem .items() .size() == FILESYSTEMS .size() )
{
menu_filesystem .items( ) .remove( menu_filesystem .items( ) .back( ) ) ;
menu_filesystem .items() .remove( menu_filesystem .items() .back() ) ;
optionmenu_filesystem .set_sensitive( true ) ;
optionmenu_filesystem .set_history( first_creatable_fs ) ;
}
@ -196,23 +217,31 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
if ( fs .MIN < cylinder_size )
fs .MIN = cylinder_size ;
}
else if ( fs .MIN < 1 )
fs .MIN = 1 ;
else if ( fs .MIN < MEBIBYTE )
fs .MIN = MEBIBYTE ;
if ( selected_partition .Get_Length_MB( ) < fs .MIN )
fs .MIN = selected_partition .Get_Length_MB( ) ;
if ( selected_partition .get_length() < fs .MIN )
fs .MIN = selected_partition .get_length() ;
fs .MAX = ( fs .MAX && ( fs .MAX - cylinder_size ) < TOTAL_MB ) ? fs .MAX - cylinder_size : TOTAL_MB ;
fs .MAX = ( fs .MAX && ( fs .MAX - cylinder_size ) < (TOTAL_MB * MEBIBYTE) ) ?
fs .MAX - cylinder_size : TOTAL_MB * MEBIBYTE ;
frame_resizer_base ->set_size_limits( static_cast<int>(fs .MIN / MB_PER_PIXEL), static_cast<int>(fs .MAX / MB_PER_PIXEL) +1 ) ;
frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set new spinbutton ranges
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_size .set_range( fs .MIN, fs .MAX ) ;
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_before .set_range(
0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_range(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_range(
0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ;
Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
}
//set fitting resizer colors
@ -224,7 +253,7 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
color_temp .set( Utils::Get_Color( fs .filesystem ) ) ;
frame_resizer_base ->set_rgb_partition_color( color_temp ) ;
frame_resizer_base ->Draw_Partition( ) ;
frame_resizer_base ->Draw_Partition() ;
}
void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
@ -232,16 +261,19 @@ 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( 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 ) ;
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() >= FILESYSTEMS[ t ] .MIN ) ;
}
//unformatted is always available
menu_filesystem .items( ) .back( ) .set_sensitive( true ) ;
menu_filesystem .items() .back() .set_sensitive( true ) ;
//find and set first enabled filesystem
for ( unsigned int t = 0 ; t < menu_filesystem .items( ) .size( ) ; t++ )
if ( menu_filesystem .items( )[ t ] .sensitive( ) )
for ( unsigned int t = 0 ; t < menu_filesystem .items() .size() ; t++ )
if ( menu_filesystem .items()[ t ] .sensitive() )
{
first_creatable_fs = t ;
break ;

View File

@ -20,11 +20,11 @@
namespace GParted
{
Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, long cylinder_size )
Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, Sector cylinder_size )
{
this ->fs = fs ;
BUF = cylinder_size *2 ;
BUF = cylinder_size * 2 ;
}
void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partition, const std::vector <Partition> & partitions )
@ -111,40 +111,46 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector <Partit
if ( fs .shrink )
{
//since some filesystems have lower limits we need to check for this
if ( selected_partition .Get_Used_MB( ) > fs .MIN )
fs .MIN = selected_partition .Get_Used_MB( ) ;
if ( selected_partition .sectors_used > fs .MIN )
fs .MIN = selected_partition .sectors_used ;
//if fs. MIN is 0 here (means used == 0 as well) it's safe to have BUF / 2
fs .MIN += fs .MIN ? BUF : BUF/2 ;
//in certain (rare) cases fs .MIN is a bit too high...
if ( fs .MIN > selected_partition .Get_Length_MB( ) )
fs .MIN = selected_partition .Get_Length_MB( ) ;
if ( fs .MIN > selected_partition .get_length() )
fs .MIN = selected_partition .get_length() ;
}
else //only grow..
fs .MIN = selected_partition .Get_Length_MB( ) ;
fs .MIN = selected_partition .get_length() ;
fs .MAX = ( ! fs .MAX || fs .MAX > TOTAL_MB ) ? TOTAL_MB : fs .MAX -= BUF/2 ;
fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) ? ( TOTAL_MB * MEBIBYTE ) : fs .MAX -= BUF/2 ;
//set values of spinbutton_before
if ( ! fixed_start )
{
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( Utils::Round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ;
}
//set values of spinbutton_size
spinbutton_size .set_range( fs .MIN, fs .MAX ) ;
spinbutton_size .set_value( selected_partition .Get_Length_MB( ) ) ;
spinbutton_size .set_range(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value(
Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ;
spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / MB_PER_PIXEL ), Utils::Round( fs .MAX / MB_PER_PIXEL ) +1 ) ;
frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ;
Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
}
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Partition> & partitions )
@ -196,7 +202,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Part
//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 ) ;
spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
else
spinbutton_before .set_range( 0, Utils::Round( Utils::sector_to_unit( first - START, GParted::UNIT_MIB ) ) ) ;
@ -204,22 +210,23 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Part
//set values of spinbutton_size
if ( first == 0 ) //no logicals
spinbutton_size .set_range( BUF/2, TOTAL_MB ) ;
spinbutton_size .set_range( Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
else
spinbutton_size .set_range( Utils::Round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
spinbutton_size .set_value( selected_partition .Get_Length_MB( ) ) ;
spinbutton_size .set_value(
Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after
if ( first == 0 ) //no logicals
spinbutton_after .set_range( 0, TOTAL_MB - BUF/2 ) ;
spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
else
spinbutton_after .set_range( 0, Utils::Round( Utils::sector_to_unit( total_length + START - first - used, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax
Set_MinMax_Text( first == 0 ? BUF/2 : Utils::Round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ),
Set_MinMax_Text( Utils::Round( Utils::sector_to_unit( first == 0 ? BUF/2 : used, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ) ;
}

View File

@ -127,13 +127,11 @@ void GParted_Core::get_devices( std::vector<Device> & 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 = Utils::Round( Utils::sector_to_unit(
temp_device .heads * temp_device .sectors,
GParted::UNIT_MIB ) ) ;
temp_device .cylsize = temp_device .heads * temp_device .sectors ;
//make sure cylsize is at least 1 MiB
if ( temp_device .cylsize < 1 )
temp_device .cylsize = 1 ;
if ( temp_device .cylsize < MEBIBYTE )
temp_device .cylsize = MEBIBYTE ;
//normal harddisk
if ( lp_disk )
@ -545,7 +543,7 @@ bool GParted_Core::create( const Device & device,
else if ( create_empty_partition(
new_partition,
operation_details,
( new_partition .Get_Length_MB() - device .cylsize ) < get_fs( new_partition .filesystem ) .MIN ) > 0 )
( new_partition .get_length() - device .cylsize ) < get_fs( new_partition .filesystem ) .MIN * MEBIBYTE ) > 0 )
{
set_proper_filesystem( new_partition .filesystem ) ;
@ -628,7 +626,7 @@ bool GParted_Core::resize( const Device & device,
if ( partition_new .get_length() < partition_old .get_length() )
{
p_filesystem ->cylinder_size = MEBIBYTE * device .cylsize ;
p_filesystem ->cylinder_size = device .cylsize ;
succes = p_filesystem ->Resize( partition_new, operation_details ) ;
}

View File

@ -43,7 +43,7 @@ Glib::ustring Operation::Get_String( )
{
Glib::ustring temp ;
Sector diff ;
switch ( operationtype )
{
case DELETE :
@ -52,11 +52,11 @@ Glib::ustring Operation::Get_String( )
else
temp = partition_original .partition ;
/*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 2345 MiB) from /dev/hda */
return String::ucompose( _("Delete %1 (%2, %3 MiB) from %4"),
/*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 345 MiB) from /dev/hda */
return String::ucompose( _("Delete %1 (%2, %3) from %4"),
temp,
Utils::Get_Filesystem_String( partition_original .filesystem ),
partition_original .Get_Length_MB( ),
Utils::format_size( partition_original .get_length() ),
device .path ) ;
case CREATE :
@ -75,49 +75,45 @@ Glib::ustring Operation::Get_String( )
default :
break;
}
/*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 2345 MiB) on /dev/hda */
return String::ucompose( _("Create %1 #%2 (%3, %4 MiB) on %5"),
/*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 345 MiB) on /dev/hda */
return String::ucompose( _("Create %1 #%2 (%3, %4) on %5"),
temp,
partition_new.partition_number,
Utils::Get_Filesystem_String( partition_new.filesystem ),
partition_new .Get_Length_MB( ),
Utils::format_size( partition_new .get_length() ),
device .path ) ;
case RESIZE_MOVE:
//if startsector has changed >= 1 MiB we consider it a move
//if startsector has changed we consider it a move
diff = std::abs( partition_new .sector_start - partition_original .sector_start ) ;
if ( diff >= MEBIBYTE )
if ( diff )
{
if ( partition_new .sector_start > partition_original .sector_start )
temp = String::ucompose( _("Move %1 forward by %2 MiB"),
partition_new.partition,
Utils::Round( Utils::sector_to_unit( diff, GParted::UNIT_MIB ) ) ) ;
temp = String::ucompose( _("Move %1 forward by %2"),
partition_new .partition,
Utils::format_size( diff ) ) ;
else
temp = String::ucompose( _("Move %1 backward by %2 MiB"),
partition_new.partition,
Utils::Round( Utils::sector_to_unit( diff, GParted::UNIT_MIB ) ) ) ;
}
//check if size has changed ( we only consider changes >= 1 MiB )
diff = std::abs( (partition_original .sector_end - partition_original .sector_start) - (partition_new .sector_end - partition_new .sector_start) ) ;
if ( diff >= MEBIBYTE )
{
if ( temp .empty( ) )
temp = String::ucompose( _("Resize %1 from %2 MiB to %3 MiB"),
partition_new.partition,
partition_original .Get_Length_MB(),
partition_new .Get_Length_MB() ) ;
else
temp += " " + String::ucompose( _("and Resize %1 from %2 MiB to %3 MiB"),
partition_new.partition,
partition_original .Get_Length_MB(),
partition_new .Get_Length_MB() ) ;
temp = String::ucompose( _("Move %1 backward by %2"),
partition_new .partition,
Utils::format_size( diff ) ) ;
}
//check if size has changed
diff = std::abs( partition_original .get_length() - partition_new .get_length() ) ;
if ( diff )
{
if ( temp .empty() )
temp = String::ucompose( _("Resize %1 from %2 to %3"),
partition_new.partition,
Utils::format_size( partition_original .get_length() ),
Utils::format_size( partition_new .get_length() ) ) ;
else
temp += " " + String::ucompose( _("and Resize %1 from %2 to %3"),
partition_new.partition,
Utils::format_size( partition_original .get_length() ),
Utils::format_size( partition_new .get_length() ) ) ;
}
if ( temp .empty( ) )
temp = _("Sorry, changes are too small to make sense");
return temp;
case FORMAT :
@ -127,11 +123,11 @@ Glib::ustring Operation::Get_String( )
Utils::Get_Filesystem_String( partition_new .filesystem ) ) ;
case COPY :
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 2500 MiB) */
return String::ucompose( _("Copy %1 to %2 (start at %3 MiB)"),
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 250 MiB) */
return String::ucompose( _("Copy %1 to %2 (start at %3)"),
partition_new .partition,
device .path,
Utils::Round( Utils::sector_to_unit( partition_new .sector_start, GParted::UNIT_MIB ) ) ) ;
Utils::format_size( partition_new .sector_start ) ) ;
default :
return "";

View File

@ -97,21 +97,6 @@ void Partition::Update_Number( int new_number )
this ->partition_number = new_number;
}
long Partition::Get_Length_MB() const
{
return Utils::Round( Utils::sector_to_unit( get_length(), GParted::UNIT_MIB ) ) ;
}
long Partition::Get_Used_MB() const
{
return Utils::Round( Utils::sector_to_unit( sectors_used, GParted::UNIT_MIB ) ) ;
}
long Partition::Get_Unused_MB() const
{
return Get_Length_MB() - Get_Used_MB( ) ;
}
Sector Partition::get_length() const
{
return sector_end - sector_start + 1 ;

View File

@ -164,22 +164,19 @@ Glib::ustring Utils::format_size( Sector size )
double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit )
{
/* NOTE: this could have been done more efficient by using static numbers.
* However, the performancegain would be unnoticable and this way its easier to read/debug
*/
switch ( size_unit )
{
case UNIT_BYTE :
return sectors * 512 ;
case UNIT_KIB :
return sector_to_unit( sectors, UNIT_BYTE ) / 1024 ;
return sectors / static_cast<double>( KIBIBYTE ) ;
case UNIT_MIB :
return sector_to_unit( sectors, UNIT_KIB ) / 1024 ;
return sectors / static_cast<double>( MEBIBYTE ) ;
case UNIT_GIB :
return sector_to_unit( sectors, UNIT_MIB ) / 1024 ;
return sectors / static_cast<double>( GIBIBYTE ) ;
case UNIT_TIB :
return sector_to_unit( sectors, UNIT_GIB ) / 1024 ;
return sectors / static_cast<double>( TEBIBYTE ) ;
default:
return sectors ;

View File

@ -705,9 +705,13 @@ void Win_GParted::set_valid_operations()
//find out if there is a copied partition and if it fits inside this unallocated space
if ( ! copied_partition .partition .empty() && ! devices[ current_device ] .readonly )
{
if ( (copied_partition .Get_Length_MB() + devices[ current_device ] .cylsize) < selected_partition .Get_Length_MB() ||
(copied_partition .filesystem == GParted::FS_XFS && (copied_partition .Get_Used_MB() + devices[ current_device ] .cylsize) < selected_partition .Get_Length_MB() )
)
Sector required_size ;
if ( copied_partition .filesystem == GParted::FS_XFS )
required_size = copied_partition .sectors_used ;
else
required_size = copied_partition .get_length() ;
if ( ( required_size + devices[ current_device ] .cylsize ) <= selected_partition .get_length() )
allow_paste( true ) ;
}
@ -1091,7 +1095,8 @@ void Win_GParted::activate_resize()
if ( operations[ t ] .device .path == devices[ current_device ] .path )
operations[ t ] .Apply_Operation_To_Visual( partitions ) ;
Dialog_Partition_Resize_Move dialog( gparted_core .get_fs( selected_partition .filesystem ), devices[ current_device ] .cylsize ) ;
Dialog_Partition_Resize_Move dialog( gparted_core .get_fs( selected_partition .filesystem ),
devices[ current_device ] .cylsize ) ;
if ( selected_partition .type == GParted::TYPE_LOGICAL )
{
@ -1281,8 +1286,8 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
//check for some limits...
fs = gparted_core .get_fs( new_fs ) ;
if ( selected_partition .Get_Length_MB() < fs .MIN ||
fs .MAX && selected_partition .Get_Length_MB() > fs .MAX )
if ( selected_partition .get_length() < fs .MIN ||
fs .MAX && selected_partition .get_length() > fs .MAX )
{
Gtk::MessageDialog dialog( *this,
String::ucompose( _("Cannot format this filesystem to %1."),
@ -1292,14 +1297,16 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
Gtk::BUTTONS_OK,
true );
if ( selected_partition .Get_Length_MB() < fs .MIN )
dialog .set_secondary_text( String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MiB."),
Utils::Get_Filesystem_String( new_fs ),
fs .MIN ) );
if ( selected_partition .get_length() < fs .MIN )
dialog .set_secondary_text( String::ucompose(
_( "A %1 filesystem requires a partition of at least %2."),
Utils::Get_Filesystem_String( new_fs ),
Utils::format_size( fs .MIN ) ) );
else
dialog .set_secondary_text( String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MiB."),
Utils::Get_Filesystem_String( new_fs ),
fs .MAX ) );
dialog .set_secondary_text( String::ucompose(
_( "A partition with a %1 filesystem has a maximum size of %2."),
Utils::Get_Filesystem_String( new_fs ),
Utils::format_size( fs .MAX ) ) );
dialog .run() ;
return ;

View File

@ -21,7 +21,7 @@
namespace GParted
{
FS fat16::get_filesystem_support( )
FS fat16::get_filesystem_support()
{
FS fs ;
fs .filesystem = GParted::FS_FAT16 ;
@ -44,8 +44,8 @@ FS fat16::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 16 ;
fs .MAX = 4096 ;
fs .MIN = 16 * MEBIBYTE ;
fs .MAX = 4096 * MEBIBYTE ;
return fs ;
}
@ -69,6 +69,7 @@ void fat16::Set_Used_Sectors( Partition & partition )
if ( N > -1 && S > -1 )
partition .Set_Unused( Utils::Round( N * ( S / 512.0 ) ) ) ;
}
//FIXME: all fs classes should send 'error' to stdout here.
}
bool fat16::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )

View File

@ -44,7 +44,7 @@ FS fat32::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ; //smaller fs'es will cause windows scandisk to fail..
fs .MIN = 32 * MEBIBYTE ; //smaller fs'es will cause windows scandisk to fail..
return fs ;
}

View File

@ -35,7 +35,7 @@ FS hfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ;
fs .MAX = 2048 ;
fs .MAX = 2048 * MEBIBYTE ;
return fs ;
}

View File

@ -61,7 +61,7 @@ FS jfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 16 ;
fs .MIN = 16 * MEBIBYTE ;
return fs ;
}

View File

@ -48,7 +48,7 @@ FS reiserfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ;
fs .MIN = 32 * MEBIBYTE ;
return fs ;
}

View File

@ -62,7 +62,7 @@ FS xfs::get_filesystem_support( )
fs .check && fs .create )
fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB...
fs .MIN = 32 * MEBIBYTE ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB...
return fs ;
}