From 7b43d527206d5d0761f9d07cffd0b178b6f7b4d2 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Fri, 3 Jan 2014 20:56:57 +0000 Subject: [PATCH] Display partition table types in order (#711098) In the Create Partition Table dialog display the entries in the combobox in order. Previously the default of MSDOS or GPT was moved to the first item in the combobox. Now the partition table types remain in order with just either MSDOS or GPT being selected as as the default as required. The partition table types are displayed in the order supplied by libparted, which is alphabetic except with "loop" last. Bug #711098 - Default partition table can not handle > 2 TiB disks --- include/Dialog_Disklabel.h | 5 +++-- include/GParted_Core.h | 2 +- src/Dialog_Disklabel.cc | 33 ++++++++++++++++++++++++++++----- src/GParted_Core.cc | 23 ++++++++--------------- src/Win_GParted.cc | 2 +- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/Dialog_Disklabel.h b/include/Dialog_Disklabel.h index 25455e93..8cd7c4d4 100644 --- a/include/Dialog_Disklabel.h +++ b/include/Dialog_Disklabel.h @@ -20,6 +20,7 @@ #define GPARTED_DIALOG_DISKLABEL_H #include "../include/Utils.h" +#include "../include/Device.h" #include #include @@ -33,8 +34,8 @@ namespace GParted class Dialog_Disklabel : public Gtk::Dialog { public: - Dialog_Disklabel( const Glib::ustring & device_path, const std::vector & disklabeltypes ) ; - + Dialog_Disklabel( const Device & device ) ; + Glib::ustring Get_Disklabel( ) ; private: diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 8f60183e..ed6a5407 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -56,7 +56,7 @@ public: const std::vector & get_filesystems() const ; const FS & get_fs( GParted::FILESYSTEM filesystem ) const ; - std::vector get_disklabeltypes( Device *device ) ; + static std::vector get_disklabeltypes() ; std::vector get_all_mountpoints() ; std::map get_available_flags( const Partition & partition ) ; Glib::ustring get_libparted_version() ; diff --git a/src/Dialog_Disklabel.cc b/src/Dialog_Disklabel.cc index 74e75a89..6493b49f 100644 --- a/src/Dialog_Disklabel.cc +++ b/src/Dialog_Disklabel.cc @@ -17,13 +17,16 @@ */ #include "../include/Dialog_Disklabel.h" +#include "../include/GParted_Core.h" namespace GParted { -Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std::vector & disklabeltypes ) +Dialog_Disklabel::Dialog_Disklabel( const Device & device ) : image(Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_DIALOG) { + const Glib::ustring device_path = device .get_path() ; + /*TO TRANSLATORS: dialogtitle, looks like Create partition table on /dev/hda */ this ->set_title( String::ucompose( _("Create partition table on %1"), device_path ) ); this ->set_has_separator( false ) ; @@ -61,13 +64,33 @@ Dialog_Disklabel::Dialog_Disklabel( const Glib::ustring & device_path, const std vbox->pack_start(*hbox, Gtk::PACK_SHRINK); } + //Default to MSDOS partition table type for disks < 2^32 sectors + // (2 TiB with 512 byte sectors) and GPT for larger disks. + Glib::ustring default_label ; + if ( device .length < 4LL * GIBIBYTE ) + default_label = "msdos" ; + else + default_label = "gpt" ; + //create and add combo with partition table types (label types) - this ->labeltypes = disklabeltypes ; + this ->labeltypes = GParted_Core::get_disklabeltypes() ; - for (unsigned int t = 0; t < labeltypes.size(); ++t) - combo_labeltypes.append_text(labeltypes[t]); + bool set_active = false ; + for ( unsigned int t = 0 ; t < labeltypes .size() ; t ++ ) + { + combo_labeltypes .append_text( labeltypes[ t ] ) ; + if ( default_label == labeltypes[ t ] ) + { + combo_labeltypes .set_active( t ) ; + set_active = true ; + } + } + //Should be impossible for libparted to not known about MSDOS and GPT + // partition table types, but just in case fallback to activating the + // first item in the combobox. + if ( ! set_active && labeltypes .size() ) + combo_labeltypes .set_active( 0 ) ; - combo_labeltypes.set_active(0); hbox->pack_start(combo_labeltypes, Gtk::PACK_SHRINK); } diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 9ce1a97b..26d7b697 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -824,23 +824,16 @@ const FS & GParted_Core::get_fs( GParted::FILESYSTEM filesystem ) const return FILESYSTEMS[ unknown ] ; } -std::vector GParted_Core::get_disklabeltypes( Device *device ) +//Return all libparted's partition table types in it's preferred ordering, +// alphabetic except with "loop" last. +// Ref: parted >= 1.8 ./libparted/libparted.c init_disk_types() +std::vector GParted_Core::get_disklabeltypes() { std::vector disklabeltypes ; - const char *default_label ; - - //Default to MSDOS partition table type for disks < 2^32 sectors - // (2 TiB with 512 byte sectors) and GPT for larger disks. - if ( device ->length < 4LL * GIBIBYTE ) - default_label = "msdos"; - else - default_label = "gpt"; - disklabeltypes.push_back( default_label ) ; - - PedDiskType *disk_type ; - for ( disk_type = ped_disk_type_get_next( NULL ) ; disk_type ; disk_type = ped_disk_type_get_next( disk_type ) ) - if ( Glib::ustring( disk_type->name ) != default_label ) - disklabeltypes .push_back( disk_type->name ) ; + + PedDiskType *disk_type ; + for ( disk_type = ped_disk_type_get_next( NULL ) ; disk_type ; disk_type = ped_disk_type_get_next( disk_type ) ) + disklabeltypes .push_back( disk_type->name ) ; return disklabeltypes ; } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 9f59027b..ce0b2068 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -2333,7 +2333,7 @@ void Win_GParted::activate_disklabel() } //Display dialog for creating a new partition table. - Dialog_Disklabel dialog( devices[ current_device ] .get_path(), gparted_core .get_disklabeltypes( &devices[ current_device ] ) ) ; + Dialog_Disklabel dialog( devices[ current_device ] ) ; dialog .set_transient_for( *this ); if ( dialog .run() == Gtk::RESPONSE_APPLY )