[gparted] Additionally write partition information to saved details (#639176)



commit f7790029722720b01ef6975cec74dce718ee7dd2
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Apr 5 11:18:35 2019 +0100

    Additionally write partition information to saved details (#639176)
    
    Bug 639176 - Save partition layout to gparted_details.htm

 include/Dialog_Progress.h |  2 ++
 include/Partition.h       |  4 +++-
 src/Dialog_Progress.cc    | 52 +++++++++++++++++++++++++++++++++++++++++++++++
 src/Partition.cc          | 35 +++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 1 deletion(-)
---
diff --git a/include/Dialog_Progress.h b/include/Dialog_Progress.h
index bddfe3f1..bef03bea 100644
--- a/include/Dialog_Progress.h
+++ b/include/Dialog_Progress.h
@@ -22,6 +22,7 @@
 #include "Utils.h"
 #include "Device.h"
 #include "Operation.h"
+#include "Partition.h"
 
 #include <gtkmm/dialog.h>
 #include <gtkmm/progressbar.h>
@@ -52,6 +53,7 @@ private:
        void on_cancel() ;
        void on_save() ;
        void write_device_details(const Device& device, std::ofstream& out);
+       void write_partition_details(const Partition& partition, std::ofstream& out);
        void echo_operation_details( const OperationDetail & operation_detail, std::ofstream & out ) ;
        
        void on_response( int response_id ) ;
diff --git a/include/Partition.h b/include/Partition.h
index 87b103ca..594e3b4f 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -147,7 +147,9 @@ public:
 
        bool operator==( const Partition & partition ) const ;
        bool operator!=( const Partition & partition ) const ;
-               
+
+       static const Glib::ustring get_partition_type_string(PartitionType type);
+
        //some public members
        Glib::ustring device_path ;
        int partition_number;
diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc
index 35689770..3c8b56a7 100644
--- a/src/Dialog_Progress.cc
+++ b/src/Dialog_Progress.cc
@@ -19,6 +19,7 @@
 #include "Device.h"
 #include "GParted_Core.h"
 #include "OperationDetail.h"
+#include "Partition.h"
 #include "ProgressBar.h"
 #include "Utils.h"
 
@@ -384,6 +385,7 @@ void Dialog_Progress::on_save()
                        << "<title>" << _("GParted Details") << "</title>" << std::endl
                        << "<style type='text/css'>" << std::endl
                        << "th {text-align:left}" << std::endl  // Left align all table headers
+                       << ".number_col {text-align:right}" << std::endl  // Class for right alignment
                        << "</style>" << std::endl
                        << "</head>" << std::endl
                        << "<body>" << std::endl;
@@ -437,7 +439,57 @@ void Dialog_Progress::write_device_details(const Device& device, std::ofstream&
        // Partition table type
        out << "<tr><th>" << _("Partition table:") << "</th><td>" << device.disktype << "</td></tr>" << 
std::endl;
 
+       out << "<tr><td colspan='2'>&nbsp;</td></tr>" << std::endl;
        out << "</table>" << std::endl;
+
+       out << "<table border='0'>" << std::endl;
+
+       // Partition headings
+       out << "<tr>"
+           << "<th>" << _("Partition") << "</th>"
+           << "<th>" << _("Type") << "</th>"
+           << "<th class='number_col'>" << _("Start") << "</th>"
+           << "<th class='number_col'>" << _("End") << "</th>"
+           << "<th>" << _("Flags") << "</th>"
+           << "<th>" << _("Partition Name") << "</th>"
+           << "<th>" << _("File System") << "</th>"
+           << "<th>" << _("Label") << "</th>"
+           << "<th>" << _("Mount Point") << "</th>"
+           << "</tr>" << std::endl;
+
+       // Partition details
+       for (unsigned int i = 0; i < device.partitions.size(); i++)
+       {
+               if (device.partitions[i].type != TYPE_UNALLOCATED)
+                       write_partition_details(device.partitions[i], out);
+
+               if (device.partitions[i].type == TYPE_EXTENDED)
+               {
+                       for (unsigned int j = 0; j < device.partitions[i].logicals.size(); j++)
+                       {
+                               if (device.partitions[i].logicals[j].type != TYPE_UNALLOCATED)
+                                       write_partition_details(device.partitions[i].logicals[j], out);
+                       }
+               }
+       }
+
+       out << "</table>" << std::endl;
+}
+
+
+void Dialog_Progress::write_partition_details(const Partition& partition, std::ofstream& out)
+{
+       out << "<tr>"
+           << "<td>" << (partition.inside_extended ? "&nbsp;&nbsp;&nbsp; " : "") << partition.get_path() << 
"</td>"
+           << "<td>" << Partition::get_partition_type_string(partition.type) << "</td>"
+           << "<td class='number_col'>" << partition.sector_start << "</td>"
+           << "<td class='number_col'>" << partition.sector_end << "</td>"
+           << "<td>" << Glib::build_path(", ", partition.flags) << "</td>"
+           << "<td>" << partition.name << "</td>"
+           << "<td>" << Utils::get_filesystem_string(partition.filesystem) << "</td>"
+           << "<td>" << partition.get_filesystem_label() << "</td>"
+           << "<td>" << Glib::build_path(", ", partition.get_mountpoints()) << "</td>"
+           << "</tr>" << std::endl;
 }
 
 
diff --git a/src/Partition.cc b/src/Partition.cc
index 02a2f9d3..94e08d6e 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -391,6 +391,41 @@ void Partition::clear_mountpoints()
        mountpoints .clear() ;
 }
 
+
+const Glib::ustring Partition::get_partition_type_string(PartitionType type)
+{
+       switch (type)
+       {
+               case TYPE_PRIMARY:
+                                        /* TO TRANSLATORS: Primary
+                                         * A "Primary" type of partition on a partitioned drive.
+                                         */
+                                        return _("Primary");
+               case TYPE_LOGICAL:
+                                        /* TO TRANSLATORS: Logical
+                                         * A "Logical" type of partition on a partitioned drive.
+                                         */
+                                        return _("Logical");
+               case TYPE_EXTENDED:
+                                        /* TO TRANSLATORS: Extended
+                                         * An "Extended" type of partition on a partitioned drive.
+                                         */
+                                       return _("Extended");
+               case TYPE_UNALLOCATED:
+                                        /* TO TRANSLATORS: Unallocated
+                                         * Unused space outside of any partition on a partitioned drive.
+                                         */
+                                        return _("Unallocated");
+               case TYPE_UNPARTITIONED:
+                                        /* TO TRANSLATORS: Unpartitioned
+                                         * A drive which has no partition table.
+                                         */
+                                        return _("Unpartitioned");
+               default:                 return "";
+       }
+}
+
+
 //Return threshold of sectors which is considered above the intrinsic
 //  level for a file system which "fills" the partition.  Calculation
 //  is:


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