[Summary]: safe behaviour of ProgressDialog::set_progress in case of calling this method NOT from gui thread. [Reviewed] Paul Davis

This commit is contained in:
YPozdnyakov 2015-02-09 16:40:06 +02:00
parent b59990cdf2
commit ce17593a1a
2 changed files with 16 additions and 18 deletions

View file

@ -127,18 +127,14 @@ ProgressDialog::show_pd ()
{
WavesDialog::show ();
/* Make sure the progress dialog is drawn */
while (Glib::MainContext::get_default()->iteration (false)) {
/* do nothing */
}
Glib::MainContext::get_default()->iteration (false);
}
void
ProgressDialog::hide_pd ()
{
/* Make sure the progress dialog is drawn */
while (Glib::MainContext::get_default()->iteration (false)) {
/* do nothing */
}
Glib::MainContext::get_default()->iteration (false);
set_progress (0);
WavesDialog::hide ();
}
@ -164,19 +160,21 @@ ProgressDialog::set_cancel_button_sensitive (bool sensitive)
void
ProgressDialog::set_progress (float p)
{
if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {
// IF WE ARE NOT IN GUI THREAD
// we push method set_progress () to gui event loop
// from which it will be called afterwards
Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ProgressDialog::set_progress , this, p));
return;
}
// IF WE ARE NOT IN GUI THREAD
// we push method set_progress () to gui event loop
// from which it will be called afterwards
Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ProgressDialog::set_progress_in_gui_thread , this, p));
}
void
ProgressDialog::set_progress_in_gui_thread (float p)
{
// it's provided that this method can be called
// just from gui thread
_progress_bar.set_fraction (p);
// Make sure the progress widget gets updated
// it can be called just from gui-thread
while (Glib::MainContext::get_default()->iteration (false)) {
/* do nothing */
}
}
}

View file

@ -58,7 +58,7 @@ private:
const std::string& top_message,
const std::string& progress_message,
const std::string& bottom_message);
void set_progress_in_gui_thread (float);
Gtk::Label& _top_label;
Gtk::Label& _bottom_label;
Gtk::ProgressBar& _progress_bar;