prevent crasher when visual_disks is empty. load devices at startup on
* src/FrameVisualDisk.cc: prevent crasher when visual_disks is empty. * include/Win_GParted.h, src/Win_GParted.cc: load devices at startup on signal_show instead of dispatching it from the c'tor. Also did some cleanups in the behaviour of opening and closing of the operationslist.
This commit is contained in:
parent
a538361d3d
commit
283b40b892
|
@ -1,3 +1,12 @@
|
|||
2006-02-22 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* src/FrameVisualDisk.cc: prevent crasher when visual_disks is empty.
|
||||
* include/Win_GParted.h,
|
||||
src/Win_GParted.cc: load devices at startup on signal_show instead
|
||||
of dispatching it from the c'tor.
|
||||
Also did some cleanups in the behaviour of opening and closing of
|
||||
the operationslist.
|
||||
|
||||
2006-02-20 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||
|
||||
* include/GParted_Core.h,
|
||||
|
|
|
@ -49,13 +49,13 @@ public:
|
|||
Win_GParted( const std::vector<Glib::ustring> & user_devices ) ;
|
||||
|
||||
private:
|
||||
void init_menubar( ) ;
|
||||
void init_toolbar( ) ;
|
||||
void init_partition_menu( ) ;
|
||||
Gtk::Menu * create_format_menu( ) ;
|
||||
void init_device_info( ) ;
|
||||
void init_operationslist( ) ;
|
||||
void init_hpaned_main( ) ;
|
||||
void init_menubar() ;
|
||||
void init_toolbar() ;
|
||||
void init_partition_menu() ;
|
||||
Gtk::Menu * create_format_menu() ;
|
||||
void init_device_info() ;
|
||||
void init_operationslist() ;
|
||||
void init_hpaned_main() ;
|
||||
|
||||
void refresh_combo_devices() ;
|
||||
void show_pulsebar( const Glib::ustring & status_message ) ;
|
||||
|
@ -67,50 +67,52 @@ private:
|
|||
bool on_delete_event( GdkEventAny* ) ;
|
||||
|
||||
void Add_Operation( OperationType, const Partition & );
|
||||
void Refresh_Visual( );
|
||||
bool Quit_Check_Operations( );
|
||||
void Refresh_Visual();
|
||||
bool Quit_Check_Operations();
|
||||
void set_valid_operations() ;
|
||||
|
||||
//convenience functions
|
||||
void allow_new( bool b ) {
|
||||
menu_partition .items( )[ 0 ] .set_sensitive( b );
|
||||
menu_partition .items()[ 0 ] .set_sensitive( b );
|
||||
toolbar_main .get_nth_item( 0 ) ->set_sensitive( b ); }
|
||||
|
||||
void allow_delete( bool b ) {
|
||||
menu_partition .items( )[ 1 ] .set_sensitive( b );
|
||||
menu_partition .items()[ 1 ] .set_sensitive( b );
|
||||
toolbar_main .get_nth_item( 1 ) ->set_sensitive( b ); }
|
||||
|
||||
void allow_resize( bool b ) {
|
||||
menu_partition .items( )[ 3 ] .set_sensitive( b );
|
||||
menu_partition .items()[ 3 ] .set_sensitive( b );
|
||||
toolbar_main .get_nth_item( 3 ) ->set_sensitive( b ); }
|
||||
|
||||
void allow_copy( bool b ) {
|
||||
menu_partition .items( )[ 5 ] .set_sensitive( b );
|
||||
menu_partition .items()[ 5 ] .set_sensitive( b );
|
||||
toolbar_main .get_nth_item( 5 ) ->set_sensitive( b ); }
|
||||
|
||||
void allow_paste( bool b ) {
|
||||
menu_partition .items( )[ 6 ] .set_sensitive( b );
|
||||
menu_partition .items()[ 6 ] .set_sensitive( b );
|
||||
toolbar_main .get_nth_item( 6 ) ->set_sensitive( b ); }
|
||||
|
||||
void allow_format( bool b ) {
|
||||
menu_partition .items( )[ 8 ] .set_sensitive( b ); }
|
||||
menu_partition .items()[ 8 ] .set_sensitive( b ); }
|
||||
|
||||
void allow_unmount( bool b ) {
|
||||
menu_partition .items( )[ 10 ] .set_sensitive( b ); }
|
||||
menu_partition .items()[ 10 ] .set_sensitive( b ); }
|
||||
|
||||
void allow_toggle_swap( bool b ) {
|
||||
menu_partition .items( )[ 11 ] .set_sensitive( b ); }
|
||||
menu_partition .items()[ 11 ] .set_sensitive( b ); }
|
||||
|
||||
void allow_info( bool b ) {
|
||||
menu_partition .items( )[ 13 ] .set_sensitive( b ); }
|
||||
menu_partition .items()[ 13 ] .set_sensitive( b ); }
|
||||
|
||||
void allow_undo( bool b ) {
|
||||
toolbar_main .get_nth_item( 8 ) ->set_sensitive( b );
|
||||
( (Gtk::CheckMenuItem *) & menubar_main .items( ) [ 1 ] .get_submenu( ) ->items( ) [ 0 ] ) ->set_sensitive( b ) ; }
|
||||
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 0 ] )
|
||||
->set_sensitive( b ) ; }
|
||||
|
||||
void allow_apply( bool b ) {
|
||||
toolbar_main .get_nth_item( 9 ) ->set_sensitive( b );
|
||||
( (Gtk::CheckMenuItem *) & menubar_main .items( ) [ 1 ] .get_submenu( ) ->items( ) [ 1 ] ) ->set_sensitive( b ) ; }
|
||||
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 1 ] )
|
||||
->set_sensitive( b ) ; }
|
||||
|
||||
//threads..
|
||||
void thread_refresh_devices() ;
|
||||
|
@ -118,19 +120,20 @@ private:
|
|||
void thread_toggle_swap( bool * succes, Glib::ustring * error ) ;
|
||||
|
||||
//signal handlers
|
||||
void open_operationslist( ) ;
|
||||
void close_operationslist( ) ;
|
||||
void clear_operationslist( ) ;
|
||||
void combo_devices_changed( );
|
||||
void open_operationslist() ;
|
||||
void close_operationslist() ;
|
||||
void clear_operationslist() ;
|
||||
void combo_devices_changed();
|
||||
void radio_devices_changed( unsigned int item ) ;
|
||||
void on_signal_show() ;
|
||||
|
||||
void menu_gparted_refresh_devices( );
|
||||
void menu_gparted_filesystems( );
|
||||
void menu_gparted_quit( );
|
||||
void menu_view_harddisk_info( );
|
||||
void menu_view_operations( );
|
||||
void menu_help_contents( );
|
||||
void menu_help_about( );
|
||||
void menu_gparted_refresh_devices();
|
||||
void menu_gparted_filesystems();
|
||||
void menu_gparted_quit();
|
||||
void menu_view_harddisk_info();
|
||||
void menu_view_operations();
|
||||
void menu_help_contents();
|
||||
void menu_help_about();
|
||||
|
||||
void on_partition_selected( const Partition & partition, bool src_is_treeview ) ;
|
||||
void on_partition_activated() ;
|
||||
|
@ -222,6 +225,7 @@ private:
|
|||
unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions
|
||||
unsigned short new_count;//new_count keeps track of the new created partitions
|
||||
FS fs ;
|
||||
bool OPERATIONSLIST_OPEN ;
|
||||
|
||||
GParted_Core gparted_core ;
|
||||
GParted::Device *temp_device ;
|
||||
|
@ -229,8 +233,6 @@ private:
|
|||
|
||||
//stuff for progress overview and pulsebar
|
||||
Glib::Thread *thread ;
|
||||
Glib::Dispatcher dispatcher;
|
||||
sigc::connection conn ;
|
||||
bool pulse ;
|
||||
};
|
||||
|
||||
|
|
|
@ -374,7 +374,7 @@ void FrameVisualDisk::on_resize( Gtk::Allocation & allocation )
|
|||
while ( TOTAL <= 0 && MIN_SIZE > 0 ) ;
|
||||
|
||||
//due to rounding a few px may be lost (max. 2), lets add these to the last partition.
|
||||
if ( allocation .get_width() > calced )
|
||||
if ( allocation .get_width() > calced && visual_partitions .size() )
|
||||
visual_partitions .back() .length += ( allocation .get_width() - calced ) ;
|
||||
|
||||
calc_position_and_height( visual_partitions, 0, 0 ) ;
|
||||
|
|
|
@ -29,19 +29,17 @@
|
|||
#include <gtkmm/radiobuttongroup.h>
|
||||
#include <gtkmm/main.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <sys/swap.h>
|
||||
|
||||
namespace GParted
|
||||
{
|
||||
|
||||
Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
|
||||
{
|
||||
copied_partition .Reset( ) ;
|
||||
selected_partition .Reset( ) ;
|
||||
copied_partition .Reset() ;
|
||||
selected_partition .Reset() ;
|
||||
new_count = 1;
|
||||
current_device = 0 ;
|
||||
pulse = false ;
|
||||
OPERATIONSLIST_OPEN = true ;
|
||||
gparted_core .set_user_devices( user_devices ) ;
|
||||
|
||||
//==== GUI =========================
|
||||
|
@ -60,12 +58,14 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
|
|||
//Pack the main box
|
||||
this ->add( vbox_main );
|
||||
|
||||
this ->signal_show() .connect( sigc::mem_fun(*this, &Win_GParted::on_signal_show) );
|
||||
|
||||
//menubar....
|
||||
init_menubar( ) ;
|
||||
init_menubar() ;
|
||||
vbox_main .pack_start( menubar_main, Gtk::PACK_SHRINK );
|
||||
|
||||
//toolbar....
|
||||
init_toolbar( ) ;
|
||||
init_toolbar() ;
|
||||
vbox_main.pack_start( hbox_toolbar, Gtk::PACK_SHRINK );
|
||||
|
||||
//frame_visualdisk... ( contains the visual represenation of the disks )
|
||||
|
@ -75,17 +75,17 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
|
|||
vbox_main .pack_start( frame_visualdisk, Gtk::PACK_SHRINK ) ;
|
||||
|
||||
//hpaned_main (NOTE: added to vpaned_main)
|
||||
init_hpaned_main( ) ;
|
||||
init_hpaned_main() ;
|
||||
vpaned_main .pack1( hpaned_main, true, true ) ;
|
||||
|
||||
//vpaned_main....
|
||||
vbox_main .pack_start( vpaned_main );
|
||||
|
||||
//device info...
|
||||
init_device_info( ) ;
|
||||
init_device_info() ;
|
||||
|
||||
//operationslist...
|
||||
init_operationslist( ) ;
|
||||
init_operationslist() ;
|
||||
vpaned_main .pack2( hbox_operations, true, true ) ;
|
||||
|
||||
//statusbar...
|
||||
|
@ -93,63 +93,59 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
|
|||
statusbar .add( pulsebar );
|
||||
vbox_main .pack_start( statusbar, Gtk::PACK_SHRINK );
|
||||
|
||||
this ->show_all_children( );
|
||||
this ->show_all_children();
|
||||
|
||||
//make sure harddisk information and operationlist are closed..
|
||||
hpaned_main .get_child1( ) ->hide( ) ;
|
||||
close_operationslist( ) ;
|
||||
|
||||
conn = dispatcher .connect( sigc::mem_fun( *this, &Win_GParted::menu_gparted_refresh_devices ) );
|
||||
dispatcher() ;
|
||||
//make sure harddisk information is closed..
|
||||
hpaned_main .get_child1() ->hide() ;
|
||||
}
|
||||
|
||||
void Win_GParted::init_menubar( )
|
||||
void Win_GParted::init_menubar()
|
||||
{
|
||||
//fill menubar_main and connect callbacks
|
||||
//gparted
|
||||
menu = manage( new Gtk::Menu( ) ) ;
|
||||
menu = manage( new Gtk::Menu() ) ;
|
||||
image = manage( new Gtk::Image( Gtk::Stock::REFRESH, Gtk::ICON_SIZE_MENU ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::ImageMenuElem( _("_Refresh devices"), Gtk::AccelKey("<control>r"), *image, sigc::mem_fun(*this, &Win_GParted::menu_gparted_refresh_devices) ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( _("_Refresh devices"), Gtk::AccelKey("<control>r"), *image, sigc::mem_fun(*this, &Win_GParted::menu_gparted_refresh_devices) ) );
|
||||
|
||||
image = manage( new Gtk::Image( Gtk::Stock::HARDDISK, Gtk::ICON_SIZE_MENU ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( _("Devices"), *image ) ) ;
|
||||
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::SeparatorElem( ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("Filesystems"), sigc::mem_fun( *this, &Win_GParted::menu_gparted_filesystems ) ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::SeparatorElem( ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::QUIT, sigc::mem_fun(*this, &Win_GParted::menu_gparted_quit) ) );
|
||||
menubar_main .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("_GParted"), *menu ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::SeparatorElem( ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Filesystems"), sigc::mem_fun( *this, &Win_GParted::menu_gparted_filesystems ) ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::SeparatorElem( ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::QUIT, sigc::mem_fun(*this, &Win_GParted::menu_gparted_quit) ) );
|
||||
menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_GParted"), *menu ) );
|
||||
|
||||
//edit
|
||||
menu = manage( new Gtk::Menu( ) ) ;
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::UNDO, Gtk::AccelKey("<control>z"), sigc::mem_fun(*this, &Win_GParted::activate_undo) ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::APPLY, sigc::mem_fun(*this, &Win_GParted::activate_apply) ) );
|
||||
menubar_main .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("_Edit"), *menu ) );
|
||||
menu = manage( new Gtk::Menu() ) ;
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::UNDO, Gtk::AccelKey("<control>z"), sigc::mem_fun(*this, &Win_GParted::activate_undo) ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::APPLY, sigc::mem_fun(*this, &Win_GParted::activate_apply) ) );
|
||||
menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_Edit"), *menu ) );
|
||||
|
||||
//view
|
||||
menu = manage( new Gtk::Menu( ) ) ;
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Harddisk Information"), sigc::mem_fun(*this, &Win_GParted::menu_view_harddisk_info) ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Operations"), sigc::mem_fun(*this, &Win_GParted::menu_view_operations) ) );
|
||||
menubar_main .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("_View"), *menu ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Harddisk Information"), sigc::mem_fun(*this, &Win_GParted::menu_view_harddisk_info) ) );
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Operations"), sigc::mem_fun(*this, &Win_GParted::menu_view_operations) ) );
|
||||
menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_View"), *menu ) );
|
||||
|
||||
//device
|
||||
menu = manage( new Gtk::Menu( ) ) ;
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("Set Disklabel"), sigc::mem_fun(*this, &Win_GParted::activate_disklabel) ) );
|
||||
menubar_main .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("_Device"), *menu ) );
|
||||
menu = manage( new Gtk::Menu() ) ;
|
||||
menu ->items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Set Disklabel"), sigc::mem_fun(*this, &Win_GParted::activate_disklabel) ) );
|
||||
menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_Device"), *menu ) );
|
||||
|
||||
//partition
|
||||
init_partition_menu( ) ;
|
||||
menubar_main .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( _("_Partition"), menu_partition ) );
|
||||
init_partition_menu() ;
|
||||
menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_Partition"), menu_partition ) );
|
||||
|
||||
//help
|
||||
menu = manage( new Gtk::Menu() ) ;
|
||||
menu ->items( ) .push_back(Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::HELP, sigc::mem_fun(*this, &Win_GParted::menu_help_contents) ) );
|
||||
menu ->items() .push_back(Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::HELP, sigc::mem_fun(*this, &Win_GParted::menu_help_contents) ) );
|
||||
menu ->items( ) .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::ABOUT, sigc::mem_fun(*this, &Win_GParted::menu_help_about) ) );
|
||||
|
||||
menubar_main.items( ) .push_back( Gtk::Menu_Helpers::MenuElem(_("_Help"), *menu ) );
|
||||
menubar_main.items() .push_back( Gtk::Menu_Helpers::MenuElem(_("_Help"), *menu ) );
|
||||
}
|
||||
|
||||
void Win_GParted::init_toolbar( )
|
||||
void Win_GParted::init_toolbar()
|
||||
{
|
||||
//initialize and pack toolbar_main
|
||||
hbox_toolbar.pack_start( toolbar_main );
|
||||
|
@ -489,7 +485,6 @@ void Win_GParted::show_pulsebar( const Glib::ustring & status_message )
|
|||
}
|
||||
|
||||
thread ->join() ;
|
||||
conn .disconnect() ;
|
||||
|
||||
pulsebar .hide();
|
||||
statusbar .pop() ;
|
||||
|
@ -753,41 +748,44 @@ void Win_GParted::set_valid_operations()
|
|||
}
|
||||
}
|
||||
|
||||
void Win_GParted::open_operationslist( )
|
||||
void Win_GParted::open_operationslist()
|
||||
{
|
||||
hbox_operations .show( ) ;
|
||||
int x,y; this ->get_size( x, y );
|
||||
y -= 300;
|
||||
|
||||
for ( int t = vpaned_main .get_position( ) ; t > y ; t-=5 )
|
||||
if ( ! OPERATIONSLIST_OPEN )
|
||||
{
|
||||
vpaned_main .set_position( t );
|
||||
while ( Gtk::Main::events_pending( ) )
|
||||
Gtk::Main::iteration( );
|
||||
}
|
||||
OPERATIONSLIST_OPEN = true ;
|
||||
hbox_operations .show() ;
|
||||
|
||||
( (Gtk::CheckMenuItem *) & menubar_main .items( ) [ 2 ] .get_submenu( ) ->items( ) [ 1 ] ) ->set_active( true ) ;
|
||||
for ( int t = vpaned_main .get_height() ; t > ( vpaned_main .get_height() - 100 ) ; t -= 5 )
|
||||
{
|
||||
vpaned_main .set_position( t );
|
||||
while ( Gtk::Main::events_pending() )
|
||||
Gtk::Main::iteration() ;
|
||||
}
|
||||
|
||||
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 2 ] .get_submenu() ->items()[ 1 ] )
|
||||
->set_active( true ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void Win_GParted::close_operationslist( )
|
||||
void Win_GParted::close_operationslist()
|
||||
{
|
||||
//FIXME: when started like 'gparted bla' it wil crash in this function
|
||||
//most likely this has something to do with the removal of the legend which rendered
|
||||
//the '210' incorrect. This static numbering sucks anyway, so i should find a way to open and
|
||||
//close the operationslist without these static numbers. See also open_operationslist()
|
||||
int x,y; this ->get_size( x, y );
|
||||
y -= 210 ; //height of whole app - menubar - visualdisk - statusbar ....
|
||||
for ( int t = vpaned_main .get_position() ; t < y ; t+=5 )
|
||||
if ( OPERATIONSLIST_OPEN )
|
||||
{
|
||||
vpaned_main .set_position( t );
|
||||
while ( Gtk::Main::events_pending() )
|
||||
Gtk::Main::iteration();
|
||||
}
|
||||
OPERATIONSLIST_OPEN = false ;
|
||||
|
||||
hbox_operations .hide() ;
|
||||
static_cast<Gtk::CheckMenuItem *>(
|
||||
& menubar_main .items()[ 2 ] .get_submenu() ->
|
||||
items()[ 1 ] ) ->set_active( false ) ;
|
||||
for ( int t = vpaned_main .get_position() ; t < vpaned_main .get_height() ; t += 5 )
|
||||
{
|
||||
vpaned_main .set_position( t ) ;
|
||||
|
||||
while ( Gtk::Main::events_pending() )
|
||||
Gtk::Main::iteration();
|
||||
}
|
||||
|
||||
hbox_operations .hide() ;
|
||||
|
||||
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 2 ] .get_submenu() ->items()[ 1 ] )
|
||||
->set_active( false ) ;
|
||||
}
|
||||
}
|
||||
|
||||
void Win_GParted::clear_operationslist()
|
||||
|
@ -825,6 +823,14 @@ void Win_GParted::radio_devices_changed( unsigned int item )
|
|||
}
|
||||
}
|
||||
|
||||
void Win_GParted::on_signal_show()
|
||||
{
|
||||
vpaned_main .set_position( vpaned_main .get_height() ) ;
|
||||
close_operationslist() ;
|
||||
|
||||
menu_gparted_refresh_devices() ;
|
||||
}
|
||||
|
||||
void Win_GParted::thread_refresh_devices()
|
||||
{
|
||||
gparted_core .get_devices( devices ) ;
|
||||
|
|
Loading…
Reference in New Issue