First load gui and then scan devices, this resulted in way faster startup

* include/Win_GParted.h,
  src/Win_GParted.cc: First load gui and then scan devices, this resulted in way faster startup and is more satisfactory (imho)
  Also did some minor code cleanups and rearranged some functions needed for applying operations.
* src/Dialog_Progress.cc: few minor code cleanups.
This commit is contained in:
Bart Hakvoort 2004-10-16 15:42:08 +00:00
parent 8f89cc02ce
commit dde4f4d709
4 changed files with 72 additions and 61 deletions

View File

@ -1,3 +1,10 @@
2004-10-16 Bart Hakvoort <gparted@users.sf.net>
* include/Win_GParted.h,
src/Win_GParted.cc: First load gui and then scan devices, this resulted in way faster startup and is more satisfactory (imho)
Also did some minor code cleanups and rearranged some functions needed for applying operations.
* src/Dialog_Progress.cc: few minor code cleanups.
2004-10-14 Bart Hakvoort <gparted@users.sf.net>
* include/Operation.h,

View File

@ -167,7 +167,6 @@ private:
//usefull variables which are used by many different functions...
sigc::connection s2,s3;//used for disconnecting and destroying a connection ( see optionmenu_devices_changed() and activate_apply() )
bool any_logic,any_extended;//used in some checks (e.g. see optionmenu_devices_changed()
unsigned short highest_logic_busy ;//highest_logic_busy contains the number of the highest logical which is busy ( 0 if none is busy)
unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions
@ -179,10 +178,11 @@ private:
std::vector <Gtk::Label *> device_info ;
std::vector <FS> FILESYSTEMS ;
//stuff for progress overview
//stuff for progress overview and pulsebar
Dialog_Progress *dialog_progress;
Glib::Thread *thread ;
Glib::Dispatcher dispatcher_next_operation;
Glib::Dispatcher dispatcher;
sigc::connection conn ;
bool apply, pulse ;
};

View File

@ -58,15 +58,11 @@ Dialog_Progress::Dialog_Progress( int count_operations, const Glib::ustring & fi
this->get_vbox() ->set_spacing( 5 ) ;
this->get_vbox() ->set_border_width( 15 ) ;
this->add_button( Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL );//doesn't work for current operation
this->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL );
this->show_all_children() ;
}
Dialog_Progress::~Dialog_Progress()
{
}
void Dialog_Progress::Set_Next_Operation( )
void Dialog_Progress::Set_Next_Operation( )
{
progressbar_all.set_fraction( progressbar_all.get_fraction() + fraction );
@ -87,4 +83,9 @@ void Dialog_Progress::Set_Progress_Current_Operation( )
progressbar_current.set_text( String::ucompose( _("about %1 minutes and %2 seconds left"), time_left/60, time_left % 60 ) ) ;
}
Dialog_Progress::~Dialog_Progress()
{
}
}//GParted

View File

