[gparted] Change partition alignment check box to a drop down menu



commit 2cdfb4c55ad9b10867a21c35626f16f5f6a01fe0
Author: Curtis Gedak <gedakc gmail com>
Date:   Sun May 9 14:45:26 2010 -0600

    Change partition alignment check box to a drop down menu
    
    Also add signal handler to alignment menu to update file system
    minimum size.
    This enhancement is to prepare for adding a third alignment
    option to align to MiB.

 include/Dialog_Base_Partition.h |    4 +++-
 include/Dialog_Partition_New.h  |    1 -
 include/Partition.h             |    8 +++++++-
 src/Dialog_Base_Partition.cc    |   30 +++++++++++++++++++++++-------
 src/Dialog_Partition_New.cc     |   20 +++++++++++++++-----
 src/GParted_Core.cc             |   19 ++++++++++---------
 src/Partition.cc                |    2 +-
 7 files changed, 59 insertions(+), 25 deletions(-)
---
diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h
index 7bff0b2..d1b4131 100644
--- a/include/Dialog_Base_Partition.h
+++ b/include/Dialog_Base_Partition.h
@@ -29,6 +29,7 @@
 #include <gtkmm/table.h>
 #include <gtkmm/box.h>
 #include <gtkmm/tooltips.h>
+#include <gtkmm/optionmenu.h>
 
 namespace GParted
 {
@@ -69,7 +70,8 @@ protected:
 
 	Gtk::HBox hbox_main ;
 	Gtk::SpinButton spinbutton_before, spinbutton_size, spinbutton_after;
-	Gtk::CheckButton checkbutton_round_to_cylinders ;
+	Gtk::OptionMenu optionmenu_alignment ;
+	Gtk::Menu menu_alignment ;
 
 	//used to enable/disable OKbutton...
 	int ORIG_BEFORE, ORIG_SIZE, ORIG_AFTER ;
diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h
index be7c55c..b870ad8 100644
--- a/include/Dialog_Partition_New.h
+++ b/include/Dialog_Partition_New.h
@@ -22,7 +22,6 @@
 #include "../include/Dialog_Base_Partition.h"
 
 #include <gtkmm/optionmenu.h>
-#include <gtkmm/checkbutton.h>
 
 namespace GParted
 {
diff --git a/include/Partition.h b/include/Partition.h
index 1418a08..a014b72 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -44,6 +44,12 @@ enum PartitionStatus {
 	STAT_FORMATTED	=	3
 };
 
+enum PartitionAlignment {
+	ALIGN_CYLINDER = 0,    //Align to nearest cylinder
+	ALIGN_STRICT   = 1     //Strict alignment - no rounding
+	                       //  Indicator if start and end sectors must remain unchanged
+};
+
 //FIXME: we should make a difference between partition- and file system size. 
 //especially in the core this can make a difference when giving detailed feedback. With new cairosupport in gtkmm
 //it's even possible to make stuff like this visible in the GUI in a nice and clear way
@@ -101,6 +107,7 @@ public:
 	int partition_number;
 	PartitionType type;// UNALLOCATED, PRIMARY, LOGICAL, etc...
 	PartitionStatus status; //STAT_REAL, STAT_NEW, etc..
+	PartitionAlignment alignment;   //ALIGN_CYLINDER, ALIGN_STRICT, etc
 	FILESYSTEM filesystem ;
 	Glib::ustring label ;
 	Glib::ustring uuid ;
@@ -116,7 +123,6 @@ public:
 	
 	std::vector<Partition> logicals ;
 
-	bool strict ;		//Indicator if start and end sectors must stay unchanged
 	bool strict_start ;	//Indicator if start sector must stay unchanged
 
 	Byte_Value sector_size ;  //Sector size of the disk device needed for converting to/from sectors and bytes.
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index fff3c9c..c6d279c 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -79,11 +79,6 @@ Dialog_Base_Partition::Dialog_Base_Partition()
 	if ( ! fixed_start )
 		before_value = spinbutton_before .get_value() ;
 
-	//add checkbutton
-	checkbutton_round_to_cylinders .set_label( _("Round to cylinders") ) ;
-	checkbutton_round_to_cylinders .set_active( true ) ;
-	table_resize.attach( checkbutton_round_to_cylinders, 0, 1, 3, 4 ) ;
-
 	//connect signalhandlers of the spinbuttons
 	if ( ! fixed_start )
 		spinbutton_before .signal_value_changed() .connect( 
@@ -97,6 +92,21 @@ Dialog_Base_Partition::Dialog_Base_Partition()
 		sigc::bind<SPINBUTTON>( 
 			sigc::mem_fun(*this, &Dialog_Base_Partition::on_spinbutton_value_changed), AFTER ) ) ;
 
+	//add alignment
+	/*TO TRANSLATORS: used as label for a list of choices.   Align to: <optionmenu with choices> */
+	table_resize .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Align to:") ) + "\t" ),
+	                      0, 1, 3, 4, Gtk::FILL );
+
+	//fill partition alignment menu
+	/*TO TRANSLATORS: Menu option for drop down menu "Align to:" */
+	menu_alignment .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Cylinder") ) ) ;
+	/*TO TRANSLATORS: Menu option for drop down menu "Align to:" */
+	menu_alignment .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("None") ) ) ;
+
+	optionmenu_alignment .set_menu( menu_alignment );
+
+	table_resize .attach( optionmenu_alignment, 1, 2, 3, 4, Gtk::FILL );
+
 	this->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL );
 	this ->show_all_children() ;
 }
@@ -153,8 +163,14 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
 	if ( selected_partition .sectors_used != -1 )
 		selected_partition .sectors_unused = selected_partition .get_sector_length() - selected_partition .sectors_used ;
 
