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>
|
2006-02-02 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||||
|
|
||||||
* include/TreeView_Detail.h,
|
* include/TreeView_Detail.h,
|
||||||
|
|
|
@ -44,6 +44,7 @@ class GParted_Core
|
||||||
public:
|
public:
|
||||||
GParted_Core( ) ;
|
GParted_Core( ) ;
|
||||||
void find_supported_filesystems( ) ;
|
void find_supported_filesystems( ) ;
|
||||||
|
void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
|
||||||
void get_devices( std::vector<Device> & devices ) ;
|
void get_devices( std::vector<Device> & devices ) ;
|
||||||
|
|
||||||
bool apply_operation_to_disk( Operation & operation );
|
bool apply_operation_to_disk( Operation & operation );
|
||||||
|
@ -69,6 +70,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GParted::FILESYSTEM get_filesystem() ;
|
GParted::FILESYSTEM get_filesystem() ;
|
||||||
|
bool check_device_path( const Glib::ustring & device_path ) ;
|
||||||
void set_device_partitions( Device & device ) ;
|
void set_device_partitions( Device & device ) ;
|
||||||
void init_maps() ;
|
void init_maps() ;
|
||||||
void set_mountpoints( std::vector<Partition> & partitions ) ;
|
void set_mountpoints( std::vector<Partition> & partitions ) ;
|
||||||
|
@ -106,6 +108,8 @@ private:
|
||||||
Glib::ustring temp ;
|
Glib::ustring temp ;
|
||||||
Partition partition_temp ;
|
Partition partition_temp ;
|
||||||
FS fs ;
|
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> mount_info ;
|
||||||
std::map<Glib::ustring, Glib::ustring> short_paths ;
|
std::map<Glib::ustring, Glib::ustring> short_paths ;
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace GParted
|
||||||
class Win_GParted : public Gtk::Window
|
class Win_GParted : public Gtk::Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Win_GParted( );
|
Win_GParted( const std::vector<Glib::ustring> & user_devices ) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init_menubar( ) ;
|
void init_menubar( ) ;
|
||||||
|
|
|
@ -70,44 +70,57 @@ void GParted_Core::find_supported_filesystems( )
|
||||||
FILESYSTEMS .push_back( fs ) ;
|
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 )
|
void GParted_Core::get_devices( std::vector<Device> & devices )
|
||||||
{
|
{
|
||||||
devices .clear() ;
|
devices .clear() ;
|
||||||
|
|
||||||
//try to find all available devices and put these in a list
|
|
||||||
ped_device_probe_all();
|
|
||||||
|
|
||||||
Device temp_device ;
|
Device temp_device ;
|
||||||
std::vector<Glib::ustring> device_paths ;
|
|
||||||
|
|
||||||
init_maps() ;
|
init_maps() ;
|
||||||
|
|
||||||
/* in certain cases (e.g. when there's a cd in the cdrom-drive) ped_device_probe_all will find a
|
//only probe if no devices were specified as arguments..
|
||||||
* 'ghost' device that has no name or contains random garbage.
|
if ( probe_devices )
|
||||||
* Those checks try to prevent such a ghostdevice from being initialized..
|
|
||||||
*/
|
|
||||||
lp_device = ped_device_get_next( NULL );
|
|
||||||
while ( lp_device )
|
|
||||||
{
|
{
|
||||||
if ( strlen( lp_device ->path ) > 6 &&
|
device_paths .clear() ;
|
||||||
static_cast<Glib::ustring>( 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 ) ;
|
//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++ )
|
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() ;
|
temp_device .Reset() ;
|
||||||
|
|
||||||
//device info..
|
//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 .realpath = lp_device ->path ;
|
||||||
temp_device .model = lp_device ->model ;
|
temp_device .model = lp_device ->model ;
|
||||||
temp_device .heads = lp_device ->bios_geom .heads ;
|
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 .cylinders = lp_device ->bios_geom .cylinders ;
|
||||||
temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ;
|
temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ;
|
||||||
temp_device .cylsize = Utils::Round( Utils::sector_to_unit(
|
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
|
//make sure cylsize is at least 1 MiB
|
||||||
if ( temp_device .cylsize < 1 )
|
if ( temp_device .cylsize < 1 )
|
||||||
|
|
|
@ -34,13 +34,14 @@
|
||||||
namespace GParted
|
namespace GParted
|
||||||
{
|
{
|
||||||
|
|
||||||
Win_GParted::Win_GParted( )
|
Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
|
||||||
{
|
{
|
||||||
copied_partition .Reset( ) ;
|
copied_partition .Reset( ) ;
|
||||||
selected_partition .Reset( ) ;
|
selected_partition .Reset( ) ;
|
||||||
new_count = 1;
|
new_count = 1;
|
||||||
current_device = 0 ;
|
current_device = 0 ;
|
||||||
pulse = false ;
|
pulse = false ;
|
||||||
|
gparted_core .set_user_devices( user_devices ) ;
|
||||||
|
|
||||||
//==== GUI =========================
|
//==== GUI =========================
|
||||||
this ->set_title( _("GParted") );
|
this ->set_title( _("GParted") );
|
||||||
|
@ -460,8 +461,6 @@ void Win_GParted::refresh_combo_devices()
|
||||||
if ( menu ->items() .size() )
|
if ( menu ->items() .size() )
|
||||||
menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_submenu( *menu ) ;
|
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 ) ;
|
combo_devices .set_active( current_device ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,6 +864,7 @@ void Win_GParted::menu_gparted_refresh_devices( )
|
||||||
this ->set_title( _("GParted") );
|
this ->set_title( _("GParted") );
|
||||||
combo_devices .hide() ;
|
combo_devices .hide() ;
|
||||||
|
|
||||||
|
menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_sensitive( false ) ;
|
||||||
menubar_main .items()[ 1 ] .set_sensitive( false ) ;
|
menubar_main .items()[ 1 ] .set_sensitive( false ) ;
|
||||||
menubar_main .items()[ 2 ] .set_sensitive( false ) ;
|
menubar_main .items()[ 2 ] .set_sensitive( false ) ;
|
||||||
menubar_main .items()[ 3 ] .set_sensitive( false ) ;
|
menubar_main .items()[ 3 ] .set_sensitive( false ) ;
|
||||||
|
@ -891,6 +891,7 @@ void Win_GParted::menu_gparted_refresh_devices( )
|
||||||
{
|
{
|
||||||
combo_devices .show() ;
|
combo_devices .show() ;
|
||||||
|
|
||||||
|
menubar_main .items()[ 0 ] .get_submenu() ->items()[ 1 ] .set_sensitive( true ) ;
|
||||||
menubar_main .items()[ 1 ] .set_sensitive( true ) ;
|
menubar_main .items()[ 1 ] .set_sensitive( true ) ;
|
||||||
menubar_main .items()[ 2 ] .set_sensitive( true ) ;
|
menubar_main .items()[ 2 ] .set_sensitive( true ) ;
|
||||||
menubar_main .items()[ 3 ] .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
|
//check UID
|
||||||
if ( getuid() != 0 )
|
if ( getuid() != 0 )
|
||||||
{
|
{
|
||||||
Gtk::MessageDialog dialog( _("Root privileges are required for running GParted"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK ) ;
|
Gtk::MessageDialog dialog( _("Root privileges are required for running GParted"),
|
||||||
dialog .set_secondary_text( _( "Since GParted can be a weapon of mass destruction only root may run it.") ) ;
|
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() ;
|
dialog .run() ;
|
||||||
exit( 0 ) ;
|
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 ) ;
|
Gtk::Main::run( win_gparted ) ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
Loading…
Reference in New Issue