* src/Dialog_Partition_Info.cc,
  src/DrawingAreaVisualDisk.cc: cleanups
This commit is contained in:
Bart Hakvoort 2006-03-15 16:56:28 +00:00
parent 9532c3cad1
commit ebad1f133b
3 changed files with 108 additions and 58 deletions

View File

@ -1,3 +1,8 @@
2006-03-15 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/Dialog_Partition_Info.cc,
src/DrawingAreaVisualDisk.cc: cleanups
2006-03-15 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-03-15 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Partition.h, * include/Partition.h,

View File

@ -28,24 +28,25 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition )
this ->set_has_separator( false ) ; this ->set_has_separator( false ) ;
/*TO TRANSLATORS: dialogtitle, looks like Information about /dev/hda3 */ /*TO TRANSLATORS: dialogtitle, looks like Information about /dev/hda3 */
this ->set_title( String::ucompose( _( "Information about %1"), partition .get_path() ) ); this ->set_title( String::ucompose( _("Information about %1"), partition .get_path() ) );
init_drawingarea( ) ; init_drawingarea() ;
//add label for detail and fill with relevant info //add label for detail and fill with relevant info
Display_Info( ) ; Display_Info() ;
//display error (if any) //display error (if any)
if ( partition .error != "" ) if ( partition .error != "" )
{ {
frame = manage( new Gtk::Frame( ) ); frame = manage( new Gtk::Frame() );
frame ->set_border_width( 10 ); frame ->set_border_width( 10 );
image = manage( new Gtk::Image( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON ) ); image = manage( new Gtk::Image( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON ) );
hbox = manage( new Gtk::HBox( ) ); hbox = manage( new Gtk::HBox() );
hbox ->pack_start( *image, Gtk::PACK_SHRINK ) ; hbox ->pack_start( *image, Gtk::PACK_SHRINK ) ;
hbox ->pack_start( * Utils::mk_label( "<b> " + (Glib::ustring) _( "Warning:" ) + " </b>" ), Gtk::PACK_SHRINK ) ; hbox ->pack_start( * Utils::mk_label( "<b> " + static_cast<Glib::ustring>(_( "Warning:") ) + " </b>" ),
Gtk::PACK_SHRINK ) ;
frame ->set_label_widget( *hbox ) ; frame ->set_label_widget( *hbox ) ;
frame ->add( * Utils::mk_label( "<i>" + partition.error + "</i>", true, true, true ) ) ; frame ->add( * Utils::mk_label( "<i>" + partition.error + "</i>", true, true, true ) ) ;
@ -54,14 +55,14 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition )
} }
this ->add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_OK ) ; this ->add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_OK ) ;
this ->show_all_children( ) ; this ->show_all_children() ;
} }
void Dialog_Partition_Info::drawingarea_on_realize( ) void Dialog_Partition_Info::drawingarea_on_realize()
{ {
gc = Gdk::GC::create( drawingarea .get_window( ) ) ; gc = Gdk::GC::create( drawingarea .get_window() ) ;
drawingarea .get_window( ) ->set_background( color_partition ) ; drawingarea .get_window() ->set_background( color_partition ) ;
} }
bool Dialog_Partition_Info::drawingarea_on_expose( GdkEventExpose *ev ) bool Dialog_Partition_Info::drawingarea_on_expose( GdkEventExpose *ev )
@ -84,26 +85,27 @@ bool Dialog_Partition_Info::drawingarea_on_expose( GdkEventExpose *ev )
return true; return true;
} }
void Dialog_Partition_Info::init_drawingarea( ) void Dialog_Partition_Info::init_drawingarea()
{ {
drawingarea .set_size_request( 400, 60 ) ; drawingarea .set_size_request( 400, 60 ) ;
drawingarea .signal_realize( ).connect( sigc::mem_fun(*this, &Dialog_Partition_Info::drawingarea_on_realize) ) ; drawingarea .signal_realize().connect( sigc::mem_fun(*this, &Dialog_Partition_Info::drawingarea_on_realize) ) ;
drawingarea .signal_expose_event( ).connect( sigc::mem_fun(*this, &Dialog_Partition_Info::drawingarea_on_expose) ) ; drawingarea .signal_expose_event().connect( sigc::mem_fun(*this, &Dialog_Partition_Info::drawingarea_on_expose) ) ;
frame = manage( new Gtk::Frame( ) ) ; frame = manage( new Gtk::Frame() ) ;
frame ->add( drawingarea ) ; frame ->add( drawingarea ) ;
frame ->set_shadow_type( Gtk::SHADOW_ETCHED_OUT ) ; frame ->set_shadow_type( Gtk::SHADOW_ETCHED_OUT ) ;
frame ->set_border_width( 10 ) ; frame ->set_border_width( 10 ) ;
hbox = manage( new Gtk::HBox( ) ) ; hbox = manage( new Gtk::HBox() ) ;
hbox ->pack_start( *frame, Gtk::PACK_EXPAND_PADDING ) ; hbox ->pack_start( *frame, Gtk::PACK_EXPAND_PADDING ) ;
this ->get_vbox( ) ->pack_start( *hbox, Gtk::PACK_SHRINK ) ; this ->get_vbox() ->pack_start( *hbox, Gtk::PACK_SHRINK ) ;
//calculate proportional width of used and unused //calculate proportional width of used and unused
used = unused = 0 ; used = unused = 0 ;
//FIXME: use Partition::get_length().. used = Utils::Round(
used = Utils::Round( (400 - BORDER *2) / ( static_cast<double>(partition .sector_end - partition .sector_start) / partition .sectors_used ) ) ; (400 - BORDER *2) / ( static_cast<double>( partition .get_length() ) / partition .sectors_used ) ) ;
unused = 400 - used - BORDER *2 ; unused = 400 - used - BORDER *2 ;
//allocate some colors //allocate some colors
@ -124,22 +126,34 @@ void Dialog_Partition_Info::init_drawingarea( )
partition .get_path() + "\n" + Utils::format_size( partition .get_length() ) ) ; partition .get_path() + "\n" + Utils::format_size( partition .get_length() ) ) ;
} }
void Dialog_Partition_Info::Display_Info( ) void Dialog_Partition_Info::Display_Info()
{ {
int top =0, bottom = 1; int top = 0, bottom = 1 ;
table = manage( new Gtk::Table( ) ) ; table = manage( new Gtk::Table() ) ;
table ->set_border_width( 5 ) ; table ->set_border_width( 5 ) ;
table ->set_col_spacings(10 ) ; table ->set_col_spacings(10 ) ;
this ->get_vbox( ) ->pack_start( *table, Gtk::PACK_SHRINK ) ; this ->get_vbox() ->pack_start( *table, Gtk::PACK_SHRINK ) ;
//filesystem //filesystem
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Filesystem:" ) + "</b>" ) , 0, 1, top, bottom, Gtk::FILL ); table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Filesystem:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::Get_Filesystem_String( partition .filesystem ) ), 1, 2, top++, bottom++, Gtk::FILL ); 0, 1,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::Get_Filesystem_String( partition .filesystem ) ),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
//size //size
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Size:" ) + "</b>" ), 0,1,top, bottom,Gtk::FILL); table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Size:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .get_length() ) ), 1, 2, top++, bottom++,Gtk::FILL ); 0, 1,
top, bottom,
Gtk::FILL) ;
table ->attach( * Utils::mk_label( Utils::format_size( partition .get_length() ) ),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
if ( partition.sectors_used != -1 ) if ( partition.sectors_used != -1 )
{ {
@ -148,20 +162,41 @@ void Dialog_Partition_Info::Display_Info( )
Utils::Round( partition .sectors_used / static_cast<double>( partition .get_length() ) * 100 ) ; Utils::Round( partition .sectors_used / static_cast<double>( partition .get_length() ) * 100 ) ;
//used //used
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Used:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Used:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .sectors_used ) ), 1, 2, top, bottom, Gtk::FILL ) ; 0, 1,
table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::format_size( partition .sectors_used ) ),
1, 2,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( percent_used ) + "% )"),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
//unused //unused
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Unused:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL); table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Unused:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::format_size( this ->partition .sectors_unused ) ), 1, 2, top, bottom, Gtk::FILL ) ; 0, 1,
table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( 100 - percent_used ) + "% )"), 1, 2, top++, bottom++, Gtk::FILL ) ; top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::format_size( partition .sectors_unused ) ),
1, 2,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( "\t\t\t( " + Utils::num_to_str( 100 - percent_used ) + "% )"),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
} }
//flags //flags
if ( partition.type != GParted::TYPE_UNALLOCATED ) if ( partition.type != GParted::TYPE_UNALLOCATED )
{ {
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Flags:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Flags:") ) + "</b>" ),
0, 1,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Glib::build_path( ", ", partition .flags ) ), table ->attach( * Utils::mk_label( Glib::build_path( ", ", partition .flags ) ),
1, 2, 1, 2,
top++, bottom++, top++, bottom++,
@ -174,7 +209,7 @@ void Dialog_Partition_Info::Display_Info( )
if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW ) if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW )
{ {
//path //path
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Path:" ) + "</b>" ), table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Path:") ) + "</b>" ),
0, 1, 0, 1,
top, bottom, top, bottom,
Gtk::FILL ) ; Gtk::FILL ) ;
@ -185,14 +220,14 @@ void Dialog_Partition_Info::Display_Info( )
//status //status
Glib::ustring str_temp ; Glib::ustring str_temp ;
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Status:" ) + "</b>" ), table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Status:") ) + "</b>" ),
0, 1, 0, 1,
top, bottom, top, bottom,
Gtk::FILL) ; Gtk::FILL ) ;
if ( partition .busy ) if ( partition .busy )
{ {
if ( partition .type == GParted::TYPE_EXTENDED ) if ( partition .type == GParted::TYPE_EXTENDED )
str_temp = _("Busy (At least one logical partition is mounted)" ) ; str_temp = _("Busy (At least one logical partition is mounted)") ;
else if ( partition .filesystem == FS_LINUX_SWAP ) else if ( partition .filesystem == FS_LINUX_SWAP )
str_temp = _("Active") ; str_temp = _("Active") ;
else if ( partition .get_mountpoints() .size() ) else if ( partition .get_mountpoints() .size() )
@ -200,11 +235,11 @@ void Dialog_Partition_Info::Display_Info( )
Glib::build_path( ", ", partition .get_mountpoints() ) ) ; Glib::build_path( ", ", partition .get_mountpoints() ) ) ;
} }
else if ( partition.type == GParted::TYPE_EXTENDED ) else if ( partition.type == GParted::TYPE_EXTENDED )
str_temp = _("Not busy (There are no mounted logical partitions)" ) ; str_temp = _("Not busy (There are no mounted logical partitions)") ;
else if ( partition.filesystem == GParted::FS_LINUX_SWAP ) else if ( partition.filesystem == GParted::FS_LINUX_SWAP )
str_temp = _("Not active" ) ; str_temp = _("Not active") ;
else else
str_temp = _("Not mounted" ) ; str_temp = _("Not mounted") ;
table ->attach( * Utils::mk_label( str_temp ), 1, 2, top++, bottom++, Gtk::FILL ) ; table ->attach( * Utils::mk_label( str_temp ), 1, 2, top++, bottom++, Gtk::FILL ) ;
} }
@ -213,17 +248,34 @@ void Dialog_Partition_Info::Display_Info( )
table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ;
//first sector //first sector
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "First Sector:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("First Sector:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::num_to_str( partition.sector_start ) ), 1,2, top++, bottom++,Gtk::FILL); 0, 1,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::num_to_str( partition .sector_start ) ),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
//last sector //last sector
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Last Sector:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Last Sector:") ) + "</b>" ),
table ->attach( * Utils::mk_label( Utils::num_to_str( partition.sector_end ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; 0, 1,
top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::num_to_str( partition.sector_end ) ),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
//total sectors //total sectors
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Total Sectors:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + static_cast<Glib::ustring>( _("Total Sectors:") ) + "</b>" ),
//FIXME: use Partition::get_length() here.. 0, 1,
table ->attach( * Utils::mk_label( Utils::num_to_str( partition .sector_end - partition .sector_start ) ), 1, 2, top++, bottom++, Gtk::FILL ) ; top, bottom,
Gtk::FILL ) ;
table ->attach( * Utils::mk_label( Utils::num_to_str( partition .get_length() ) ),
1, 2,
top++, bottom++,
Gtk::FILL ) ;
} }
Dialog_Partition_Info::~Dialog_Partition_Info() Dialog_Partition_Info::~Dialog_Partition_Info()

