From b179990dc97c800567dd385aaffcfe992772012a Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Tue, 7 Mar 2006 11:55:27 +0000 Subject: [PATCH] show greyed-out mountpoint of unmounted partitions in the treeview as an * include/GParted_Core.h, include/TreeView_Detail.h, src/GParted_Core.cc, src/TreeView_Detail.cc: show greyed-out mountpoint of unmounted partitions in the treeview as an improved way to identify partitions. (#333027) * src/Win_GParted.cc: cleanups --- ChangeLog | 10 ++++++++++ include/GParted_Core.h | 4 +++- include/TreeView_Detail.h | 5 +++-- src/GParted_Core.cc | 39 ++++++++++++++++++++++++--------------- src/TreeView_Detail.cc | 18 +++++++++++++----- src/Win_GParted.cc | 33 +++++++++++++++++++-------------- 6 files changed, 72 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index f4fd3942..882ace15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-03-06 Bart Hakvoort + + * include/GParted_Core.h, + include/TreeView_Detail.h, + src/GParted_Core.cc, + src/TreeView_Detail.cc: show greyed-out mountpoint of unmounted + partitions in the treeview as an improved way to identify + partitions. (#333027) + * src/Win_GParted.cc: cleanups + 2006-03-06 Bart Hakvoort * include/TreeView_Detail.h, diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 7274ab91..0afc5d97 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -73,7 +73,8 @@ private: GParted::FILESYSTEM get_filesystem() ; bool check_device_path( const Glib::ustring & device_path ) ; void set_device_partitions( Device & device ) ; - void read_mountpoints_from_file( const Glib::ustring & filename ) ; + void read_mountpoints_from_file( const Glib::ustring & filename, + std::map< Glib::ustring, std::vector > & map ) ; void init_maps() ; void set_mountpoints( std::vector & partitions ) ; void set_short_paths( std::vector & partitions ) ; @@ -120,6 +121,7 @@ private: bool probe_devices ; std::map< Glib::ustring, std::vector > mount_info ; + std::map< Glib::ustring, std::vector > fstab_info ; std::map< Glib::ustring, Glib::ustring > short_paths ; std::map< Glib::ustring, Glib::ustring >::iterator iter ; std::map< Glib::ustring, std::vector >::iterator iter_mp ; diff --git a/include/TreeView_Detail.h b/include/TreeView_Detail.h index 08eb056a..b652b864 100644 --- a/include/TreeView_Detail.h +++ b/include/TreeView_Detail.h @@ -72,6 +72,7 @@ private: Gtk::TreeModelColumn unused; Gtk::TreeModelColumn< Glib::RefPtr > color; Gtk::TreeModelColumn text_color; + Gtk::TreeModelColumn mount_text_color; Gtk::TreeModelColumn< Glib::RefPtr > status_icon; Gtk::TreeModelColumn< Glib::RefPtr > error_icon; Gtk::TreeModelColumn flags; @@ -80,8 +81,8 @@ private: treeview_detail_Columns() { add( path ); add( filesystem ); add( mountpoint ) ; - add( size ); add( used ); add( unused ); - add( color ); add( text_color ); add( status_icon ); + add( size ); add( used ); add( unused ); add( color ); + add( text_color ); add( mount_text_color ); add( status_icon ); add( error_icon ) ; add( flags ); add( partition ); } }; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index e1cc1535..19f61e05 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -149,10 +149,7 @@ void GParted_Core::get_devices( std::vector & devices ) set_device_partitions( temp_device ) ; set_short_paths( temp_device .partitions ) ; - - if ( temp_device .highest_busy ) - set_mountpoints( temp_device .partitions ) ; - + set_mountpoints( temp_device .partitions ) ; set_used_sectors( temp_device .partitions ) ; if ( temp_device .highest_busy ) @@ -178,9 +175,11 @@ void GParted_Core::get_devices( std::vector & devices ) //clear leftover information... //NOTE that we cannot clear mountinfo since it might be needed in get_all_mountpoints() short_paths .clear() ; + fstab_info .clear() ; } -void GParted_Core::read_mountpoints_from_file( const Glib::ustring & filename ) +void GParted_Core::read_mountpoints_from_file( const Glib::ustring & filename, + std::map< Glib::ustring, std::vector > & map ) { std::string line ; char node[255], mountpoint[255] ; @@ -200,7 +199,7 @@ void GParted_Core::read_mountpoints_from_file( const Glib::ustring & filename ) if ( index < line .length() ) line .replace( index, 4, " " ) ; - mount_info[ node ] .push_back( line ) ; + map[ node ] .push_back( line ) ; } file .close() ; @@ -211,11 +210,13 @@ void GParted_Core::init_maps() { short_paths .clear() ; mount_info .clear() ; + fstab_info .clear() ; - read_mountpoints_from_file( "/proc/mounts" ) ; - read_mountpoints_from_file( "/etc/mtab" ) ; + read_mountpoints_from_file( "/proc/mounts", mount_info ) ; + read_mountpoints_from_file( "/etc/mtab", mount_info ) ; + read_mountpoints_from_file( "/etc/fstab", fstab_info ) ; - //sort the mountpoints and remove duplicates.. + //sort the mountpoints and remove duplicates.. (no need to do this for fstab_info) for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp ) { std::sort( iter_mp ->second .begin(), iter_mp ->second .end() ) ; @@ -382,9 +383,11 @@ void GParted_Core::set_mountpoints( std::vector & partitions ) { for ( unsigned int t = 0 ; t < partitions .size() ; t++ ) { - if ( partitions[ t ] .busy && partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP ) + if ( ( partitions[ t ] .type == GParted::TYPE_PRIMARY || + partitions[ t ] .type == GParted::TYPE_LOGICAL ) && + partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP ) { - if ( partitions[ t ] .type == GParted::TYPE_PRIMARY || partitions[ t ] .type == GParted::TYPE_LOGICAL ) + if ( partitions[ t ] .busy ) { iter_mp = mount_info .find( partitions[ t ] .partition ); if ( iter_mp != mount_info .end() ) @@ -392,9 +395,15 @@ void GParted_Core::set_mountpoints( std::vector & partitions ) else partitions[ t ] .error = _("Unable to find mountpoint") ; } - else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) - set_mountpoints( partitions[ t ] .logicals ) ; + else + { + iter_mp = fstab_info .find( partitions[ t ] .partition ); + if ( iter_mp != fstab_info .end() ) + partitions[ t ] .mountpoints = iter_mp ->second ; + } } + else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) + set_mountpoints( partitions[ t ] .logicals ) ; } } @@ -440,11 +449,11 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) { if ( partitions[ t ] .mountpoints .size() > 0 ) { - if ( statvfs( partitions[ t ] .mountpoints .back() .c_str(), &sfs ) == 0 ) + if ( statvfs( partitions[ t ] .mountpoints .front() .c_str(), &sfs ) == 0 ) partitions[ t ] .Set_Unused( sfs .f_bfree * (sfs .f_bsize / 512) ) ; else partitions[ t ] .error = - "statvfs (" + partitions[ t ] .mountpoints .back() + "): " + Glib::strerror( errno ); + "statvfs (" + partitions[ t ] .mountpoints .front() + "): " + Glib::strerror( errno ); } } else diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index c4d85b56..5018cac1 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -43,15 +43,17 @@ TreeView_Detail::TreeView_Detail() get_column( 0 ) ->pack_start( treeview_detail_columns .error_icon, false ); get_column( 0 ) ->pack_start( treeview_detail_columns .status_icon, false ); - //filesystem text - get_column( 1 ) ->pack_start( treeview_detail_columns .filesystem, true ); - + //PARTITION //colored text in Partition column Gtk::CellRendererText *cell_renderer_text = dynamic_cast( get_column( 0 ) ->get_first_cell_renderer() ); get_column( 0 ) ->add_attribute( cell_renderer_text ->property_foreground(), treeview_detail_columns .text_color ); + //FILESYSTEM + //filesystem text + get_column( 1 ) ->pack_start( treeview_detail_columns .filesystem, true ); + //colored text in Filesystem column std::vector renderers = get_column( 1 ) ->get_cell_renderers() ; cell_renderer_text = dynamic_cast( renderers .back() ) ; @@ -61,6 +63,12 @@ TreeView_Detail::TreeView_Detail() //pixbuf and text are both left aligned get_column( 1 ) ->get_first_cell_renderer() ->property_xalign() = Gtk::ALIGN_LEFT ; cell_renderer_text ->property_xalign() = Gtk::ALIGN_LEFT ; + + //MOUNTPOINT + //colored text in mountpoint column + cell_renderer_text = dynamic_cast( get_column( 2 ) ->get_first_cell_renderer() ); + get_column( 2 ) ->add_attribute( cell_renderer_text ->property_foreground(), + treeview_detail_columns .mount_text_color ); //set alignment of numeric columns to right for( short t = 3 ; t < 6 ; t++ ) @@ -163,8 +171,8 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition Utils::Get_Filesystem_String( partition .filesystem ) ; //mountpoint - treerow[ treeview_detail_columns .mountpoint ] = - Glib::build_path( ", ", partition .mountpoints ) ; + treerow[ treeview_detail_columns .mount_text_color ] = partition .busy ? "black" : "darkgrey" ; + treerow[ treeview_detail_columns .mountpoint ] = Glib::build_path( ", ", partition .mountpoints ) ; //size treerow[ treeview_detail_columns .size ] = Utils::format_size( partition .get_length() ) ; diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 5a23fbbb..e9f8dc97 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -69,9 +69,12 @@ Win_GParted::Win_GParted( const std::vector & user_devices ) vbox_main.pack_start( hbox_toolbar, Gtk::PACK_SHRINK ); //frame_visualdisk... ( contains the visual represenation of the disks ) - frame_visualdisk .signal_partition_selected .connect( sigc::mem_fun( this, &Win_GParted::on_partition_selected ) ) ; - frame_visualdisk .signal_partition_activated .connect( sigc::mem_fun( this, &Win_GParted::on_partition_activated ) ) ; - frame_visualdisk .signal_popup_menu .connect( sigc::mem_fun( this, &Win_GParted::on_partition_popup_menu ) ); + frame_visualdisk .signal_partition_selected .connect( + sigc::mem_fun( this, &Win_GParted::on_partition_selected ) ) ; + frame_visualdisk .signal_partition_activated .connect( + sigc::mem_fun( this, &Win_GParted::on_partition_activated ) ) ; + frame_visualdisk .signal_popup_menu .connect( + sigc::mem_fun( this, &Win_GParted::on_partition_popup_menu ) ); vbox_main .pack_start( frame_visualdisk, Gtk::PACK_SHRINK ) ; //hpaned_main (NOTE: added to vpaned_main) @@ -1113,38 +1116,39 @@ void Win_GParted::activate_resize() dialog .set_transient_for( *this ) ; - if ( dialog .run( ) == Gtk::RESPONSE_OK ) + if ( dialog .run() == Gtk::RESPONSE_OK ) { - dialog .hide( ) ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) + dialog .hide() ; - //if selected_partition is NEW we simply remove the NEW operation from the list and add it again with the new size and position ( unless it's an EXTENDED ) - if ( selected_partition .status == GParted::STAT_NEW && selected_partition.type != GParted::TYPE_EXTENDED ) + //if selected_partition is NEW we simply remove the NEW operation from the list and add + //it again with the new size and position ( unless it's an EXTENDED ) + if ( selected_partition .status == GParted::STAT_NEW && selected_partition .type != GParted::TYPE_EXTENDED ) { //remove operation which creates this partition - for ( unsigned int t = 0 ; t < operations .size( ) ; t++ ) + for ( unsigned int t = 0 ; t < operations .size() ; t++ ) { if ( operations[ t ] .partition_new .partition == selected_partition .partition ) { - operations.erase( operations .begin( ) + t ) ; + operations.erase( operations .begin() + t ) ; //And add the new partition to the end of the operations list - Add_Operation( GParted::CREATE, dialog .Get_New_Partition( ) ); + Add_Operation( GParted::CREATE, dialog .Get_New_Partition() ); break; } } } else//normal move/resize on existing partition - Add_Operation( GParted::RESIZE_MOVE, dialog .Get_New_Partition( ) ); + Add_Operation( GParted::RESIZE_MOVE, dialog .Get_New_Partition() ); } } -void Win_GParted::activate_copy( ) +void Win_GParted::activate_copy() { copied_partition = selected_partition ; } -void Win_GParted::activate_paste( ) +void Win_GParted::activate_paste() { if ( ! max_amount_prim_reached() ) { @@ -1184,7 +1188,8 @@ void Win_GParted::activate_new() if ( dialog .run() == Gtk::RESPONSE_OK ) { - dialog .hide() ;//make sure the dialog is gone _before_ operationslist shows up (only matters if first operation) + dialog .hide() ; + new_count++ ; Add_Operation( GParted::CREATE, dialog .Get_New_Partition() ); }