added basic support for mounting unmounted partitions on mountpoints found

* include/Win_GParted.h,
  src/Win_GParted.cc: added basic support for mounting unmounted
  partitions on mountpoints found in /etc/fstab
This commit is contained in:
Bart Hakvoort 2006-03-09 19:37:50 +00:00
parent 225b294899
commit ff3dd1accc
3 changed files with 114 additions and 67 deletions

View File

@ -1,3 +1,9 @@
2006-03-09 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Win_GParted.h,
src/Win_GParted.cc: added basic support for mounting unmounted
partitions on mountpoints found in /etc/fstab
2006-03-09 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/DrawingAreaVisualDisk.cc: changed MIN_SIZE from static 20 to

View File

@ -95,14 +95,11 @@ private:
void allow_format( bool b ) {
menu_partition .items()[ 8 ] .set_sensitive( b ); }
void allow_unmount( bool b ) {
void allow_toggle_swap_mount_state( bool b ) {
menu_partition .items()[ 10 ] .set_sensitive( b ); }
void allow_toggle_swap( bool b ) {
menu_partition .items()[ 11 ] .set_sensitive( b ); }
void allow_info( bool b ) {
menu_partition .items()[ 13 ] .set_sensitive( b ); }
menu_partition .items()[ 12 ] .set_sensitive( b ); }
void allow_undo( bool b ) {
toolbar_main .get_nth_item( 8 ) ->set_sensitive( b );
@ -117,6 +114,7 @@ private:
//threads..
void thread_refresh_devices() ;
void thread_unmount_partition( bool * succes, Glib::ustring * error ) ;
void thread_mount_partition( bool * succes, Glib::ustring * error ) ;
void thread_toggle_swap( bool * succes, Glib::ustring * error ) ;
//signal handlers
@ -148,8 +146,7 @@ private:
void activate_delete();
void activate_info();
void activate_format( GParted::FILESYSTEM new_fs );
void activate_unmount() ;
void activate_toggle_swap() ;
void toggle_swap_mount_state() ;
void activate_disklabel() ;
void activate_undo();

View File

@ -251,11 +251,7 @@ void Win_GParted::init_partition_menu( )
menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("unmount"),
sigc::mem_fun( *this, &Win_GParted::activate_unmount ) ) );
menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("swapoff"),
sigc::mem_fun( *this, &Win_GParted::activate_toggle_swap ) ) );
sigc::mem_fun( *this, &Win_GParted::toggle_swap_mount_state ) ) );
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() );
@ -670,11 +666,12 @@ bool Win_GParted::Quit_Check_Operations()
void Win_GParted::set_valid_operations()
{
//FIXME: we shouldn't allow NEW partitions to be activated (swap/mount)
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_toggle_swap( false ) ;
allow_paste( false ); allow_format( false ); allow_info( false ) ;
allow_toggle_swap_mount_state( false ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() ) ->set_label( _("swapoff") ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() ) ->set_label( _("unmount") ) ;
//no partition selected...
if ( selected_partition .partition .empty() )
@ -686,20 +683,30 @@ void Win_GParted::set_valid_operations()
//deal with swap...
if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
{
allow_toggle_swap( true ) ;
allow_toggle_swap_mount_state( true ) ;
if ( selected_partition .busy )
{
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() )
->set_label( _("swapoff") ) ;
return ;
}
else
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 11 ] .get_child() )
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() )
->set_label( _("swapon") ) ;
}
//only unmount/swapoff is allowed (if ! extended)
//only unmount is allowed (if ! extended)
if ( selected_partition .busy )
{
if ( selected_partition .type != GParted::TYPE_EXTENDED )
allow_unmount( true ) ;
{
allow_toggle_swap_mount_state( true ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() )
->set_label( _("unmount") ) ;
}
return ;
}
@ -755,6 +762,14 @@ void Win_GParted::set_valid_operations()
if ( selected_partition .status == GParted::STAT_REAL && fs .copy )
allow_copy( true ) ;
if ( selected_partition .mountpoints .size() )
{
allow_toggle_swap_mount_state( true ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() )
->set_label( _("mount") ) ;
}
return ;
}
}
@ -1391,32 +1406,25 @@ void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error
pulse = false ;
}
void Win_GParted::activate_unmount()
void Win_GParted::thread_mount_partition( bool * succes, Glib::ustring * error )
{
bool succes ;
Glib::ustring error ;
Glib::ustring dummy ;
std::vector<Glib::ustring> errors ;
pulse = true ;
thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), &succes, &error ), true ) ;
show_pulsebar( String::ucompose( _("Unmounting %1"), selected_partition .partition ) ) ;
if ( ! succes )
*succes = true ;
for ( unsigned int t = 0 ; t < selected_partition .mountpoints .size() ; t++ )
if ( Utils::execute_command( "mount -v " + selected_partition .partition + " " + selected_partition .mountpoints[ t ],
dummy,
*error ) )
{
Gtk::MessageDialog dialog( *this,
String::ucompose( _("Could not unmount %1"), selected_partition .partition ),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK,
true );
dialog .set_secondary_text( error, true ) ;
dialog.run() ;
*succes = false ;
errors .push_back( *error ) ;
}
menu_gparted_refresh_devices() ;
if ( ! *succes )
*error = "<i>" + Glib::build_path( "\n", errors ) + "</i>" ;
pulse = false ;
}
void Win_GParted::thread_toggle_swap( bool * succes, Glib::ustring * error )
@ -1431,13 +1439,15 @@ void Win_GParted::thread_toggle_swap( bool * succes, Glib::ustring * error )
pulse = false ;
}
void Win_GParted::activate_toggle_swap()
void Win_GParted::toggle_swap_mount_state()
{
bool succes = false ;
Glib::ustring error ;
pulse = true ;
if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
{
thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_toggle_swap ), &succes, &error ), true ) ;
@ -1459,6 +1469,40 @@ void Win_GParted::activate_toggle_swap()
dialog.run() ;
}
}
else
{
if ( selected_partition .busy )
{
thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_unmount_partition ), &succes, &error ), true ) ;
show_pulsebar( String::ucompose( _("Unmounting %1"), selected_partition .partition ) ) ;
}
else
{
thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
sigc::mem_fun( *this, &Win_GParted::thread_mount_partition ), &succes, &error ), true ) ;
show_pulsebar( String::ucompose( _("mounting %1"), selected_partition .partition ) ) ;
}
if ( ! succes )
{
Gtk::MessageDialog dialog( *this,
String::ucompose( selected_partition .busy ? _("Could not unmount %1") : _("Could not mount %1"),
selected_partition .partition ),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK,
true );
dialog .set_secondary_text( error, true ) ;
dialog.run() ;
}
}
menu_gparted_refresh_devices() ;
}