implemented real 'cancel'.

* include/Dialog_Progress.h,
  src/Dialog_Progress.cc: implemented real 'cancel'.
This commit is contained in:
Bart Hakvoort 2006-01-25 23:30:43 +00:00
parent 06cab31e44
commit b08a1a838d
3 changed files with 71 additions and 41 deletions

View File

@ -12,6 +12,11 @@
* src/Dialog_Partition_Info.cc: use Utils::format_size() instead of
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>
* src/Utils.cc: use realpath() to get absolute path to 'real'

View File

@ -43,7 +43,7 @@ public:
private:
void update_operation_details( const Gtk::TreeRow & treerow, const OperationDetails & operation_details ) ;
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 ) ;
@ -78,8 +78,8 @@ private:
treeview_operations_Columns treeview_operations_columns;
std::vector<Operation> operations ;
bool pulse, succes ;
Glib::Thread *thread ;
bool pulse, succes, cancel ;
pthread_t pthread ;
double fraction ;
unsigned int t ;
Glib::ustring str_temp ;

View File

@ -30,6 +30,7 @@ Dialog_Progress::Dialog_Progress( const std::vector<Operation> & operations )
this ->set_title( _("Applying pending operations") ) ;
this ->operations = operations ;
succes = true ;
cancel = false ;
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() ->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 ->show_all_children() ;
@ -151,9 +152,9 @@ void Dialog_Progress::update_operation_details( const Gtk::TreeRow & treerow,
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_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 ] ) ) ;
pulse = true ;
thread = Glib::Thread::create( sigc::bind<Operation *>(
sigc::mem_fun( *this, &Dialog_Progress::thread_apply_operation ), &( operations[ t ] ) ), true );
pthread_create( & pthread, NULL, Dialog_Progress::static_pthread_apply_operation, this );
treerow = treestore_operations ->children()[ t ] ;
while ( pulse )
@ -179,8 +179,6 @@ void Dialog_Progress::on_signal_show()
usleep( 10000 ) ;
}
thread ->join() ;
//final updates for this operation
update_operation_details( treerow, operations[ t ] .operation_details ) ;
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 ->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
children = this ->get_vbox() ->get_children() ;
children[ 1 ] ->hide() ;
progressbar_current .hide() ;
label_current .hide() ;
}
//deal with succes/error...
if ( succes )
@ -206,9 +212,10 @@ void Dialog_Progress::on_signal_show()
}
else
{
progressbar_all .set_text( _("Not all operations were succesfully completed") ) ;
expander_details .set_expanded( true ) ;
if ( ! cancel )
{
Gtk::MessageDialog dialog( *this,
_("An error occurred while applying the operations"),
false,
@ -224,26 +231,44 @@ void Dialog_Progress::on_signal_show()
dialog .set_secondary_text( str_temp, true ) ;
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 )
{
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:
//press the 'cancel' button
//close the dialog by pressing the cross
std::cout << "CANCEL!! yet to be implemented... ;)" << std::endl ;
}
Gtk::MessageDialog dialog( *this,
_("Are you sure you want to cancel the current operation?"),
false,
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()