[gparted] Remove Set_Data() from the copy, resize/move and new dialog class APIs



commit 7a4a375ed629fea77995c98d13bd1992231be6fb
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Jun 2 13:10:45 2015 +0100

    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.

 include/Dialog_Partition_Copy.h        |    5 +++--
 include/Dialog_Partition_New.h         |   14 +++++++++-----
 include/Dialog_Partition_Resize_Move.h |    5 +++--
 src/Dialog_Partition_Copy.cc           |    7 +++++--
 src/Dialog_Partition_New.cc            |   10 ++++++++--
 src/Dialog_Partition_Resize_Move.cc    |    8 +++++---
 src/Win_GParted.cc                     |   32 +++++++++++++++-----------------
 7 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h
index 877459e..daadbff 100644
--- a/include/Dialog_Partition_Copy.h
+++ b/include/Dialog_Partition_Copy.h
@@ -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
diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h
index 93046dc..6f85065 100644
--- a/include/Dialog_Partition_New.h
+++ b/include/Dialog_Partition_New.h
@@ -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;
diff --git a/include/Dialog_Partition_Resize_Move.h b/include/Dialog_Partition_Resize_Move.h
index c3ec246..e803ba6 100644
--- a/include/Dialog_Partition_Resize_Move.h
+++ b/include/Dialog_Partition_Resize_Move.h
@@ -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 ) ;
 };
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index a8504d8..21963d1 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -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() ) ) ;
        
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 4d2ce2d..f67f83e 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -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,
diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc
index 527932d..68425aa 100644
--- a/src/Dialog_Partition_Resize_Move.cc
+++ b/src/Dialog_Partition_Resize_Move.cc
@@ -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
 
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index b4ba88b..cdb08e3 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -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 )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]