[gparted] Add mechanism to capture exception messages into an OperationDetail (#790842)



commit 2ed7feb2f56e18974dcaea14b68de05409847d79
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Nov 25 13:20:21 2017 +0000

    Add mechanism to capture exception messages into an OperationDetail (#790842)
    
    All code implementing a step of an operation follows this pattern:
    
        od.add_child(OperationDetail("Step heading"));
        od.get_last_child().add_child(OperationDetail("More details"));
        // Do step
        success = ...
        od.get_last_child().set_status(success ? STATUS_SUCCESS
                                               : STATUS_ERROR);
    
    At this point any libparted messages reported via exceptions need to be
    added into the OperationDetail tree.  Also adding further children into
    the tree after collecting those errors needs to be prohibited (as much
    as the previous patch prohibited it).
    
    Add a new method which will replace the final set_status() call above
    like this which set the status, captures the errors and flags that
    further children shouldn't be added:
    
        ...
        od.get_last_child().set_success_and_capture_errors(status);
    
    It emits a callback to capture the errors to provide flexibility and so
    that the OperationDetail class doesn't have to get into the details of
    how GParted_Core saves libparted exception messages.
    
    Bug 790842 - Report libparted messages into operation details at the
                 point at which they occur

 include/OperationDetail.h |    2 ++
 src/OperationDetail.cc    |    7 +++++++
 2 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/include/OperationDetail.h b/include/OperationDetail.h
index 2fe4c5b..a1a224a 100644
--- a/include/OperationDetail.h
+++ b/include/OperationDetail.h
@@ -60,6 +60,7 @@ public:
        void set_description( const Glib::ustring & description, Font font = FONT_NORMAL ) ;
        Glib::ustring get_description() const ;
        void set_status( OperationDetailStatus status ) ;
+       void set_success_and_capture_errors( bool success );
        OperationDetailStatus get_status() const ;
        void set_treepath( const Glib::ustring & treepath ) ;
        Glib::ustring get_treepath() const ;
@@ -74,6 +75,7 @@ public:
 
        sigc::signal< void, const OperationDetail & > signal_update ;
        sigc::signal< void, bool > signal_cancel;
+       sigc::signal< void, OperationDetail & > signal_capture_errors;
        char cancelflag;
 
 private:
diff --git a/src/OperationDetail.cc b/src/OperationDetail.cc
index 3a703a8..8e11f45 100644
--- a/src/OperationDetail.cc
+++ b/src/OperationDetail.cc
@@ -106,6 +106,13 @@ void OperationDetail::set_status( OperationDetailStatus status )
        }
 }
 
+void OperationDetail::set_success_and_capture_errors( bool success )
+{
+       set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+       signal_capture_errors.emit( *this );
+       no_more_children = true;
+}
+
 OperationDetailStatus OperationDetail::get_status() const
 {
        return status ;


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