2004-09-19 14:24:53 -06:00
|
|
|
/* Copyright (C) 2004 Bart
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../include/Dialog_Partition_Info.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition )
|
|
|
|
{
|
|
|
|
this -> partition = partition ;
|
|
|
|
|
|
|
|
this->set_resizable( false );
|
|
|
|
|
|
|
|
/*TO TRANSLATORS: dialogtitle, looks like Information about /dev/hda3 */
|
2004-09-24 19:10:21 -06:00
|
|
|
this->set_title( String::ucompose( _( "Information about %1"), partition.partition ) );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
init_drawingarea() ;
|
|
|
|
|
|
|
|
//add label for detail and fill with relevant info
|
|
|
|
Display_Info() ;
|
|
|
|
|
|
|
|
//display error (if any)
|
|
|
|
if ( partition .error != "" )
|
|
|
|
{
|
|
|
|
frame = manage( new Gtk::Frame() );
|
|
|
|
frame ->set_border_width( 10 );
|
|
|
|
|
|
|
|
image = manage( new Gtk::Image( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON ) );
|
|
|
|
label = manage( new Gtk::Label( ) ) ;
|
2004-09-24 19:10:21 -06:00
|
|
|
label ->set_markup( "<b> " + (Glib::ustring) _( "Libparted message:" ) + " </b>" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
hbox = manage( new Gtk::HBox() );
|
|
|
|
hbox ->pack_start( *image, Gtk::PACK_SHRINK ) ;
|
|
|
|
hbox ->pack_start( *label, Gtk::PACK_SHRINK ) ;
|
|
|
|
|
|
|
|
frame ->set_label_widget( *hbox ) ;
|
|
|
|
|
|
|
|
label = manage( new Gtk::Label( ) ) ;
|
|
|
|
label ->set_markup( "<i>" + partition.error + "</i>") ;
|
|
|
|
label ->set_selectable( true ) ;
|
|
|
|
label ->set_line_wrap( true ) ;
|
|
|
|
frame ->add( *label );
|
|
|
|
|
|
|
|
this ->get_vbox() ->pack_start( *frame, Gtk::PACK_SHRINK ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->add_button( Gtk::Stock::CLOSE, Gtk::RESPONSE_OK );
|
|
|
|
this->show_all_children();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_Partition_Info::drawingarea_on_realize( )
|
|
|
|
{
|
|
|
|
gc = Gdk::GC::create( drawingarea .get_window() );
|
|
|
|
|
|
|
|
drawingarea .get_window() ->set_background( color_partition );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Dialog_Partition_Info::drawingarea_on_expose( GdkEventExpose *ev )
|
|
|
|
{
|
|
|
|
if ( partition.type != GParted::UNALLOCATED )
|
|
|
|
{
|
|
|
|
//used
|
|
|
|
gc ->set_foreground( color_used );
|
|
|
|
drawingarea .get_window() ->draw_rectangle( gc, true, BORDER, BORDER, used ,34 );
|
|
|
|
|
|
|
|
//unused
|
|
|
|
gc ->set_foreground( color_unused );
|
|
|
|
drawingarea .get_window() ->draw_rectangle( gc, true, BORDER + used, BORDER, unused,34 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//text
|
|
|
|
gc ->set_foreground( color_text );
|
|
|
|
drawingarea .get_window() ->draw_layout( gc, BORDER +5, BORDER +1 , pango_layout ) ;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_Partition_Info::init_drawingarea()
|
|
|
|
{
|
|
|
|
drawingarea .set_size_request( 375, 50 ) ;
|
|
|
|
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) ) ;
|
|
|
|
|
|
|
|
frame = manage( new Gtk::Frame() );
|
|
|
|
frame ->add ( drawingarea ) ;
|
|
|
|
|
|
|
|
frame ->set_shadow_type(Gtk::SHADOW_ETCHED_OUT);
|
|
|
|
frame ->set_border_width( 10 );
|
|
|
|
hbox = manage( new Gtk::HBox() ) ;
|
|
|
|
hbox ->pack_start( *frame, Gtk::PACK_EXPAND_PADDING ) ;
|
|
|
|
|
|
|
|
this ->get_vbox() ->pack_start( *hbox, Gtk::PACK_SHRINK ) ;
|
|
|
|
|
|
|
|
//calculate proportional width of used and unused
|
|
|
|
used = unused = 0 ;
|
2004-10-02 03:39:16 -06:00
|
|
|
used = (int) ( ( (375 - BORDER *2) / ( (double) (partition.sector_end - partition.sector_start) / partition.sectors_used ) )+0.5 ) ;
|
|
|
|
unused = 375 - used - (BORDER *2) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//allocate some colors
|
2004-10-01 15:09:19 -06:00
|
|
|
color_used.set( "#F8F8BA" ); this ->get_colormap() ->alloc_color( color_used ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-10-02 03:39:16 -06:00
|
|
|
partition .type == GParted::EXTENDED ? color_unused.set( "darkgrey" ) : color_unused.set( "white" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
this ->get_colormap() ->alloc_color( color_unused ) ;
|
|
|
|
|
2004-10-01 15:09:19 -06:00
|
|
|
color_text.set( "black" ); this ->get_colormap() ->alloc_color( color_text ) ;
|
|
|
|
color_partition = partition.color ; this ->get_colormap() ->alloc_color( color_partition ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//set text of pangolayout
|
2004-10-02 03:39:16 -06:00
|
|
|
pango_layout = drawingarea .create_pango_layout ( partition .partition + "\n" + String::ucompose( _("%1 MB"), partition .Get_Length_MB() ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_Partition_Info::Display_Info()
|
|
|
|
{
|
2004-09-28 15:12:20 -06:00
|
|
|
int top =0, bottom = 1;
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
table = manage( new Gtk::Table() ) ;
|
|
|
|
table ->set_border_width( 5 ) ;
|
|
|
|
table ->set_col_spacings(10 ) ;
|
|
|
|
this ->get_vbox() ->pack_start( *table , Gtk::PACK_SHRINK ) ;
|
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//filesystem
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Filesystem:" ) + "</b>" ) , 0,1,top, bottom ,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( partition .filesystem ), 1,2, top++, bottom++, Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//size
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Size:" ) + "</b>" ), 0,1,top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Length_MB() ) ) , 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
if ( partition.sectors_used != -1 )
|
2004-09-28 15:12:20 -06:00
|
|
|
{
|
|
|
|
//calculate relative diskusage
|
2004-10-02 03:39:16 -06:00
|
|
|
int percent_used = (int) ( (double) partition.Get_Used_MB() / partition .Get_Length_MB() *100 +0.5 ) ;
|
2004-09-28 15:12:20 -06:00
|
|
|
|
|
|
|
//used
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Used:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Used_MB() ) ) , 1,2, top, bottom,Gtk::FILL);
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( "\t\t\t( " + num_to_str( percent_used ) + "% )"), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-28 15:12:20 -06:00
|
|
|
|
|
|
|
//unused
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Unused:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( String::ucompose( _("%1 MB"), this ->partition .Get_Unused_MB() ) ) , 1,2, top, bottom,Gtk::FILL);
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( "\t\t\t( " + num_to_str( 100 - percent_used ) + "% )"), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//flags
|
|
|
|
if ( partition.type != GParted::UNALLOCATED )
|
|
|
|
{
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Flags:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( partition .flags ), 1,2, top++, bottom++,Gtk::FILL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//one blank line
|
|
|
|
table ->attach( * mk_label( "" ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
if ( partition.type != GParted::UNALLOCATED && partition .status != GParted::STAT_NEW )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-09-28 15:12:20 -06:00
|
|
|
//path
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Path:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( partition .partition ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//realpath (this sucks)
|
2004-09-19 14:24:53 -06:00
|
|
|
char real_path[4096] ;
|
|
|
|
realpath( partition.partition.c_str() , real_path );
|
|
|
|
|
|
|
|
//only show realpath if it's diffent from the short path...
|
|
|
|
if ( partition.partition != real_path )
|
|
|
|
{
|
2004-09-28 15:12:20 -06:00
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Real Path:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( real_path ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//status
|
2004-10-02 03:39:16 -06:00
|
|
|
Glib::ustring str_temp ;
|
2004-09-28 15:12:20 -06:00
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Status:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
if ( partition.busy )
|
2004-10-02 03:39:16 -06:00
|
|
|
str_temp = Find_Status() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
else if ( partition.type == GParted::EXTENDED )
|
2004-10-02 03:39:16 -06:00
|
|
|
str_temp = _("Not busy (There are no mounted logical partitions)" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
else if ( partition.filesystem == "linux-swap" )
|
2004-10-02 03:39:16 -06:00
|
|
|
str_temp = _("Not active" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
else
|
2004-10-02 03:39:16 -06:00
|
|
|
str_temp = _("Not mounted" ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( str_temp ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-28 15:12:20 -06:00
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//one blank line
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//first sector
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "First Sector:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL);
|
|
|
|
table ->attach( * mk_label( num_to_str( partition.sector_start ) ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//last sector
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Last Sector:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( num_to_str( partition.sector_end ) ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
//total sectors
|
|
|
|
table ->attach( * mk_label( "<b>" + (Glib::ustring) _( "Total Sectors:" ) + "</b>" ), 0,1, top, bottom,Gtk::FILL);
|
2004-10-02 03:39:16 -06:00
|
|
|
table ->attach( * mk_label( num_to_str( partition.sector_end - partition.sector_start ) ), 1,2, top++, bottom++,Gtk::FILL);
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2004-10-02 03:39:16 -06:00
|
|
|
Glib::ustring Dialog_Partition_Info::Find_Status()
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
|
|
|
if ( partition.type == GParted::EXTENDED )
|
2004-10-02 03:39:16 -06:00
|
|
|
return _("Busy (At least one logical partition is mounted)" ) ;
|
|
|
|
else if ( partition.filesystem == "linux-swap" )
|
|
|
|
return _("Active") ;
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//try to find the mountpoint in /proc/mounts
|
|
|
|
//get realpath
|
|
|
|
char real_path[4096] ;
|
|
|
|
realpath( partition.partition.c_str() , real_path );
|
|
|
|
Glib::ustring mountpoint, partition_real_path = real_path ; //because root partition is listed as /dev/root we need te compare against te real path..
|
|
|
|
|
|
|
|
|
|
|
|
std::ifstream file_mounts( "/proc/mounts" ) ;
|
|
|
|
std::string line ;
|
|
|
|
|
|
|
|
while ( getline( file_mounts, line ) )
|
|
|
|
{
|
2004-10-02 03:39:16 -06:00
|
|
|
realpath( line.substr( 0, line.find( ' ' ) ) .c_str(), real_path );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
if ( partition_real_path == real_path )
|
|
|
|
{
|
2004-10-02 03:39:16 -06:00
|
|
|
//this is so cool =)
|
|
|
|
mountpoint = line.substr( line.find( ' ' ) +1, line .length() ) ;
|
|
|
|
mountpoint = mountpoint .substr( 0, mountpoint .find( ' ' ) ) ;
|
2004-09-24 19:10:21 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
file_mounts .close() ;
|
|
|
|
|
|
|
|
//sometimes rootdevices are not listed as paths. I'll take a guess and just enter / here...( we'll look into this when complaints start coming in :P )
|
2004-10-02 03:39:16 -06:00
|
|
|
if ( mountpoint .empty() )
|
|
|
|
mountpoint = "/" ;
|
|
|
|
|
|
|
|
return String::ucompose( _("Mounted on %1"), mountpoint ) ;
|
|
|
|
|
2004-09-28 15:12:20 -06:00
|
|
|
}
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
Dialog_Partition_Info::~Dialog_Partition_Info()
|
|
|
|
{
|
|
|
|
this ->get_colormap() ->free_colors( color_used, 1 ) ;
|
|
|
|
this ->get_colormap() ->free_colors( color_unused, 1 ) ;
|
|
|
|
this ->get_colormap() ->free_colors( color_text, 1 ) ;
|
|
|
|
this ->get_colormap() ->free_colors( color_partition, 1 ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} //GParted
|