added get_color_as_pixbuf() to create colored squares of custom sizes.

* include/Utils.h,
  src/Utils.cc: added get_color_as_pixbuf() to create colored squares
  of custom sizes. These can be use troughout the app to represent
  filesystems. e.g. in the treeview and convertmenu.
* include/TreeView_Detail.h,
  src/TreeView_Detail.cc,
  include/VBox_VisualDisk.h,
  src/VBox_VisualDisk.cc,
  include/Win_GParted.h,
  src/Win_GParted.cc: use Utils::get_color_as_pixbuf() instead of
  custom drawn widgets.
This commit is contained in:
Bart Hakvoort 2005-12-15 15:10:34 +00:00
parent 0f4155c498
commit 9564cf841b
9 changed files with 109 additions and 79 deletions

View File

@ -1,3 +1,17 @@
2005-12-15 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Utils.h,
src/Utils.cc: added get_color_as_pixbuf() to create colored squares
of custom sizes. These can be use troughout the app to represent
filesystems. e.g. in the treeview and convertmenu.
* include/TreeView_Detail.h,
src/TreeView_Detail.cc,
include/VBox_VisualDisk.h,
src/VBox_VisualDisk.cc,
include/Win_GParted.h,
src/Win_GParted.cc: use Utils::get_color_as_pixbuf() instead of
custom drawn widgets.
2005-12-14 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/FileSystem.h,

View File

