implemented real 'cancel'.
* include/Dialog_Progress.h, src/Dialog_Progress.cc: implemented real 'cancel'.
This commit is contained in:
parent
06cab31e44
commit
b08a1a838d
|
@ -12,6 +12,11 @@
|
||||||
* src/Dialog_Partition_Info.cc: use Utils::format_size() instead of
|
* src/Dialog_Partition_Info.cc: use Utils::format_size() instead of
|
||||||
displaying every value in MiB's. Also some cleanups and changes.
|
displaying every value in MiB's. Also some cleanups and changes.
|
||||||
|
|
||||||
|
2006-01-26 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||||
|
|
||||||
|
* include/Dialog_Progress.h,
|
||||||
|
src/Dialog_Progress.cc: implemented real 'cancel'.
|
||||||
|
|
||||||
2006-01-24 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
2006-01-24 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||||
|
|
||||||
* src/Utils.cc: use realpath() to get absolute path to 'real'
|
* src/Utils.cc: use realpath() to get absolute path to 'real'
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void update_operation_details( const Gtk::TreeRow & treerow, const OperationDetails & operation_details ) ;
|
void update_operation_details( const Gtk::TreeRow & treerow, const OperationDetails & operation_details ) ;
|
||||||
void on_signal_show() ;
|
void on_signal_show() ;
|
||||||
void thread_apply_operation( Operation * operation ) ;
|
static void *static_pthread_apply_operation( void * p_dialog_progress ) ;
|
||||||
|
|
||||||
void on_response( int response_id ) ;
|
void on_response( int response_id ) ;
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ private:
|
||||||
treeview_operations_Columns treeview_operations_columns;
|
treeview_operations_Columns treeview_operations_columns;
|
||||||
|
|
||||||
std::vector<Operation> operations ;
|
std::vector<Operation> operations ;
|
||||||
bool pulse, succes ;
|
bool pulse, succes, cancel ;
|
||||||
Glib::Thread *thread ;
|
pthread_t pthread ;
|
||||||
double fraction ;
|
double fraction ;
|
||||||
unsigned int t ;
|
unsigned int t ;
|
||||||
Glib::ustring str_temp ;
|
Glib::ustring str_temp ;
|
||||||
|
|
|
@ -30,6 +30,7 @@ Dialog_Progress::Dialog_Progress( const std::vector<Operation> & operations )
|
||||||
this ->set_title( _("Applying pending operations") ) ;
|
this ->set_title( _("Applying pending operations") ) ;
|
||||||
this ->operations = operations ;
|
this ->operations = operations ;
|
||||||
succes = true ;
|
succes = true ;
|
||||||
|
cancel = false ;
|
||||||
|
|
||||||
fraction = 1.00 / operations .size() ;
|
fraction = 1.00 / operations .size() ;
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ Dialog_Progress::Dialog_Progress( const std::vector<Operation> & operations )
|
||||||
this ->get_vbox() ->pack_start( expander_details, Gtk::PACK_EXPAND_WIDGET ) ;
|
this ->get_vbox() ->pack_start( expander_details, Gtk::PACK_EXPAND_WIDGET ) ;
|
||||||
this ->get_vbox() ->set_spacing( 5 ) ;
|
this ->get_vbox() ->set_spacing( 5 ) ;
|
||||||
|
|
||||||
this ->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_NONE ) ;
|
this ->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL ) ;
|
||||||
|
|
||||||
this ->signal_show() .connect( sigc::mem_fun(*this, &Dialog_Progress::on_signal_show) );
|
this ->signal_show() .connect( sigc::mem_fun(*this, &Dialog_Progress::on_signal_show) );
|
||||||
this ->show_all_children() ;
|
this ->show_all_children() ;
|
||||||
|
@ -151,9 +152,9 @@ void Dialog_Progress::update_operation_details( const Gtk::TreeRow & treerow,
|
||||||
|
|
||||||
void Dialog_Progress::on_signal_show()
|
void Dialog_Progress::on_signal_show()
|
||||||
{
|
{
|
||||||
for ( t = 0 ; t < operations .size() && succes ; t++ )
|
for ( t = 0 ; t < operations .size() && succes && ! cancel ; t++ )
|
||||||
{
|
{
|
||||||
label_current .set_markup( "<i>" + operations[ t ] .str_operation + "</i>" ) ;
|
label_current .set_markup( "<i>" + operations[ t ] .str_operation + "</i>\n" ) ;
|
||||||
|
|
||||||
progressbar_all .set_text( String::ucompose( _("%1 of %2 operations completed"), t, operations .size() ) ) ;
|
progressbar_all .set_text( String::ucompose( _("%1 of %2 operations completed"), t, operations .size() ) ) ;
|
||||||
progressbar_all .set_fraction( fraction * t ) ;
|
progressbar_all .set_fraction( fraction * t ) ;
|
||||||
|
@ -163,8 +164,7 @@ void Dialog_Progress::on_signal_show()
|
||||||
treeview_operations .set_cursor( static_cast<Gtk::TreePath>( treestore_operations ->children()[ t ] ) ) ;
|
treeview_operations .set_cursor( static_cast<Gtk::TreePath>( treestore_operations ->children()[ t ] ) ) ;
|
||||||
|
|
||||||
pulse = true ;
|
pulse = true ;
|
||||||
thread = Glib::Thread::create( sigc::bind<Operation *>(
|
pthread_create( & pthread, NULL, Dialog_Progress::static_pthread_apply_operation, this );
|
||||||
sigc::mem_fun( *this, &Dialog_Progress::thread_apply_operation ), &( operations[ t ] ) ), true );
|
|
||||||
|
|
||||||
treerow = treestore_operations ->children()[ t ] ;
|
treerow = treestore_operations ->children()[ t ] ;
|
||||||
while ( pulse )
|
while ( pulse )
|
||||||
|
@ -179,8 +179,6 @@ void Dialog_Progress::on_signal_show()
|
||||||
usleep( 10000 ) ;
|
usleep( 10000 ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread ->join() ;
|
|
||||||
|
|
||||||
//final updates for this operation
|
//final updates for this operation
|
||||||
update_operation_details( treerow, operations[ t ] .operation_details ) ;
|
update_operation_details( treerow, operations[ t ] .operation_details ) ;
|
||||||
static_cast<Gtk::TreeRow>( treestore_operations ->children()[ t ] )
|
static_cast<Gtk::TreeRow>( treestore_operations ->children()[ t ] )
|
||||||
|
@ -192,11 +190,19 @@ void Dialog_Progress::on_signal_show()
|
||||||
this ->get_action_area() ->remove( * children .back() ) ;
|
this ->get_action_area() ->remove( * children .back() ) ;
|
||||||
this ->add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_OK );
|
this ->add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_OK );
|
||||||
|
|
||||||
|
if ( cancel )
|
||||||
|
{
|
||||||
|
progressbar_current .set_text( _("Operation cancelled") ) ;
|
||||||
|
progressbar_current .set_fraction( 0.0 ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//hide 'current operation' stuff
|
//hide 'current operation' stuff
|
||||||
children = this ->get_vbox() ->get_children() ;
|
children = this ->get_vbox() ->get_children() ;
|
||||||
children[ 1 ] ->hide() ;
|
children[ 1 ] ->hide() ;
|
||||||
progressbar_current .hide() ;
|
progressbar_current .hide() ;
|
||||||
label_current .hide() ;
|
label_current .hide() ;
|
||||||
|
}
|
||||||
|
|
||||||
//deal with succes/error...
|
//deal with succes/error...
|
||||||
if ( succes )
|
if ( succes )
|
||||||
|
@ -206,9 +212,10 @@ void Dialog_Progress::on_signal_show()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
progressbar_all .set_text( _("Not all operations were succesfully completed") ) ;
|
|
||||||
expander_details .set_expanded( true ) ;
|
expander_details .set_expanded( true ) ;
|
||||||
|
|
||||||
|
if ( ! cancel )
|
||||||
|
{
|
||||||
Gtk::MessageDialog dialog( *this,
|
Gtk::MessageDialog dialog( *this,
|
||||||
_("An error occurred while applying the operations"),
|
_("An error occurred while applying the operations"),
|
||||||
false,
|
false,
|
||||||
|
@ -225,25 +232,43 @@ void Dialog_Progress::on_signal_show()
|
||||||
dialog .run() ;
|
dialog .run() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Dialog_Progress::thread_apply_operation( Operation * operation )
|
void * Dialog_Progress::static_pthread_apply_operation( void * p_dialog_progress )
|
||||||
{
|
{
|
||||||
succes = signal_apply_operation .emit( *operation ) ;
|
Dialog_Progress *dp = static_cast<Dialog_Progress *>( p_dialog_progress ) ;
|
||||||
|
|
||||||
pulse = false ;
|
dp ->succes = dp ->signal_apply_operation .emit( dp ->operations[ dp ->t ] ) ;
|
||||||
|
|
||||||
|
dp ->pulse = false ;
|
||||||
|
|
||||||
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog_Progress::on_response( int response_id )
|
void Dialog_Progress::on_response( int response_id )
|
||||||
{
|
{
|
||||||
if ( pulse && ( response_id == Gtk::RESPONSE_DELETE_EVENT || response_id == Gtk::RESPONSE_CANCEL ) )
|
if ( response_id == Gtk::RESPONSE_CANCEL )
|
||||||
{
|
{
|
||||||
//FIXME i guess this is the best place to implement the cancel. there are 2 ways to trigger this:
|
Gtk::MessageDialog dialog( *this,
|
||||||
//press the 'cancel' button
|
_("Are you sure you want to cancel the current operation?"),
|
||||||
//close the dialog by pressing the cross
|
false,
|
||||||
std::cout << "CANCEL!! yet to be implemented... ;)" << std::endl ;
|
Gtk::MESSAGE_QUESTION,
|
||||||
}
|
Gtk::BUTTONS_NONE,
|
||||||
|
true ) ;
|
||||||
|
|
||||||
Gtk::Dialog::on_response( response_id ) ;
|
dialog .set_secondary_text( _("Cancelling an operation may cause SEVERE filesystem damage.") ) ;
|
||||||
|
|
||||||
|
dialog .add_button( _("Continue Operation"), Gtk::RESPONSE_NONE ) ;
|
||||||
|
dialog .add_button( _("Cancel Operation"), Gtk::RESPONSE_CANCEL ) ;
|
||||||
|
|
||||||
|
if ( dialog .run() == Gtk::RESPONSE_CANCEL )
|
||||||
|
{
|
||||||
|
pthread_cancel( pthread ) ;
|
||||||
|
cancel = true ;
|
||||||
|
pulse = false ;
|
||||||
|
succes = false ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog_Progress::~Dialog_Progress()
|
Dialog_Progress::~Dialog_Progress()
|
||||||
|
|
Loading…
Reference in New Issue