[gparted] Provide virtual Partition::get_filesystem_partition() method (#774818)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Provide virtual Partition::get_filesystem_partition() method (#774818)
- Date: Sat, 14 Jan 2017 15:52:30 +0000 (UTC)
commit 53fd80e6ca588627d07a248df51fc093b5c6400e
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Sep 6 07:33:26 2016 +0100
Provide virtual Partition::get_filesystem_partition() method (#774818)
There are multiple cases of code wanting to work with the Partition
object directly containing the file system, regardless of whether it is
within a PartitionLUKS object or not. The code had to do something
similar to this to access it:
const Partition * filesystem_ptn = &partition;
if ( partition.filesystem == FS_LUKS && partition.busy )
filesystem_ptn = &dynamic_cast<const PartitionLUKS *>( &partition )->get_encrypted();
...
// Access Partition object directly containing the file system
filesystem_ptn-> ...
Implement and use virtual accessor get_filesystem_partition() which
allows the code to be simplified like this:
const Partition & filesystem_ptn = partition.get_filesystem_partition();
...
// Access Partition object directly containing the file system
filesystem_ptn. ...
Bug 774818 - Implement LUKS read-write actions NOT requiring a
passphrase
include/Dialog_Partition_Info.h | 1 -
include/Partition.h | 4 ++
include/PartitionLUKS.h | 2 +
src/Dialog_Partition_Info.cc | 67 +++++++++++++++++++--------------------
src/DrawingAreaVisualDisk.cc | 7 +---
src/PartitionLUKS.cc | 7 ++++
src/TreeView_Detail.cc | 33 ++++++-------------
7 files changed, 58 insertions(+), 63 deletions(-)
---
diff --git a/include/Dialog_Partition_Info.h b/include/Dialog_Partition_Info.h
index a9043a8..cf52076 100644
--- a/include/Dialog_Partition_Info.h
+++ b/include/Dialog_Partition_Info.h
@@ -50,7 +50,6 @@ private:
bool drawingarea_on_expose( GdkEventExpose *ev );
const Partition & partition; // (Alias to element in Win_GParted::display_partitions[] vector).
- const Partition * filesystem; // (Alias to above partition or encrypted file system within).
Gtk::HBox *hbox ;
Gtk::DrawingArea drawingarea ;
diff --git a/include/Partition.h b/include/Partition.h
index 20860d7..1f89397 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -131,6 +131,10 @@ public:
void append_messages( const std::vector<Glib::ustring> msgs )
{ messages.insert( messages.end(), msgs.begin(), msgs.end() ); }
+ // Interface to return reference to the Partition object directly containing the
+ // file system. Will be overridden in derived PartitionLUKS.
+ virtual const Partition & get_filesystem_partition() const { return *this; };
+
bool operator==( const Partition & partition ) const ;
bool operator!=( const Partition & partition ) const ;
diff --git a/include/PartitionLUKS.h b/include/PartitionLUKS.h
index 0a810b0..feb9bd3 100644
--- a/include/PartitionLUKS.h
+++ b/include/PartitionLUKS.h
@@ -53,6 +53,8 @@ public:
virtual std::vector<Glib::ustring> get_messages() const;
virtual void clear_messages();
+ virtual const Partition & get_filesystem_partition() const;
+
private:
Partition encrypted;
Sector header_size; // Size of the LUKS header (everything up to the start of the mapping)
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index e676ee5..ee84b36 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -30,12 +30,6 @@ namespace GParted
Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : partition( partition )
{
- // Filesystem points to the Partition object, or for an open LUKS mapping, the
- // encrypted Partition object member within containing the encrypted file system.
- filesystem = &partition;
- if ( partition.filesystem == FS_LUKS && partition.busy )
- filesystem = &dynamic_cast<const PartitionLUKS *>( &partition )->get_encrypted();
-
this ->set_has_separator( false ) ;
// Set minimum dialog height so it fits on an 800x600 screen without too much
// whitespace (~500 px max for GNOME desktop). Allow extra space if have any
@@ -203,7 +197,7 @@ void Dialog_Partition_Info::init_drawingarea()
color_text .set( "black" );
this ->get_colormap() ->alloc_color( color_text ) ;
- color_partition.set( Utils::get_color( filesystem->filesystem ) );
+ color_partition.set( Utils::get_color( partition.get_filesystem_partition().filesystem ) );
this ->get_colormap() ->alloc_color( color_partition ) ;
//set text of pangolayout
@@ -224,11 +218,16 @@ void Dialog_Partition_Info::Display_Info()
//+-+------------+-------------+-------------+------------+---------------+
//0 1 2 3 4 5 6
+ // Refers to the Partition object containing the file system. Either the same as
+ // partition, or for an open LUKS mapping, the encrypted Partition object member
+ // within containing the encrypted file system.
+ const Partition & filesystem_ptn = partition.get_filesystem_partition();
+
Sector ptn_sectors = partition .get_sector_length() ;
Glib::ustring vgname = "" ; //Also used in partition status message
- if ( filesystem->filesystem == FS_LVM2_PV )
- vgname = LVM2_PV_Info::get_vg_name( filesystem->get_path() );
+ if ( filesystem_ptn.filesystem == FS_LVM2_PV )
+ vgname = LVM2_PV_Info::get_vg_name( filesystem_ptn.get_path() );
bool filesystem_accessible = false;
if ( partition.filesystem != FS_LUKS || partition.busy )
@@ -265,13 +264,13 @@ void Dialog_Partition_Info::Display_Info()
Gtk::FILL ) ;
if ( filesystem_accessible )
{
- table->attach( *Utils::mk_label( Utils::get_filesystem_string( filesystem->filesystem ),
true, false, true ),
+ table->attach( *Utils::mk_label( Utils::get_filesystem_string( filesystem_ptn.filesystem ),
true, false, true ),
2, 3, top, bottom, Gtk::FILL );
}
top++, bottom++;
//label
- if ( filesystem->type != TYPE_UNALLOCATED && filesystem->type != TYPE_EXTENDED )
+ if ( filesystem_ptn.type != TYPE_UNALLOCATED && filesystem_ptn.type != TYPE_EXTENDED )
{
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Label:") ) + "</b>"),
1, 2,
@@ -279,14 +278,14 @@ void Dialog_Partition_Info::Display_Info()
Gtk::FILL) ;
if ( filesystem_accessible )
{
- table->attach( *Utils::mk_label( filesystem->get_filesystem_label(), true, false,
true ),
+ table->attach( *Utils::mk_label( filesystem_ptn.get_filesystem_label(), true, false,
true ),
2, 3, top, bottom, Gtk::FILL);
}
top++, bottom++;
}
// file system uuid
- if ( filesystem->type != TYPE_UNALLOCATED && filesystem->type != TYPE_EXTENDED )
+ if ( filesystem_ptn.type != TYPE_UNALLOCATED && filesystem_ptn.type != TYPE_EXTENDED )
{
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("UUID:") ) + "</b>"),
1, 2,
@@ -294,7 +293,7 @@ void Dialog_Partition_Info::Display_Info()
Gtk::FILL) ;
if ( filesystem_accessible )
{
- table->attach( *Utils::mk_label( filesystem->uuid, true, false, true ),
+ table->attach( *Utils::mk_label( filesystem_ptn.uuid, true, false, true ),
2, 3, top, bottom, Gtk::FILL);
}
top++, bottom++;
@@ -310,7 +309,7 @@ void Dialog_Partition_Info::Display_Info()
static Glib::ustring luks_closed = _("Closed");
//status
- if ( filesystem->type != TYPE_UNALLOCATED && filesystem->status != STAT_NEW )
+ if ( filesystem_ptn.type != TYPE_UNALLOCATED && filesystem_ptn.status != STAT_NEW )
{
//status
Glib::ustring str_temp ;
@@ -325,9 +324,9 @@ void Dialog_Partition_Info::Display_Info()
*/
str_temp = _("Not accessible (Encrypted)");
}
- else if ( filesystem->busy )
+ else if ( filesystem_ptn.busy )
{
- if ( filesystem->type == TYPE_EXTENDED )
+ if ( filesystem_ptn.type == TYPE_EXTENDED )
{
/* TO TRANSLATORS: Busy (At least one logical partition is mounted)
* means that this extended partition contains at least one logical
@@ -335,9 +334,9 @@ void Dialog_Partition_Info::Display_Info()
*/
str_temp = _("Busy (At least one logical partition is mounted)") ;
}
- else if ( filesystem->filesystem == FS_LINUX_SWAP ||
- filesystem->filesystem == FS_LINUX_SWRAID ||
- filesystem->filesystem == FS_LVM2_PV )
+ else if ( filesystem_ptn.filesystem == FS_LINUX_SWAP ||
+ filesystem_ptn.filesystem == FS_LINUX_SWRAID ||
+ filesystem_ptn.filesystem == FS_LVM2_PV )
{
/* TO TRANSLATORS: Active
* means that this linux swap, linux software raid partition, or
@@ -345,7 +344,7 @@ void Dialog_Partition_Info::Display_Info()
*/
str_temp = _("Active") ;
}
- else if ( filesystem->filesystem == FS_LUKS )
+ else if ( filesystem_ptn.filesystem == FS_LUKS )
{
// NOTE: LUKS within LUKS
// Only ever display LUKS information in the file system
@@ -353,15 +352,15 @@ void Dialog_Partition_Info::Display_Info()
// another LUKS encryption!
str_temp = luks_open;
}
- else if ( filesystem->get_mountpoints().size() )
+ else if ( filesystem_ptn.get_mountpoints().size() )
{
str_temp = String::ucompose(
/* TO TRANSLATORS: looks like Mounted on /mnt/mymountpoint
*/
_("Mounted on %1"),
- Glib::build_path( ", ", filesystem->get_mountpoints() ) );
+ Glib::build_path( ", ", filesystem_ptn.get_mountpoints() ) );
}
}
- else if ( filesystem->type == TYPE_EXTENDED )
+ else if ( filesystem_ptn.type == TYPE_EXTENDED )
{
/* TO TRANSLATORS: Not busy (There are no mounted logical partitions)
* means that this extended partition contains no mounted or otherwise
@@ -369,8 +368,8 @@ void Dialog_Partition_Info::Display_Info()
*/
str_temp = _("Not busy (There are no mounted logical partitions)") ;
}
- else if ( filesystem->filesystem == FS_LINUX_SWAP ||
- filesystem->filesystem == FS_LINUX_SWRAID )
+ else if ( filesystem_ptn.filesystem == FS_LINUX_SWAP ||
+ filesystem_ptn.filesystem == FS_LINUX_SWRAID )
{
/* TO TRANSLATORS: Not active
* means that this linux swap or linux software raid partition
@@ -378,12 +377,12 @@ void Dialog_Partition_Info::Display_Info()
*/
str_temp = _("Not active") ;
}
- else if ( filesystem->filesystem == FS_LUKS )
+ else if ( filesystem_ptn.filesystem == FS_LUKS )
{
// NOTE: LUKS within LUKS
str_temp = luks_closed;
}
- else if ( filesystem->filesystem == FS_LVM2_PV )
+ else if ( filesystem_ptn.filesystem == FS_LVM2_PV )
{
if ( vgname .empty() )
/* TO TRANSLATORS: Not active (Not a member of any volume group)
@@ -419,7 +418,7 @@ void Dialog_Partition_Info::Display_Info()
}
//Optional, LVM2 Volume Group name
- if ( filesystem->filesystem == FS_LVM2_PV )
+ if ( filesystem_ptn.filesystem == FS_LVM2_PV )
{
//Volume Group
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Volume Group:") ) + "</b>"),
@@ -429,18 +428,18 @@ void Dialog_Partition_Info::Display_Info()
}
//Optional, members of multi-device file systems
- if ( filesystem->filesystem == FS_LVM2_PV ||
- filesystem->filesystem == FS_BTRFS )
+ if ( filesystem_ptn.filesystem == FS_LVM2_PV ||
+ filesystem_ptn.filesystem == FS_BTRFS )
{
//Members
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Members:") ) + "</b>", true,
false, false, 0.0 /* ALIGN_TOP */ ),
1, 2, top, bottom, Gtk::FILL ) ;
std::vector<Glib::ustring> members ;
- switch ( filesystem->filesystem )
+ switch ( filesystem_ptn.filesystem )
{
case FS_BTRFS:
- members = btrfs::get_members( filesystem->get_path() );
+ members = btrfs::get_members( filesystem_ptn.get_path() );
break ;
case FS_LVM2_PV:
if ( ! vgname .empty() )
@@ -454,7 +453,7 @@ void Dialog_Partition_Info::Display_Info()
2, 3, top++, bottom++, Gtk::FILL );
}
- if ( filesystem->filesystem == FS_LVM2_PV )
+ if ( filesystem_ptn.filesystem == FS_LVM2_PV )
{
//Logical Volumes
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Logical Volumes:") ) + "</b>",
true, false, false, 0.0 /* ALIGN_TOP */ ),
diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc
index 2622ccf..17daa52 100644
--- a/src/DrawingAreaVisualDisk.cc
+++ b/src/DrawingAreaVisualDisk.cc
@@ -100,12 +100,7 @@ void DrawingAreaVisualDisk::set_static_data( const PartitionVector & partitions,
Sector partition_length = partitions[ t ] .get_sector_length() ;
visual_partitions .back() .fraction = partition_length / static_cast<double>( length ) ;
- Glib::ustring color_str = Utils::get_color( partitions[t].filesystem );
- if ( partitions[t].filesystem == FS_LUKS && partitions[t].busy )
- {
- const Partition & encrypted = dynamic_cast<const PartitionLUKS *>( &partitions[t]
)->get_encrypted();
- color_str = Utils::get_color( encrypted.filesystem );
- }
+ Glib::ustring color_str = Utils::get_color(
partitions[t].get_filesystem_partition().filesystem );
visual_partitions.back().color.set( color_str );
get_colormap() ->alloc_color( visual_partitions .back() .color );
diff --git a/src/PartitionLUKS.cc b/src/PartitionLUKS.cc
index 83e0049..c16fd79 100644
--- a/src/PartitionLUKS.cc
+++ b/src/PartitionLUKS.cc
@@ -201,4 +201,11 @@ void PartitionLUKS::clear_messages()
encrypted.clear_messages();
}
+const Partition & PartitionLUKS::get_filesystem_partition() const
+{
+ if ( busy )
+ return encrypted;
+ return *this;
+}
+
} //GParted
diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc
index 3ef4608..e71c809 100644
--- a/src/TreeView_Detail.cc
+++ b/src/TreeView_Detail.cc
@@ -24,6 +24,7 @@
#include <gtkmm/cellrenderer.h>
#include <gtkmm/cellrenderertext.h>
#include <pangomm/layout.h>
+#include <glibmm/ustring.h>
namespace GParted
{
@@ -154,10 +155,8 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow,
bool & show_mountpoints,
bool & show_labels )
{
- const Partition * filesystem_ptn = &partition;
- if ( partition.filesystem == FS_LUKS && partition.busy )
- filesystem_ptn = &dynamic_cast<const PartitionLUKS *>( &partition )->get_encrypted();
- if ( filesystem_ptn->busy )
+ const Partition & filesystem_ptn = partition.get_filesystem_partition();
+ if ( filesystem_ptn.busy )
treerow[ treeview_detail_columns .icon1 ] =
render_icon( Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON );
@@ -183,42 +182,32 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow,
if ( ! partition.name.empty() )
show_names = true;
+ // file system
+ treerow[treeview_detail_columns.color] = Utils::get_color_as_pixbuf( filesystem_ptn.filesystem, 16,
16 );
if ( partition.filesystem == FS_LUKS && partition.busy )
{
const Partition & encrypted = dynamic_cast<const PartitionLUKS *>( &partition
)->get_encrypted();
-
- // file system
- treerow[treeview_detail_columns.color] = Utils::get_color_as_pixbuf( encrypted.filesystem,
16, 16 );
/* TO TRANSLATORS: means that this is an encrypted file system */
treerow[treeview_detail_columns.filesystem] = "[" + Glib::ustring( _("Encrypted") ) + "] " +
Utils::get_filesystem_string(
encrypted.filesystem );
-
- // mount point
- treerow[treeview_detail_columns.mountpoint] = Glib::build_path( ", ",
encrypted.get_mountpoints() );
}
else if ( partition.filesystem == FS_LUKS && ! partition.busy )
{
- // file system
- treerow[treeview_detail_columns.color] = Utils::get_color_as_pixbuf( partition.filesystem,
16, 16 );
treerow[treeview_detail_columns.filesystem] = "[" + Glib::ustring( _("Encrypted") ) + "]";
-
- // mount point
- treerow[treeview_detail_columns.mountpoint] = Glib::build_path( ", ",
partition.get_mountpoints() );
}
else
{
- // file system
- treerow[treeview_detail_columns.color] = Utils::get_color_as_pixbuf( partition.filesystem,
16, 16 );
treerow[treeview_detail_columns.filesystem] = Utils::get_filesystem_string(
partition.filesystem );
-
- // mount point
- treerow[treeview_detail_columns.mountpoint] = Glib::build_path( ", ",
partition.get_mountpoints() );
}
- if ( ! static_cast<Glib::ustring>( treerow[treeview_detail_columns.mountpoint] ).empty() )
+
+ // mount point
+ std::vector<Glib::ustring> temp_mountpoints = filesystem_ptn.get_mountpoints();
+ treerow[treeview_detail_columns.mountpoint] = Glib::build_path( ", ", temp_mountpoints );
+ if ( ! temp_mountpoints.empty() )
show_mountpoints = true;
//label
- Glib::ustring temp_filesystem_label = partition.get_filesystem_label();
+ Glib::ustring temp_filesystem_label = filesystem_ptn.get_filesystem_label();
treerow[treeview_detail_columns.label] = temp_filesystem_label;
if ( ! temp_filesystem_label.empty() )
show_labels = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]