From 3b5471516c569df865caf395f4da03b171817105 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Thu, 10 Sep 2015 17:40:35 +0100 Subject: [PATCH] Localise counting of primary partitions into max_amount_prim_reached() Now that display_partitions is a Win_GParted member variable and therefore available throughout the class, since commit [1], calculation of primary_count can be localised in max_amount_prim_reached() where it is used. Implements a FIXME and removes primary_count as a member variable. [1] 545b75d9574e053cadb9ddd5cf15fc28181da87c Move vector of partition objects to a Win_GParted class member (#750168) --- include/Win_GParted.h | 1 - src/Win_GParted.cc | 20 +++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/Win_GParted.h b/include/Win_GParted.h index ee1d668f..ddeb6b36 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -256,7 +256,6 @@ private: //usefull variables which are used by many different functions... int index_extended ; //position of the extended partition (-1 means there isn't one) - 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 FS fs ; bool OPERATIONSLIST_OPEN ; diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 5fe4ccd4..d60de132 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -929,11 +929,9 @@ void Win_GParted::Refresh_Visual() if ( ! operations .size() ) allow_undo_clear_apply( false ) ; - // Count primary partitions for check in max_amount_prim_reached(), check for an - // extended partition, refresh copy partition source as necessary and select the - // largest unallocated partition if there is one. + // Check for an extended partition, refresh copy partition source as necessary and + // select the largest unallocated partition if there is one. index_extended = -1 ; - primary_count = 0; selected_partition_ptr = NULL; Sector largest_unalloc_size = -1 ; @@ -946,13 +944,8 @@ void Win_GParted::Refresh_Visual() switch ( display_partitions[t].type ) { - case TYPE_PRIMARY: - primary_count++; - break; - case TYPE_EXTENDED: index_extended = t ; - primary_count++; for ( unsigned int u = 0 ; u < display_partitions[t].logicals.size() ; u ++ ) { @@ -1693,8 +1686,13 @@ void Win_GParted::on_partition_popup_menu( unsigned int button, unsigned int tim bool Win_GParted::max_amount_prim_reached() { - //FIXME: this is the only place where primary_count is used... instead of counting the primaries on each - //refresh, we could just count them here. + int primary_count = 0; + for ( unsigned int i = 0 ; i < display_partitions.size() ; i ++ ) + { + if ( display_partitions[i].type == TYPE_PRIMARY || display_partitions[i].type == TYPE_EXTENDED ) + primary_count ++; + } + //Display error if user tries to create more primary partitions than the partition table can hold. if ( ! selected_partition_ptr->inside_extended && primary_count >= devices[current_device].max_prims ) {