From 2773e874e36c835f705e2e15e986acc59b65753d Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 2 Mar 2006 21:55:04 +0000 Subject: [PATCH] improved the algorithm to deal with lost pixels after seeing some problems * include/FrameVisualDisk.h, src/FrameVisualDisk.cc: improved the algorithm to deal with lost pixels after seeing some problems with rather insane partitiontables. * src/Dialog_Partition_Info.cc: minor cleanup * src/GParted_Core.cc: show error in partitioninfo if statvfs fails * src/TreeView_Detail.cc: added FIXME --- ChangeLog | 10 +++++++++ include/FrameVisualDisk.h | 1 + src/Dialog_Partition_Info.cc | 2 +- src/FrameVisualDisk.cc | 40 ++++++++++++++++++++++++++++++------ src/GParted_Core.cc | 7 +++++-- src/TreeView_Detail.cc | 3 ++- 6 files changed, 53 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 204fa95a..afdb53b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-03-02 Bart Hakvoort + + * include/FrameVisualDisk.h, + src/FrameVisualDisk.cc: improved the algorithm to deal with lost + pixels after seeing some problems with rather insane + partitiontables. + * src/Dialog_Partition_Info.cc: minor cleanup + * src/GParted_Core.cc: show error in partitioninfo if statvfs fails + * src/TreeView_Detail.cc: added FIXME + 2006-03-01 Bart Hakvoort * src/Dialog_Base_Partition.cc, diff --git a/include/FrameVisualDisk.h b/include/FrameVisualDisk.h index 14072de2..2d140346 100644 --- a/include/FrameVisualDisk.h +++ b/include/FrameVisualDisk.h @@ -59,6 +59,7 @@ private: bool set_selected( std::vector & visual_partitions, int x, int y ) ; void set_selected( std::vector & visual_partitions, const Partition & partition ) ; + int spreadout_leftover_px( std::vector & visual_partitions, int pixels ) ; void free_colors( std::vector & visual_partitions ) ; //signalhandlers diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index 91fd1f62..29d7bd44 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -48,7 +48,7 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) hbox ->pack_start( * Utils::mk_label( " " + (Glib::ustring) _( "Warning:" ) + " " ), Gtk::PACK_SHRINK ) ; frame ->set_label_widget( *hbox ) ; - frame ->add( * Utils::mk_label( "" + partition.error + "", true, true, true ) ) ; + frame ->add( * Utils::mk_label( "" + partition.error + "", true, true, true ) ) ; this ->get_vbox() ->pack_start( *frame, Gtk::PACK_SHRINK ) ; } diff --git a/src/FrameVisualDisk.cc b/src/FrameVisualDisk.cc index d25b59e7..cd774af1 100644 --- a/src/FrameVisualDisk.cc +++ b/src/FrameVisualDisk.cc @@ -357,7 +357,7 @@ void FrameVisualDisk::on_resize( Gtk::Allocation & allocation ) { MIN_SIZE = 20 ; - int calced, TOTAL ; + int calced = 0, TOTAL ; do { TOTAL = allocation .get_width() - TOT_SEP ; @@ -372,16 +372,44 @@ void FrameVisualDisk::on_resize( Gtk::Allocation & allocation ) MIN_SIZE-- ; } while ( TOTAL <= 0 && MIN_SIZE > 0 ) ; + + //due to rounding a few px may be lost. here we salvage them.. + if ( visual_partitions .size() && calced > 0 ) + { + int px_left = allocation .get_width() - calced ; + + while ( px_left > 0 ) + px_left = spreadout_leftover_px( visual_partitions, px_left ) ; + } - //due to rounding a few px may be lost (max. 2), lets add these to the last partition. - //FIXME: instead of adding all leftover px to the last partition we should spread them over all partitions - if ( allocation .get_width() > calced && visual_partitions .size() ) - visual_partitions .back() .length += ( allocation .get_width() - calced ) ; - + //and calculate the rest.. calc_position_and_height( visual_partitions, 0, 0 ) ; calc_used_unused( visual_partitions ) ; calc_text( visual_partitions ) ; } + +int FrameVisualDisk::spreadout_leftover_px( std::vector & visual_partitions, int pixels ) +{ + int extended = -1 ; + + for ( unsigned int t = 0 ; t < visual_partitions .size() && pixels > 0 ; t++ ) + if ( ! visual_partitions[ t ] .logicals .size() ) + { + visual_partitions[ t ] .length++ ; + pixels-- ; + } + else + extended = t ; + + if ( extended > -1 && pixels > 0 ) + { + int actually_used = pixels - spreadout_leftover_px( visual_partitions[ extended ] .logicals, pixels ) ; + visual_partitions[ extended ] .length += actually_used ; + pixels -= actually_used ; + } + + return pixels ; +} void FrameVisualDisk::free_colors( std::vector & visual_partitions ) { diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index bb820874..40482324 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -1,5 +1,6 @@ #include "../include/GParted_Core.h" +#include #include Glib::ustring ped_error ; //see e.g. ped_exception_handler() @@ -437,6 +438,9 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) { if ( statvfs( partitions[ t ] .mountpoints .back() .c_str(), &sfs ) == 0 ) partitions[ t ] .Set_Unused( sfs .f_bfree * (sfs .f_bsize / 512) ) ; + else + partitions[ t ] .error = + "statvfs (" + partitions[ t ] .mountpoints .back() + "): " + Glib::strerror( errno ); } else { @@ -761,8 +765,7 @@ void GParted_Core::LP_Set_Used_Sectors( Partition & partition ) constraint = ped_file_system_get_resize_constraint( fs ) ; if ( constraint ) { - partition .Set_Unused( - (partition .sector_end - partition .sector_start) - constraint ->min_size ) ; + partition .Set_Unused( partition .get_length() - constraint ->min_size ) ; ped_constraint_destroy( constraint ); } diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index 8ac20c7b..c5dba9c9 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -140,7 +140,8 @@ bool TreeView_Detail::set_selected( Gtk::TreeModel::Children rows, const Partiti void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition & partition ) { - //hereby i assume these 2 are mutual exclusive. is this wise?? Time (and bugreports) will tell :) + //FIXME: this approach is too simplistic, we need to display the lock AND the warning icon if necessary + //e.g. if statvfs in the core fails, we need to display both icons... if ( partition .busy ) treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON ); else if ( partition .error != "" )