gparted/src/TreeView_Detail.cc

189 lines
6.8 KiB
C++
Raw Normal View History

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/TreeView_Detail.h"
namespace GParted
{
TreeView_Detail::TreeView_Detail( )
{
treestore_detail = Gtk::TreeStore::create( treeview_detail_columns );
this->set_model( treestore_detail );
this->set_rules_hint(true);
this->treeselection = this->get_selection();
//append columns
this->append_column( _("Partition"), treeview_detail_columns.partition );
this->append_column( _("Type"), treeview_detail_columns.type_square );
2004-10-01 11:28:20 -06:00
this->append_column( _("Size(MB)"), treeview_detail_columns.size );
this->append_column( _("Used(MB)"), treeview_detail_columns.used );
this->append_column( _("Unused(MB)"), treeview_detail_columns.unused );
2004-09-19 14:24:53 -06:00
this->append_column( _("Flags"), treeview_detail_columns.flags );
2004-09-19 14:24:53 -06:00
//status_icon
this->get_column( 0 ) ->pack_start( treeview_detail_columns.status_icon,false );
//colored text in Partition column (used for darkgrey unallocated)
Gtk::CellRendererText *cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( this->get_column( 0 ) ->get_first_cell_renderer() );
this->get_column( 0 ) ->add_attribute(cell_renderer_text->property_foreground(), treeview_detail_columns.text_color);
//colored square in Type column
2004-09-19 14:24:53 -06:00
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( this->get_column( 1 ) ->get_first_cell_renderer() );
this->get_column( 1 ) ->add_attribute(cell_renderer_text->property_foreground(), treeview_detail_columns. color);
//colored text in Type column
this->get_column( 1 ) ->pack_start( treeview_detail_columns .type, false );
//this sucks :) get_cell_renderers doesn't return them in some order, so i have to check manually...
std::vector <Gtk::CellRenderer *> renderers = this->get_column( 1 ) ->get_cell_renderers( ) ;
if ( renderers .front() != this->get_column( 1 ) ->get_first_cell_renderer() )
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( renderers .front() ) ;
else
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( renderers .back() ) ;
this->get_column( 1 ) ->add_attribute(cell_renderer_text->property_foreground(), treeview_detail_columns. text_color);
2004-09-19 14:24:53 -06:00
//set alignment of numeric columns to right
for( short t=2;t<5;t++)
{
cell_renderer_text = dynamic_cast<Gtk::CellRendererText*>( this->get_column( t ) ->get_first_cell_renderer() );
cell_renderer_text->property_xalign () = 1;
}
}
void TreeView_Detail::Load_Partitions( const std::vector<Partition> & partitions )
2004-09-19 14:24:53 -06:00
{
treestore_detail ->clear( ) ;
2004-09-19 14:24:53 -06:00
for ( unsigned int i = 0 ; i < partitions .size( ) ; i++ )
{
row = *( treestore_detail ->append( ) );
Create_Row( row, partitions[ i ] );
if ( partitions[ i ] .type == GParted::EXTENDED )
{
for ( unsigned int t = 0 ; t < partitions[ i ] .logicals .size( ) ; t++ )
{
childrow = *( treestore_detail ->append( row.children( ) ) );
Create_Row( childrow, partitions[ i ] .logicals[ t ] );
}
}
}
2004-09-19 14:24:53 -06:00
//show logical partitions ( if any )
this ->expand_all( );
2004-09-19 14:24:53 -06:00
}
void TreeView_Detail::Set_Selected( const Partition & partition )
{
//look for appropiate row
for( iter = treestore_detail ->children( ) .begin( ) ; iter != treestore_detail ->children( ) .end( ) ; iter++ )
2004-09-19 14:24:53 -06:00
{
row = *iter;
partition_temp = row[ treeview_detail_columns.partition_struct ] ;
2004-09-19 14:24:53 -06:00
//primary's
if ( partition .sector_start >= partition_temp .sector_start &&
partition .sector_end <=partition_temp .sector_end &&
partition.inside_extended == partition_temp.inside_extended )
{
this ->set_cursor( (Gtk::TreePath) row );
return;
}
2004-09-19 14:24:53 -06:00
//logicals
if ( row .children( ) .size( ) > 0 ) //this is the row with the extended partition, search it's childrows...
2004-09-19 14:24:53 -06:00
{
for( iter_child = row .children( ) .begin( ) ; iter_child != row.children( ) .end( ) ; iter_child++ )
2004-09-19 14:24:53 -06:00
{
childrow = *iter_child;
partition_temp = childrow[ treeview_detail_columns.partition_struct ] ;
2004-09-19 14:24:53 -06:00
if ( partition .sector_start >= partition_temp .sector_start && partition .sector_end <= partition_temp .sector_end )
2004-09-19 14:24:53 -06:00
{
this ->expand_all( );
this ->set_cursor( (Gtk::TreePath) childrow );
2004-09-19 14:24:53 -06:00
return;
}
}
}
}
}
void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, const Partition & partition )
2004-09-19 14:24:53 -06:00
{
//hereby i assume these 2 are mutual exclusive. is this wise?? Time (and bugreports) will tell :)
if ( partition .busy )
treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON );
else if ( partition .filesystem == "unknown" || partition .error != "" )
treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON );
2004-09-19 14:24:53 -06:00
treerow[ treeview_detail_columns .partition ] = partition .partition;
treerow[ treeview_detail_columns .color ] = Get_Color( partition .filesystem ) ;
2004-09-19 14:24:53 -06:00
treerow[ treeview_detail_columns .text_color ] = ( partition .type == GParted::UNALLOCATED ) ? "darkgrey" : "black" ;
treerow[ treeview_detail_columns .type ] = partition .filesystem ;
treerow[ treeview_detail_columns .type_square ] = "██" ;
2004-09-19 14:24:53 -06:00
//size
treerow[ treeview_detail_columns .size ] = num_to_str( partition .Get_Length_MB( ) ) ;
2004-09-19 14:24:53 -06:00
//used
if ( partition .sectors_used != -1 )
treerow[ treeview_detail_columns .used ] = num_to_str( partition .Get_Used_MB( ) ) ;
else
treerow[ treeview_detail_columns .used ] = "---" ;
2004-09-19 14:24:53 -06:00
//unused
if ( partition .sectors_unused != -1 )
treerow[ treeview_detail_columns .unused ] = num_to_str( partition .Get_Unused_MB( ) ) ;
else
treerow[ treeview_detail_columns .unused ] = "---" ;
2004-09-19 14:24:53 -06:00
//flags
treerow[ treeview_detail_columns .flags ] = " " + partition .flags ;
2004-09-19 14:24:53 -06:00
//hidden column (partition object)
treerow[ treeview_detail_columns .partition_struct ] = partition;
2004-09-19 14:24:53 -06:00
}
bool TreeView_Detail::on_button_press_event( GdkEventButton* event )
2004-09-19 14:24:53 -06:00
{
//Call base class, to allow normal handling,
bool return_value = TreeView::on_button_press_event( event );
2004-09-19 14:24:53 -06:00
iter = treeselection ->get_selected( );
2004-09-19 14:24:53 -06:00
if ( *iter != 0 )
{
row = *iter;
signal_mouse_click .emit( event, row[ treeview_detail_columns .partition_struct ] );
2004-09-19 14:24:53 -06:00
}
return return_value;
}
} //GParted