[gparted] Write starting device overview information to saved details (#639176)



commit edb3afac7bf9fdae444bb53bb906f231f61e8b76
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Apr 5 07:44:39 2019 +0100

    Write starting device overview information to saved details (#639176)
    
    Writes the starting device overview information of all known devices to
    the top of the saved details HTML.  This is so that hopefully we don't
    need to additionally ask users for their disk layouts via 'fdisk -l',
    'parted print' and 'lsblk' when the saved details file is provided.
    
    Also moves the equals separators "==================" from below to
    above each operation so the each section is separated.
    
    Bug 639176 - Save partition layout to gparted_details.htm

 include/Dialog_Progress.h | 12 ++++++++----
 src/Dialog_Progress.cc    | 45 ++++++++++++++++++++++++++++++++++++++++++---
 src/Win_GParted.cc        |  4 ++--
 3 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/include/Dialog_Progress.h b/include/Dialog_Progress.h
index 7847376d..bddfe3f1 100644
--- a/include/Dialog_Progress.h
+++ b/include/Dialog_Progress.h
@@ -20,6 +20,7 @@
 
 #include "i18n.h"
 #include "Utils.h"
+#include "Device.h"
 #include "Operation.h"
 
 #include <gtkmm/dialog.h>
@@ -28,8 +29,9 @@
 #include <gtkmm/treestore.h>
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/expander.h>
-
 #include <fstream>
+#include <vector>
+
 
 namespace GParted
 {
@@ -37,9 +39,9 @@ namespace GParted
 class Dialog_Progress : public Gtk::Dialog
 {
 public:
-       Dialog_Progress( const std::vector<Operation *> & operations ) ;
+       Dialog_Progress(const std::vector<Device>& devices, const std::vector<Operation *>& operations);
        ~Dialog_Progress();
-       
+
        sigc::signal< bool, Operation * > signal_apply_operation ;
 
 private:
@@ -49,6 +51,7 @@ private:
        void on_cell_data_description( Gtk::CellRenderer * renderer, const Gtk::TreeModel::iterator & iter) ;
        void on_cancel() ;
        void on_save() ;
+       void write_device_details(const Device& device, std::ofstream& out);
        void echo_operation_details( const OperationDetail & operation_detail, std::ofstream & out ) ;
        
        void on_response( int response_id ) ;
@@ -86,7 +89,8 @@ private:
                } 
        };
        treeview_operations_Columns treeview_operations_columns;
-       
+
+       const std::vector<Device>& m_devices;
        std::vector<Operation *> operations ;
        Glib::ustring progress_text;
        bool succes, cancel;
diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc
index cdd6a57a..35689770 100644
--- a/src/Dialog_Progress.cc
+++ b/src/Dialog_Progress.cc
@@ -16,6 +16,7 @@
  */
 
 #include "Dialog_Progress.h"
+#include "Device.h"
 #include "GParted_Core.h"
 #include "OperationDetail.h"
 #include "ProgressBar.h"
@@ -34,7 +35,8 @@
 namespace GParted
 {
 
-Dialog_Progress::Dialog_Progress( const std::vector<Operation *> & operations )
+Dialog_Progress::Dialog_Progress(const std::vector<Device>& devices, const std::vector<Operation *>& 
operations)
+ : m_devices(devices)
 {
        this ->set_title( _("Applying pending operations") ) ;
        this ->operations = operations ;
@@ -380,6 +382,9 @@ void Dialog_Progress::on_save()
                        << "<head>" << std::endl
                        << "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' />" << std::endl
                        << "<title>" << _("GParted Details") << "</title>" << std::endl
+                       << "<style type='text/css'>" << std::endl
+                       << "th {text-align:left}" << std::endl  // Left align all table headers
+                       << "</style>" << std::endl
                        << "</head>" << std::endl
                        << "<body>" << std::endl;
 
@@ -388,11 +393,18 @@ void Dialog_Progress::on_save()
                        for (unsigned int i = 0; i < lines.size(); i++)
                                out << "<p>" << lines[i] << "</p>" << std::endl;
 
+                       // Write out starting device layout
+                       for (unsigned int i = 0; i < m_devices.size(); i++)
+                       {
+                               out << "<p>========================================</p>" << std::endl;
+                               write_device_details(m_devices[i], out);
+                       }
+
                        //Write out each operation
                        for ( unsigned int t = 0 ; t < operations .size() ; t++ )
                        {
-                               echo_operation_details( operations[ t ] ->operation_detail, out ) ;
-                               out << "<p>========================================</p>" << std::endl ;
+                               out << "<p>========================================</p>" << std::endl;
+                               echo_operation_details(operations[t]->operation_detail, out);
                        }
 
                        //Write out proper HTML finish
@@ -402,6 +414,33 @@ void Dialog_Progress::on_save()
        }
 }
 
+
+void Dialog_Progress::write_device_details(const Device& device, std::ofstream& out)
+{
+       out << "<table border='0'>" << std::endl;
+
+       // Device overview information
+       out << "<tr><th>" << _("Device:") << "</th><td>" << device.get_path() << "</td></tr>" << std::endl;
+       out << "<tr><th>" << _("Model:") << "</th><td>" << device.model << "</td></tr>" << std::endl;
+       out << "<tr><th>" << _("Serial:") << "</th><td>" << device.serial_number << "</td></tr>" << std::endl;
+       out << "<tr><th>" << _("Sector size:") << "</th><td>" << device.sector_size << "</td></tr>" << 
std::endl;
+       out << "<tr><th>" << _("Total sectors:") << "</th><td>" << device.length << "</td></tr>" << std::endl;
+
+       out << "<tr><td colspan='2'>&nbsp;</td></tr>" << std::endl;
+
+       out << "<tr><th>" << _("Heads:") << "</th><td>" << device.heads << "</td></tr>" << std::endl;
+       out << "<tr><th>" << _("Sectors/track:") << "</th><td>" << device.sectors << "</td></tr>" << 
std::endl;
+       out << "<tr><th>" << _("Cylinders:") << "</th><td>" << device.cylinders << "</td></tr>" << std::endl;
+
+       out << "<tr><td colspan='2'>&nbsp;</td></tr>" << std::endl;
+
+       // Partition table type
+       out << "<tr><th>" << _("Partition table:") << "</th><td>" << device.disktype << "</td></tr>" << 
std::endl;
+
+       out << "</table>" << std::endl;
+}
+
+
 void Dialog_Progress::echo_operation_details( const OperationDetail & operationdetail, std::ofstream & out ) 
 {
        //replace '\n' with '<br>'
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index fc082365..c99d2185 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -3431,8 +3431,8 @@ void Win_GParted::activate_apply()
        if ( dialog.run() == Gtk::RESPONSE_OK )
        {
                dialog .hide() ; //hide confirmationdialog
-               
-               Dialog_Progress dialog_progress( operations ) ;
+
+               Dialog_Progress dialog_progress(devices, operations);
                dialog_progress .set_transient_for( *this ) ;
                dialog_progress .signal_apply_operation .connect(
                        sigc::mem_fun(gparted_core, &GParted_Core::apply_operation_to_disk) ) ;


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