Rename Dialog_Progress member variable to m_curr_op

Having a member variable named 't' which is used to share state in a
Dialog_Progress object between on_signal_show() and on_cancel() methods
is horrible.  Rename to something more meaningful.

Also initialise m_curr_op in the constructor's initialisation list,
rather than later when first used in on_signal_show().  Not strictly
required, but avoids this POD (Plain Old Data) member variable being
undefined in the Dialog_Progress object between construction and when
on_signal_show() previously assigned to it for the first time and
started using it.

* C++ FAQ / Should my constructors use "initialization lists" or
  "assignment"?
  https://isocpp.org/wiki/faq/ctors#init-lists
This commit is contained in:
Mike Fleetwood 2019-04-10 12:03:46 +01:00 committed by Curtis Gedak
parent 22ce8a4c64
commit ea7bd0d419
2 changed files with 17 additions and 15 deletions

View File

@ -97,7 +97,8 @@ private:
Glib::ustring progress_text;
bool succes, cancel;
double fraction ;
unsigned int t, warnings ;
unsigned int m_curr_op;
unsigned int warnings;
sigc::connection pulsetimer;
Glib::ustring label_current_sub_text ;
unsigned int cancel_countdown;

View File

@ -37,7 +37,7 @@ namespace GParted
{
Dialog_Progress::Dialog_Progress(const std::vector<Device>& devices, const std::vector<Operation *>& operations)
: m_devices(devices)
: m_devices(devices), m_curr_op(0)
{
this ->set_title( _("Applying pending operations") ) ;
this ->operations = operations ;
@ -217,28 +217,29 @@ bool Dialog_Progress::pulsebar_pulse()
void Dialog_Progress::on_signal_show()
{
for ( t = 0 ; t < operations .size() && succes && ! cancel ; t++ )
for (m_curr_op = 0; m_curr_op < operations.size() && succes && ! cancel; m_curr_op++)
{
operations[ t ] ->operation_detail .signal_update .connect(
operations[m_curr_op]->operation_detail.signal_update.connect(
sigc::mem_fun( this, &Dialog_Progress::on_signal_update ) ) ;
label_current .set_markup( "<b>" + operations[ t ] ->description + "</b>" ) ;
progressbar_all .set_text( Glib::ustring::compose( _("%1 of %2 operations completed"), t, operations .size() ) ) ;
progressbar_all .set_fraction( fraction * t > 1.0 ? 1.0 : fraction * t ) ;
treerow = treestore_operations ->children()[ t ] ;
label_current.set_markup("<b>" + operations[m_curr_op]->description + "</b>");
progressbar_all.set_text(Glib::ustring::compose(_("%1 of %2 operations completed"),
m_curr_op, operations.size()));
progressbar_all.set_fraction(fraction * m_curr_op > 1.0 ? 1.0 : fraction * m_curr_op);
treerow = treestore_operations ->children()[m_curr_op];
//set status to 'execute'
operations[ t ] ->operation_detail .set_status( STATUS_EXECUTE ) ;
operations[m_curr_op]->operation_detail.set_status(STATUS_EXECUTE);
//set focus...
treeview_operations .set_cursor( static_cast<Gtk::TreePath>( treerow ) ) ;
succes = signal_apply_operation.emit( operations[t] );
succes = signal_apply_operation.emit(operations[m_curr_op]);
//set status (succes/error) for this operation
operations[t]->operation_detail.set_success_and_capture_errors( succes );
operations[m_curr_op]->operation_detail.set_success_and_capture_errors(succes);
}
//add save button
@ -356,7 +357,7 @@ void Dialog_Progress::on_cancel()
sigc::mem_fun(*this, &Dialog_Progress::cancel_timeout), 1000 );
}
else cancelbutton->set_label( _("Force Cancel") );
operations[t]->operation_detail.signal_cancel.emit( cancel );
operations[m_curr_op]->operation_detail.signal_cancel.emit(cancel);
cancel = true;
}
}