View File

@ -82,25 +82,18 @@ void DrawingAreaVisualDisk::set_static_data( const std::vector<Partition> & part
std::vector<visual_partition> & visual_partitions, std::vector<visual_partition> & visual_partitions,
Sector length ) Sector length )
{ {
Sector p_length ;
visual_partition vp ;
//FIXME: any particular reason why Partition::get_length() isn't used in this function?
//i'm also not sure why we use 'vp' this way.. Lets either use it or drop it :)
for ( unsigned int t = 0 ; t < partitions .size() ; t++ ) for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
{ {
visual_partitions .push_back( vp ) ; visual_partitions .push_back( visual_partition() ) ;
visual_partitions .back() .partition = partitions[ t ] ; visual_partitions .back() .partition = partitions[ t ] ;
visual_partitions .back() .fraction = partitions[ t ] .get_length() / static_cast<double>( length ) ;
p_length = partitions[ t ] .sector_end - partitions[ t ] .sector_start ;
visual_partitions .back() .fraction = p_length / static_cast<double>( length ) ;
if ( partitions[ t ] .type == GParted::TYPE_UNALLOCATED || partitions[ t ] .type == GParted::TYPE_EXTENDED ) if ( partitions[ t ] .type == GParted::TYPE_UNALLOCATED || partitions[ t ] .type == GParted::TYPE_EXTENDED )
visual_partitions .back() .fraction_used = -1 ; visual_partitions .back() .fraction_used = -1 ;
else if ( partitions[ t ] .sectors_used > 0 ) else if ( partitions[ t ] .sectors_used > 0 )
visual_partitions .back() .fraction_used = visual_partitions .back() .fraction_used =
partitions[ t ] .sectors_used / static_cast<double>( p_length ) ; partitions[ t ] .sectors_used / static_cast<double>( partitions[ t ] .get_length() ) ;
visual_partitions .back() .color = partitions[ t ] .color; visual_partitions .back() .color = partitions[ t ] .color;
this ->get_colormap() ->alloc_color( visual_partitions .back() .color ); this ->get_colormap() ->alloc_color( visual_partitions .back() .color );