[gparted] Capture libparted messages via callback at top-level only (#790842)



commit 23939331f652d53eb8146f140d69814c487cfb35
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Nov 25 13:56:56 2017 +0000

    Capture libparted messages via callback at top-level only (#790842)
    
    Replace the explicit adding of libparted exception messages with a
    callback to do it instead, and fire the callback just once per operation
    by only changing the very top-level OperationDetail to use the new
    set_success_and_capture_errors().  Therefore this still produces exactly
    the same operation details with libparted messages at the end of each
    operation.
    
    Bug 790842 - Report libparted messages into operation details at the
                 point at which they occur

 include/GParted_Core.h |    2 ++
 src/Dialog_Progress.cc |    2 +-
 src/GParted_Core.cc    |   23 ++++++++++++++---------
 3 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 26771f0..db09d5e 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -208,6 +208,8 @@ private:
        static void init_filesystems();
        static void fini_filesystems();
 
+       void capture_libparted_messages( OperationDetail & operationdetail );
+
        static bool flush_device( PedDevice * lp_device );
        static bool get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush = false 
);
        static bool get_disk( PedDevice *& lp_device, PedDisk *& lp_disk, bool strict = true );
diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc
index 55368db..87d5bca 100644
--- a/src/Dialog_Progress.cc
+++ b/src/Dialog_Progress.cc
@@ -226,7 +226,7 @@ void Dialog_Progress::on_signal_show()
                succes = signal_apply_operation.emit( operations[t] );
 
                //set status (succes/error) for this operation
-               operations[ t ] ->operation_detail .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
+               operations[t]->operation_detail.set_success_and_capture_errors( succes );
        }
        
        //add save button
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 8223db6..f17b11a 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -556,6 +556,8 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
 {
        bool success = false;
        libparted_messages .clear() ;
+       operation->operation_detail.signal_capture_errors.connect(
+                       sigc::mem_fun( *this, &GParted_Core::capture_libparted_messages ) );
 
        switch ( operation->type )
        {
@@ -673,15 +675,6 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
                        break;
        }
 
-       if ( libparted_messages .size() > 0 )
-       {
-               operation ->operation_detail .add_child( OperationDetail( _("libparted messages"), 
STATUS_INFO ) ) ;
-
-               for ( unsigned int t = 0 ; t < libparted_messages .size() ; t++ )
-                       operation ->operation_detail .get_last_child() .add_child(
-                               OperationDetail( libparted_messages[ t ], STATUS_NONE, FONT_ITALIC ) ) ;
-       }
-
        return success;
 }
 
@@ -4112,6 +4105,18 @@ void GParted_Core::fini_filesystems()
        }
 }
 
+void GParted_Core::capture_libparted_messages( OperationDetail & operationdetail )
+{
+       if ( libparted_messages.size() > 0 )
+       {
+               operationdetail.add_child( OperationDetail( _("libparted messages"), STATUS_INFO ) );
+               for ( unsigned int i = 0 ; i < libparted_messages.size() ; i++ )
+                       operationdetail.get_last_child().add_child(
+                                       OperationDetail( libparted_messages[i], STATUS_NONE, FONT_ITALIC ) );
+               libparted_messages.clear();
+       }
+}
+
 bool GParted_Core::useable_device( PedDevice * lp_device )
 {
        g_assert( lp_device != NULL );  // Bug: Not initialised by call to ped_device_get() or 
ped_device_get_next()


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