Fixed a bunch of bugs (some of them crashers) which showed up if no

* Fixed a bunch of bugs (some of them crashers) which showed up if no devices were detected.
This commit is contained in:
Bart Hakvoort 2005-02-01 17:04:03 +00:00
parent a5163572cf
commit 758f5e63a8
8 changed files with 111 additions and 51 deletions

View File

@ -1,3 +1,7 @@
2005-02-01 Bart Hakvoort <hakvoort@cvs.gnome.org>
* Fixed a bunch of bugs (some of them crashers) which showed up if no devices were detected.
2005-01-30 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Win_GParted.h,

View File

@ -86,7 +86,6 @@ private:
PedPartition *c_partition ;
Glib::ustring temp ;
Partition partition_temp ;
FS fs ;
};

View File

@ -38,6 +38,7 @@ public:
TreeView_Detail( );
void Load_Partitions( const std::vector<Partition> & partitions ) ;
void Set_Selected( const Partition & partition );
void Clear( ) ;
//signals for interclass communication
sigc::signal<void, GdkEventButton *, const Partition & > signal_mouse_click;

View File

@ -66,7 +66,7 @@ private:
void Show_Pulsebar( ) ;
//Fill txtview_device_info_buffer with some information about the selected device
void Fill_Label_Device_Info( );
void Fill_Label_Device_Info( bool clear = false );
//overridden signalhandler
virtual bool on_delete_event( GdkEventAny* ) ;

View File

@ -8,7 +8,6 @@ GParted_Core::GParted_Core( )
device = NULL ;
disk = NULL ;
c_partition = NULL ;
p_filesystem = NULL ;
textbuffer = Gtk::TextBuffer::create( ) ;

View File

@ -54,11 +54,11 @@ TreeView_Detail::TreeView_Detail( )
std::vector <Gtk::CellRenderer *> renderers = this ->get_column( 1 ) ->get_cell_renderers( ) ;
if ( renderers .front( ) != this ->get_column( 1 ) ->get_first_cell_renderer( ) )
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( renderers .front( ) ) ;
cell_renderer_text = dynamic_cast <Gtk::CellRendererText*> ( renderers .front( ) ) ;
else
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( renderers .back( ) ) ;
cell_renderer_text = dynamic_cast <Gtk::CellRendererText*> ( renderers .back( ) ) ;
this ->get_column( 1 ) ->add_attribute(cell_renderer_text ->property_foreground( ), treeview_detail_columns .text_color );
this ->get_column( 1 ) ->add_attribute( cell_renderer_text ->property_foreground( ), treeview_detail_columns .text_color );
//set alignment of numeric columns to right
@ -108,13 +108,12 @@ void TreeView_Detail::Set_Selected( const Partition & partition )
partition .sector_end <=partition_temp .sector_end &&
partition.inside_extended == partition_temp.inside_extended )
{
this ->set_cursor( (Gtk::TreePath) row );
this ->set_cursor( static_cast <Gtk::TreePath> ( row ) );
return;
}
//logicals
if ( row .children( ) .size( ) > 0 ) //this is the row with the extended partition, search it's childrows...
{
for( iter_child = row .children( ) .begin( ) ; iter_child != row.children( ) .end( ) ; iter_child++ )
{
childrow = *iter_child;
@ -123,15 +122,17 @@ void TreeView_Detail::Set_Selected( const Partition & partition )
if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <= partition_temp .sector_end )
{
this ->expand_all( );
this ->set_cursor( (Gtk::TreePath) childrow );
this ->set_cursor( static_cast <Gtk::TreePath> ( childrow ) );
return;
}
}
}
}
}
void TreeView_Detail::Clear( )
{
treestore_detail ->clear( ) ;
}
void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, const Partition & partition )

View File

