diff --git a/ChangeLog b/ChangeLog index d3d88d8f..fbd58084 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-03-15 Bart Hakvoort + + * include/Device.h, + src/Device.cc: overloaded == and != + * src/Win_GParted.cc: cleanups + 2006-03-15 Bart Hakvoort * src/Dialog_Partition_Info.cc, diff --git a/include/Device.h b/include/Device.h index c8b18cc6..e8f69c3f 100644 --- a/include/Device.h +++ b/include/Device.h @@ -32,8 +32,11 @@ public: void add_path( const Glib::ustring & path, bool clear_paths = false ) ; void add_paths( const std::vector & paths, bool clear_paths = false ) ; - Glib::ustring get_path() ; - std::vector get_paths() ; + Glib::ustring get_path() const ; + std::vector get_paths() const ; + + bool operator==( const Device & device ) const ; + bool operator!=( const Device & device ) const ; void Reset() ; std::vector partitions ; diff --git a/src/Device.cc b/src/Device.cc index c71f56ae..3241d6f8 100644 --- a/src/Device.cc +++ b/src/Device.cc @@ -56,7 +56,7 @@ void Device::add_paths( const std::vector & paths, bool clear_pat sort_paths_and_remove_duplicates() ; } -Glib::ustring Device::get_path() +Glib::ustring Device::get_path() const { if ( paths .size() > 0 ) return paths .front() ; @@ -64,10 +64,20 @@ Glib::ustring Device::get_path() return "" ; } -std::vector Device::get_paths() +std::vector Device::get_paths() const { return paths ; } + +bool Device::operator==( const Device & device ) const +{ + return this ->get_path() == device .get_path() ; +} + +bool Device::operator!=( const Device & device ) const +{ + return ! ( *this == device ) ; +} void Device::sort_paths_and_remove_duplicates() { diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 0aeaa3de..97e5c263 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -572,8 +572,8 @@ void Win_GParted::Refresh_Visual() //make all operations visible for ( unsigned int t = 0 ; t < operations .size(); t++ ) - { //FIXME: overload == operator for Device and use that instead of this.. - if ( operations[ t ] .device .get_path() == devices[ current_device ] .get_path() ) + { + if ( operations[ t ] .device == devices[ current_device ] ) operations[ t ] .Apply_Operation_To_Visual( partitions ) ; treerow = *( liststore_operations ->append() ); @@ -857,7 +857,7 @@ void Win_GParted::thread_refresh_devices() pulse = false ; } -void Win_GParted::menu_gparted_refresh_devices( ) +void Win_GParted::menu_gparted_refresh_devices() { pulse = true ; thread = Glib::Thread::create( sigc::mem_fun( *this, &Win_GParted::thread_refresh_devices ), true ) ; @@ -869,17 +869,17 @@ void Win_GParted::menu_gparted_refresh_devices( ) current_device = 0 ; //show read-only warning if necessary - Glib::ustring readonly_paths ; - //FIXME: push relevant devices in vector en construct error using Glib::build_path + std::vector readonly_paths ; for ( unsigned int t = 0 ; t < devices .size() ; t++ ) if ( devices[ t ] .readonly ) - readonly_paths += "\n- " + devices[ t ] .get_path() ; + readonly_paths .push_back( "\n- " + devices[ t ] .get_path() ) ; - if ( ! readonly_paths .empty() ) + if ( readonly_paths .size() > 0 ) { Gtk::MessageDialog dialog( *this, - _("The kernel is unable to re-read the partitiontables on the following devices:") + readonly_paths, + _("The kernel is unable to re-read the partitiontables on the following devices:") + + Glib::build_path( "", readonly_paths ), false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, @@ -893,10 +893,11 @@ void Win_GParted::menu_gparted_refresh_devices( ) //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 :-) + //FIXME: this actually sucks ;) see if we can use STL predicates here.. unsigned int i ; for ( unsigned int t = 0 ; t < operations .size() ; t++ ) - {//FIXME same as above, use Device::== - for ( i = 0 ; i < devices .size() && devices[ i ] .get_path() != operations[ t ] .device .get_path() ; i++ ) {} + { + for ( i = 0 ; i < devices .size() && devices[ i ] != operations[ t ] .device ; i++ ) {} if ( i >= devices .size() ) operations .erase( operations .begin() + t-- ) ;//decrease t bij one.. @@ -1105,10 +1106,10 @@ bool Win_GParted::max_amount_prim_reached() void Win_GParted::activate_resize() { std::vector partitions = devices[ current_device ] .partitions ; -//FIXME use DEvice::== + if ( operations .size() ) for (unsigned int t = 0 ; t < operations .size() ; t++ ) - if ( operations[ t ] .device .get_path() == devices[ current_device ] .get_path() ) + if ( operations[ t ] .device == devices[ current_device ] ) operations[ t ] .Apply_Operation_To_Visual( partitions ) ; Dialog_Partition_Resize_Move dialog( gparted_core .get_fs( selected_partition .filesystem ),