2004-09-19 14:24:53 -06:00
|
|
|
/* Copyright (C) 2004 Bart
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../include/Dialog_Partition_New.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
Dialog_Partition_New::Dialog_Partition_New()
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
|
|
|
/*TO TRANSLATORS: dialogtitle */
|
|
|
|
this ->set_title( _("Create new Partition") ) ;
|
|
|
|
Set_Resizer( false ) ;
|
|
|
|
Set_Confirm_Button( NEW ) ;
|
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
//set used (in pixels)...
|
2004-09-19 14:24:53 -06:00
|
|
|
frame_resizer_base ->set_used( 0 ) ;
|
2006-01-07 08:04:42 -07:00
|
|
|
|
|
|
|
//checkbutton..
|
|
|
|
checkbutton_round_to_cylinders .set_label( _("Round to cylinders") ) ;
|
|
|
|
checkbutton_round_to_cylinders .set_active( true ) ;
|
|
|
|
checkbutton_round_to_cylinders .signal_clicked() .connect(
|
|
|
|
sigc::bind<bool>( sigc::mem_fun(*this, &Dialog_Partition_New::optionmenu_changed), false ) ) ;
|
|
|
|
|
|
|
|
this ->get_vbox() ->pack_start( checkbutton_round_to_cylinders, Gtk::PACK_SHRINK ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
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 )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-10-06 09:32:40 -06:00
|
|
|
this ->new_count = new_count;
|
|
|
|
this ->selected_partition = partition;
|
2004-12-10 13:42:23 -07:00
|
|
|
this ->cylinder_size = cylinder_size ;
|
2004-10-06 09:32:40 -06:00
|
|
|
this ->FILESYSTEMS = FILESYSTEMS ;
|
2006-02-25 03:09:30 -07:00
|
|
|
this ->FILESYSTEMS .back() .filesystem = GParted::FS_UNFORMATTED ;
|
|
|
|
this ->FILESYSTEMS .back() .create = GParted::FS::LIBPARTED ;
|
2004-12-10 13:42:23 -07:00
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
FS fs_tmp ;
|
|
|
|
fs_tmp .filesystem = GParted::FS_EXTENDED ;
|
2004-12-12 07:57:04 -07:00
|
|
|
this ->FILESYSTEMS .push_back( fs_tmp ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
//add table with selection menu's...
|
2004-09-19 14:24:53 -06:00
|
|
|
table_create .set_border_width( 10 ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
table_create .set_row_spacings( 5 ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
hbox_main .pack_start( table_create, Gtk::PACK_SHRINK );
|
|
|
|
|
|
|
|
/*TO TRANSLATORS: used as label for a list of choices. Create as: <optionmenu with choices> */
|
2006-02-25 03:09:30 -07:00
|
|
|
table_create .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Create as:") ) + "\t" ),
|
|
|
|
0, 1, 0, 1,
|
|
|
|
Gtk::FILL );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//fill partitiontype menu
|
2006-02-25 03:09:30 -07:00
|
|
|
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") ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//determine which PartitionType is allowed
|
2004-12-12 07:57:04 -07:00
|
|
|
if ( partition .inside_extended )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_type .items()[ 0 ] .set_sensitive( false );
|
|
|
|
menu_type .items()[ 2 ] .set_sensitive( false );
|
2004-12-12 07:57:04 -07:00
|
|
|
menu_type .set_active( 1 );
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_type .items()[ 1 ] .set_sensitive( false );
|
2004-10-06 09:32:40 -06:00
|
|
|
if ( any_extended )
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_type .items()[ 2 ] .set_sensitive( false );
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
optionmenu_type .set_menu( menu_type );
|
2006-02-25 03:09:30 -07:00
|
|
|
|
|
|
|
//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 ) );
|
2004-12-12 07:57:04 -07:00
|
|
|
table_create .attach( optionmenu_type, 1, 2, 0, 1, Gtk::FILL );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//filesystems to choose from
|
2006-02-25 03:09:30 -07:00
|
|
|
table_create .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Filesystem:") ) + "\t" ),
|
|
|
|
0, 1, 1, 2,
|
|
|
|
Gtk::FILL );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
Build_Filesystems_Menu( only_unformatted ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
optionmenu_filesystem .set_menu( menu_filesystem );
|
2006-02-25 03:09:30 -07:00
|
|
|
optionmenu_filesystem .signal_changed() .connect(
|
|
|
|
sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) );
|
2004-12-12 07:57:04 -07:00
|
|
|
table_create .attach( optionmenu_filesystem, 1, 2, 1, 2, Gtk::FILL );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//set some widely used values...
|
|
|
|
START = partition.sector_start ;
|
|
|
|
total_length = partition.sector_end - partition.sector_start ;
|
2006-03-28 05:40:29 -07:00
|
|
|
TOTAL_MB = Utils::round( Utils::sector_to_unit( this ->selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
|
2005-01-19 13:01:39 -07:00
|
|
|
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
//set first enabled filesystem
|
|
|
|
optionmenu_filesystem .set_history( first_creatable_fs ) ;
|
|
|
|
optionmenu_changed( false ) ;
|
2004-12-10 13:42:23 -07:00
|
|
|
|
2004-12-12 07:57:04 -07:00
|
|
|
//set spinbuttons initial values
|
|
|
|
spinbutton_after .set_value( 0 ) ;
|
2006-03-28 05:40:29 -07:00
|
|
|
spinbutton_size .set_value( Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
spinbutton_before .set_value( 0 ) ;
|
|
|
|
|
2004-12-10 13:42:23 -07:00
|
|
|
//euhrm, this wil only happen when there's a very small free space (usually the effect of a bad partitionmanager)
|
2006-02-25 03:09:30 -07:00
|
|
|
if ( TOTAL_MB * MEBIBYTE < this ->cylinder_size )
|
2004-12-10 13:42:23 -07:00
|
|
|
frame_resizer_base ->set_sensitive( false ) ;
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
this ->show_all_children() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Partition Dialog_Partition_New::Get_New_Partition()
|
|
|
|
{
|
|
|
|
Partition part_temp ;
|
2005-12-07 04:21:27 -07:00
|
|
|
PartitionType part_type ;
|
2004-09-19 14:24:53 -06:00
|
|
|
Sector new_start, new_end;
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
switch ( optionmenu_type .get_history() )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2005-12-07 04:21:27 -07:00
|
|
|
case 0 : part_type = GParted::TYPE_PRIMARY; break;
|
|
|
|
case 1 : part_type = GParted::TYPE_LOGICAL; break;
|
|
|
|
case 2 : part_type = GParted::TYPE_EXTENDED; break;
|
|
|
|
|
|
|
|
default : part_type = GParted::TYPE_UNALLOCATED ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
new_start = START + (spinbutton_before .get_value_as_int() * MEBIBYTE) ;
|
|
|
|
new_end = new_start + (spinbutton_size .get_value_as_int() * MEBIBYTE) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2006-01-20 16:35:06 -07:00
|
|
|
/* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new
|
2006-01-07 08:04:42 -07:00
|
|
|
* partition thinks it's bigger then it can be. Here we try to solve this.*/
|
2004-09-19 14:24:53 -06:00
|
|
|
if ( new_start < selected_partition.sector_start )
|
|
|
|
new_start = selected_partition.sector_start ;
|
|
|
|
if ( new_end > selected_partition.sector_end )
|
|
|
|
new_end = selected_partition.sector_end ;
|
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
part_temp .status = GParted::STAT_NEW ;
|
2005-12-07 15:44:40 -07:00
|
|
|
part_temp .Set( selected_partition .device_path,
|
|
|
|
String::ucompose( _("New Partition #%1"), new_count ),
|
2004-11-17 06:00:25 -07:00
|
|
|
new_count, part_type,
|
2006-02-25 03:09:30 -07:00
|
|
|
FILESYSTEMS[ optionmenu_filesystem .get_history() ] .filesystem,
|
2004-11-17 06:00:25 -07:00
|
|
|
new_start, new_end,
|
2006-02-25 03:09:30 -07:00
|
|
|
selected_partition .inside_extended, false ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2006-01-20 16:35:06 -07:00
|
|
|
//grow new partition a bit if freespaces are < 1 MiB
|
2006-01-21 17:07:27 -07:00
|
|
|
if ( (part_temp.sector_start - selected_partition.sector_start) < MEBIBYTE )
|
2004-09-19 14:24:53 -06:00
|
|
|
part_temp.sector_start = selected_partition.sector_start ;
|
2006-01-21 17:07:27 -07:00
|
|
|
if ( (selected_partition.sector_end - part_temp.sector_end) < MEBIBYTE )
|
2004-09-19 14:24:53 -06:00
|
|
|
part_temp.sector_end = selected_partition.sector_end ;
|
2004-11-06 04:55:03 -07:00
|
|
|
|
|
|
|
//if new is extended...
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( part_temp .type == GParted::TYPE_EXTENDED )
|
2004-11-06 04:55:03 -07:00
|
|
|
{
|
|
|
|
Partition UNALLOCATED ;
|
2006-02-25 03:09:30 -07:00
|
|
|
UNALLOCATED .Set_Unallocated( part_temp .device_path,
|
|
|
|
part_temp .sector_start,
|
|
|
|
part_temp .sector_end,
|
|
|
|
true ) ;
|
2004-11-06 04:55:03 -07:00
|
|
|
part_temp .logicals .push_back( UNALLOCATED ) ;
|
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2006-01-07 08:04:42 -07:00
|
|
|
part_temp .strict = ! checkbutton_round_to_cylinders .get_active() ;
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
return part_temp;
|
|
|
|
}
|
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
void Dialog_Partition_New::optionmenu_changed( bool type )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
|
|
|
//optionmenu_type
|
|
|
|
if ( type )
|
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
if ( optionmenu_type .get_history() == GParted::TYPE_EXTENDED &&
|
|
|
|
menu_filesystem .items() .size() < FILESYSTEMS .size() )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_filesystem .items() .push_back(
|
2006-03-28 05:40:29 -07:00
|
|
|
Gtk::Menu_Helpers::MenuElem( Utils::get_filesystem_string( GParted::FS_EXTENDED ) ) ) ;
|
2006-02-25 03:09:30 -07:00
|
|
|
optionmenu_filesystem .set_history( menu_filesystem .items() .size() -1 ) ;
|
2004-11-23 12:03:39 -07:00
|
|
|
optionmenu_filesystem .set_sensitive( false ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
2006-02-25 03:09:30 -07:00
|
|
|
else if ( optionmenu_type .get_history() != GParted::TYPE_EXTENDED &&
|
|
|
|
menu_filesystem .items() .size() == FILESYSTEMS .size() )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_filesystem .items() .remove( menu_filesystem .items() .back() ) ;
|
2004-11-23 12:03:39 -07:00
|
|
|
optionmenu_filesystem .set_sensitive( true ) ;
|
2004-11-29 06:20:05 -07:00
|
|
|
optionmenu_filesystem .set_history( first_creatable_fs ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//optionmenu_filesystem
|
|
|
|
if ( ! type )
|
|
|
|
{
|
2006-01-07 08:04:42 -07:00
|
|
|
fs = FILESYSTEMS[ optionmenu_filesystem .get_history() ] ;
|
|
|
|
|
|
|
|
if ( checkbutton_round_to_cylinders .get_active() )
|
|
|
|
{
|
|
|
|
if ( fs .MIN < cylinder_size )
|
|
|
|
fs .MIN = cylinder_size ;
|
|
|
|
}
|
2006-02-25 03:09:30 -07:00
|
|
|
else if ( fs .MIN < MEBIBYTE )
|
|
|
|
fs .MIN = MEBIBYTE ;
|
2004-12-10 13:42:23 -07:00
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
if ( selected_partition .get_length() < fs .MIN )
|
|
|
|
fs .MIN = selected_partition .get_length() ;
|
2004-12-10 13:42:23 -07:00
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
fs .MAX = ( fs .MAX && ( fs .MAX - cylinder_size ) < (TOTAL_MB * MEBIBYTE) ) ?
|
|
|
|
fs .MAX - cylinder_size : TOTAL_MB * MEBIBYTE ;
|
2004-12-09 15:56:33 -07:00
|
|
|
|
2006-03-28 05:40:29 -07:00
|
|
|
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
|
|
|
|
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set new spinbutton ranges
|
2006-02-25 03:09:30 -07:00
|
|
|
spinbutton_before .set_range(
|
2006-03-28 05:40:29 -07:00
|
|
|
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
|
2006-02-25 03:09:30 -07:00
|
|
|
spinbutton_size .set_range(
|
2006-03-28 05:40:29 -07:00
|
|
|
Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
|
|
|
|
Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
|
2006-02-25 03:09:30 -07:00
|
|
|
spinbutton_after .set_range(
|
2006-03-28 05:40:29 -07:00
|
|
|
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
|
2004-12-01 14:31:59 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set contents of label_minmax
|
2006-02-25 03:09:30 -07:00
|
|
|
Set_MinMax_Text(
|
2006-03-28 05:40:29 -07:00
|
|
|
Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
|
|
|
|
Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//set fitting resizer colors
|
|
|
|
//backgroundcolor..
|
2006-01-07 08:04:42 -07:00
|
|
|
color_temp .set( optionmenu_type .get_history() == 2 ? "darkgrey" : "white" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
frame_resizer_base ->override_default_rgb_unused_color( color_temp );
|
|
|
|
|
|
|
|
//partitioncolor..
|
2006-03-28 05:40:29 -07:00
|
|
|
color_temp .set( Utils::get_color( fs .filesystem ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
frame_resizer_base ->set_rgb_partition_color( color_temp ) ;
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
frame_resizer_base ->Draw_Partition() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-10-06 09:32:40 -06:00
|
|
|
//fill the filesystem menu with the filesystems (except for extended)
|
2004-11-29 06:20:05 -07:00
|
|
|
for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) -1 ; t++ )
|
2004-10-06 09:32:40 -06:00
|
|
|
{
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_filesystem .items() .push_back(
|
2006-03-28 05:40:29 -07:00
|
|
|
Gtk::Menu_Helpers::MenuElem( Utils::get_filesystem_string( FILESYSTEMS[ t ] .filesystem ) ) ) ;
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_filesystem .items()[ t ] .set_sensitive(
|
|
|
|
! only_unformatted && FILESYSTEMS[ t ] .create &&
|
|
|
|
this ->selected_partition .get_length() >= FILESYSTEMS[ t ] .MIN ) ;
|
2004-10-06 09:32:40 -06:00
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-11-29 06:20:05 -07:00
|
|
|
//unformatted is always available
|
2006-02-25 03:09:30 -07:00
|
|
|
menu_filesystem .items() .back() .set_sensitive( true ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-12-01 14:31:59 -07:00
|
|
|
//find and set first enabled filesystem
|
2006-02-25 03:09:30 -07:00
|
|
|
for ( unsigned int t = 0 ; t < menu_filesystem .items() .size() ; t++ )
|
|
|
|
if ( menu_filesystem .items()[ t ] .sensitive() )
|
2004-12-01 14:31:59 -07:00
|
|
|
{
|
|
|
|
first_creatable_fs = t ;
|
|
|
|
break ;
|
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|