added support for activating swap (#392672)

* include/Win_GParted.h,
  src/Win_GParted.cc: added support for activating swap (#392672)
This commit is contained in:
Bart Hakvoort 2006-02-08 20:36:18 +00:00
parent 4e54226462
commit 1a46adf114
3 changed files with 69 additions and 39 deletions

View File

@ -1,3 +1,8 @@
2006-02-08 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Win_GParted.h,
src/Win_GParted.cc: added support for activating swap (#392672)
2006-02-07 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-02-07 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/Dialog_Progress.cc: commented set_do_overwrite_confirmation() * src/Dialog_Progress.cc: commented set_do_overwrite_confirmation()

View File

@ -70,7 +70,7 @@ private:
void Add_Operation( OperationType, const Partition & ); void Add_Operation( OperationType, const Partition & );
void Refresh_Visual( ); void Refresh_Visual( );
bool Quit_Check_Operations( ); bool Quit_Check_Operations( );
void Set_Valid_Operations( ) ; //determines which operations are allowed on selected_partition void set_valid_operations() ;
//convenience functions //convenience functions
void allow_new( bool b ) { void allow_new( bool b ) {
@ -99,7 +99,7 @@ private:
void allow_unmount( bool b ) { void allow_unmount( bool b ) {
menu_partition .items( )[ 10 ] .set_sensitive( b ); } menu_partition .items( )[ 10 ] .set_sensitive( b ); }
void allow_disable_swap( bool b ) { void allow_toggle_swap( bool b ) {
menu_partition .items( )[ 11 ] .set_sensitive( b ); } menu_partition .items( )[ 11 ] .set_sensitive( b ); }
void allow_info( bool b ) { void allow_info( bool b ) {
@ -116,7 +116,7 @@ private:
//threads.. //threads..
void thread_refresh_devices() ; void thread_refresh_devices() ;
void thread_unmount_partition() ; void thread_unmount_partition() ;
void thread_deactivate_swap() ; void thread_toggle_swap() ;
//signal handlers //signal handlers
void open_operationslist( ) ; void open_operationslist( ) ;
@ -147,7 +147,7 @@ private:
void activate_info(); void activate_info();
void activate_format( GParted::FILESYSTEM new_fs ); void activate_format( GParted::FILESYSTEM new_fs );
void activate_unmount() ; void activate_unmount() ;
void activate_disable_swap() ; void activate_toggle_swap() ;
void activate_disklabel() ; void activate_disklabel() ;
void activate_undo(); void activate_undo();

View File

@ -255,7 +255,7 @@ void Win_GParted::init_partition_menu( )
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("Deactivate"), Gtk::Menu_Helpers::MenuElem( _("Deactivate"),
sigc::mem_fun( *this, &Win_GParted::activate_disable_swap ) ) ); sigc::mem_fun( *this, &Win_GParted::activate_toggle_swap ) ) );
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() );
@ -638,21 +638,27 @@ void Win_GParted::Refresh_Visual( )
//no partition can be selected after a refresh.. //no partition can be selected after a refresh..
selected_partition .Reset() ; selected_partition .Reset() ;
Set_Valid_Operations() ; set_valid_operations() ;
} }
bool Win_GParted::Quit_Check_Operations( ) bool Win_GParted::Quit_Check_Operations( )
{ {
if ( operations .size() ) if ( operations .size() )
{ {
str_temp = "<span weight=\"bold\" size=\"larger\">" + (Glib::ustring) _( "Quit GParted?" ) + "</span>\n\n" ; Gtk::MessageDialog dialog( *this,
_("Quit GParted?"),
false,
Gtk::MESSAGE_QUESTION,
Gtk::BUTTONS_NONE,
true );
if ( operations .size() != 1 ) if ( operations .size() != 1 )
str_temp += String::ucompose( _("%1 operations are currently pending."), operations .size() ) ; str_temp = String::ucompose( _("%1 operations are currently pending."), operations .size() ) ;
else else
str_temp += _("1 operation is currently pending."); str_temp = _("1 operation is currently pending.");
dialog .set_secondary_text( str_temp ) ;
Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
dialog .add_button( Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE ); dialog .add_button( Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE );
dialog .add_button( Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL ); dialog .add_button( Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL );
@ -663,11 +669,13 @@ bool Win_GParted::Quit_Check_Operations( )
return true; //close GParted return true; //close GParted
} }
void Win_GParted::Set_Valid_Operations( ) void Win_GParted::set_valid_operations( )
{ {
allow_new( false ); allow_delete( false ); allow_resize( false ); allow_copy( false ); allow_new( false ); allow_delete( false ); allow_resize( false ); allow_copy( false );
allow_paste( false ); allow_format( false ); allow_unmount( false ) ; allow_info( false ) ; allow_paste( false ); allow_format( false ); allow_unmount( false ) ; allow_info( false ) ;
allow_disable_swap( false ) ; allow_toggle_swap( false ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("Deactivate") ) ;
//no partition selected... //no partition selected...
if ( selected_partition .partition .empty() ) if ( selected_partition .partition .empty() )
@ -676,18 +684,24 @@ void Win_GParted::Set_Valid_Operations( )
//if there's something, there's some info ;) //if there's something, there's some info ;)
allow_info( true ) ; allow_info( true ) ;
//only unmount is allowed //deal with swap...
if ( selected_partition .busy ) if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
{ {
if ( selected_partition .type != GParted::TYPE_EXTENDED ) allow_toggle_swap( true ) ;
{
if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
allow_disable_swap( true ) ;
else
allow_unmount( true ) ;
}
return; if ( selected_partition .busy )
return ;
else
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() )
->set_label( _("Activate") ) ;
}
//only unmount is allowed
if ( selected_partition .busy && selected_partition .type != GParted::TYPE_EXTENDED )
{
allow_unmount( true ) ;
return ;
} }
//UNALLOCATED //UNALLOCATED
@ -1011,7 +1025,7 @@ void Win_GParted::on_partition_selected( const Partition & partition, bool src_i
{ {
selected_partition = partition; selected_partition = partition;
Set_Valid_Operations() ; set_valid_operations() ;
if ( src_is_treeview ) if ( src_is_treeview )
vbox_visual_disk .set_selected( partition ) ; vbox_visual_disk .set_selected( partition ) ;
@ -1350,33 +1364,44 @@ void Win_GParted::activate_unmount( )
menu_gparted_refresh_devices() ; menu_gparted_refresh_devices() ;
} }
void Win_GParted::thread_deactivate_swap() void Win_GParted::thread_toggle_swap()
{ {
if ( swapoff( selected_partition .partition .c_str() ) ) bool succes = false ;
str_temp = Glib::strerror( errno ) ;
if ( selected_partition .busy )
succes = ! swapoff( selected_partition .partition .c_str() ) ;
else else
succes = ! swapon( selected_partition .partition .c_str(), 0 ) ;
if ( succes )
str_temp .clear() ; str_temp .clear() ;
else
str_temp = Glib::strerror( errno ) ;
pulse = false ; pulse = false ;
} }
void Win_GParted::activate_disable_swap() void Win_GParted::activate_toggle_swap()
{ {
pulse = true ; pulse = true ;
thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_deactivate_swap ), true ) ; thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), true ) ;
show_pulsebar( String::ucompose( _("Deactivating swap on %1"), selected_partition .partition ) ) ; show_pulsebar(
String::ucompose( selected_partition .busy ? _("Deactivating swap on %1") : _("Activating swap on %1"),
selected_partition .partition ) ) ;
if ( ! str_temp .empty() ) if ( ! str_temp .empty() )
{ {
Gtk::MessageDialog dialog( *this, Gtk::MessageDialog dialog(
"<span weight=\"bold\" size=\"larger\">" + *this,
static_cast<Glib::ustring>( _("Could not deactivate swap") ) + selected_partition .busy ? _("Could not deactivate swap") : _("Could not activate swap"),
"</span>\n\n" + str_temp, false,
true, Gtk::MESSAGE_ERROR,
Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
Gtk::BUTTONS_OK, true ) ;
true );
dialog .set_secondary_text( str_temp ) ;
dialog.run() ; dialog.run() ;
} }