@ -59,19 +59,22 @@ private:
struct treeview_detail_Columns : public Gtk::TreeModelColumnRecord
{
Gtk::TreeModelColumn<Glib::ustring> partition;
Gtk::TreeModelColumn<Glib::ustring> type;
Gtk::TreeModelColumn<Glib::ustring> type_square;
Gtk::TreeModelColumn<Glib::ustring> filesystem;
Gtk::TreeModelColumn<Glib::ustring> size;
Gtk::TreeModelColumn<Glib::ustring> used;
Gtk::TreeModelColumn<Glib::ustring> unused;
Gtk::TreeModelColumn<Glib::ustring> color;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > color;
Gtk::TreeModelColumn<Glib::ustring> text_color;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > status_icon;
Gtk::TreeModelColumn<Glib::ustring> flags;
Gtk::TreeModelColumn<Partition> partition_struct; //hidden column ( see also on_button_press_event )
treeview_detail_Columns( ) {
add( partition ); add( type ); add( type_square ); add( size ); add( used ); add( unused ); add( color ); add( text_color ); add( status_icon ); add( flags ); add(partition_struct);
treeview_detail_Columns( )
{
add( partition ); add( filesystem );
add( size ); add( used ); add( unused );
add( color ); add( text_color ); add( status_icon );
add( flags ); add(partition_struct);
}
};

View File

@ -45,6 +45,7 @@ enum FILESYSTEM
FS_UNKNOWN = 1,
FS_UNFORMATTED = 2,
FS_EXTENDED = 3,
FS_EXT2 = 4,
FS_EXT3 = 5,
FS_LINUX_SWAP = 6,
@ -57,7 +58,10 @@ enum FILESYSTEM
FS_JFS = 13,
FS_HFS = 14,
FS_HFSPLUS = 15,
FS_UFS = 16
FS_UFS = 16,
FS_USED = 17,
FS_UNUSED = 18
};
//struct to store filesysteminformation
@ -101,6 +105,7 @@ public:
const Glib::ustring & text_color = "black" ) ;
static Glib::ustring num_to_str( Sector number, bool use_C_locale = false ) ;
static Glib::ustring Get_Color( FILESYSTEM filesystem ) ;
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ;
static Glib::ustring Get_Filesystem_String( FILESYSTEM filesystem ) ;
static bool mount( const Glib::ustring & node,
const Glib::ustring & mountpoint,

View File

@ -27,6 +27,7 @@
#include <gtkmm/tooltips.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/image.h>
#define BORDER 8
@ -80,6 +81,7 @@ private:
Gtk::HBox hbox_disk_main, *hbox_disk, *hbox_extended, hbox_legend_main, *hbox_legend;
Gtk::CheckButton checkbutton_filesystem;
Gtk::Tooltips tooltips;
Gtk::Image *image ;
Visual_Partition *visual_partition;
std::vector <Visual_Partition *> visual_partitions;

View File

@ -173,11 +173,8 @@ private:
Gtk::Button *button;
Gtk::Table *table ;
Gtk::MenuItem *menu_item;
Gtk::Entry *entry;
Gtk::ProgressBar *pulsebar ;
Gdk::Color color ;
VBox_VisualDisk *vbox_visual_disk;
TreeView_Detail treeview_detail;

View File

@ -29,7 +29,7 @@ TreeView_Detail::TreeView_Detail( )
//append columns
this->append_column( _("Partition"), treeview_detail_columns .partition );
this->append_column( _("Filesystem"), treeview_detail_columns.type_square );
this->append_column( _("Filesystem"), treeview_detail_columns .color );
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 );
@ -39,35 +39,21 @@ TreeView_Detail::TreeView_Detail( )
//status_icon
this ->get_column( 0 ) ->pack_start( treeview_detail_columns.status_icon, false );
//colored text in Partition column (used for darkgrey unallocated)
//filesystem text
this ->get_column( 1 ) ->pack_start( treeview_detail_columns .filesystem, true );
//colored text in Partition column
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 Filesystem column
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 Filesystem column
this ->get_column( 1 ) ->pack_start( treeview_detail_columns .type, true );
//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 );
//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;
}
dynamic_cast<Gtk::CellRendererText*>( this ->get_column( t ) ->get_first_cell_renderer() ) ->property_xalign() = 1 ;
}
void TreeView_Detail::Load_Partitions( const std::vector<Partition> & partitions )
@ -144,11 +130,10 @@ void TreeView_Detail::Create_Row( const Gtk::TreeRow & treerow, const Partition
treerow[ treeview_detail_columns .status_icon ] = render_icon( Gtk::Stock::DIALOG_WARNING, Gtk::ICON_SIZE_BUTTON );
treerow[ treeview_detail_columns .partition ] = partition .partition;
treerow[ treeview_detail_columns .color ] = Utils::Get_Color( partition .filesystem ) ;
treerow[ treeview_detail_columns .color ] = Utils::get_color_as_pixbuf( partition .filesystem, 16, 16 ) ;
treerow[ treeview_detail_columns .text_color ] = ( partition .type == GParted::TYPE_UNALLOCATED ) ? "darkgrey" : "black" ;
treerow[ treeview_detail_columns .type ] = Utils::Get_Filesystem_String( partition .filesystem ) ;
treerow[ treeview_detail_columns .type_square ] = "██" ;
treerow[ treeview_detail_columns .filesystem ] = Utils::Get_Filesystem_String( partition .filesystem ) ;
//size
treerow[ treeview_detail_columns .size ] = Utils::num_to_str( partition .Get_Length_MB( ) ) ;

View File

@ -68,14 +68,14 @@ Glib::ustring Utils::Get_Color( FILESYSTEM filesystem )
{
switch( filesystem )
{
case FS_UNALLOCATED : return "darkgrey" ;
case FS_UNKNOWN : return "black" ;
case FS_UNFORMATTED : return "black" ;
case FS_UNALLOCATED : return "#A9A9A9" ;
case FS_UNKNOWN : return "#000000" ;
case FS_UNFORMATTED : return "#000000" ;
case FS_EXTENDED : return "#7DFCFE" ;
case FS_EXT2 : return "#9DB8D2" ;
case FS_EXT3 : return "#7590AE" ;
case FS_LINUX_SWAP : return "#C1665A" ;
case FS_FAT16 : return "green" ;
case FS_FAT16 : return "#00FF00" ;
case FS_FAT32 : return "#18D918" ;
case FS_NTFS : return "#42E5AC" ;
case FS_REISERFS : return "#ADA7C8" ;
@ -85,11 +85,29 @@ Glib::ustring Utils::Get_Color( FILESYSTEM filesystem )
case FS_HFS : return "#E0B6AF" ;
case FS_HFSPLUS : return "#C0A39E" ;
case FS_UFS : return "#D1940C" ;
case FS_USED : return "#F8F8BA" ;
case FS_UNUSED : return "#FFFFFF" ;
default : return "black" ;
default : return "#000000" ;
}
}
Glib::RefPtr<Gdk::Pixbuf> Utils::get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height )
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create( Gdk::COLORSPACE_RGB, false, 8, width, height ) ;
if ( pixbuf )
{
std::stringstream hex( Get_Color( filesystem ) .substr( 1 ) + "00" ) ;
unsigned long dec ;
hex >> std::hex >> dec ;
pixbuf ->fill( dec ) ;
}
return pixbuf ;
}
Glib::ustring Utils::Get_Filesystem_String( FILESYSTEM filesystem )
{
switch( filesystem )
@ -111,6 +129,8 @@ Glib::ustring Utils::Get_Filesystem_String( FILESYSTEM filesystem )
case FS_HFS : return "hfs" ;
case FS_HFSPLUS : return "hfs+" ;
case FS_UFS : return "ufs" ;
case FS_USED : return _("used") ;
case FS_UNUSED : return _("unused") ;
default : return "" ;
}

