added support for commandline arguments (#329414)
* 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)
This commit is contained in:
parent
35593e5747
commit
4161252b32
|
@ -1,3 +1,11 @@
|
|||
2006-02-02 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* 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 <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/TreeView_Detail.h,
|
||||
|
|
|
@ -44,6 +44,7 @@ class GParted_Core
|
|||
public:
|
||||
GParted_Core( ) ;
|
||||
void find_supported_filesystems( ) ;
|
||||
void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
|
||||
void get_devices( std::vector<Device> & 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<Partition> & partitions ) ;
|
||||
|
@ -106,6 +108,8 @@ private:
|
|||
Glib::ustring temp ;
|
||||
Partition partition_temp ;
|
||||
FS fs ;
|
||||
std::vector<Glib::ustring> device_paths ;
|
||||
bool probe_devices ;
|
||||
|
||||
std::map<Glib::ustring, Glib::ustring> mount_info ;
|
||||
std::map<Glib::ustring, Glib::ustring> short_paths ;
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace GParted
|
|||
class Win_GParted : public Gtk::Window
|
||||
{
|
||||
public:
|
||||
Win_GParted( );
|
||||
Win_GParted( const std::vector<Glib::ustring> & user_devices ) ;
|
||||
|
||||
private:
|
||||
void init_menubar( ) ;
|
||||
|
|
|
@ -70,44 +70,57 @@ void GParted_Core::find_supported_filesystems( )
|
|||
FILESYSTEMS .push_back( fs ) ;
|
||||
}
|
||||
|
||||
void GParted_Core::set_user_devices( const std::vector<Glib::ustring> & 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<Device> & devices )
|
||||
{
|
||||
devices .clear() ;
|
||||
|
||||
//try to find all available devices and put these in a list
|
||||
ped_device_probe_all();
|
||||
|
||||
Device temp_device ;
|
||||
std::vector<Glib::ustring> 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..
|
||||
*/
|
||||
//only probe if no devices were specified as arguments..
|
||||
if ( probe_devices )
|
||||
{
|
||||
device_paths .clear() ;
|
||||
|
||||
//try to find all available devices
|
||||
ped_device_probe_all();
|
||||
|
||||
lp_device = ped_device_get_next( NULL );
|
||||
while ( lp_device )
|
||||
{
|
||||
if ( strlen( lp_device ->path ) > 6 &&
|
||||
static_cast<Glib::ustring>( lp_device ->path ) .is_ascii() &&
|
||||
open_device( lp_device ->path )
|
||||
)
|
||||
device_paths .push_back( get_short_path( lp_device ->path ) ) ;
|
||||
device_paths .push_back( lp_device ->path ) ;
|
||||
|
||||
lp_device = ped_device_get_next( lp_device ) ;
|
||||
}
|
||||
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<Device> & 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 )
|
||||
|
|
|
@ -34,13 +34,14 @@
|
|||
namespace GParted
|
||||
{
|
||||
|
||||
Win_GParted::Win_GParted( )
|
||||
Win_GParted::Win_GParted( const std::vector<Glib::ustring> & 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") );
|
||||
|
@ -460,8 +461,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 ) ;
|
||||
|
|
16
src/main.cc
16
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 ) ;
|
||||
}
|
||||
|
||||
GParted::Win_GParted win_gparted ;
|
||||
//deal with arguments..
|
||||
std::vector<Glib::ustring> user_devices ;
|
||||
|
||||
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 ;
|
||||
|
|
Loading…
Reference in New Issue