@ -249,12 +249,12 @@ void Win_GParted::init_device_info()
table ->attach( * mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL );
//disktype
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "DiskType:" ) + "</b>" ) , 0, 1, top, bottom, Gtk::FILL );
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "DiskType:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL );
device_info .push_back( mk_label( "" ) ) ;
table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL );
//heads
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Heads:" ) + "</b>" ) , 0, 1, top, bottom, Gtk::FILL );
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Heads:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL );
device_info .push_back( mk_label( "" ) ) ;
table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL );
@ -264,12 +264,12 @@ void Win_GParted::init_device_info()
table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL );
//cylinders
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Cylinders:" ) + "</b>" ) , 0, 1, top, bottom, Gtk::FILL );
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Cylinders:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL );
device_info .push_back( mk_label( "" ) ) ;
table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL );
//total sectors
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Total Sectors:" ) + "</b>" ) , 0, 1, top, bottom, Gtk::FILL );
table ->attach( * mk_label( " <b>" + (Glib::ustring) _( "Total Sectors:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL );
device_info .push_back( mk_label( "" ) ) ;
table ->attach( * device_info .back( ), 1, 2, top++, bottom++, Gtk::FILL );
@ -336,13 +336,14 @@ void Win_GParted::init_hpaned_main( )
//connect signal and add treeview_detail
treeview_detail .signal_mouse_click .connect( sigc::mem_fun( this, &Win_GParted::mouse_click ) );
scrollwindow ->add( treeview_detail );
hpaned_main.pack2( *scrollwindow, true,true );
hpaned_main.pack2( *scrollwindow, true, true );
}
void Win_GParted::Refresh_OptionMenu( )
{
//fill optionmenu_devices
optionmenu_devices .get_menu( ) ->items( ) .clear( ) ;
//fill optionmenu_devices
for ( unsigned int i = 0 ; i < devices .size( ) ; i++ )
{
hbox = manage( new Gtk::HBox( ) );
@ -358,7 +359,7 @@ void Win_GParted::Refresh_OptionMenu( )
optionmenu_devices .get_menu( ) ->items( ) .push_back( *menu_item );
}
optionmenu_devices .get_menu( ) ->show_all_children( );
hbox_toolbar .show_all_children( );
optionmenu_devices .set_history( current_device ) ;
}
@ -398,22 +399,29 @@ void Win_GParted::Show_Pulsebar( )
menu_partition .set_sensitive( true ) ;
}
void Win_GParted::Fill_Label_Device_Info( )
void Win_GParted::Fill_Label_Device_Info( bool clear )
{
short t = 0;
if ( clear )
for ( unsigned int t = 0 ; t < device_info .size( ) ; t++ )
device_info[ t ] ->set_text( "" ) ;
//global info...
device_info[ t++ ] ->set_text( devices[ current_device ] .model ) ;
device_info[ t++ ] ->set_text( String::ucompose( _("%1 MB"), Sector_To_MB( devices[ current_device ] .length ) ) ) ;
device_info[ t++ ] ->set_text( devices[ current_device ] .path ) ;
device_info[ t++ ] ->set_text( devices[ current_device ] .realpath ) ;
else
{
short t = 0;
//detailed info
device_info[ t++ ] ->set_text( devices[ current_device ] .disktype ) ;
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .heads ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .sectors ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .cylinders ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .length ) );
//global info...
device_info[ t++ ] ->set_text( devices[ current_device ] .model ) ;
device_info[ t++ ] ->set_text( String::ucompose( _("%1 MB"), Sector_To_MB( devices[ current_device ] .length ) ) ) ;
device_info[ t++ ] ->set_text( devices[ current_device ] .path ) ;
device_info[ t++ ] ->set_text( devices[ current_device ] .realpath ) ;
//detailed info
device_info[ t++ ] ->set_text( devices[ current_device ] .disktype ) ;
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .heads ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .sectors ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .cylinders ) );
device_info[ t++ ] ->set_text( num_to_str( devices[ current_device ] .length ) );
}
}
bool Win_GParted::on_delete_event( GdkEventAny *event )
@ -436,9 +444,9 @@ void Win_GParted::Add_Operation( OperationType operationtype, const Partition &
open_operationslist( ) ;
//make scrollwindow focus on the last operation in the list
Gtk::TreeIter iter = liststore_operations->children().end() ;
Gtk::TreeIter iter = liststore_operations ->children( ) .end( ) ;
iter-- ;
treeview_operations .set_cursor( (Gtk::TreePath) (Gtk::TreeRow) *iter);
treeview_operations .set_cursor( static_cast <Gtk::TreePath> ( static_cast <Gtk::TreeRow> ( *iter ) ) ) ;
}
void Win_GParted::Refresh_Visual( )
@ -688,8 +696,6 @@ void Win_GParted::menu_gparted_refresh_devices( )
if ( current_device >= devices .size( ) )
current_device = 0 ;
Refresh_OptionMenu( ) ;
//show read-only warning if necessary
Glib::ustring readonly_paths ;
@ -711,6 +717,56 @@ void Win_GParted::menu_gparted_refresh_devices( )
Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true ) ;
dialog .run( ) ;
}
//see if there are any pending operations on non-existent devices
//NOTE that this isn't 100% foolproof since some stuff (e.g. sourcedevice of copy) may slip through.
//but anyone who removes the sourcedevice before applying the operations gets what he/she deserves :-)
unsigned int i ;
for ( unsigned int t = 0 ; t < operations .size( ) ; t++ )
{
for ( i = 0 ; i < devices .size( ) && devices[ i ] .path != operations[ t ] .device .path ; i++ ) {}
if ( i >= devices .size( ) )
operations .erase( operations .begin( ) + t-- ) ;//decrease t bij one..
}
//if no devices were detected we disable some stuff and show a message in the statusbar
if ( devices .empty( ) )
{
optionmenu_devices .hide( ) ;
menubar_main .items( )[ 2 ] .set_sensitive( false ) ;
menubar_main .items( )[ 3 ] .set_sensitive( false ) ;
toolbar_main .set_sensitive( false ) ;
optionmenu_devices .set_sensitive( false ) ;
Fill_Label_Device_Info( true ) ;
if ( vbox_visual_disk != NULL )
{
hbox_visual .remove( *vbox_visual_disk );
delete( vbox_visual_disk ) ;
vbox_visual_disk = NULL ;
}
treeview_detail .Clear( ) ;
//hmzz, this is really paranoid, but i think it's the right thing to do ;)
liststore_operations ->clear( ) ;
close_operationslist( ) ;
operations .clear( ) ;
statusbar .pop( ) ;
statusbar .push( _( "No devices detected" ) );
}
else //at least one device detected
{
menubar_main .items( )[ 2 ] .set_sensitive( true ) ;
menubar_main .items( )[ 3 ] .set_sensitive( true ) ;
Refresh_OptionMenu( ) ;
}
}
void Win_GParted::menu_gparted_filesystems( )
@ -821,7 +877,7 @@ bool Win_GParted::max_amount_prim_reached( )
return false ;
}
void Win_GParted::activate_resize()
void Win_GParted::activate_resize( )
{
//show warning when one tries to resize a fat16 filesystem
if ( selected_partition .filesystem == "fat16" )

View File

@ -18,23 +18,23 @@
#include "../include/Win_GParted.h"
int main( int argc, char *argv[] )
int main( int argc, char *argv[ ] )
{
//initialize thread system
Glib::thread_init();
Glib::thread_init( );
Gtk::Main kit(argc, argv);
Gtk::Main kit( argc, argv );
//i18n
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
textdomain( GETTEXT_PACKAGE );
//check UID
if ( getuid() != 0 )
if ( getuid( ) != 0 )
{
Gtk::MessageDialog dialog( "<span weight=\"bold\" size=\"larger\">" + (Glib::ustring) _( "Root privileges are required for running GParted" ) + "</span>\n\n" + (Glib::ustring) _( "Since GParted can be a weapon of mass destruction only root may run it.") ,true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dialog.run();
dialog .run( ) ;
exit( 0 );
}