From 24dccdd8f30a00d42091fd12056f7c9eaa7217cc Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Sat, 6 Nov 2004 11:55:03 +0000 Subject: [PATCH] instead of listing all partition in one list, logical partitions are now * instead of listing all partition in one list, logical partitions are now stored in a sublist in extended partition object. This makes partitionhandling in gparted more natural and transparant. It also allowed me to clean up this ugly Operation class ;) --- ChangeLog | 5 + include/Device.h | 6 +- include/Operation.h | 14 +- include/Partition.h | 2 + include/Utils.h | 3 +- include/VBox_VisualDisk.h | 9 +- include/Win_GParted.h | 2 +- src/Device.cc | 46 +++- src/Dialog_Partition_New.cc | 8 + src/Dialog_Partition_Resize_Move.cc | 40 ++- src/Operation.cc | 388 +++++++++------------------- src/Partition.cc | 1 + src/TreeView_Detail.cc | 21 +- src/VBox_VisualDisk.cc | 168 ++++++------ src/Win_GParted.cc | 167 ++++++------ 15 files changed, 411 insertions(+), 469 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b498d3c..2a085a57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-11-06 Bart Hakvoort + + * instead of listing all partition in one list, logical partitions are now stored in a sublist in extended partition object. + This makes partitionhandling in gparted more natural and transparant. It also allowed me to clean up this ugly Operation class ;) + 2004-10-31 Bart Hakvoort * include/Partition.h, diff --git a/include/Device.h b/include/Device.h index 96d74106..028ba80e 100644 --- a/include/Device.h +++ b/include/Device.h @@ -39,7 +39,6 @@ #include - namespace GParted { @@ -54,7 +53,7 @@ public: void Read_Disk_Layout( bool deep_scan = true ) ; bool Delete_Partition( const Partition & partition ) ; bool Create_Partition_With_Filesystem( Partition & new_part, PedTimer *timer) ; - bool Move_Resize_Partition( const Partition & partition_original, const Partition & partition_new , PedTimer *timer) ; + bool Move_Resize_Partition( const Partition & partition_original, const Partition & partition_new, PedTimer *timer) ; bool Set_Partition_Filesystem( const Partition & new_partition, PedTimer * timer); bool Copy_Partition( Device *source_device, const Partition & source_partition, PedTimer * timer ) ; int Create_Empty_Partition( const Partition & new_partition, PedConstraint * constraint = NULL ) ; @@ -73,7 +72,8 @@ public: Glib::ustring Get_DiskType() ; bool Get_any_busy() ; int Get_Max_Amount_Of_Primary_Partitions() ; - + int Get_Highest_Logical_Busy( ) ; + private: //make a try to get the amount of used sectors on a filesystem ( see comments in implementation ) Sector Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path ); diff --git a/include/Operation.h b/include/Operation.h index c9f79e90..03d5c8cf 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -55,12 +55,14 @@ public: Glib::ustring str_operation ; private: - std::vector Apply_Delete_To_Visual( std::vector & partitions ); - std::vector Apply_Create_To_Visual( std::vector & partitions ); - std::vector Apply_Resize_Move_To_Visual( std::vector & partitions ); - std::vector Apply_Resize_Move_Extended_To_Visual( std::vector & partitions ); - std::vector Apply_Convert_To_Visual( std::vector & partitions ); - + void Insert_Unallocated( std::vector & partitions, Sector start, Sector end ); + int Get_Index_Original( std::vector & partitions ) ; + + void Apply_Delete_To_Visual( std::vector & partitions ); + void Apply_Create_To_Visual( std::vector & partitions ); + void Apply_Resize_Move_To_Visual( std::vector & partitions ); + void Apply_Resize_Move_Extended_To_Visual( std::vector & partitions ); + Glib::ustring Get_String(); //only used during in c'tor void Show_Error( Glib::ustring message ) ; diff --git a/include/Partition.h b/include/Partition.h index 284599b5..b010ad02 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -93,6 +93,8 @@ public: Glib::ustring error; Glib::ustring flags; + std::vector logicals ; + private: diff --git a/include/Utils.h b/include/Utils.h index 9718de06..5a04a2c9 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -127,12 +127,11 @@ inline Glib::ustring Get_Color( const Glib::ustring & filesystem ) else if ( filesystem == "unallocated" ) return "darkgrey"; else if ( filesystem == "extended" ) return "#7DFCFE" ; - //unknown filesystem ( damaged, unknown or simply no filesystem ) + //unknown filesystem ( damaged, unknown or simply no filesystem ) else return "black"; } - }//GParted #endif //UTILS diff --git a/include/VBox_VisualDisk.h b/include/VBox_VisualDisk.h index 727ce013..4f2d8fbb 100644 --- a/include/VBox_VisualDisk.h +++ b/include/VBox_VisualDisk.h @@ -63,13 +63,14 @@ public: private: - void Build_Visual_Disk( int ) ; //i still dream of some fully resizeable visualdisk.... + void Build_Visual_Disk( ) ; //i still dream of some fully resizeable visualdisk.... + void Create_Visual_Partition( Partition & partition ) ; void Build_Legend( ) ; //signal handlers - void drawingarea_on_realize( Visual_Partition * ); + void drawingarea_on_realize( Visual_Partition * ); bool drawingarea_on_expose( GdkEventExpose *, Visual_Partition* ); - bool on_drawingarea_button_press( GdkEventButton *, const Partition & ); + bool on_drawingarea_button_press( GdkEventButton *, const Partition & ); std::vector partitions; Sector device_length; @@ -86,7 +87,7 @@ private: Glib::ustring str_temp ; - int temp,selected_partition; + int temp, selected_partition, SCREEN_WIDTH; }; } //GParted diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 999ba48b..a3fbbedb 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -105,6 +105,7 @@ private: void menu_help_about(); void mouse_click( GdkEventButton*, const Partition & ); + bool max_amount_prim_reached() ; void activate_resize(); void activate_copy(); @@ -168,7 +169,6 @@ private: //usefull variables which are used by many different functions... bool any_logic,any_extended;//used in some checks (e.g. see optionmenu_devices_changed() - unsigned short highest_logic_busy ;//highest_logic_busy contains the number of the highest logical which is busy ( 0 if none is busy) unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions unsigned short new_count;//new_count keeps track of the new created partitions Glib::ustring str_temp ; //mostly used for constructing dialogmessages diff --git a/src/Device.cc b/src/Device.cc index 9d83b9f5..f7d86ed0 100644 --- a/src/Device.cc +++ b/src/Device.cc @@ -98,10 +98,11 @@ Device::Device( const Glib::ustring & device_path, std::vector *filesystems void Device::Read_Disk_Layout( bool deep_scan ) { Glib::ustring part_path ; + int EXT_INDEX = -1 ; //clear partitions - this ->device_partitions .clear() ; - + this ->device_partitions .clear( ) ; + c_partition = ped_disk_next_partition( disk, NULL ) ; while ( c_partition ) { @@ -131,7 +132,7 @@ void Device::Read_Disk_Layout( bool deep_scan ) c_partition ->type == 0 ? GParted::PRIMARY : GParted::LOGICAL , temp, c_partition ->geom .start, c_partition ->geom .end, - c_partition ->type , + c_partition ->type, ped_partition_is_busy( c_partition ) ); if ( deep_scan ) @@ -139,6 +140,7 @@ void Device::Read_Disk_Layout( bool deep_scan ) partition_temp .flags = Get_Flags( c_partition ) ; partition_temp .error = this ->error ;//most likely useless, but paranoia me leaves it here.. =) + break ; @@ -153,6 +155,7 @@ void Device::Read_Disk_Layout( bool deep_scan ) ped_partition_is_busy( c_partition ) ); partition_temp .flags = Get_Flags( c_partition ) ; + EXT_INDEX = device_partitions .size ( ) ; break ; @@ -160,13 +163,29 @@ void Device::Read_Disk_Layout( bool deep_scan ) case 5: //freespace inside extended (there's no enumvalue for that..) partition_temp.Set_Unallocated( c_partition ->geom .start, c_partition ->geom .end, c_partition ->type == 4 ? false : true ); break ; + + case PED_PARTITION_METADATA: + if ( device_partitions .size( ) && device_partitions .back( ) .type == GParted::UNALLOCATED ) + device_partitions .back( ) .sector_end = c_partition ->geom .end ; + + break ; + + case 9: //metadata inside extended (there's no enumvalue for that..) + if ( device_partitions[ EXT_INDEX ] .logicals .size( ) && device_partitions[ EXT_INDEX ] .logicals .back( ) .type == GParted::UNALLOCATED ) + device_partitions[ EXT_INDEX ] .logicals .back( ) .sector_end = c_partition ->geom .end ; + break ; default: break; } - if ( partition_temp .Get_Length_MB( ) >= 1 ) //paranoia check for unallocated < 1MB - device_partitions.push_back( partition_temp ); + if ( partition_temp .Get_Length_MB( ) >= 1 ) // check for unallocated < 1MB, and metadatasituations (see PED_PARTITION_METADATA and 9 ) + { + if ( ! partition_temp .inside_extended ) + device_partitions.push_back( partition_temp ); + else + device_partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ; + } //reset stuff.. this ->error = error_message = "" ; @@ -449,6 +468,23 @@ int Device::Get_Max_Amount_Of_Primary_Partitions() return ped_disk_get_max_primary_partition_count( disk ) ; } +int Device::Get_Highest_Logical_Busy( ) +{ + int highest_logic_busy = -1 ; + + for ( unsigned int t = 0 ; t < device_partitions .size( ) ; t++ ) + if ( device_partitions [ t ] .type == GParted::EXTENDED ) + { + for ( unsigned int i = 0 ; i < device_partitions[ t ] .logicals .size( ) ; i++ ) + if ( device_partitions[ t ] .logicals[ i ] .busy && device_partitions[ t ] .logicals[ i ] .partition_number > highest_logic_busy ) + highest_logic_busy = device_partitions[ t ] .logicals[ i ] .partition_number ; + + break ; + } + + return highest_logic_busy ; +} + Sector Device::Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path) { /* This is quite an unreliable process, atm i try two different methods, but since both are far from perfect the results are diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index e89cfa6e..9078437f 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -143,6 +143,14 @@ Partition Dialog_Partition_New::Get_New_Partition() part_temp.sector_start = selected_partition.sector_start ; if ( (selected_partition.sector_end - part_temp.sector_end) < MEGABYTE ) part_temp.sector_end = selected_partition.sector_end ; + + //if new is extended... + if ( part_temp .type == GParted::EXTENDED ) + { + Partition UNALLOCATED ; + UNALLOCATED .Set_Unallocated( part_temp .sector_start, part_temp .sector_end, true ) ; + part_temp .logicals .push_back( UNALLOCATED ) ; + } return part_temp; } diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index acade8c8..c9c3dac0 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -62,7 +62,6 @@ void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partitio void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector & partitions ) { - //see if we need a fixed_start if ( selected_partition.filesystem == "ext2" || selected_partition.filesystem == "ext3" || selected_partition.filesystem == "reiserfs" ) { @@ -81,13 +80,16 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector = 1 && partitions[t -1].type == GParted::UNALLOCATED && selected_partition.filesystem != "ext2" && selected_partition.filesystem != "ext3" && selected_partition.filesystem != "reiserfs" && partitions[t -1] .inside_extended == selected_partition.inside_extended ) + if ( t >= 1 && partitions[t -1].type == GParted::UNALLOCATED && + selected_partition.filesystem != "ext2" && + selected_partition.filesystem != "ext3" && + selected_partition.filesystem != "reiserfs" ) { previous = partitions[t -1] .sector_end - partitions[t -1] .sector_start ; START = partitions[t -1] .sector_start ; @@ -95,7 +97,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector device = device; - this->device_path = device ->Get_Path() ; + this ->device = device; + this ->device_path = device ->Get_Path( ) ; //this is only used when operationtype == COPY - this->source_device = source_device; - this->source_device_path = source_device ->Get_Path() ; + this ->source_device = source_device; + this ->source_device_path = source_device ->Get_Path( ) ; - this->partition_original = partition_original; - this->partition_new = partition_new; - this->operationtype = operationtype; + this ->partition_original = partition_original; + this ->partition_new = partition_new; + this ->operationtype = operationtype; - str_operation = Get_String() ; + str_operation = Get_String( ) ; //not the nicest place to put this, but definetly the most efficient :) if ( operationtype == COPY ) - this->partition_new .partition = String::ucompose( _("copy of %1"), this->partition_new .partition ); + this ->partition_new .partition = String::ucompose( _("copy of %1"), this ->partition_new .partition ); } -Glib::ustring Operation::Get_String() +Glib::ustring Operation::Get_String( ) { Glib::ustring temp ; Sector diff ; @@ -80,19 +80,19 @@ Glib::ustring Operation::Get_String() if ( diff >= MEGABYTE ) { - if ( temp .empty() ) + if ( temp .empty( ) ) temp = String::ucompose( _("Resize %1 from %2 MB to %3 MB"), partition_new.partition, partition_original .Get_Length_MB(), partition_new .Get_Length_MB() ) ; else temp += " " + String::ucompose( _("and Resize %1 from %2 MB to %3 MB"), partition_new.partition, partition_original .Get_Length_MB(), partition_new .Get_Length_MB() ) ; } - if ( temp .empty() ) + if ( temp .empty( ) ) temp = _("Sorry, changes are too small to make sense"); return temp; case CONVERT : /*TO TRANSLATORS: looks like Convert /dev/hda4 from ntfs to linux-swap */ return String::ucompose( _( "Convert %1 from %2 to %3"), partition_original .partition, partition_original .filesystem, partition_new .filesystem ) ; case COPY : /*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 2500 MB) */ - return String::ucompose( _("Copy %1 to %2 (start at %3 MB)"), partition_new .partition, device ->Get_Path(), Sector_To_MB( partition_new .sector_start ) ) ; + return String::ucompose( _("Copy %1 to %2 (start at %3 MB)"), partition_new .partition, device ->Get_Path( ), Sector_To_MB( partition_new .sector_start ) ) ; default : return ""; } @@ -103,11 +103,11 @@ std::vector Operation::Apply_Operation_To_Visual( std::vector Operation::Apply_Delete_To_Visual( std::vector & partitions ) +void Operation::Insert_Unallocated( std::vector & partitions, Sector start, Sector end ) { - unsigned int t ; + Partition UNALLOCATED ; + UNALLOCATED .Set_Unallocated( 0, 0, partitions .front( ) .inside_extended ) ; - for ( t=0;tpartition_original.type == GParted::EXTENDED && partitions[t].type == GParted::EXTENDED ) + UNALLOCATED .sector_start = start ; + UNALLOCATED .sector_end = end ; + + partitions .push_back( UNALLOCATED ); + + return ; + } + + //start <---> first partition start + if ( (partitions .front( ) .sector_start - start) >= MEGABYTE ) + { + UNALLOCATED .sector_start = start ; + UNALLOCATED .sector_end = partitions .front( ) .sector_start -1 ; + + partitions .insert( partitions .begin( ), UNALLOCATED ); + } + + //look for gaps in between + for ( unsigned int t =0 ; t < partitions .size( ) -1 ; t++ ) + if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= MEGABYTE ) { - partitions[t+1].inside_extended = false; - partitions.erase( partitions.begin() + t ); - break;//we're done here ;-) + UNALLOCATED .sector_start = partitions[ t ] .sector_end +1 ; + UNALLOCATED .sector_end = partitions[ t +1 ] .sector_start -1 ; + + partitions .insert( partitions .begin( ) + ++t, UNALLOCATED ); } - else if ( partitions[t].sector_start == this-> partition_original.sector_start ) - { - partitions[t].Set_Unallocated( partition_original.sector_start , partition_original.sector_end, partition_original.inside_extended ); - break;//we're done here ;-) - } - } - - - //if deleted partition was logical we have to decrease the partitionnumbers of the logicals with higher numbers by one (only if its a real partition) - if ( partition_original.type == GParted::LOGICAL && partition_original .status != GParted::STAT_NEW ) - for ( t=0;t partition_original.partition_number ) - partitions[t].Update_Number( partitions[t].partition_number -1 ); - - - //now we merge separate unallocated spaces next to each other together FIXME: more performance if we only check t -1 and t +1 - for ( t=0;t end + if ( (end - partitions .back( ) .sector_end ) >= MEGABYTE ) { - if ( partitions[t].type == GParted::UNALLOCATED && partitions[t +1].type == GParted::UNALLOCATED && partitions[t].inside_extended == partitions[t +1].inside_extended ) - { - partitions[t].sector_end = partitions[t+1].sector_end; - partitions.erase( partitions.begin() + t + 1 ); - t--; - } + UNALLOCATED .sector_start = partitions .back( ) .sector_end +1 ; + UNALLOCATED .sector_end = end ; + + partitions .push_back( UNALLOCATED ); } - - return partitions; } -std::vector Operation::Apply_Create_To_Visual( std::vector & partitions ) -{ - Partition partition_temp; - - //find the original partition and replace it with the new one (original "partition" is unallocated space of course) - unsigned int t; - for ( t=0;t= partitions[t].sector_start && partition_new.sector_start <= partitions[t].sector_end && partitions[t].type != GParted::EXTENDED ) - { - partition_original = partitions[t] ; - partitions.erase( partitions.begin() + t ); - partitions.insert( partitions.begin() + t, partition_new ); - break; - } - - } - - - //check borders and create new elements if necessary - //BEFORE new partition - if ( (partition_new.sector_start - partition_original.sector_start) >= MEGABYTE ) //at least 1 MB between begin new partition and begin original one - { - partition_temp.Set_Unallocated( partition_original.sector_start, partition_new.sector_start -1 , partition_new.inside_extended ); - partitions.insert( partitions.begin() + t, partition_temp ); - t++; - } - - //AFTER new partition - if ( ( partition_original.sector_end - partition_new.sector_end) >= MEGABYTE ) //at least 1 MB between end new partition and end original one - { - partition_temp.Set_Unallocated( partition_new.sector_end +1, partition_original.sector_end ,partition_new.inside_extended ); - partitions.insert( partitions.begin() + t +1, partition_temp ); - } - - //if new created partition is an extended partition, we need to add unallocated space of the same size to the list - if ( partition_new.type == GParted::EXTENDED ) - { - partition_temp.Set_Unallocated( partition_new.sector_start, partition_new.sector_end , true ); - partitions.insert( partitions.begin() + t +1, partition_temp ); - } - - return partitions; -} - -std::vector Operation::Apply_Resize_Move_To_Visual( std::vector & partitions) +int Operation::Get_Index_Original( std::vector & partitions ) { - //extended handling is so different i decided to take it apart from normal handling - if ( partition_original.type == GParted::EXTENDED ) - return Apply_Resize_Move_Extended_To_Visual( partitions ) ; - - //normal partitions ( Primary and Logical ) - Partition partition_temp; - - unsigned int t; - for ( t=0;t= partitions[t].sector_start && partition_original.sector_start <= partitions[t].sector_end && partitions[t].type != GParted::EXTENDED ) + for ( int t = 0 ; t < (int)partitions .size( ) ; t++ ) + if ( partition_original .sector_start >= partitions[ t ] .sector_start && partition_original .sector_end <= partitions[ t ] .sector_end ) { - partition_original = partitions[t] ; - partitions[t].sector_start = partition_new.sector_start ; - partitions[t].sector_end = partition_new.sector_end ; - partitions[t].sectors_unused = partition_new.sectors_unused ; - break; - } - } - - //determine correct perimeters of moving/resizing space - Sector START = partition_original.sector_start ; - Sector END = partition_original.sector_end ; - - - //now we have the index of the original partition we can remove the surrounding partitions ( if UNALLOCATED and inside_extended is the same ) - if ( t > 0 && partitions[t -1].type == GParted::UNALLOCATED && partitions[t -1].inside_extended == partition_new.inside_extended ) - { - START = partitions[t -1] .sector_start ; - partitions.erase( partitions.begin() + t -1 ); - t-- ; - } + //remove unallocated space preceding the original partition + if ( t -1 >= 0 && partitions[ t -1 ] .type == GParted::UNALLOCATED ) + partitions .erase( partitions .begin( ) + --t ); + + //remove unallocated space following the original partition + if ( t +1 < (int)partitions .size( ) && partitions[ t +1 ] .type == GParted::UNALLOCATED ) + partitions .erase( partitions .begin( ) + t +1 ); - if ( t +1 < partitions.size() && partitions[t +1].type == GParted::UNALLOCATED && partitions[t +1].inside_extended == partition_new.inside_extended) - { - END = partitions[t +1] .sector_end ; - partitions.erase( partitions.begin() + t +1 ); - } - - //now look for unallocated space > 1 MB and add to the list - if ( (partition_new.sector_start - START) >= MEGABYTE ) - { - partition_temp.Set_Unallocated( START, partition_new.sector_start -1 , partition_new.inside_extended ); - partitions.insert( partitions.begin() + t , partition_temp ); - t++; - } + return t ; + } - if ( (END - partition_new.sector_end) >= MEGABYTE ) - { - partition_temp.Set_Unallocated( partition_new.sector_end +1, END , partition_new.inside_extended ); - partitions.insert( partitions.begin() + t +1, partition_temp ); - } - - - return partitions; + return -1 ; } -std::vector Operation::Apply_Resize_Move_Extended_To_Visual( std::vector & partitions ) +void Operation::Apply_Delete_To_Visual( std::vector & partitions ) { - unsigned int t, INDEX =0; + if ( ! partition_original .inside_extended ) + { + partitions .erase( partitions .begin( ) + Get_Index_Original( partitions ) ); - //look for index of partition and set the extended partition's new size. - for ( t=0;tGet_Length( ) -1 ) ; + } + else + { + //unsigned int ext = Get_Index_Extended( partitions ) ; + unsigned int ext = 0 ; + while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; + partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) + Get_Index_Original( partitions[ ext ] .logicals ) ); + + + //if deleted partition was logical we have to decrease the partitionnumbers of the logicals with higher numbers by one (only if its a real partition) + if ( partition_original .status != GParted::STAT_NEW ) + for ( unsigned int t = 0 ; t < partitions[ ext ] .logicals .size( ) ; t++ ) + if ( partitions[ ext ] .logicals[ t ] .partition_number > partition_original .partition_number ) + partitions[ ext ] .logicals[ t ] .Update_Number( partitions[ ext ] .logicals[ t ] .partition_number -1 ); - break; - } + + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; } - - - /* remove all relevant unallocated spaces... - * E.G. partitions looks like: P-P-U-E-U-L-L-U-U <--- last U is OUTSIDE extended!! - * 1-2 - 3- 4- 5 -6-7- 8 - 9 - * now we check 3, 5, 8 and 9 . If any of them is unallocated we remove it. In this case all of them.. :) - */ - - //check 3 - if ( partitions[ INDEX -1 ] .type == GParted::UNALLOCATED ) - partitions .erase( partitions .begin() + --INDEX ) ; - - //check 5 - if ( partitions[ INDEX +1 ] .type == GParted::UNALLOCATED ) - partitions .erase( partitions .begin() + INDEX +1 ) ; - - //find index of last logic - for ( t = partitions.size() -1 ; ! partitions[ t ] .inside_extended && t > INDEX ; t-- ) {} - - //check 8 - if ( t > INDEX && partitions[ t ] .type == GParted::UNALLOCATED ) - partitions .erase( partitions .begin() + t ) ; - else - t++ ; - - //check 9 - if ( t < partitions .size( ) && partitions[ t ] .type == GParted::UNALLOCATED ) - partitions .erase( partitions .begin() + t ) ; - - - - //and insert new unallocated spaces at fitting places - Sector TEMP ; - Partition partition_temp ; - - //check 3 - TEMP = INDEX > 0 ? partitions[ INDEX -1 ] .sector_end +1 : 0 ; - if ( ( partitions[ INDEX ] .sector_start - TEMP ) > MEGABYTE ) - { - partition_temp.Set_Unallocated( TEMP, partitions[ INDEX ] .sector_start -1, false ) ; - partitions.insert( partitions.begin() + INDEX, partition_temp ); - INDEX++; - } - - //check 5 - if ( (INDEX +1) < partitions .size() && partitions[ INDEX +1 ] .type == GParted::LOGICAL ) - TEMP = partitions[ INDEX +1 ] .sector_start -1 ; - else - TEMP = partition_new .sector_end ; - - if ( ( TEMP - partitions[ INDEX ] .sector_start ) > MEGABYTE ) - { - partition_temp.Set_Unallocated( partitions[ INDEX ] .sector_start, TEMP, true ) ; - partitions.insert( partitions.begin() +INDEX +1, partition_temp ); - } - - - //find index of last logic - for ( t = partitions .size( ) -1 ; ! partitions[ t ] .inside_extended && t > INDEX ; t-- ) { } - - //check 8 - if ( partitions[ t ] .type != GParted::UNALLOCATED && ( partition_new .sector_end - partitions[ t ] .sector_end ) > MEGABYTE ) - { - partition_temp.Set_Unallocated( partitions[ t ] .sector_end +1, partition_new .sector_end, true ) ; - partitions.insert( partitions.begin() +t +1, partition_temp ); - t++ ; - } - - //check 9 - t++ ; - TEMP = t < partitions .size() ? partitions[ t ] .sector_start -1 : device ->Get_Length() -1; - - if ( ( TEMP - partition_new .sector_end ) > MEGABYTE ) - { - partition_temp.Set_Unallocated( partition_new .sector_end +1, TEMP -1, false ) ; - partitions.insert( partitions.begin() +t, partition_temp ); - } - - - return partitions ; } -std::vector Operation::Apply_Convert_To_Visual( std::vector & partitions ) -{ - for ( unsigned int t=0;t= partitions[t].sector_start && partition_original.sector_start <= partitions[t].sector_end && partitions[t].type != GParted::EXTENDED ) - { - partitions[ t ] = partition_new ; - break; - } +void Operation::Apply_Create_To_Visual( std::vector & partitions ) +{ + if ( ! partition_original .inside_extended ) + { + partitions[ Get_Index_Original( partitions ) ] = partition_new ; + + Insert_Unallocated( partitions, 0, device ->Get_Length( ) -1 ) ; } + else + { + unsigned int ext = 0 ; + while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; + partitions[ ext ] .logicals[ Get_Index_Original( partitions[ ext ] .logicals ) ] = partition_new ; + + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; + } +} + +void Operation::Apply_Resize_Move_To_Visual( std::vector & partitions) +{ + if ( partition_original .type == GParted::EXTENDED ) + Apply_Resize_Move_Extended_To_Visual( partitions ) ; + else + Apply_Create_To_Visual( partitions ) ; +} + +void Operation::Apply_Resize_Move_Extended_To_Visual( std::vector & partitions ) +{ + //stuff OUTSIDE extended partition + partitions[ Get_Index_Original( partitions ) ] = partition_new ; + Insert_Unallocated( partitions, 0, device ->Get_Length( ) -1 ) ; - return partitions; + //stuff INSIDE extended partition + unsigned int ext = 0 ; + while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; + if ( partitions[ ext ] .logicals .size( ) && partitions[ ext ] .logicals .front( ) .type == GParted::UNALLOCATED ) + partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) ) ; + + if ( partitions[ ext ] .logicals .size( ) && partitions[ ext ] .logicals .back( ) .type == GParted::UNALLOCATED ) + partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .end( ) -1 ) ; + + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; } void Operation::Show_Error( Glib::ustring message ) diff --git a/src/Partition.cc b/src/Partition.cc index 083e3844..1c8ebb3d 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -33,6 +33,7 @@ void Partition::Reset( ) partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1; color.set( "black" ) ; inside_extended = busy = false ; + logicals .clear( ) ; } void Partition::Set( const Glib::ustring & partition, diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index db9cb772..02b34445 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -51,7 +51,7 @@ TreeView_Detail::TreeView_Detail( ) this->get_column( 1 ) ->pack_start( treeview_detail_columns .type, false ); //this sucks :) get_cell_renderers doesn't return them in some order, so i have to check manually... - std::vector renderers = this->get_column( 1 ) ->get_cell_renderers() ; + std::vector renderers = this->get_column( 1 ) ->get_cell_renderers( ) ; if ( renderers .front() != this->get_column( 1 ) ->get_first_cell_renderer() ) cell_renderer_text = dynamic_cast( renderers .front() ) ; @@ -74,7 +74,7 @@ void TreeView_Detail::Load_Partitions( std::vector & partitions ) { treestore_detail ->clear() ; - for ( unsigned int i=0;i & partitions ) Create_Row( childrow, partitions[i] ); } } +*/ + + for ( unsigned int i=0;iappend()); + Create_Row( row, partitions[i] ); + + if ( partitions[i] .type == GParted::EXTENDED ) + { + for ( unsigned int t=0;tappend( row.children() )); + Create_Row( childrow, partitions[i] .logicals[ t ] ); + } + + } + } //show logical partitions ( if any ) this->expand_all(); diff --git a/src/VBox_VisualDisk.cc b/src/VBox_VisualDisk.cc index 1c1f9ef0..381d8f92 100644 --- a/src/VBox_VisualDisk.cc +++ b/src/VBox_VisualDisk.cc @@ -62,103 +62,114 @@ VBox_VisualDisk::VBox_VisualDisk( const std::vector & partitions, con } //draw visual disk and its legend - Build_Visual_Disk( 750 - Round( extra_pixels ) ) ; - - Build_Legend( ) ; + this ->SCREEN_WIDTH = 750 - Round( extra_pixels ) ; + Build_Visual_Disk( ) ; + Build_Legend( ) ; } -void VBox_VisualDisk::Build_Visual_Disk( int SCREEN_WIDTH ) +void VBox_VisualDisk::Build_Visual_Disk( ) { //since there is a 5 pixel space between every partition.... ( extended adds 2 *5 more, but that doesn't matter that much. //NOTE that a part < 20 will also grow to 20, so length in pixels may vary across different devices.. - SCREEN_WIDTH -= ( (partitions .size() -1) *5 ) ; + this ->SCREEN_WIDTH -= ( (partitions .size() -1) *5 ) ; //create hbox_disk and add to frame hbox_disk = manage( new Gtk::HBox() ) ; hbox_disk ->set_spacing( 5 ); - frame_disk_legend ->add ( *hbox_disk ); + frame_disk_legend ->add( *hbox_disk ); //walk through all partitions.... - int x,y;//for pango_layout check for ( unsigned int i=0;iindex = i ; - visual_partitions.back() ->sector_start = partitions[i].sector_start ; + Create_Visual_Partition( partitions[i] ) ; - if ( partitions[i].type == GParted::EXTENDED ) - { - visual_partitions.back() ->drawingarea = NULL ;//it's just a dummy ;-) ( see Set_Selected() ) - visual_partitions.back() ->length = 0 ; //keeps total_length clean - - eventbox_extended = manage( new Gtk::EventBox() ) ; - eventbox_extended ->set_size_request( -1, 60 ); - eventbox_extended ->modify_bg( eventbox_extended ->get_state(), partitions[i].color ); - hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ; - - hbox_extended = manage( new Gtk::HBox() ) ; - hbox_extended ->set_border_width( 5 ); - hbox_extended ->set_spacing( 5 ); - eventbox_extended ->add( *hbox_extended ) ; - continue; - } - - visual_partitions.back() ->length = (int) (SCREEN_WIDTH / (double) ( device_length / (double) ( partitions[i].sector_end - partitions[i].sector_start) ) ); - if ( visual_partitions.back() ->length < 20 )//we need a min. size. Otherwise some small partitions wouldn't be visible - partitions[i] .type == GParted::UNALLOCATED ? visual_partitions.back() ->length = 15 : visual_partitions.back() ->length = 20 ; - - if ( partitions[i].inside_extended ) - { visual_partitions.back() ->height = 34 ; visual_partitions.back() ->text_y = 9 ; } - else - { visual_partitions.back() ->height = 44 ;visual_partitions.back() ->text_y = 15 ; } - - if ( partitions[i].type == GParted::UNALLOCATED ) - visual_partitions.back() ->used = -1; - else - visual_partitions.back() ->used = (int) ( (visual_partitions.back() ->length - (BORDER *2)) / (double) ( ( partitions[i].sector_end - partitions[i].sector_start) / (double)partitions[i].sectors_used ) ) ; - - - visual_partitions.back() ->color_fs = partitions[i] .color; - this ->get_colormap() ->alloc_color(visual_partitions.back() ->color_fs); - - visual_partitions.back() ->drawingarea = manage( new Gtk::DrawingArea() ) ; - visual_partitions.back() ->drawingarea ->set_size_request( visual_partitions.back() ->length +1, 60 ); - visual_partitions.back() ->drawingarea ->set_events(Gdk::BUTTON_PRESS_MASK); - - //connect signal handlers - visual_partitions.back() ->drawingarea ->signal_button_press_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::on_drawingarea_button_press), partitions[i] ) ); - visual_partitions.back() ->drawingarea ->signal_realize().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize), visual_partitions.back() ) ); - visual_partitions.back() ->drawingarea ->signal_expose_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose), visual_partitions.back() )); - - //create pangolayout and see if it fits in the visual partition - str_temp = partitions[i] .partition + "\n" + String::ucompose( _("%1 MB"), partitions[i] .Get_Length_MB() ) ; - visual_partitions.back() ->pango_layout = visual_partitions.back() ->drawingarea ->create_pango_layout ( str_temp ) ; - - visual_partitions.back() ->pango_layout ->get_pixel_size( x, y ) ; - if ( visual_partitions.back() ->length - BORDER * 2 -2 < x ) - visual_partitions.back() ->pango_layout ->set_text( "" ) ; - - //tooltip - str_temp = "" ; - if ( partitions[i].type != GParted::UNALLOCATED ) - str_temp = partitions[i] .filesystem + "\n" ; - - str_temp += partitions[i] .partition + "\n" + String::ucompose( _("%1 MB"), partitions[i] .Get_Length_MB() ) ; - tooltips.set_tip( *(visual_partitions.back() ->drawingarea), str_temp ) ; - - if ( partitions[i] .inside_extended ) - hbox_extended ->pack_start( *(visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; - else - hbox_disk ->pack_start( *(visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; - + if ( partitions[i].type != GParted::EXTENDED ) + hbox_disk ->pack_start( *( visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; } this ->show_all_children() ; } +void VBox_VisualDisk::Create_Visual_Partition( Partition & partition ) +{ + int x,y;//for pango_layout check + + visual_partition = new Visual_Partition() ; + visual_partitions.push_back( visual_partition ) ; + visual_partitions.back() ->index = visual_partitions .size() -1 ; // <---- BELACHELIJK!! DOE DAAR IETS AAN!!! + visual_partitions.back() ->sector_start = partition .sector_start ; + + if ( partition .type == GParted::EXTENDED ) + { + visual_partitions.back() ->drawingarea = NULL ;//it's just a dummy ;-) ( see Set_Selected() ) + visual_partitions.back() ->length = 0 ; //keeps total_length clean + + eventbox_extended = manage( new Gtk::EventBox() ) ; + eventbox_extended ->set_size_request( -1, 60 ); + eventbox_extended ->modify_bg( eventbox_extended ->get_state(), partition .color ); + hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ; + + hbox_extended = manage( new Gtk::HBox() ) ; + hbox_extended ->set_border_width( 5 ); + hbox_extended ->set_spacing( 5 ); + eventbox_extended ->add( *hbox_extended ) ; + + for ( unsigned int t=0;tpack_start( *( visual_partitions.back() ->drawingarea), Gtk::PACK_SHRINK ) ; + } + + + return ; + } + + visual_partitions.back() ->length = (int) (SCREEN_WIDTH / (double) ( device_length / (double) ( partition .sector_end - partition .sector_start) ) ); + if ( visual_partitions.back() ->length < 20 )//we need a min. size. Otherwise some small partitions wouldn't be visible + partition .type == GParted::UNALLOCATED ? visual_partitions.back() ->length = 15 : visual_partitions.back() ->length = 20 ; + + if ( partition .inside_extended ) + { visual_partitions.back() ->height = 34 ; visual_partitions.back() ->text_y = 9 ; } + else + { visual_partitions.back() ->height = 44 ;visual_partitions.back() ->text_y = 15 ; } + + if ( partition .type == GParted::UNALLOCATED ) + visual_partitions.back() ->used = -1; + else + visual_partitions.back() ->used = (int) ( (visual_partitions.back() ->length - (BORDER *2)) / (double) ( ( partition .sector_end - partition .sector_start) / (double)partition .sectors_used ) ) ; + + + visual_partitions.back() ->color_fs = partition .color; + this ->get_colormap() ->alloc_color(visual_partitions.back() ->color_fs); + + visual_partitions.back() ->drawingarea = manage( new Gtk::DrawingArea() ) ; + visual_partitions.back() ->drawingarea ->set_size_request( visual_partitions.back() ->length +1, 60 ); + visual_partitions.back() ->drawingarea ->set_events(Gdk::BUTTON_PRESS_MASK); + + //connect signal handlers + visual_partitions.back() ->drawingarea ->signal_button_press_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::on_drawingarea_button_press), partition ) ); + visual_partitions.back() ->drawingarea ->signal_realize().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_realize), visual_partitions.back() ) ); + visual_partitions.back() ->drawingarea ->signal_expose_event().connect( sigc::bind(sigc::mem_fun(*this, &VBox_VisualDisk::drawingarea_on_expose), visual_partitions.back() )); + + //create pangolayout and see if it fits in the visual partition + str_temp = partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB() ) ; + visual_partitions.back() ->pango_layout = visual_partitions.back() ->drawingarea ->create_pango_layout ( str_temp ) ; + + visual_partitions.back() ->pango_layout ->get_pixel_size( x, y ) ; + if ( visual_partitions.back() ->length - BORDER * 2 -2 < x ) + visual_partitions.back() ->pango_layout ->set_text( "" ) ; + + //tooltip + str_temp = "" ; + if ( partition .type != GParted::UNALLOCATED ) + str_temp = partition .filesystem + "\n" ; + + str_temp += partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB() ) ; + tooltips.set_tip( *(visual_partitions.back() ->drawingarea), str_temp ) ; +} + void VBox_VisualDisk::Build_Legend( ) { @@ -234,11 +245,10 @@ void VBox_VisualDisk::Set_Selected( const Partition & partition ) } } - } -void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp ) +void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp ) { vp ->gc = Gdk::GC::create( vp ->drawingarea ->get_window() ); @@ -249,7 +259,7 @@ void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp ) } -bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partition* vp ) +bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partition* vp ) { vp ->drawingarea ->get_window() ->clear() ; diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index de0d7fb0..7d5b6f31 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -504,15 +504,15 @@ void Win_GParted::Refresh_Visual( ) liststore_operations ->clear(); //make all operations visible - for (unsigned int t=0;tGet_Path() == devices[ current_device ] ->Get_Path() ) - partitions = operations[t].Apply_Operation_To_Visual( partitions ) ; - - treerow = *(liststore_operations->append()); - treerow[ treeview_operations_columns.operation_number ] = t +1; - treerow[ treeview_operations_columns.operation_description ] = operations[t] .str_operation ; - switch ( operations[t].operationtype ) + for ( unsigned int t = 0 ; t < operations .size( ); t++ ) + { + if ( operations[ t ] .device ->Get_Path( ) == devices[ current_device ] ->Get_Path( ) ) + partitions = operations[ t ] .Apply_Operation_To_Visual( partitions ) ; + + treerow = *(liststore_operations ->append( )); + treerow[ treeview_operations_columns .operation_number ] = t +1; + treerow[ treeview_operations_columns .operation_description ] = operations[ t ] .str_operation ; + switch ( operations[ t ] .operationtype ) { case GParted::DELETE : treerow[ treeview_operations_columns.operation_icon ] =render_icon(Gtk::Stock::DELETE, Gtk::ICON_SIZE_MENU); break; @@ -529,13 +529,13 @@ void Win_GParted::Refresh_Visual( ) } //set new statusbartext - statusbar .pop() ; - if ( operations.size() != 1 ) - statusbar .push( String::ucompose( _("%1 operations pending"), operations.size() ) .c_str() ); + statusbar .pop( ) ; + if ( operations .size( ) != 1 ) + statusbar .push( String::ucompose( _("%1 operations pending"), operations .size( ) ) .c_str( ) ); else statusbar .push( _( "1 operation pending" ) ); - if ( ! operations.size() ) + if ( ! operations .size( ) ) { allow_undo( false ); allow_apply( false ); @@ -543,22 +543,19 @@ void Win_GParted::Refresh_Visual( ) //count primary's, check for extended and logic and see if any logical is busy any_logic = any_extended = false; - primary_count = highest_logic_busy = 0; - for (unsigned int t=0;t highest_logic_busy ) - highest_logic_busy = partitions[t].partition_number ; + any_logic = partitions[ t ] .logicals .size( ) -1 ; break; default : break; } @@ -608,11 +605,11 @@ void Win_GParted::Set_Valid_Operations() allow_new( false ); allow_delete( false ); allow_resize( false ); allow_copy( false ); allow_paste( false ); allow_convert( false ); //we can't perform any operation on a busy (mounted) filesystem - if ( selected_partition.busy ) + if ( selected_partition .busy ) return; //UNALLOCATED - if ( selected_partition.type == GParted::UNALLOCATED ) + if ( selected_partition .type == GParted::UNALLOCATED ) { allow_new( true ); @@ -632,7 +629,7 @@ void Win_GParted::Set_Valid_Operations() } //PRIMARY and LOGICAL - if ( selected_partition.type != GParted::EXTENDED ) + if ( selected_partition .type != GParted::EXTENDED ) { allow_delete( true ) ; allow_convert( true ) ; @@ -652,7 +649,7 @@ void Win_GParted::Set_Valid_Operations() //EXTENDED - else if ( selected_partition.type == GParted::EXTENDED ) + else if ( selected_partition .type == GParted::EXTENDED ) { if ( ! any_logic ) //deletion is only allowed when there are nog logical partitions inside. allow_delete( true ) ; @@ -826,6 +823,23 @@ void Win_GParted::mouse_click( GdkEventButton *event, const Partition & partitio } } +bool Win_GParted::max_amount_prim_reached( ) +{ + //Display error if user tries to create more primary partitions than the partition table can hold. + if ( ! selected_partition .inside_extended && primary_count >= devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions( ) ) + { + str_temp = "" ; + str_temp += String::ucompose( _("It is not possible to create more than %1 primary partitions"), devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions( ) ) ; + str_temp += "\n\n" ; + str_temp += _( "If you want more partitions you should first create an extended partition. Such a partition can contain other partitions.") ; + + Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true ) ; + dialog.run( ) ; + return true ; + } + + return false ; +} void Win_GParted::activate_resize() { @@ -848,24 +862,33 @@ void Win_GParted::activate_resize() hbox_resize_move .pack_start( * mk_label( _("Resize/Move") ), Gtk::PACK_SHRINK ) ; button_resize_move .add( hbox_resize_move ) ; - dialog .add_action_widget ( button_resize_move,Gtk::RESPONSE_OK ) ; - dialog .show_all_children() ; + dialog .add_action_widget ( button_resize_move, Gtk::RESPONSE_OK ) ; + dialog .show_all_children( ) ; - if ( dialog.run() == Gtk::RESPONSE_CANCEL ) + if ( dialog.run( ) == Gtk::RESPONSE_CANCEL ) return ; } - std::vector partitions = devices[ current_device ] -> Get_Partitions() ; + std::vector partitions = devices[ current_device ] ->Get_Partitions( ) ; if ( operations.size() ) for (unsigned int t=0;tGet_Path() == devices[ current_device ] ->Get_Path() ) + if ( operations[t]. device ->Get_Path( ) == devices[ current_device ] ->Get_Path( ) ) partitions = operations[t].Apply_Operation_To_Visual( partitions ) ; Dialog_Partition_Resize_Move dialog; - dialog.Set_Data( selected_partition, partitions); + + if ( selected_partition .type == GParted::LOGICAL ) + { + unsigned int ext = 0 ; + while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; + dialog .Set_Data( selected_partition, partitions[ ext ] .logicals ); + } + else + dialog .Set_Data( selected_partition, partitions ); + dialog .set_transient_for( *this ) ; if ( dialog.run() == Gtk::RESPONSE_OK ) @@ -903,57 +926,35 @@ void Win_GParted::activate_copy() void Win_GParted::activate_paste() { - //Display error if user tries to create more primary partitions than the partition table can hold. - if ( ! selected_partition.inside_extended && primary_count >=devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions() ) + if ( ! max_amount_prim_reached( ) ) { - str_temp = "" ; - str_temp += String::ucompose( _("It is not possible to create more than %1 primary partitions"), devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions() ) ; - str_temp += "\n\n" ; - str_temp += _( "If you want more partitions you should first create an extended partition. Such a partition can contain other partitions.") ; - - Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); - dialog.run(); - return; + Dialog_Partition_Copy dialog ; + dialog .Set_Data( selected_partition, copied_partition ) ; + dialog .set_transient_for( *this ); + + if ( dialog.run() == Gtk::RESPONSE_OK ) + { + dialog .hide( ) ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) + Add_Operation( GParted::COPY, dialog .Get_New_Partition( ) ); + } } - - Dialog_Partition_Copy dialog ; - dialog .Set_Data( selected_partition, copied_partition ) ; - dialog.set_transient_for( *this ); - - if ( dialog.run() == Gtk::RESPONSE_OK ) - { - dialog.hide() ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) - Add_Operation( GParted::COPY, dialog.Get_New_Partition() ); - } - } void Win_GParted::activate_new() { - //Display error if user tries to create more primary partitions than the partition table can hold. - if ( ! selected_partition.inside_extended && primary_count >= devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions() ) - { - str_temp = "" ; - str_temp += String::ucompose( _("It is not possible to create more than %1 primary partitions"), devices[ current_device ] ->Get_Max_Amount_Of_Primary_Partitions() ) ; - str_temp += "\n\n" ; - str_temp += _( "If you want more partitions you should first create an extended partition. Such a partition can contain other partitions.") ; - - Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); - dialog.run(); - return; - } - - Dialog_Partition_New dialog; - dialog.Set_Data( selected_partition, any_extended, new_count, FILESYSTEMS ) ; - dialog.set_transient_for( *this ); - - if ( dialog.run() == Gtk::RESPONSE_OK ) - { - dialog.hide() ;//make sure the dialog is gone _before_ operationslist shows up (only matters if first operation) - new_count++; - Add_Operation( GParted::CREATE, dialog.Get_New_Partition() ); - } + if ( ! max_amount_prim_reached( ) ) + { + Dialog_Partition_New dialog; + dialog .Set_Data( selected_partition, any_extended, new_count, FILESYSTEMS ) ; + dialog .set_transient_for( *this ); + if ( dialog.run() == Gtk::RESPONSE_OK ) + { + dialog .hide( ) ;//make sure the dialog is gone _before_ operationslist shows up (only matters if first operation) + new_count++ ; + Add_Operation( GParted::CREATE, dialog .Get_New_Partition( ) ); + } + } } void Win_GParted::activate_delete() @@ -962,19 +963,21 @@ void Win_GParted::activate_delete() //e.g. consider /dev/hda5 /dev/hda6 /dev/hda7. Now after removal of /dev/hda6, /dev/hda7 is renumbered to /dev/hda6 //the new situation is now /dev/hda5 /dev/hda6. If /dev/hda7 was mounted the OS cannot find /dev/hda7 anymore and the results aren't that pretty //it seems best to check for this and prohibit deletion with some explanation to the user. - if ( selected_partition.type == GParted::LOGICAL && selected_partition .status != GParted::STAT_NEW && selected_partition.partition_number < highest_logic_busy ) + if ( selected_partition .type == GParted::LOGICAL && + selected_partition .status != GParted::STAT_NEW && + selected_partition .partition_number < devices [ current_device ] -> Get_Highest_Logical_Busy( ) ) { str_temp = "" ; str_temp += _( "Unable to delete partition!") ; str_temp += "\n\n" ; str_temp += String::ucompose( _("Please unmount any logical partitions having a number higher than %1"), selected_partition.partition_number ) ; - Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); - dialog.run() ; + Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true ) ; + dialog .run( ) ; return; } str_temp = "" ; - str_temp += String::ucompose( _( "Are you sure you want to delete %1?"), selected_partition.partition ) + "" ; + str_temp += String::ucompose( _( "Are you sure you want to delete %1?"), selected_partition .partition ) + "" ; if ( selected_partition .partition == copied_partition .partition ) { str_temp += "\n\n" ; @@ -1008,12 +1011,12 @@ void Win_GParted::activate_delete() { if ( operations[t] .partition_new .partition == selected_partition .partition ) { - operations.erase( operations .begin() + t ) ; + operations.erase( operations .begin( ) + t ) ; t-- ; } } - + //determine lowest possible new_count new_count = 0 ; for ( unsigned int t=0;t