diff --git a/ChangeLog b/ChangeLog index 2cb3bf6a..894bd289 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-02-02 Bart Hakvoort + + * include/GParted_Core.h, + include/Win_GParted.h, + src/GParted_Core.cc, + src/Win_GParted.cc, + src/main.cc: added support for commandline arguments (#329414) + 2006-02-02 Bart Hakvoort * include/TreeView_Detail.h, diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 7a53a950..cb86050d 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -43,7 +43,8 @@ class GParted_Core { public: GParted_Core( ) ; - void find_supported_filesystems( ) ; + void find_supported_filesystems( ) ; + void set_user_devices( const std::vector & user_devices ) ; void get_devices( std::vector & devices ) ; bool apply_operation_to_disk( Operation & operation ); @@ -69,6 +70,7 @@ public: private: GParted::FILESYSTEM get_filesystem() ; + bool check_device_path( const Glib::ustring & device_path ) ; void set_device_partitions( Device & device ) ; void init_maps() ; void set_mountpoints( std::vector & partitions ) ; @@ -106,6 +108,8 @@ private: Glib::ustring temp ; Partition partition_temp ; FS fs ; + std::vector device_paths ; + bool probe_devices ; std::map mount_info ; std::map short_paths ; diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 42752452..1ab22605 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -47,7 +47,7 @@ namespace GParted class Win_GParted : public Gtk::Window { public: - Win_GParted( ); + Win_GParted( const std::vector & user_devices ) ; private: void init_menubar( ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index a40370ca..c157218a 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -69,45 +69,58 @@ void GParted_Core::find_supported_filesystems( ) FS fs ; fs .filesystem = GParted::FS_UNKNOWN ; FILESYSTEMS .push_back( fs ) ; } + +void GParted_Core::set_user_devices( const std::vector & user_devices ) +{ + this ->device_paths = user_devices ; + this ->probe_devices = ! user_devices .size() ; +} + +bool GParted_Core::check_device_path( const Glib::ustring & device_path ) +{ + if ( device_path .length() > 6 && device_path .is_ascii() && open_device( device_path ) ) + { + close_device_and_disk() ; + return true ; + } + + return false ; +} void GParted_Core::get_devices( std::vector & devices ) { devices .clear() ; - - //try to find all available devices and put these in a list - ped_device_probe_all(); - Device temp_device ; - std::vector device_paths ; init_maps() ; - /* in certain cases (e.g. when there's a cd in the cdrom-drive) ped_device_probe_all will find a - * 'ghost' device that has no name or contains random garbage. - * Those checks try to prevent such a ghostdevice from being initialized.. - */ - lp_device = ped_device_get_next( NULL ); - while ( lp_device ) + //only probe if no devices were specified as arguments.. + if ( probe_devices ) { - if ( strlen( lp_device ->path ) > 6 && - static_cast( lp_device ->path ) .is_ascii() && - open_device( lp_device ->path ) - ) - device_paths .push_back( get_short_path( lp_device ->path ) ) ; - - lp_device = ped_device_get_next( lp_device ) ; + device_paths .clear() ; + + //try to find all available devices + ped_device_probe_all(); + + lp_device = ped_device_get_next( NULL ); + while ( lp_device ) + { + device_paths .push_back( lp_device ->path ) ; + + lp_device = ped_device_get_next( lp_device ) ; + } + close_device_and_disk() ; } - close_device_and_disk() ; for ( unsigned int t = 0 ; t < device_paths .size() ; t++ ) { - if ( open_device_and_disk( device_paths[ t ], false ) ) + if ( check_device_path( device_paths[ t ] ) && open_device_and_disk( device_paths[ t ], false ) ) { temp_device .Reset() ; //device info.. - temp_device .path = device_paths[ t ] ; + temp_device .path = get_short_path( device_paths[ t ] ) ; temp_device .realpath = lp_device ->path ; temp_device .model = lp_device ->model ; temp_device .heads = lp_device ->bios_geom .heads ; @@ -115,7 +128,8 @@ void GParted_Core::get_devices( std::vector & devices ) temp_device .cylinders = lp_device ->bios_geom .cylinders ; temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ; temp_device .cylsize = Utils::Round( Utils::sector_to_unit( - temp_device .heads * temp_device .sectors, GParted::UNIT_MIB ) ) ; + temp_device .heads * temp_device .sectors, + GParted::UNIT_MIB ) ) ; //make sure cylsize is at least 1 MiB if ( temp_device .cylsize < 1 ) diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 0e3cd8c0..b6c776f5 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -34,13 +34,14 @@ namespace GParted { -Win_GParted::Win_GParted( ) +Win_GParted::Win_GParted( const std::vector & user_devices ) { copied_partition .Reset( ) ; selected_partition .Reset( ) ; new_count = 1; current_device = 0 ; pulse = false ; + gparted_core .set_user_devices( user_devices ) ; //==== GUI ========================= this ->set_title( _("GParted") ); @@ -459,8 +460,6 @@ void Win_GParted::refresh_combo_devices() if ( menu ->items() .size() ) menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_submenu( *menu ) ; - - menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_sensitive( menu ->items() .size() ) ; combo_devices .set_active( current_device ) ; } @@ -865,6 +864,7 @@ void Win_GParted::menu_gparted_refresh_devices( ) this ->set_title( _("GParted") ); combo_devices .hide() ; + menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_sensitive( false ) ; menubar_main .items()[ 1 ] .set_sensitive( false ) ; menubar_main .items()[ 2 ] .set_sensitive( false ) ; menubar_main .items()[ 3 ] .set_sensitive( false ) ; @@ -891,6 +891,7 @@ void Win_GParted::menu_gparted_refresh_devices( ) { combo_devices .show() ; + menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_sensitive( true ) ; menubar_main .items()[ 1 ] .set_sensitive( true ) ; menubar_main .items()[ 2 ] .set_sensitive( true ) ; menubar_main .items()[ 3 ] .set_sensitive( true ) ; diff --git a/src/main.cc b/src/main.cc index 5b31bad5..8c3151c4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -34,14 +34,24 @@ int main( int argc, char *argv[] ) //check UID if ( getuid() != 0 ) { - Gtk::MessageDialog dialog( _("Root privileges are required for running GParted"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK ) ; - dialog .set_secondary_text( _( "Since GParted can be a weapon of mass destruction only root may run it.") ) ; + Gtk::MessageDialog dialog( _("Root privileges are required for running GParted"), + false, + Gtk::MESSAGE_ERROR, + Gtk::BUTTONS_OK ) ; + dialog .set_secondary_text( + _("Since GParted can be a weapon of mass destruction only root may run it.") ) ; dialog .run() ; exit( 0 ) ; } + + //deal with arguments.. + std::vector user_devices ; - GParted::Win_GParted win_gparted ; + for ( int t = 1 ; t < argc ; t++ ) + user_devices .push_back( argv[ t ] ) ; + + GParted::Win_GParted win_gparted( user_devices ) ; Gtk::Main::run( win_gparted ) ; return 0 ;