made 'deep-scan' optional in Read_Disk_Layout. Removed obsolete (already)

* include/Device.h,
  src/Device.cc: made 'deep-scan' optional in Read_Disk_Layout. Removed obsolete (already) commented function.
* include/Partition.h,
  src/Partition.cc: Took used sectors out of Set() and added a Set_Used() function instead. Also added Reset() .
* src/Dialog_Partition_New.cc: minor change to make use of the new Set() in Partition..
* include/Win_GParted.h,
  src/Win_GParted.cc: show pulsing progressbar while refreshing devices.
This commit is contained in:
Bart Hakvoort 2004-10-11 10:23:24 +00:00
parent 61d4d36633
commit 9c328738c9
8 changed files with 140 additions and 74 deletions

View File

@ -1,3 +1,13 @@
2004-10-11 Bart Hakvoort <gparted@users.sf.net>
* include/Device.h,
src/Device.cc: made 'deep-scan' optional in Read_Disk_Layout. Removed obsolete (already) commented function.
* include/Partition.h,
src/Partition.cc: Took used sectors out of Set() and added a Set_Used() function instead. Also added Reset() .
* src/Dialog_Partition_New.cc: minor change to make use of the new Set() in Partition..
* include/Win_GParted.h,
src/Win_GParted.cc: show pulsing progressbar while refreshing devices.
2004-10-08 Bart Hakvoort <gparted@users.sf.net>
* src/Partition.cc: changed color of reiserfs from blue to purple highlight. + some cosmetics.

View File

@ -51,7 +51,7 @@ public:
Device( const Glib::ustring & device_path, std::vector<FS> *filesystems );
~Device() ;
//this function creates a fresh list with al the partitions and free spaces
void Read_Disk_Layout() ;
void Read_Disk_Layout( bool deep_scan = true ) ;
bool Delete_Partition( const Partition & partition ) ;
bool Create_Partition_With_Filesystem( Partition & new_part, PedTimer *timer) ;
bool Move_Resize_Partition( const Partition & partition_original, const Partition & partition_new , PedTimer *timer) ;
@ -77,7 +77,6 @@ public:
private:
//make a try to get the amount of used sectors on a filesystem ( see comments in implementation )
Sector Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path );
//bool Supported( const Glib::ustring & filesystem ) ;
Glib::ustring Get_Flags( PedPartition *c_partition ) ;

View File

