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
This commit is contained in:
Bart Hakvoort 2006-03-02 21:55:04 +00:00
parent 58f812484c
commit 2773e874e3
6 changed files with 53 additions and 10 deletions

View File

@ -1,3 +1,13 @@
2006-03-02 Bart Hakvoort <hakvoort@cvs.gnome.org>
* 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 <hakvoort@cvs.gnome.org>
* src/Dialog_Base_Partition.cc,

View File

@ -59,6 +59,7 @@ private:
bool set_selected( std::vector<visual_partition> & visual_partitions, int x, int y ) ;
void set_selected( std::vector<visual_partition> & visual_partitions, const Partition & partition ) ;
int spreadout_leftover_px( std::vector<visual_partition> & visual_partitions, int pixels ) ;
void free_colors( std::vector<visual_partition> & visual_partitions ) ;
//signalhandlers

View File

@ -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 ;
@ -373,16 +373,44 @@ 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.
//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 ) ;
//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 ) ;
}
//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_partition> & 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_partition> & visual_partitions )
{
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )

View File

@ -1,5 +1,6 @@
#include "../include/GParted_Core.h"
#include <cerrno>
#include <sys/statvfs.h>
Glib::ustring ped_error ; //see e.g. ped_exception_handler()
@ -437,6 +438,9 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & 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 );
}

View File

@ -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 != "" )