@ -32,7 +32,7 @@ Win_GParted::Win_GParted( )
Find_Supported_Filesystems() ;
//locate all available devices and store them in devices vector
Find_Devices( ) ;
Find_Devices( false ) ;
Refresh_OptionMenu( ) ;
//==== GUI =========================
@ -84,6 +84,9 @@ Win_GParted::Win_GParted( )
//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 ( ) ;
}
void Win_GParted::init_menubar()
@ -367,27 +370,27 @@ void Win_GParted::Find_Supported_Filesystems()
void Win_GParted::Find_Devices( bool deep_scan )
{
for ( unsigned int t=0;t<devices.size() ; t++ )
for ( unsigned int t = 0 ; t < devices .size( ) ; t++ )
delete devices[ t ] ;
devices.clear() ;
devices .clear( ) ;
//try to find all available devices and put these in a list
ped_device_probe_all ();
ped_device_probe_all( );
PedDevice *device = ped_device_get_next (NULL);
PedDevice *device = ped_device_get_next ( NULL );
while ( device )
{
temp_device = new GParted::Device( device ->path, &FILESYSTEMS );
if ( temp_device ->Get_Length() > 0 )
{
temp_device ->Read_Disk_Layout( deep_scan ) ;
devices.push_back( temp_device ) ;
devices .push_back( temp_device ) ;
}
else
delete temp_device ;
device = ped_device_get_next (device) ;
device = ped_device_get_next ( device ) ;
}
}
@ -435,6 +438,7 @@ void Win_GParted::Show_Pulsebar( )
}
thread ->join( ) ;
conn .disconnect( ) ;
pulsebar ->hide( );
statusbar .pop( ) ;
@ -561,15 +565,14 @@ void Win_GParted::Refresh_Visual( )
//vbox visual
if ( vbox_visual_disk != NULL )
{
hbox_visual.remove( *vbox_visual_disk );
s2.disconnect();
hbox_visual .remove( *vbox_visual_disk );
delete ( vbox_visual_disk );
}
vbox_visual_disk = new VBox_VisualDisk ( partitions, devices[ current_device ] ->Get_Length() );
s2 = vbox_visual_disk->signal_mouse_click.connect( sigc::mem_fun( this, &Win_GParted::mouse_click) );
hbox_visual.pack_start( *vbox_visual_disk, Gtk::PACK_EXPAND_PADDING );
hbox_visual .show_all_children();
vbox_visual_disk = new VBox_VisualDisk ( partitions, devices[ current_device ] ->Get_Length( ) ) ;
vbox_visual_disk ->signal_mouse_click.connect( sigc::mem_fun( this, &Win_GParted::mouse_click ) ) ;
hbox_visual .pack_start( *vbox_visual_disk, Gtk::PACK_EXPAND_PADDING ) ;
hbox_visual .show_all_children( ) ;
//treeview details
treeview_detail .Load_Partitions( partitions ) ;
@ -1116,6 +1119,22 @@ void Win_GParted::activate_undo()
}
//-------AFAIK it's not possible to use a C++ memberfunction as a callback for a C libary function (if you know otherwise, PLEASE contact me)------------
Dialog_Progress *dp;
Glib::Dispatcher dispatcher_set_progress;
void progress_callback( PedTimer * timer, void *context )
{
if ( time(NULL) - timer ->start > 0 )
{
dp ->time_left = timer ->predicted_end - time(NULL) ;
dp ->fraction_current = timer ->frac ;
dispatcher_set_progress() ;
}
}
//---------------------------------------------------------------------------------------
void Win_GParted::activate_apply()
{
str_temp = "<span weight=\"bold\" size=\"larger\">" ;
@ -1123,36 +1142,39 @@ void Win_GParted::activate_apply()
str_temp += "</span>\n\n" ;
str_temp += _( "It is recommended to backup valueable data before proceeding.") ;
Gtk::MessageDialog dialog( *this, str_temp,true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE, true);
Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE, true);
dialog.set_title( _( "Apply operations to harddisk" ) );
dialog.add_button( Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL );
dialog.add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL );
dialog.add_button( Gtk::Stock::APPLY, Gtk::RESPONSE_OK );
dialog.show_all_children();
dialog.show_all_children( ) ;
if ( dialog.run() == Gtk::RESPONSE_OK )
{
dialog.hide() ; //hide confirmationdialog
apply = true;
dialog_progress = new Dialog_Progress ( operations.size(), operations.front() .str_operation ) ;
s3 = dispatcher_next_operation.connect( sigc::mem_fun(*dialog_progress, &Dialog_Progress::Set_Next_Operation) );
dp = dialog_progress ;
conn = dispatcher .connect( sigc::mem_fun(*dialog_progress, &Dialog_Progress::Set_Next_Operation) );
dispatcher_set_progress .connect( sigc::mem_fun( *dialog_progress, &Dialog_Progress::Set_Progress_Current_Operation ) );
thread = Glib::Thread::create(SigC::slot_class(*this, &Win_GParted::apply_operations_thread), true);
dialog_progress->set_transient_for( *this );
while ( dialog_progress->run() != Gtk::RESPONSE_OK )
apply = false;//finish current operation . then stop applying operations
dialog_progress ->set_transient_for( *this );
while ( dialog_progress ->run( ) != Gtk::RESPONSE_OK )
apply = false ;//finish current operation . then stop applying operations
//after hiding the progressdialog
s3.disconnect();
delete ( dialog_progress ) ;
thread ->join() ;
thread ->join( ) ;
conn .disconnect( ) ;
//make list of involved devices which have at least one busy partition..
std::vector <Glib::ustring> devicenames ;
for (unsigned int t=0; t<operations .size(); t++ )
if ( std::find( devicenames .begin(), devicenames .end() , operations[ t ] .device ->Get_Path() ) == devicenames .end() &&
operations[ t ] .device ->Get_any_busy()
operations[ t ] .device ->Get_any_busy()
)
devicenames .push_back( operations[ t ] .device ->Get_Path() ) ;
@ -1180,53 +1202,34 @@ void Win_GParted::activate_apply()
//wipe operations...
operations.clear();
liststore_operations ->clear();
close_operationslist() ;
operations.clear( ) ;
liststore_operations ->clear( ) ;
close_operationslist( ) ;
//reset new_count to 1
new_count = 1;
new_count = 1 ;
//reread devices and their layouts...
menu_gparted_refresh_devices() ;
menu_gparted_refresh_devices( ) ;
}
}
//-------AFAIK it's not possible to use a C++ memberfunction as a callback for a C libary function (if you know otherwise, PLEASE contact me------------
Dialog_Progress *dp;
Glib::Dispatcher dispatcher_current_operation;
void progress_callback(PedTimer * timer, void *context )
void Win_GParted::apply_operations_thread( )
{
if ( time(NULL) - timer ->start > 0 )
{
dp ->time_left = timer ->predicted_end - time(NULL) ;
dp ->fraction_current = timer ->frac ;
dispatcher_current_operation() ;
}
}
//---------------------------------------------------------------------------------------
void Win_GParted::apply_operations_thread()
{
dp = dialog_progress ;
sigc::connection signal = dispatcher_current_operation.connect( sigc::mem_fun(*dialog_progress, &Dialog_Progress::Set_Progress_Current_Operation) );
PedTimer *timer = ped_timer_new( progress_callback, NULL ) ;
for ( unsigned int t=0;t<operations.size() && apply ;t++ )
{
operations[t] .Apply_To_Disk( timer );
operations[t] .Apply_To_Disk( ped_timer_new( progress_callback, NULL ) );
if ( t < operations .size() -1 )
{
dialog_progress ->current_operation = operations[ t +1 ] .str_operation ;
dispatcher_next_operation() ;
dispatcher( ) ;
}
}
dialog_progress->response( Gtk::RESPONSE_OK );
signal.disconnect() ;
dialog_progress ->response( Gtk::RESPONSE_OK );
}