-	//set indicator of whether to use strict sector values, or to round to cylinders
-	selected_partition .strict = ! checkbutton_round_to_cylinders .get_active() ;
+	//set alignment
+	switch ( optionmenu_alignment .get_history() )
+	{
+		case  0 :  selected_partition .alignment = ALIGN_CYLINDER;  break;
+		case  1 :  selected_partition .alignment = ALIGN_STRICT;  break;
+
+		default :  selected_partition .alignment = ALIGN_CYLINDER ;
+	}
 
 	//if the original before value has not changed, then set indicator to keep start sector unchanged
 	if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() )
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 0195934..eb38f3c 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -157,7 +157,11 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
 	//euhrm, this wil only happen when there's a very small free space (usually the effect of a bad partitionmanager)
 	if ( TOTAL_MB * (MEBIBYTE / this ->selected_partition .sector_size) < this ->cylinder_size )
 		frame_resizer_base ->set_sensitive( false ) ;
-			
+
+	//connect signal handler for Dialog_Base_Partiton optionmenu_alignment
+	optionmenu_alignment .signal_changed() .connect( 
+		sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) );
+
 	this ->show_all_children() ;
 }
 
@@ -218,8 +222,14 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
 		part_temp .logicals .push_back( UNALLOCATED ) ;
 	}
 
-	//set indicator of whether to use strict sector values, or to round to cylinders
-	part_temp .strict = ! checkbutton_round_to_cylinders .get_active() ;
+	//set alignment
+	switch ( optionmenu_alignment .get_history() )
+	{
+		case  0 :  part_temp .alignment = GParted::ALIGN_CYLINDER;  break;
+		case  1 :  part_temp .alignment = GParted::ALIGN_STRICT;  break;
+
+		default :  part_temp .alignment = GParted::ALIGN_CYLINDER ;
+	}
 
 	return part_temp;
 }
@@ -246,12 +256,12 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
 		}
 	}
 	
-	//optionmenu_filesystem
+	//optionmenu_filesystem and optionmenu_alignment
 	if ( ! type )
 	{
 		fs = FILESYSTEMS[ optionmenu_filesystem .get_history() ] ;
 
-		if ( checkbutton_round_to_cylinders .get_active() )
+		if ( optionmenu_alignment .get_history() == ALIGN_CYLINDER )
 		{
 			if ( (fs .MIN / selected_partition .sector_size) < cylinder_size )
 				fs .MIN = cylinder_size * selected_partition .sector_size ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 50b11fc..cdef24b 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -372,11 +372,11 @@ Glib::ustring GParted_Core::get_thread_status_message( )
 
 bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partition, Glib::ustring & error ) 
 {
-	if ( ! partition .strict )
+	if ( partition .alignment != ALIGN_STRICT )
 	{
 		Sector diff = 0;
 		if ( partition.type == TYPE_LOGICAL ||
-			 partition.sector_start == device .sectors
+		     partition.sector_start == device .sectors
 		   ) {
 			//Must account the relative offset between:
 			// (A) the Extended Boot Record sector and the next track of the
@@ -1375,7 +1375,7 @@ bool GParted_Core::create_partition( Partition & new_partition, OperationDetail
 	
 		if ( lp_partition )
 		{
-			if ( new_partition .strict )
+			if ( new_partition .alignment == ALIGN_STRICT )
 			{
 				PedGeometry *geom = ped_geometry_new( lp_device,
 								      new_partition .sector_start,
@@ -1547,9 +1547,9 @@ bool GParted_Core::resize_move( const Device & device,
 			  	Partition & partition_new,
 			  	OperationDetail & operationdetail ) 
 {
-	if (   partition_new .strict
-		|| partition_new .strict_start
-		|| calculate_exact_geom( partition_old, partition_new, operationdetail )
+	if (   (partition_new .alignment == ALIGN_STRICT)
+	    || partition_new .strict_start
+	    || calculate_exact_geom( partition_old, partition_new, operationdetail )
 	   )
 	{
 		if ( partition_old .type == TYPE_EXTENDED )
@@ -1576,9 +1576,10 @@ bool GParted_Core::resize_move( const Device & device,
 			temp .sector_end = partition_old .sector_start + partition_new .get_sector_length() -1 ;
 		}
 
-		temp .strict = true ;
+		PartitionAlignment previous_alignment = temp .alignment ;
+		temp .alignment = ALIGN_STRICT ;
 		bool succes = resize_move( device, partition_old, temp, operationdetail ) ;
-		temp .strict = false ;
+		temp .alignment = previous_alignment ;
 
 		return succes && resize_move( device, temp, partition_new, operationdetail ) ;
 	}
@@ -1889,7 +1890,7 @@ bool GParted_Core::resize_move_partition( const Partition & partition_old,
 		
 		if ( lp_partition )
 		{
-			if ( partition_new .strict || partition_new .strict_start ) {
+			if ( (partition_new .alignment == ALIGN_STRICT) || partition_new .strict_start ) {
 				PedGeometry *geom = ped_geometry_new( lp_device,
 									  partition_new .sector_start,
 									  partition_new .get_sector_length() ) ;
diff --git a/src/Partition.cc b/src/Partition.cc
index 139b2ed..66ca19a 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -45,7 +45,7 @@ void Partition::Reset()
 	partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1;
 	sector_size = 0 ;
 	color .set( "black" ) ;
-	inside_extended = busy = strict = strict_start = false ;
+	inside_extended = busy = strict_start = false ;
 	logicals .clear() ;
 	flags .clear() ;
 	mountpoints .clear() ;



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