merry christmas cleanups replaced popen() with

* merry christmas
* src/GParted_Core.cc,
  src/VBox_VisualDisk.cc,
  src/Win_GParted.cc: cleanups
* include/FileSystem.h,
  src/FileSystem.cc,
  src/ext2.cc,
  src/ext3.cc: replaced popen() with Glib::spawn_command_line_sync()
This commit is contained in:
Bart Hakvoort 2005-12-24 23:55:54 +00:00
parent 45e29fb694
commit 4fc49c2760
8 changed files with 81 additions and 50 deletions

View File

@ -1,3 +1,14 @@
2005-12-25 Bart Hakvoort <hakvoort@cvs.gnome.org>
* merry christmas
* src/GParted_Core.cc,
src/VBox_VisualDisk.cc,
src/Win_GParted.cc: cleanups
* include/FileSystem.h,
src/FileSystem.cc,
src/ext2.cc,
src/ext3.cc: replaced popen() with Glib::spawn_command_line_sync()
2005-12-24 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/TreeView_Detail.cc: replaced C-style cast with static_cast

View File

@ -33,10 +33,10 @@ namespace GParted
class FileSystem
{
public:
FileSystem( ) ;
virtual ~FileSystem( ) { }
FileSystem() ;
virtual ~FileSystem() {}
virtual FS get_filesystem_support( ) = 0 ;
virtual FS get_filesystem_support() = 0 ;
virtual void Set_Used_Sectors( Partition & partition ) = 0 ;
virtual bool Create( const Partition & new_partition ) = 0 ;
virtual bool Resize( const Partition & partition_new, bool fill_partition = false ) = 0 ;
@ -50,11 +50,15 @@ public:
protected:
int Execute_Command( Glib::ustring command ) ;
std::string output ;
Sector free_blocks, blocksize ;
unsigned int index ;
private:
void Update_Textview( ) ;
void Update_Textview() ;
Glib::ustring output ;
Glib::ustring cmd_output ;
};

View File

@ -34,7 +34,7 @@ int FileSystem::Execute_Command( Glib::ustring command )
//stderr to stdout
//command += " 2>&1" ;
std::cout << command << std::endl ;
output = command + "\n\n" ;
cmd_output = command + "\n\n" ;
dispatcher ( ) ;
char c_buf[ 512 ] ;
@ -47,7 +47,7 @@ int FileSystem::Execute_Command( Glib::ustring command )
//dispatcher ( ) ;disabled for the moment. Hier moet ik nog eens fris naar kijken. (anjuta had zo'n ingebouwde terminal, hoe deed die dat?? !!!
}
output = "" ;
cmd_output = "" ;
dispatcher( ) ;
return pclose( f ) ;
@ -56,7 +56,7 @@ int FileSystem::Execute_Command( Glib::ustring command )
void FileSystem::Update_Textview( )
{
//std::cout << output << std::endl;
textbuffer ->set_text( output ) ;
textbuffer ->set_text( cmd_output ) ;
//textbuffer ->insert( textbuffer ->end( ), output ) ;
}

View File

@ -860,7 +860,7 @@ void GParted_Core::Show_Error( Glib::ustring message )
void GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem )
{
if ( ! p_filesystem )
if ( p_filesystem )
delete p_filesystem ;
switch( filesystem )

View File

@ -371,7 +371,6 @@ bool VBox_VisualDisk::set_selected( std::vector<visual_partition> & visual_parti
if ( visual_partitions[ t ] .logicals .size() > 0 )
visual_partitions[ t ] .selected &= ! set_selected( visual_partitions[ t ] .logicals, x, y ) ;
}
return found ;

View File

@ -34,9 +34,14 @@ Win_GParted::Win_GParted( )
this ->set_title( _("GParted") );
this ->set_default_size( 775, 500 );
try {
try
{
this ->set_icon_from_file( GNOME_ICONDIR "/gparted.png" ) ;
} catch ( Glib::Exception & e ) { std::cout << e .what() << std::endl ; }
}
catch ( Glib::Exception & e )
{
std::cout << e .what() << std::endl ;
}
//Pack the main box
this ->add( vbox_main );

View File

@ -52,28 +52,34 @@ FS ext2::get_filesystem_support( )
void ext2::Set_Used_Sectors( Partition & partition )
{
char c_buf[ 512 ] ;
FILE *f ;
Glib::ustring output ;
Sector free_blocks = -1, blocksize = -1 ;
//get free blocks..
f = popen( ( "LC_ALL=C dumpe2fs -h " + partition .partition ) .c_str( ), "r" ) ;
while ( fgets( c_buf, 512, f ) )
try
{
output = Glib::locale_to_utf8( c_buf ) ;
//free blocks
if ( output .find( "Free blocks" ) < output .length( ) )
free_blocks = atol( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ;
//blocksize
if ( output .find( "Block size" ) < output .length( ) )
blocksize = atol( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ;
Glib::spawn_command_line_sync("dumpe2fs -h " + partition .partition, &output ) ;
}
pclose( f ) ;
catch ( Glib::Exception & e )
{
std::cout << e .what() << std::endl ;
return ;
}
index = output .find( "Free blocks:" ) ;
if ( index < output .length() )
{
output = output.substr( index );
free_blocks = atol( output .substr( 13, output .find( "\n" ) - 13 ) .c_str() ) ;
}
else
free_blocks = -1 ;
index = output .find( "Block size:" ) ;
if ( index < output.length() )
{
output = output.substr( index );
blocksize = atol( output .substr( 12, output .find( "\n" ) - 12 ) .c_str() ) ;
}
else
blocksize = -1 ;
if ( free_blocks > -1 && blocksize > -1 )
partition .Set_Unused( free_blocks * blocksize / 512 ) ;
}

View File

@ -52,28 +52,34 @@ FS ext3::get_filesystem_support( )
void ext3::Set_Used_Sectors( Partition & partition )
{
char c_buf[ 512 ] ;
FILE *f ;
Glib::ustring output ;
Sector free_blocks = -1, blocksize = -1 ;
//get free blocks..
f = popen( ( "LC_ALL=C dumpe2fs -h " + partition .partition ) .c_str( ), "r" ) ;
while ( fgets( c_buf, 512, f ) )
try
{
output = Glib::locale_to_utf8( c_buf ) ;
//free blocks
if ( output .find( "Free blocks" ) < output .length( ) )
free_blocks = atol( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ;
//blocksize
if ( output .find( "Block size" ) < output .length( ) )
blocksize = atol( (output .substr( output .find( ":" ) +1, output .length( ) ) ) .c_str( ) ) ;
Glib::spawn_command_line_sync("dumpe2fs -h " + partition .partition, &output ) ;
}
pclose( f ) ;
catch ( Glib::Exception & e )
{
std::cout << e .what() << std::endl ;
return ;
}
index = output .find( "Free blocks:" ) ;
if ( index < output .length() )
{
output = output.substr( index );
free_blocks = atol( output .substr( 13, output .find( "\n" ) - 13 ) .c_str() ) ;
}
else
free_blocks = -1 ;
index = output .find( "Block size:" ) ;
if ( index < output.length() )
{
output = output.substr( index );
blocksize = atol( output .substr( 12, output .find( "\n" ) - 12 ) .c_str() ) ;
}
else
blocksize = -1 ;
if ( free_blocks > -1 && blocksize > -1 )
partition .Set_Unused( free_blocks * blocksize / 512 ) ;
}