Remove Set_Data() from the copy, resize/move and new dialog class APIs
The copy, resize/move and new dialog classes (Dialog_Partition_Copy, Dialog_Partition_Resize_Move and Dialog_Partition_New respectively) had to be used like this: construct dialog object passing some parameters call Set_Data() to pass more parameters run() dialog call Get_New_Partition() There is nothing in the classes which forces Set_Data() to be called, but it must be called for the dialogs to work and prevent GParted from crashing. Make these class APIs safer by making it impossible to program incorrectly in this regard. Move all the additional parameters from each Set_Data() method to each constructor. The constructors just call the now private set_data() methods.
This commit is contained in:
parent
32a5ace156
commit
7a4a375ed6
|
@ -26,12 +26,13 @@ namespace GParted
|
|||
class Dialog_Partition_Copy : public Dialog_Base_Partition
|
||||
{
|
||||
public:
|
||||
Dialog_Partition_Copy( const FS & fs );
|
||||
void Set_Data( const Partition & selected_partition, const Partition & copied_partition );
|
||||
Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
|
||||
const Partition & copied_partition );
|
||||
|
||||
Partition Get_New_Partition( Byte_Value sector_size ) ;
|
||||
|
||||
private:
|
||||
void set_data( const Partition & selected_partition, const Partition & copied_partition );
|
||||
};
|
||||
|
||||
}//GParted
|
||||
|
|
|
@ -29,15 +29,19 @@ namespace GParted
|
|||
class Dialog_Partition_New : public Dialog_Base_Partition
|
||||
{
|
||||
public:
|
||||
Dialog_Partition_New() ;
|
||||
void Set_Data( const Device & device,
|
||||
Dialog_Partition_New(const Device & device,
|
||||
const Partition & partition,
|
||||
bool any_extended,
|
||||
unsigned short new_count,
|
||||
const std::vector<FS> & FILESYSTEMS );
|
||||
Partition Get_New_Partition( Byte_Value sector_size ) ;//overridden function
|
||||
|
||||
private:
|
||||
void set_data( const Device & device,
|
||||
const Partition & partition,
|
||||
bool any_extended,
|
||||
unsigned short new_count,
|
||||
const std::vector<FS> & FILESYSTEMS );
|
||||
Partition Get_New_Partition( Byte_Value sector_size ) ;//overridden function
|
||||
|
||||
private:
|
||||
void Build_Filesystems_Menu( bool only_unformatted ) ;
|
||||
|
||||
Gtk::Table table_create;
|
||||
|
|
|
@ -25,10 +25,11 @@ namespace GParted
|
|||
class Dialog_Partition_Resize_Move : public Dialog_Base_Partition
|
||||
{
|
||||
public:
|
||||
Dialog_Partition_Resize_Move( const FS & fs );
|
||||
void Set_Data( const Partition & selected_partition, const std::vector <Partition> & partitions ) ;
|
||||
Dialog_Partition_Resize_Move( const FS & fs, const Partition & selected_partition,
|
||||
const std::vector <Partition> & partitions );
|
||||
|
||||
private:
|
||||
void set_data( const Partition & selected_partition, const std::vector <Partition> & partitions );
|
||||
void Resize_Move_Normal( const std::vector <Partition> & partitions ) ;
|
||||
void Resize_Move_Extended( const std::vector <Partition> & partitions ) ;
|
||||
};
|
||||
|
|
|
@ -21,15 +21,18 @@
|
|||
namespace GParted
|
||||
{
|
||||
|
||||
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs )
|
||||
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
|
||||
const Partition & copied_partition )
|
||||
{
|
||||
this ->fs = fs ;
|
||||
|
||||
Set_Resizer( false ) ;
|
||||
Set_Confirm_Button( PASTE ) ;
|
||||
|
||||
set_data( selected_partition, copied_partition );
|
||||
}
|
||||
|
||||
void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, const Partition & copied_partition )
|
||||
void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & copied_partition )
|
||||
{
|
||||
this ->set_title( String::ucompose( _("Paste %1"), copied_partition .get_path() ) ) ;
|
||||
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
namespace GParted
|
||||
{
|
||||
|
||||
Dialog_Partition_New::Dialog_Partition_New()
|
||||
Dialog_Partition_New::Dialog_Partition_New( const Device & device,
|
||||
const Partition & partition,
|
||||
bool any_extended,
|
||||
unsigned short new_count,
|
||||
const std::vector<FS> & FILESYSTEMS )
|
||||
{
|
||||
/*TO TRANSLATORS: dialogtitle */
|
||||
this ->set_title( _("Create new Partition") ) ;
|
||||
|
@ -30,9 +34,11 @@ Dialog_Partition_New::Dialog_Partition_New()
|
|||
|
||||
//set used (in pixels)...
|
||||
frame_resizer_base ->set_used( 0 ) ;
|
||||
|
||||
set_data(device, partition, any_extended, new_count, FILESYSTEMS );
|
||||
}
|
||||
|
||||
void Dialog_Partition_New::Set_Data( const Device & device,
|
||||
void Dialog_Partition_New::set_data( const Device & device,
|
||||
const Partition & partition,
|
||||
bool any_extended,
|
||||
unsigned short new_count,
|
||||
|
|
|
@ -21,13 +21,15 @@
|
|||
namespace GParted
|
||||
{
|
||||
|
||||
Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs )
|
||||
Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, const Partition & selected_partition,
|
||||
const std::vector<Partition> & partitions )
|
||||
{
|
||||
this ->fs = fs ;
|
||||
set_data( selected_partition, partitions );
|
||||
}
|
||||
|
||||
void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partition,
|
||||
const std::vector<Partition> & partitions )
|
||||
void Dialog_Partition_Resize_Move::set_data( const Partition & selected_partition,
|
||||
const std::vector<Partition> & partitions )
|
||||
{
|
||||
GRIP = true ; //prevents on spinbutton_changed from getting activated prematurely
|
||||
|
||||
|
|
|
@ -1712,18 +1712,18 @@ void Win_GParted::activate_resize()
|
|||
g_assert( selected_partition_ptr != NULL ); // Bug: Partition callback without a selected partition
|
||||
g_assert( valid_display_partition_ptr( selected_partition_ptr ) ); // Bug: Not pointing at a valid display partition object
|
||||
|
||||
Dialog_Partition_Resize_Move dialog( gparted_core.get_fs( selected_partition_ptr->filesystem ) );
|
||||
|
||||
std::vector<Partition> & display_partitions_ref = display_partitions;
|
||||
if ( selected_partition_ptr->type == TYPE_LOGICAL )
|
||||
{
|
||||
unsigned int ext = 0 ;
|
||||
while ( ext < display_partitions.size() && display_partitions[ext].type != TYPE_EXTENDED )
|
||||
ext++;
|
||||
dialog.Set_Data( *selected_partition_ptr, display_partitions[ext].logicals );
|
||||
display_partitions_ref = display_partitions[ext].logicals;
|
||||
}
|
||||
else
|
||||
dialog.Set_Data( *selected_partition_ptr, display_partitions );
|
||||
|
||||
Dialog_Partition_Resize_Move dialog( gparted_core.get_fs( selected_partition_ptr->filesystem ),
|
||||
*selected_partition_ptr,
|
||||
display_partitions_ref );
|
||||
dialog .set_transient_for( *this ) ;
|
||||
|
||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||
|
@ -1835,14 +1835,15 @@ void Win_GParted::activate_paste()
|
|||
{
|
||||
if ( ! max_amount_prim_reached() )
|
||||
{
|
||||
Dialog_Partition_Copy dialog( gparted_core.get_fs( copied_partition.filesystem ) );
|
||||
|
||||
// We don't want the messages, mount points or name of the source
|
||||
// partition for the new partition being created.
|
||||
copied_partition .messages .clear() ;
|
||||
copied_partition .clear_mountpoints() ;
|
||||
copied_partition .name.clear() ;
|
||||
dialog.Set_Data( *selected_partition_ptr, copied_partition );
|
||||
|
||||
Dialog_Partition_Copy dialog( gparted_core.get_fs( copied_partition.filesystem ),
|
||||
*selected_partition_ptr,
|
||||
copied_partition );
|
||||
dialog .set_transient_for( *this );
|
||||
|
||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||
|
@ -1938,15 +1939,12 @@ void Win_GParted::activate_new()
|
|||
show_disklabel_unrecognized( devices [current_device ] .get_path() ) ;
|
||||
}
|
||||
else if ( ! max_amount_prim_reached() )
|
||||
{
|
||||
Dialog_Partition_New dialog;
|
||||
|
||||
dialog.Set_Data( devices[current_device],
|
||||
*selected_partition_ptr,
|
||||
index_extended > -1,
|
||||
new_count,
|
||||
gparted_core.get_filesystems() );
|
||||
|
||||
{
|
||||
Dialog_Partition_New dialog( devices[current_device],
|
||||
*selected_partition_ptr,
|
||||
index_extended > -1,
|
||||
new_count,
|
||||
gparted_core.get_filesystems() );
|
||||
dialog .set_transient_for( *this );
|
||||
|
||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||
|
|
Loading…
Reference in New Issue