From 170a79b3a08cbcd20415ea02d12a3995539ed9e8 Mon Sep 17 00:00:00 2001 From: Rogier Goossens Date: Fri, 27 Jan 2012 12:41:31 -0700 Subject: [PATCH] Use custom text functions for mount/unmount and swapon/swapoff texts Part 3 of 4 to provide new UUID support for NTFS. See Bug #667278 - Add support for setting UUID --- include/Utils.h | 2 ++ include/linux_swap.h | 2 ++ src/FileSystem.cc | 13 ++++++++- src/Win_GParted.cc | 63 +++++++++++++++++++++++--------------------- src/linux_swap.cc | 16 +++++++++++ 5 files changed, 65 insertions(+), 31 deletions(-) diff --git a/include/Utils.h b/include/Utils.h index ef547777..121f7e02 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -94,6 +94,8 @@ enum SIZE_UNIT enum CUSTOM_TEXT { CTEXT_NONE, + CTEXT_ACTIVATE_FILESYSTEM, // Activate text ('Mount', 'Swapon', ...) + CTEXT_DEACTIVATE_FILESYSTEM, // Deactivate text ('Unmount', 'Swapoff', ...) } ; //struct to store file system information diff --git a/include/linux_swap.h b/include/linux_swap.h index b7d1beba..6be8c230 100644 --- a/include/linux_swap.h +++ b/include/linux_swap.h @@ -28,6 +28,8 @@ namespace GParted class linux_swap : public FileSystem { public: + virtual const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ; + FS get_filesystem_support() ; void set_used_sectors( Partition & partition ) ; void read_label( Partition & partition ) ; diff --git a/src/FileSystem.cc b/src/FileSystem.cc index d196155a..8b02404c 100644 --- a/src/FileSystem.cc +++ b/src/FileSystem.cc @@ -34,7 +34,18 @@ const Glib::ustring FileSystem::get_custom_text( CUSTOM_TEXT ttype, int index ) const Glib::ustring FileSystem::get_generic_text( CUSTOM_TEXT ttype, int index ) { - return "" ; + /*TO TRANSLATORS: these labels will be used in the partition menu */ + static const Glib::ustring activate_text = _( "_Mount" ) ; + static const Glib::ustring deactivate_text = _( "_Unmount" ) ; + + switch ( ttype ) { + case CTEXT_ACTIVATE_FILESYSTEM : + return index == 0 ? activate_text : "" ; + case CTEXT_DEACTIVATE_FILESYSTEM : + return index == 0 ? deactivate_text : "" ; + default : + return "" ; + } } int FileSystem::execute_command( const Glib::ustring & command, OperationDetail & operationdetail ) diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 67d3605b..dead3e90 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -303,6 +303,7 @@ void Win_GParted::init_toolbar() void Win_GParted::init_partition_menu() { int index = 0 ; + //fill menu_partition image = manage( new Gtk::Image( Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU ) ); menu_partition .items() .push_back( @@ -356,7 +357,8 @@ void Win_GParted::init_partition_menu() index++ ; menu_partition .items() .push_back( - Gtk::Menu_Helpers::MenuElem( _("Unmount"), + //This is a placeholder text. It will be replaced with some other text before it is used + Gtk::Menu_Helpers::MenuElem( "--placeholder--", sigc::mem_fun( *this, &Win_GParted::toggle_swap_mount_state ) ) ); MENU_TOGGLE_MOUNT_SWAP = index++ ; @@ -903,8 +905,8 @@ void Win_GParted::set_valid_operations() allow_manage_flags( false ) ; allow_check( false ) ; allow_label_partition( false ) ; allow_change_uuid( false ); allow_info( false ) ; - dynamic_cast( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) - ->set_label( _("_Unmount") ) ; + dynamic_cast( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) + ->set_label( FileSystem::get_generic_text ( CTEXT_DEACTIVATE_FILESYSTEM ) ) ; menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .show() ; menu_partition .items()[ MENU_MOUNT ] .hide() ; @@ -920,34 +922,37 @@ void Win_GParted::set_valid_operations() if ( selected_partition .type != GParted::TYPE_UNALLOCATED && selected_partition .status == GParted::STAT_REAL ) allow_manage_flags( true ) ; - //deal with swap... - if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP ) - { - if ( selected_partition .status == GParted::STAT_REAL ) - allow_toggle_swap_mount_state( true ) ; + //Activate / deactivate + if ( gparted_core .get_filesystem_object ( selected_partition .filesystem ) ) + dynamic_cast( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) + ->set_label( gparted_core .get_filesystem_object ( selected_partition .filesystem ) + ->get_custom_text ( selected_partition .busy + ? CTEXT_DEACTIVATE_FILESYSTEM + : CTEXT_ACTIVATE_FILESYSTEM + ) + ) ; + else + dynamic_cast( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) + ->set_label( FileSystem::get_generic_text ( selected_partition .busy + ? CTEXT_DEACTIVATE_FILESYSTEM + : CTEXT_ACTIVATE_FILESYSTEM ) + ) ; - if ( selected_partition .busy ) - { - dynamic_cast(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) - ->set_label( _("_Swapoff") ) ; - - return ; - } - else - dynamic_cast(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() ) - ->set_label( _("_Swapon") ) ; - } - - //only unmount is allowed (if ! extended) - if ( selected_partition .busy ) - { - if ( selected_partition .type != GParted::TYPE_EXTENDED && - selected_partition .filesystem != GParted::FS_LVM2_PV ) - allow_toggle_swap_mount_state( true ) ; + //Only permit mount/unmount, swapon/swapoff, ... if action is available + if ( selected_partition .status == GParted::STAT_REAL + && selected_partition .type != GParted::TYPE_EXTENDED + && selected_partition .filesystem != GParted::FS_LVM2_PV + && ( selected_partition .busy + || selected_partition .get_mountpoints() .size() /* Have mount point(s) */ + || selected_partition .filesystem == GParted::FS_LINUX_SWAP + ) + ) + allow_toggle_swap_mount_state( true ) ; + //only unmount/swapoff/... is allowed if busy + if ( selected_partition .busy ) return ; - } - + //UNALLOCATED if ( selected_partition .type == GParted::TYPE_UNALLOCATED ) { @@ -1050,8 +1055,6 @@ void Win_GParted::set_valid_operations() && selected_partition .get_mountpoints() .size() ) { - allow_toggle_swap_mount_state( true ) ; - menu = menu_partition .items()[ MENU_MOUNT ] .get_submenu() ; menu ->items() .clear() ; for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ ) diff --git a/src/linux_swap.cc b/src/linux_swap.cc index aa345ef7..05f7efb2 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -22,6 +22,22 @@ namespace GParted { +const Glib::ustring linux_swap::get_custom_text( CUSTOM_TEXT ttype, int index ) +{ + /*TO TRANSLATORS: these labels will be used in the partition menu */ + static const Glib::ustring activate_text = _( "_Swapon" ) ; + static const Glib::ustring deactivate_text = _( "_Swapoff" ) ; + + switch ( ttype ) { + case CTEXT_ACTIVATE_FILESYSTEM : + return index == 0 ? activate_text : "" ; + case CTEXT_DEACTIVATE_FILESYSTEM : + return index == 0 ? deactivate_text : "" ; + default : + return "" ; + } +} + FS linux_swap::get_filesystem_support() { FS fs ;