[gparted] Add unimplemented open/close encryption to the partition menu (#795617)



commit e4959c520f02167a21220f71f9ab6e1329a9025b
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Oct 25 10:47:38 2016 +0100

    Add unimplemented open/close encryption to the partition menu (#795617)
    
    Add new item to the partition menu to allow the user to open and close
    the LUKS mapping.  However for now the menu item is always disabled and
    there is no implementation behind it to actually open or close the LUKS
    mapping.  Fragment of the partition menu is now:
    
        ...
        Format to       >
        -----------------
        Open Encryption      <- New menu item
        Mount
        -----------------
        Name Partition
        ...
    
    Has to be two separate menu items to clearly represent to the user that
    LUKS mappings and file system mounting are two separate busy states.
    And also in the case of an open but unmounted file system to offer both
    actions; close encryption and mount file system.
    
    The text of the menu item automatically changes similarly to how it does
    for the Mount/Unmount, Swapon/Swapoff, Activate/Deactivate item
    depending on the state of the LUKS mapping.  For open LUKS mappings it
    will show "Close Encryption" and for all other cases (closed LUKS
    mapping or partition is not encrypted) "Open Encryption".  Again similar
    to how the default of "Mount" is shown for unallocated and unknown
    partitions.
    
    Bug 795617 - Implement opening and closing of LUKS mappings

 include/Win_GParted.h |    5 ++++
 include/luks.h        |    1 +
 src/Win_GParted.cc    |   65 +++++++++++++++++++++++++++++++++++++------------
 src/luks.cc           |   17 +++++++++++++
 4 files changed, 72 insertions(+), 16 deletions(-)
---
diff --git a/include/Win_GParted.h b/include/Win_GParted.h
index 74845fa..a8d3c93 100644
--- a/include/Win_GParted.h
+++ b/include/Win_GParted.h
@@ -107,6 +107,9 @@ private:
        void allow_format( bool state ) { 
                toggle_item( state, MENU_FORMAT ) ; }
 
+       void allow_toggle_crypt_busy_state( bool state ) {
+               toggle_item( state, MENU_TOGGLE_CRYPT_BUSY ); }
+
        void allow_toggle_fs_busy_state( bool state ) {
                toggle_item( state, MENU_TOGGLE_FS_BUSY ); }
 
@@ -177,6 +180,7 @@ private:
        void activate_delete();
        void activate_info();
        void activate_format( FSType new_fs );
+       void toggle_crypt_busy_state();
        bool check_toggle_busy_allowed( const Glib::ustring & disallowed_msg );
        void show_toggle_failure_dialog( const Glib::ustring & failure_summary,
                                         const Glib::ustring & marked_up_error );
@@ -258,6 +262,7 @@ private:
         MENU_COPY, TOOLBAR_COPY,
         MENU_PASTE, TOOLBAR_PASTE,
         MENU_FORMAT,
+       MENU_TOGGLE_CRYPT_BUSY,
        MENU_TOGGLE_FS_BUSY,
         MENU_MOUNT,
        MENU_NAME_PARTITION,
diff --git a/include/luks.h b/include/luks.h
index ea84de7..24c86c7 100644
--- a/include/luks.h
+++ b/include/luks.h
@@ -27,6 +27,7 @@ namespace GParted
 class luks : public FileSystem
 {
 public:
+       const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) const;
        FS get_filesystem_support();
        bool is_busy( const Glib::ustring & path );
        void set_used_sectors( Partition & partition );
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index a98f15f..da3610b 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -69,6 +69,7 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
         MENU_COPY = TOOLBAR_COPY =
         MENU_PASTE = TOOLBAR_PASTE =
         MENU_FORMAT =
+       MENU_TOGGLE_CRYPT_BUSY =
        MENU_TOGGLE_FS_BUSY =
         MENU_MOUNT =
         MENU_NAME_PARTITION =
@@ -373,7 +374,13 @@ void Win_GParted::init_partition_menu()
        
        menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ;
        index++ ;
-       
+
+       menu_partition.items().push_back(
+                       // Placeholder text, replaced in set_valid_operations() before the menu is shown
+                       Gtk::Menu_Helpers::MenuElem( "--toggle crypt busy--",
+                                                    sigc::mem_fun( *this, 
&Win_GParted::toggle_crypt_busy_state ) ) );
+       MENU_TOGGLE_CRYPT_BUSY = index++;
+
        menu_partition .items() .push_back(
                        // Placeholder text, replaced in set_valid_operations() before the menu is shown
                        Gtk::Menu_Helpers::MenuElem( "--toggle fs busy--",
@@ -1050,13 +1057,19 @@ bool Win_GParted::Quit_Check_Operations()
 void Win_GParted::set_valid_operations()
 {
        allow_new( false ); allow_delete( false ); allow_resize( false ); allow_copy( false );
-       allow_paste( false ); allow_format( false ); allow_toggle_fs_busy_state( false );
+       allow_paste( false ); allow_format( false );
+       allow_toggle_crypt_busy_state( false ); allow_toggle_fs_busy_state( false );
        allow_name_partition( false ); allow_manage_flags( false ); allow_check( false );
        allow_label_filesystem( false ); allow_change_uuid( false ); allow_info( false );
 
+       // Set default name for the open/close crypt menu item.
+       const FileSystem * luks_filesystem_object = gparted_core.get_filesystem_object( FS_LUKS );
+       g_assert( luks_filesystem_object != NULL );  // Bug: LUKS FileSystem object not found
+       dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_CRYPT_BUSY].get_child() )
+               ->set_label( luks_filesystem_object->get_custom_text( CTEXT_ACTIVATE_FILESYSTEM ) );
        // Set default name for the file system active/deactivate menu item.
        dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_FS_BUSY].get_child() )
-               ->set_label( FileSystem::get_generic_text ( CTEXT_DEACTIVATE_FILESYSTEM ) ) ;
+               ->set_label( FileSystem::get_generic_text( CTEXT_ACTIVATE_FILESYSTEM ) );
 
        menu_partition.items()[MENU_TOGGLE_FS_BUSY].show();
        menu_partition .items()[ MENU_MOUNT ] .hide() ; 
@@ -1076,19 +1089,33 @@ void Win_GParted::set_valid_operations()
        //if there's something, there's some info ;)
        allow_info( true ) ;
 
-       // Set an appropriate name for the activate/deactivate menu item.
-       const FileSystem * filesystem_object = gparted_core.get_filesystem_object( 
selected_filesystem.filesystem );
-       if ( filesystem_object )
-               dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_FS_BUSY].get_child() )
-                       ->set_label( filesystem_object->get_custom_text(   selected_filesystem.busy
-                                                                        ? CTEXT_DEACTIVATE_FILESYSTEM
-                                                                        : CTEXT_ACTIVATE_FILESYSTEM ) );
-       else
-               dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_FS_BUSY].get_child() )
-                       ->set_label( FileSystem::get_generic_text (  selected_filesystem.busy
-                                                                  ? CTEXT_DEACTIVATE_FILESYSTEM
-                                                                  : CTEXT_ACTIVATE_FILESYSTEM )
-                                                                 ) ;
+       // Set appropriate name for the open/close crypt menu item.
+       if ( selected_partition_ptr->filesystem == FS_LUKS )
+       {
+               dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_CRYPT_BUSY].get_child() )
+                       ->set_label( luks_filesystem_object->get_custom_text(   selected_partition_ptr->busy
+                                                                             ? CTEXT_DEACTIVATE_FILESYSTEM
+                                                                             : CTEXT_ACTIVATE_FILESYSTEM ) );
+       }
+       // Set appropriate name for the file system active/deactivate menu item.
+       if ( selected_partition_ptr->filesystem != FS_LUKS || selected_partition_ptr->busy )
+       {
+               const FileSystem * filesystem_object = gparted_core.get_filesystem_object( 
selected_filesystem.filesystem );
+               if ( filesystem_object )
+               {
+                       dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_FS_BUSY].get_child() )
+                               ->set_label( filesystem_object->get_custom_text(   selected_filesystem.busy
+                                                                                ? CTEXT_DEACTIVATE_FILESYSTEM
+                                                                                : CTEXT_ACTIVATE_FILESYSTEM 
) );
+               }
+               else
+               {
+                       dynamic_cast<Gtk::Label*>( menu_partition.items()[MENU_TOGGLE_FS_BUSY].get_child() )
+                               ->set_label( FileSystem::get_generic_text (  selected_filesystem.busy
+                                                                          ? CTEXT_DEACTIVATE_FILESYSTEM
+                                                                          : CTEXT_ACTIVATE_FILESYSTEM ) );
+               }
+       }
 
        // Only permit file system mount/unmount and swapon/swapoff when available
        if (    selected_partition_ptr->status == STAT_REAL
@@ -2385,6 +2412,12 @@ void Win_GParted::activate_format( FSType new_fs )
        temp_ptn = NULL;
 }
 