View File

@ -200,6 +200,7 @@ void VBox_VisualDisk::Build_Legend( )
Prepare_Legend( legend, partitions ) ;
bool hide_used_unused = true;
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
for ( unsigned int t = 0 ; t < legend .size( ) ; t++ )
{
if ( legend[ t ] != GParted::FS_UNALLOCATED && legend[ t ] != GParted::FS_EXTENDED && legend[ t ] != GParted::FS_LINUX_SWAP )
@ -207,19 +208,14 @@ void VBox_VisualDisk::Build_Legend( )
if ( t )
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
else
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( legend[ t ], 16, 16 ) ) ) ;
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( "██ ", false, false, false, Utils::Get_Color( legend[ t ] ) ), Gtk::PACK_SHRINK );
if ( legend[ t ] == GParted::FS_UNALLOCATED )
{
str_temp = Utils::Get_Filesystem_String( GParted::FS_UNALLOCATED ) ;//_("unallocated") ;
hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK );
}
else
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( legend[ t ] ) + " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( legend[ t ] ) ), Gtk::PACK_SHRINK );
}
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
//if there are any partitions add used/unused
if ( ! hide_used_unused )
@ -231,12 +227,24 @@ void VBox_VisualDisk::Build_Legend( )
hbox_legend ->set_border_width( 2 ) ;
frame_disk_legend ->add( *hbox_legend );
hbox_legend ->pack_start( * Utils::mk_label( " ██ ", false, false, false, "#F8F8BA" ), Gtk::PACK_SHRINK );
str_temp = _("used") ;
hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( "██ ", false, false, false, "white" ), Gtk::PACK_SHRINK );
str_temp = _("unused") ;
hbox_legend ->pack_start( * Utils::mk_label( str_temp + " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
//used
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( GParted::FS_USED, 16, 16 ) ) ) ;
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( GParted::FS_USED ) ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
//unused
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( GParted::FS_UNUSED, 16, 16 ) ) ) ;
hbox_legend ->pack_start( *image, Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( Utils::Get_Filesystem_String( GParted::FS_UNUSED ) ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK );
}
}

View File

@ -197,15 +197,11 @@ void Win_GParted::init_convert_menu()
{
for ( unsigned int t=0; t < gparted_core .get_filesystems( ) .size( ) -1 ; t++ )
{
color .set( Utils::Get_Color( gparted_core .get_filesystems( )[ t ] .filesystem ) );
hbox = manage( new Gtk::HBox( ) );
//the colored square
entry = manage ( new Gtk::Entry( ) );
entry ->set_sensitive( false );
entry ->set_size_request( 12, 12 );
entry ->modify_base( entry ->get_state( ), color );
hbox ->pack_start( *entry, Gtk::PACK_SHRINK );
image = manage( new Gtk::Image( Utils::get_color_as_pixbuf( gparted_core .get_filesystems()[ t ] .filesystem, 16, 16 ) ) ) ;
hbox ->pack_start( *image, Gtk::PACK_SHRINK );
//the label...
hbox ->pack_start( * Utils::mk_label( " " + Utils::Get_Filesystem_String( gparted_core .get_filesystems( )[ t ] .filesystem ) ), Gtk::PACK_SHRINK );