improved scanning for root mountpoint (/) use Utils::format_size() instead
* src/GParted_Core.cc: improved scanning for root mountpoint (/) * src/Dialog_Partition_Info.cc: use Utils::format_size() instead of displaying every value in MiB's. Also some cleanups and changes.
This commit is contained in:
parent
aa2f32522b
commit
409096f739
|
@ -1,3 +1,9 @@
|
||||||
|
2006-01-25 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||||
|
|
||||||
|
* src/GParted_Core.cc: improved scanning for root mountpoint (/)
|
||||||
|
* src/Dialog_Partition_Info.cc: use Utils::format_size() instead of
|
||||||
|
displaying every value in MiB's. Also some cleanups and changes.
|
||||||
|
|
||||||
2006-01-24 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
2006-01-24 Bart Hakvoort <hakvoort@cvs.gnome.org>
|
||||||
|
|
||||||
* src/Utils.cc: use realpath() to get absolute path to 'real'
|
* src/Utils.cc: use realpath() to get absolute path to 'real'
|
||||||
|
|
|
@ -53,7 +53,6 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition )
|
||||||
this ->get_vbox() ->pack_start( *frame, Gtk::PACK_SHRINK ) ;
|
this ->get_vbox() ->pack_start( *frame, Gtk::PACK_SHRINK ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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( ) ;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +62,6 @@ 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 )
|
||||||
|
@ -72,23 +70,23 @@ bool Dialog_Partition_Info::drawingarea_on_expose( GdkEventExpose *ev )
|
||||||
{
|
{
|
||||||
//used
|
//used
|
||||||
gc ->set_foreground( color_used );
|
gc ->set_foreground( color_used );
|
||||||
drawingarea .get_window( ) ->draw_rectangle( gc, true, BORDER, BORDER, used, 34 ) ;
|
drawingarea .get_window() ->draw_rectangle( gc, true, BORDER, BORDER, used, 44 ) ;
|
||||||
|
|
||||||
//unused
|
//unused
|
||||||
gc ->set_foreground( color_unused );
|
gc ->set_foreground( color_unused );
|
||||||
drawingarea .get_window( ) ->draw_rectangle( gc, true, BORDER + used, BORDER, unused, 34 ) ;
|
drawingarea .get_window() ->draw_rectangle( gc, true, BORDER + used, BORDER, unused, 44 ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//text
|
//text
|
||||||
gc ->set_foreground( color_text );
|
gc ->set_foreground( color_text );
|
||||||
drawingarea .get_window( ) ->draw_layout( gc, BORDER +5, BORDER +1 ,pango_layout ) ;
|
drawingarea .get_window() ->draw_layout( gc, 180, BORDER + 6, pango_layout ) ;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog_Partition_Info::init_drawingarea( )
|
void Dialog_Partition_Info::init_drawingarea( )
|
||||||
{
|
{
|
||||||
drawingarea .set_size_request( 375, 50 ) ;
|
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) ) ;
|
||||||
|
|
||||||
|
@ -104,20 +102,25 @@ void Dialog_Partition_Info::init_drawingarea( )
|
||||||
|
|
||||||
//calculate proportional width of used and unused
|
//calculate proportional width of used and unused
|
||||||
used = unused = 0 ;
|
used = unused = 0 ;
|
||||||
used = Utils::Round( (375 - BORDER *2) / ( static_cast<double> (partition .sector_end - partition .sector_start) / partition .sectors_used ) ) ;
|
used = Utils::Round( (400 - BORDER *2) / ( static_cast<double>(partition .sector_end - partition .sector_start) / partition .sectors_used ) ) ;
|
||||||
unused = 375 - used - BORDER *2 ;
|
unused = 400 - used - BORDER *2 ;
|
||||||
|
|
||||||
//allocate some colors
|
//allocate some colors
|
||||||
color_used.set( "#F8F8BA" ); this ->get_colormap( ) ->alloc_color( color_used ) ;
|
color_used.set( "#F8F8BA" );
|
||||||
|
this ->get_colormap() ->alloc_color( color_used ) ;
|
||||||
|
|
||||||
partition .type == GParted::TYPE_EXTENDED ? color_unused .set( "darkgrey" ) : color_unused .set( "white" ) ;
|
color_unused .set( partition .type == GParted::TYPE_EXTENDED ? "darkgrey" : "white" ) ;
|
||||||
this ->get_colormap( ) ->alloc_color( color_unused ) ;
|
this ->get_colormap() ->alloc_color( color_unused ) ;
|
||||||
|
|
||||||
color_text .set( "black" ); this ->get_colormap( ) ->alloc_color( color_text ) ;
|
color_text .set( "black" );
|
||||||
color_partition = partition .color ; this ->get_colormap( ) ->alloc_color( color_partition ) ;
|
this ->get_colormap() ->alloc_color( color_text ) ;
|
||||||
|
|
||||||
|
color_partition = partition .color ;
|
||||||
|
this ->get_colormap() ->alloc_color( color_partition ) ;
|
||||||
|
|
||||||
//set text of pangolayout
|
//set text of pangolayout
|
||||||
pango_layout = drawingarea .create_pango_layout ( partition .partition + "\n" + String::ucompose( _("%1 MiB"), partition .Get_Length_MB( ) ) ) ;
|
pango_layout = drawingarea .create_pango_layout(
|
||||||
|
partition .partition + "\n" + Utils::format_size( partition .get_length() ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog_Partition_Info::Display_Info( )
|
void Dialog_Partition_Info::Display_Info( )
|
||||||
|
@ -186,8 +189,10 @@ void Dialog_Partition_Info::Display_Info( )
|
||||||
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
|
else if ( ! partition .mountpoint .empty() )
|
||||||
str_temp = String::ucompose( _("Mounted on %1"), partition .mountpoint ) ;
|
str_temp = String::ucompose( _("Mounted on %1"), partition .mountpoint ) ;
|
||||||
|
else
|
||||||
|
str_temp = _("Unable to find mountpoint") ;
|
||||||
}
|
}
|
||||||
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)" ) ;
|
||||||
|
|
|
@ -162,18 +162,37 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
|
||||||
|
|
||||||
void GParted_Core::init_maps()
|
void GParted_Core::init_maps()
|
||||||
{
|
{
|
||||||
|
std::string line ;
|
||||||
|
|
||||||
//initialize mountpoints..
|
//initialize mountpoints..
|
||||||
std::ifstream input( "/proc/mounts" ) ;
|
char node[255], mountpoint[255] ;
|
||||||
if ( input )
|
std::ifstream proc_mounts( "/proc/mounts" ) ;
|
||||||
|
if ( proc_mounts )
|
||||||
{
|
{
|
||||||
char node[255], mountpoint[255] ;
|
while ( getline( proc_mounts, line ) )
|
||||||
std::string line ;
|
if ( line .length() > 0 &&
|
||||||
|
line[ 0 ] == '/' &&
|
||||||
while ( getline( input, line ) )
|
sscanf( line .c_str(), "%s %s", node, mountpoint ) == 2 )
|
||||||
if ( line .length() > 0 && line[ 0 ] == '/' && sscanf( line .c_str(), "%s %s", node, mountpoint ) == 2 )
|
mount_info[ node ] = mountpoint ;
|
||||||
mount_info[ node ] = mountpoint ;
|
|
||||||
|
|
||||||
input .close() ;
|
proc_mounts .close() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
//above list lacks the root mountpoint, try to get it from /etc/mtab
|
||||||
|
std::ifstream etc_mtab( "/etc/mtab" ) ;
|
||||||
|
if ( etc_mtab )
|
||||||
|
{
|
||||||
|
while ( getline( etc_mtab, line ) )
|
||||||
|
if ( line .length() > 0 &&
|
||||||
|
line[ 0 ] == '/' &&
|
||||||
|
sscanf( line .c_str(), "%s %s", node, mountpoint ) == 2 &&
|
||||||
|
static_cast<Glib::ustring>( mountpoint ) == "/" )
|
||||||
|
{
|
||||||
|
mount_info[ node ] = mountpoint ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
etc_mtab .close() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize shortpaths...
|
//initialize shortpaths...
|
||||||
|
@ -181,7 +200,6 @@ void GParted_Core::init_maps()
|
||||||
if ( proc_partitions )
|
if ( proc_partitions )
|
||||||
{
|
{
|
||||||
char c_str[255] ;
|
char c_str[255] ;
|
||||||
std::string line ;
|
|
||||||
|
|
||||||
while ( getline( proc_partitions, line ) )
|
while ( getline( proc_partitions, line ) )
|
||||||
if ( sscanf( line .c_str(), "%*d %*d %*d %255s", c_str ) == 1 )
|
if ( sscanf( line .c_str(), "%*d %*d %*d %255s", c_str ) == 1 )
|
||||||
|
@ -342,8 +360,6 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
|
||||||
partitions[ t ] .mountpoint = iter ->second ;
|
partitions[ t ] .mountpoint = iter ->second ;
|
||||||
mount_info .erase( iter ) ;
|
mount_info .erase( iter ) ;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
partitions[ t ] .mountpoint = "/" ;
|
|
||||||
}
|
}
|
||||||
else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
|
||||||
set_mountpoints( partitions[ t ] .logicals ) ;
|
set_mountpoints( partitions[ t ] .logicals ) ;
|
||||||
|
|
Loading…
Reference in New Issue