[gparted] Add new method active_partitions_on_device_count



commit f7cb37831ad556c8539c819239f53adf5c6a12da
Author: Curtis Gedak <gedakc gmail com>
Date:   Tue Aug 10 12:52:59 2010 -0600

    Add new method active_partitions_on_device_count

 include/Win_GParted.h |    1 +
 src/Win_GParted.cc    |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/include/Win_GParted.h b/include/Win_GParted.h
index 8c2e78c..871a49f 100644
--- a/include/Win_GParted.h
+++ b/include/Win_GParted.h
@@ -169,6 +169,7 @@ private:
 	void activate_undo();
 	void remove_operation( int index = -1, bool remove_all = false ) ;
 	int  partition_in_operation_queue_count( const Partition & partition ) ;
+	int  active_partitions_on_device_count( const Device & device ) ;
 	void activate_apply();
 
 //private variables
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index de11b1c..2350966 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -2097,6 +2097,40 @@ int Win_GParted::partition_in_operation_queue_count( const Partition & partition
 	return operation_count ;
 }
 
+int  Win_GParted::active_partitions_on_device_count( const Device & device )
+{
+	int active_count = 0 ;
+
+	//Count the active partitions on the device
+	for ( unsigned int k=0; k < device .partitions .size(); k++ )
+	{
+		//FIXME:  Should also count other types of active partitions, such as LVM2 when we know how.
+
+		//Count the active primary partitions
+		if (   device .partitions[ k ] .busy
+		    && device .partitions[ k ] .type != TYPE_EXTENDED
+		    && device .partitions[ k ] .type != TYPE_UNALLOCATED
+		   )
+			active_count++ ;
+
+		//Count the active logical partitions
+		if (   device .partitions[ k ] .busy
+		    && device .partitions[ k ] .type == TYPE_EXTENDED
+		   )
+		{
+			for ( unsigned int j=0; j < device .partitions[ k ] .logicals .size(); j++ )
+			{
+				if (   device .partitions[ k ] .logicals [ j ] .busy
+				    && device .partitions[ k ] .logicals [ j ] .type != TYPE_UNALLOCATED
+				   )
+					active_count++ ;
+			}
+		}
+	}
+
+	return active_count ;
+}
+
 void Win_GParted::activate_apply()
 {
 	Gtk::MessageDialog dialog( *this,



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