@ -51,8 +51,10 @@ enum PartitionStatus {
class Partition
{
public:
Partition();
~Partition() ;
Partition( ) ;
~Partition( ) ;
void Reset( ) ;
//simple Set-functions. only for convenience, since most members are public
void Set( const Glib::ustring & partition,
@ -61,10 +63,11 @@ public:
const Glib::ustring & filesystem,
const Sector & sector_start,
const Sector & sector_end,
const Sector & sectors_used,
const bool inside_extended,
const bool busy ) ;
void Set_Used( Sector used ) ;
void Set_Unallocated( Sector sector_start, Sector sector_end, bool inside_extended );

View File

@ -61,13 +61,15 @@ private:
void init_hpaned_main() ;
void Find_Supported_Filesystems() ;
void Find_Devices() ;
void Find_Devices( bool deep_scan = true ) ;
void Refresh_OptionMenu( ) ;
void Show_Pulsebar( ) ;
//Fill txtview_device_info_buffer with some information about the selected device
void Fill_Label_Device_Info( );
//overridden signalhandler
virtual bool on_delete_event(GdkEventAny* ) ;
virtual bool on_delete_event( GdkEventAny* ) ;
void Add_Operation( OperationType, const Partition & );
void Refresh_Visual( );
@ -86,11 +88,14 @@ private:
void allow_undo( bool b ) { toolbar_main.get_nth_item(8) ->set_sensitive( b ); }
void allow_apply( bool b ) { toolbar_main.get_nth_item(9) ->set_sensitive( b ); }
void find_devices_thread( ) { Find_Devices( ) ; pulse = false ; }
//signal handlers
void close_operationslist() ;
void clear_operationslist() ;
void optionmenu_devices_changed( );
void menu_gparted_refresh_devices();
void menu_gparted_quit();
void menu_view_harddisk_info();
@ -136,6 +141,7 @@ private:
Gtk::Table *table ;
Gtk::MenuItem *menu_item;
Gtk::Entry *entry;
Gtk::ProgressBar *pulsebar ;
Gdk::Color color ;
@ -168,15 +174,14 @@ private:
GParted::Device *temp_device ;
std::vector <Glib::ustring> str_devices ;
std::vector <Gtk::Label *> device_info ;
std::vector <FS> FILESYSTEMS ;
//stuff for progress overview
Dialog_Progress *dialog_progress;
Glib::Thread *thread_operations;
Glib::Thread *thread ;
Glib::Dispatcher dispatcher_next_operation;
bool apply;
bool apply, pulse ;
};

View File

@ -129,23 +129,22 @@ Device::Device( const Glib::ustring & device_path, std::vector<FS> *filesystems
for ( PedPartitionFlag flag = ped_partition_flag_next ( (PedPartitionFlag) 0 ) ; flag ; flag = ped_partition_flag_next ( flag ) )
flags .push_back( flag ) ;
Read_Disk_Layout() ;
}
void Device::Read_Disk_Layout()
void Device::Read_Disk_Layout( bool deep_scan )
{
Glib::ustring part_path ;
//clear partitions
this ->device_partitions .clear () ;
this ->device_partitions .clear() ;
c_partition = ped_disk_next_partition ( disk, NULL) ;
c_partition = ped_disk_next_partition( disk, NULL ) ;
while ( c_partition )
{
partition_temp .Reset( ) ;
part_path = this ->path + num_to_str( c_partition ->num ) ;
switch( c_partition ->type )
switch ( c_partition ->type )
{
//NORMAL (PRIMARY)
case 0 : if ( c_partition ->fs_type )
@ -153,7 +152,10 @@ void Device::Read_Disk_Layout()
else
{temp = "unknown" ; this ->error = (Glib::ustring) _( "Unable to detect filesystem! Possible reasons are:" ) + "\n-" + (Glib::ustring) _( "The filesystem is damaged" ) + "\n-" + (Glib::ustring) _( "The filesystem is unknown to libparted" ) + "\n-" + (Glib::ustring) _( "There is no filesystem available (unformatted)" ) ; }
partition_temp.Set( part_path,c_partition ->num , GParted::PRIMARY, temp, c_partition ->geom .start, c_partition ->geom .end, Get_Used_Sectors( c_partition , part_path ) , false, ped_partition_is_busy( c_partition ) );
partition_temp.Set( part_path, c_partition ->num, GParted::PRIMARY, temp, c_partition ->geom .start, c_partition ->geom .end, false, ped_partition_is_busy( c_partition ) );
if ( deep_scan )
partition_temp .Set_Used( Get_Used_Sectors( c_partition, part_path ) ) ;
partition_temp .flags = Get_Flags( c_partition ) ;
partition_temp .error = this ->error ;
@ -166,15 +168,17 @@ void Device::Read_Disk_Layout()
else
{temp = "unknown" ; this ->error = (Glib::ustring) _( "Unable to detect filesystem! Possible reasons are:" ) + "\n-" + (Glib::ustring) _( "The filesystem is damaged" ) + "\n-" + (Glib::ustring) _( "The filesystem is unknown to libparted" ) + "\n-" + (Glib::ustring) _( "There is no filesystem available (unformatted)" ) ; }
partition_temp.Set( part_path, c_partition ->num, GParted::LOGICAL, temp, c_partition ->geom .start, c_partition ->geom .end, Get_Used_Sectors( c_partition , part_path ) , true, ped_partition_is_busy( c_partition ) );
partition_temp.Set( part_path, c_partition ->num, GParted::LOGICAL, temp, c_partition ->geom .start, c_partition ->geom .end, true, ped_partition_is_busy( c_partition ) );
if ( deep_scan )
partition_temp .Set_Used( Get_Used_Sectors( c_partition, part_path ) ) ;
partition_temp .flags = Get_Flags( c_partition ) ;
partition_temp .error = this ->error ;
device_partitions.push_back( partition_temp );
break;
//EXTENDED
case 2: partition_temp.Set( part_path, c_partition ->num, GParted::EXTENDED, "extended", c_partition ->geom .start, c_partition ->geom .end , -1, false, ped_partition_is_busy( c_partition ) );
case 2: partition_temp.Set( part_path, c_partition ->num, GParted::EXTENDED, "extended", c_partition ->geom .start, c_partition ->geom .end, false, ped_partition_is_busy( c_partition ) );
partition_temp .flags = Get_Flags( c_partition ) ;
partition_temp .error = this ->error ;
@ -183,7 +187,7 @@ void Device::Read_Disk_Layout()
//FREESPACE OUTSIDE EXTENDED
case 4: if ( (c_partition ->geom .end - c_partition ->geom .start) > MEGABYTE )
{
partition_temp.Set_Unallocated( c_partition ->geom .start , c_partition ->geom .end, false );
partition_temp.Set_Unallocated( c_partition ->geom .start, c_partition ->geom .end, c_partition ->type == 4 ? false : true );
device_partitions.push_back( partition_temp );
}
@ -191,7 +195,7 @@ void Device::Read_Disk_Layout()
//FREESPACE INSIDE EXTENDED
case 5: if ( (c_partition ->geom .end - c_partition ->geom .start) > MEGABYTE )
{
partition_temp.Set_Unallocated( c_partition ->geom .start , c_partition ->geom .end, true );
partition_temp.Set_Unallocated( c_partition ->geom .start, c_partition ->geom .end, true );
device_partitions.push_back( partition_temp );
}
@ -553,15 +557,6 @@ Sector Device::Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring
return -1 ; //all methods were unsuccesfull
}
/*
bool Device::Supported( const Glib::ustring & filesystem )
{
for (unsigned int t=0 ; t < FILESYSTEMS ->size() ; t++ )
if ( (*FILESYSTEMS)[ t ] .filesystem == filesystem && (*FILESYSTEMS)[ t ] .supported )
return true ;
return false ;
}*/
Glib::ustring Device::Get_Flags( PedPartition *c_partition )
{
@ -578,12 +573,12 @@ bool Device::open_device_and_disk()
{
device = ped_device_get( this->realpath .c_str() );
if ( device )
disk = ped_disk_new( device );
disk = ped_disk_new( device );
if ( ! device || ! disk )
if ( ! device || ! disk )
{
if ( device )
{ ped_device_destroy( device ) ; device = NULL ; }
{ ped_device_destroy( device ) ; device = NULL ; }
return false;
}

View File

@ -136,7 +136,7 @@ Partition Dialog_Partition_New::Get_New_Partition()
new_end = selected_partition.sector_end ;
part_temp .status = GParted::STAT_NEW ;
part_temp .Set( String::ucompose( _("New Partition #%1"), new_count ), new_count, part_type , FILESYSTEMS[ optionmenu_filesystem.get_history() ] .filesystem, new_start, new_end, -1, selected_partition.inside_extended, false) ;
part_temp .Set( String::ucompose( _("New Partition #%1"), new_count ), new_count, part_type , FILESYSTEMS[ optionmenu_filesystem.get_history() ] .filesystem, new_start, new_end, selected_partition.inside_extended, false) ;
//grow new partition a bit if freespaces are < 1 MB
if ( (part_temp.sector_start - selected_partition.sector_start) < MEGABYTE )

View File

@ -22,8 +22,17 @@ namespace GParted
Partition::Partition( )
{
this ->error = ""; //just to be sure...
this ->status = GParted::STAT_REAL ;
Reset( ) ;
}
void Partition::Reset( )
{
partition = filesystem = error = flags = color_string = "" ;
status = GParted::STAT_REAL ;
type = GParted::UNALLOCATED ;
partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1;
color.set( "black" ) ;
inside_extended = busy = false ;
}
void Partition::Set( const Glib::ustring & partition,
@ -32,7 +41,6 @@ void Partition::Set( const Glib::ustring & partition,
const Glib::ustring & filesystem,
const Sector & sector_start,
const Sector & sector_end,
const Sector & sectors_used,
const bool inside_extended,
const bool busy )
{
@ -42,17 +50,21 @@ void Partition::Set( const Glib::ustring & partition,
this ->filesystem = filesystem;
this ->sector_start = sector_start;
this ->sector_end = sector_end;
this ->sectors_used = sectors_used;
sectors_used != -1 ? this ->sectors_unused = ( sector_end - sector_start) - sectors_used : this ->sectors_unused = -1 ;
this ->color.set( Get_Color( filesystem ) );
this ->color_string = Get_Color( filesystem );
this ->inside_extended = inside_extended;
this ->busy = busy;
}
void Partition::Set_Used( Sector used )
{
this ->sectors_used = used;
this ->sectors_unused = ( sector_end - sector_start) - used ;
}
void Partition::Set_Unallocated( Sector sector_start, Sector sector_end, bool inside_extended )
{
this ->Set( _("Unallocated"), -1, GParted::UNALLOCATED, "unallocated", sector_start, sector_end , -1, inside_extended, false);
this ->Set( _("Unallocated"), -1, GParted::UNALLOCATED, "unallocated", sector_start, sector_end , inside_extended, false);
this ->error = this ->flags = "" ;
this ->status = GParted::STAT_REAL ;
}

View File

@ -26,12 +26,14 @@ Win_GParted::Win_GParted( )
new_count = 1;
current_device = source_device = 0 ;
vbox_visual_disk = NULL;
pulse = false ;
//store filesystems in vector and find out if their respective libs are installed
Find_Supported_Filesystems() ;
//locate all available devices and store them in devices vector
Find_Devices() ;
Find_Devices( ) ;
Refresh_OptionMenu( ) ;
//==== GUI =========================
this->set_title( _("GParted") );
@ -67,6 +69,9 @@ Win_GParted::Win_GParted( )
vpaned_main .pack2( hbox_operations, true, true ) ;
//statusbar...
pulsebar = manage( new Gtk::ProgressBar() );
pulsebar ->set_pulse_step( 0.01 );
statusbar .add( *pulsebar );
vbox_main.pack_start( statusbar, Gtk::PACK_SHRINK );
//popupmenu...
@ -89,7 +94,7 @@ void Win_GParted::init_menubar()
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::SeparatorElem() );
menu ->items() .push_back(Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::QUIT , sigc::mem_fun(*this, &Win_GParted::menu_gparted_quit) ) );
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 ) );
//view
@ -173,16 +178,16 @@ void Win_GParted::init_popupmenu()
void Win_GParted::init_convert_menu()
{
for ( unsigned int t=0;t < FILESYSTEMS .size() ;t++ )
for ( unsigned int t=0; t < FILESYSTEMS .size() ; t++ )
{
color .set( selected_partition .Get_Color( FILESYSTEMS[ t ] .filesystem ) );
hbox = manage( new Gtk::HBox() );
//the colored square
entry = manage ( new Gtk::Entry() );
entry->set_sensitive( false );
entry->set_size_request( 12, 12 );
entry->modify_base( entry->get_state(), color );
entry ->set_sensitive( false );
entry ->set_size_request( 12, 12 );
entry ->modify_base( entry->get_state(), color );
hbox ->pack_start( *entry, Gtk::PACK_SHRINK );
//the label...
@ -190,7 +195,7 @@ void Win_GParted::init_convert_menu()
menu_item = manage( new Gtk::MenuItem( *hbox ) ) ;
menu_convert.items().push_back( *menu_item);
menu_convert.items() .back() .signal_activate() .connect( sigc::bind<Glib::ustring>(sigc::mem_fun(*this, &Win_GParted::activate_convert), FILESYSTEMS[ t ] .filesystem ) ) ;
menu_convert.items() .back() .signal_activate() .connect( sigc::bind<Glib::ustring>(sigc::mem_fun(*this, &Win_GParted::activate_convert), FILESYSTEMS[ t ] .filesystem ) ) ;
}
menu_convert.show_all_children() ;
@ -359,33 +364,35 @@ void Win_GParted::Find_Supported_Filesystems()
}
}
void Win_GParted::Find_Devices()
void Win_GParted::Find_Devices( bool deep_scan )
{
for ( unsigned int t=0;t<devices.size() ; t++ )
delete devices[ t ] ;
devices.clear() ;
//try to find all available devices...
//try to find all available devices and put these in a list
ped_device_probe_all ();
//construct a list of device objects
PedDevice *device = ped_device_get_next (NULL);
while ( device )
{
str_devices.push_back( device ->path ) ;
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 ) ;
}
else
delete temp_device ;
device = ped_device_get_next (device) ;
}
for ( unsigned int t=0;t<str_devices.size() ; t++ )
{
temp_device = new GParted::Device( str_devices[t], &FILESYSTEMS );
temp_device ->Get_Length() > 0 ? devices.push_back( temp_device ) : delete temp_device ;
}
str_devices.clear() ;
}
void Win_GParted::Refresh_OptionMenu( )
{
//fill optionmenu_devices
menu_devices.items() .clear() ;
for ( unsigned int i=0;i<devices.size();i++ )
@ -404,7 +411,38 @@ void Win_GParted::Find_Devices()
}
menu_devices .show_all_children();
}
void Win_GParted::Show_Pulsebar( )
{
pulsebar ->show( );
statusbar .push( _("Scanning all devices...") ) ;
//disable all input stuff
toolbar_main .set_sensitive( false ) ;
menubar_main .set_sensitive( false ) ;
optionmenu_devices .set_sensitive( false ) ;
menu_popup .set_sensitive( false ) ;
//the actual 'pulsing'
pulse = true ;
while ( pulse )
{
pulsebar ->pulse();
while (Gtk::Main::events_pending()) Gtk::Main::iteration();
usleep(10000);
}
thread ->join( ) ;
pulsebar ->hide( );
statusbar .pop( ) ;
//enable all disabled stuff
toolbar_main .set_sensitive( true ) ;
menubar_main .set_sensitive( true ) ;
optionmenu_devices .set_sensitive( true ) ;
menu_popup .set_sensitive( true ) ;
}
void Win_GParted::Fill_Label_Device_Info( )
@ -679,7 +717,11 @@ void Win_GParted::optionmenu_devices_changed( )
void Win_GParted::menu_gparted_refresh_devices()
{
//find out if there was any change in available devices (think about flexible media like zipdisks/usbsticks/whatever ;-) )
Find_Devices() ;
thread = Glib::Thread::create( SigC::slot_class( *this, &Win_GParted::find_devices_thread ), true );
Show_Pulsebar( ) ;
Refresh_OptionMenu( ) ;
//refresh de pointer to the device in every operation
for ( unsigned int t=0; t< operations.size() ; t++ )
@ -755,7 +797,7 @@ void Win_GParted::mouse_click( GdkEventButton *event, const Partition & partitio
treeview_detail .Set_Selected( partition );
vbox_visual_disk ->Set_Selected( partition );
if ( event->type == GDK_2BUTTON_PRESS )
if ( event->type == GDK_2BUTTON_PRESS && ! pulse )
activate_info() ;
else if ( event->button == 3 ) //right-click
{
@ -1022,7 +1064,7 @@ void Win_GParted::activate_convert( const Glib::ustring & new_fs )
//ok we made it :P lets create an fitting partition object
Partition part_temp;
part_temp .Set( selected_partition .partition, selected_partition .partition_number, selected_partition .type, new_fs, selected_partition .sector_start, selected_partition .sector_end, -1, selected_partition .inside_extended, false ) ;
part_temp .Set( selected_partition .partition, selected_partition .partition_number, selected_partition .type, new_fs, selected_partition .sector_start, selected_partition .sector_end, /*-1,*/ selected_partition .inside_extended, false ) ;
//if selected_partition is NEW we simply remove the NEW operation from the list and add it again with the new filesystem
@ -1083,7 +1125,7 @@ void Win_GParted::activate_apply()
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) );
thread_operations = Glib::Thread::create(SigC::slot_class(*this, &Win_GParted::apply_operations_thread), true);
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 )
@ -1092,7 +1134,7 @@ void Win_GParted::activate_apply()
//after hiding the progressdialog
s3.disconnect();
delete ( dialog_progress ) ;
thread_operations->join() ;
thread ->join() ;
//make list of involved devices which have at least one busy partition..
std::vector <Glib::ustring> devicenames ;
@ -1127,14 +1169,14 @@ void Win_GParted::activate_apply()
//wipe operations...
operations.clear();
close_operationslist() ;
//reset new_count to 1
new_count = 1;
//reread devices and their layouts...
menu_gparted_refresh_devices() ;
//then clean up the rest
new_count = 1;
close_operationslist() ;
}
}