+void Win_GParted::toggle_crypt_busy_state()
+{
+       // Method not yet implemented as MENU_TOGGLE_CRYPT_BUSY item "Open/Close encrypted
+       // volume" in the partition menu is never enabled.
+}
+
 bool Win_GParted::unmount_partition( const Partition & partition, Glib::ustring & error )
 {
        const std::vector<Glib::ustring> fs_mountpoints = partition.get_mountpoints();
diff --git a/src/luks.cc b/src/luks.cc
index a5be0d9..9c6ed32 100644
--- a/src/luks.cc
+++ b/src/luks.cc
@@ -22,6 +22,23 @@
 namespace GParted
 {
 
+const Glib::ustring luks::get_custom_text( CUSTOM_TEXT ttype, int index ) const
+{
+       /* TO TRANSLATORS: these labels will be used in the partition menu */
+       static const Glib::ustring activate_text = _("Open Encryption");
+       static const Glib::ustring deactivate_text = _("Close Encryption");
+
+       switch ( ttype )
+       {
+               case CTEXT_ACTIVATE_FILESYSTEM:
+                       return index == 0 ? activate_text : "";
+               case CTEXT_DEACTIVATE_FILESYSTEM:
+                       return index == 0 ? deactivate_text : "";
+               default:
+                       return "";
+       }
+}
+
 FS luks::get_filesystem_support()
 {
        FS fs;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]