From 9564cf841be2ee0f02574e7ab4e797d0c9c2455b Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 15 Dec 2005 15:10:34 +0000 Subject: [PATCH] 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. --- ChangeLog | 14 +++++++++ include/TreeView_Detail.h | 17 ++++++----- include/Utils.h | 7 ++++- include/VBox_VisualDisk.h | 2 ++ include/Win_GParted.h | 3 -- src/TreeView_Detail.cc | 61 +++++++++++++++------------------------ src/Utils.cc | 30 +++++++++++++++---- src/VBox_VisualDisk.cc | 44 ++++++++++++++++------------ src/Win_GParted.cc | 10 ++----- 9 files changed, 109 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index b475c31a..2d47e34b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-12-15 Bart Hakvoort + + * 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 * include/FileSystem.h, diff --git a/include/TreeView_Detail.h b/include/TreeView_Detail.h index 79c0b514..cd1c693c 100644 --- a/include/TreeView_Detail.h +++ b/include/TreeView_Detail.h @@ -59,19 +59,22 @@ private: struct treeview_detail_Columns : public Gtk::TreeModelColumnRecord { Gtk::TreeModelColumn partition; - Gtk::TreeModelColumn type; - Gtk::TreeModelColumn type_square; + Gtk::TreeModelColumn filesystem; Gtk::TreeModelColumn size; Gtk::TreeModelColumn used; Gtk::TreeModelColumn unused; - Gtk::TreeModelColumn color; + Gtk::TreeModelColumn< Glib::RefPtr > color; Gtk::TreeModelColumn text_color; - Gtk::TreeModelColumn< Glib::RefPtr > status_icon; + Gtk::TreeModelColumn< Glib::RefPtr > status_icon; Gtk::TreeModelColumn flags; - Gtk::TreeModelColumn< Partition > partition_struct; //hidden column ( see also on_button_press_event ) + Gtk::TreeModelColumn 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); } }; diff --git a/include/Utils.h b/include/Utils.h index fe12262c..ddfcefd4 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -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 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, diff --git a/include/VBox_VisualDisk.h b/include/VBox_VisualDisk.h index 1191c0e2..1c10c396 100644 --- a/include/VBox_VisualDisk.h +++ b/include/VBox_VisualDisk.h @@ -27,6 +27,7 @@ #include #include #include +#include #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_partitions; diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 681b88f1..4b43e29f 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -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; diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index c4792d1f..88abc43d 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -23,51 +23,37 @@ 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(); + 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( _("Filesystem"), treeview_detail_columns.type_square ); - 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 ); - this->append_column( _("Flags"), treeview_detail_columns.flags ); + this->append_column( _("Partition"), treeview_detail_columns .partition ); + 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 ); + this->append_column( _("Flags"), treeview_detail_columns .flags ); //status_icon - this->get_column( 0 ) ->pack_start( treeview_detail_columns.status_icon, false ); + 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( 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( 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 renderers = this ->get_column( 1 ) ->get_cell_renderers( ) ; - - if ( renderers .front( ) != this ->get_column( 1 ) ->get_first_cell_renderer( ) ) - cell_renderer_text = dynamic_cast ( renderers .front( ) ) ; - else - cell_renderer_text = dynamic_cast ( renderers .back( ) ) ; - - this ->get_column( 1 ) ->add_attribute( cell_renderer_text ->property_foreground( ), treeview_detail_columns .text_color ); - + this->get_column( 0 ) ->add_attribute( cell_renderer_text ->property_foreground(), treeview_detail_columns .text_color ); + + //colored text in Filesystem column + std::vector renderers = this ->get_column( 1 ) ->get_cell_renderers() ; + cell_renderer_text = dynamic_cast( 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( this ->get_column( t ) ->get_first_cell_renderer( ) ); - cell_renderer_text ->property_xalign( ) = 1; - } - + dynamic_cast( this ->get_column( t ) ->get_first_cell_renderer() ) ->property_xalign() = 1 ; } void TreeView_Detail::Load_Partitions( const std::vector & 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( ) ) ; diff --git a/src/Utils.cc b/src/Utils.cc index 11fa242b..d3e2439a 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -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 Utils::get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) +{ + Glib::RefPtr 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 "" ; } diff --git a/src/VBox_VisualDisk.cc b/src/VBox_VisualDisk.cc index cb58f820..04274537 100644 --- a/src/VBox_VisualDisk.cc +++ b/src/VBox_VisualDisk.cc @@ -200,26 +200,22 @@ 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 ) hide_used_unused = false ; - + if ( t ) hbox_legend ->pack_start( * Utils::mk_label( " " ), Gtk::PACK_SHRINK ); - else - 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 ); + + 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 ); - 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 ); } } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 3d7f9f10..f597dcd3 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -197,16 +197,12 @@ 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 );