Commit Graph

131 Commits

Author SHA1 Message Date
Mike Fleetwood 40665913bf C++11: Convert NULL to nullptr (!117)
In C++11, nullptr [1] is the strongly typed value to use instead of the
macro NULL [2].  Use everywhere [3][4].

[1] nullptr, the pointer literal (since C++11)
    https://en.cppreference.com/w/cpp/language/nullptr
[2] NULL
    https://en.cppreference.com/w/cpp/types/NULL
[3] Bjarne Stroustrup's C++ Style and Technique FAQ, Should I use NULL
    or 0?
    https://www.stroustrup.com/bs_faq2.html#null
        "In C++, the definition of NULL is 0, so there is only an
        aesthetic difference.  I prefer to avoid macros, so I use 0.
        Another problem with NULL is that people sometimes mistakenly
        believe that it is different from 0 and/or not an integer.  In
        pre-standard code, NULL was/is sometimes defined to something
        unsuitable and therefore had/has to be avoided.  That's less
        common these days.

        If you have to name the null pointer, call it nullptr; that's
        what it's called in C++11.  Then, "nullptr" will be a keyword.
        "
[4] What is nullptr in C++? Advantages, Use Cases & Examples
    https://favtutor.com/blogs/nullptr-cpp
        "Advantages of nullptr
        ...
        Compatible: Null pointers are compatible with null pointer
        constants in the C style (such as NULL and 0).  This implies
        that old C code that uses these constants and null pointers can
        communicate with each other in C++.
        "

Closes !117 - Require C++11 compilation
2023-09-23 15:30:15 +00:00
Mike Fleetwood c8b4df5879 Fix available space calculation in Dialog_Partition_New::set_data()
The available number of sectors 'total_length' is calculated as one
sector too few.  However this doesn't matter because when composing a
new partition in Dialog_Partition_New::Get_New_Partition() the dialog
fits the end of the partition to the end of the unallocated partition
'new_partition->sector_end' in which it is being created, not the
available space.  Missed in earlier commit:
    4f84cff781
    cleanups

Anyway correct the calculation.
2023-04-27 15:54:01 +00:00
Pascal Engélibert f31fbb986f Add accessibility relations (!92)
Accessibility relations are essential for usage with screen readers.  It
enables the screen reader to read the corresponding label along with the
value of a widget when it gains focus, rather than just the value of the
widget itself.

Test by running Orca screen reader and tab around the elements of the UI
and listen to what is read out.  For example before it would be
"500 GiB", where as after it would be "Unused 500 GiB".

Closes !92 - Add accessibility relations
2021-10-09 08:34:41 +00:00
Mike Fleetwood a11c16445b Rename member variable to default_fs
... in class Dialog_Partition_New and slightly refactor the code in
build_filesystems_combo() method which sets it.

Change the name from first_creatable_fs to default_fs to be more
immediately obvious what the variable represents.  As default_fs is used
to index the items in the combo_filesystem derived ComboBox, make it's
type an int to match the type of the parameter passed to
Gtk::ComboBox::set_active() [1].  Initialise default_fs to -1 (no
selection) in the class constructor [2], which also allows removal of
local variable set_first just used to track whether first_creatable_fs
had been assigned yet or not.

[1] gtkmm: Gtk::ComboBox Class Reference, set_active()
    https://developer.gnome.org/gtkmm/stable/classGtk_1_1ComboBox.html#a4f23cf08e85733d23f120935b235096d

[2] C++ FAQ / Should my constructors use "initialization lists" or
    "assignment"?
    https://isocpp.org/wiki/faq/ctors#init-lists
2021-03-04 16:55:06 +00:00
Mike Fleetwood a97f1240fb Don't rely on unformatted being the last file system type
... in Dialog_Partition_New::build_filesystems_combo().  set_data()
populates this->FILESYSTEMS[] vector with supported file systems with
cleared, unformatted and extended added to the end.  Then
build_filesystems_combo() adds those items to combo_filesystem, skipping
extended.  It then makes the last item in the combobox sensitive,
relying on the fact that it is unformatted.

Refactor the code so build_filesystems_combo() no longer relies on
unformatted being the last item in combo_filesystem to always enable it.
2021-03-04 16:55:06 +00:00
Mike Fleetwood eb5ad50fef Remove unnecessary call to combobox_changed(false)
... in Dialog_Partition_New::set_data().  As the change signal for
combo_filesystem has already been connected, combo_changed(false) is
automatically called by setting the active selection.  Therefore remove
the unnecessary call.
2021-03-04 16:55:06 +00:00
Mike Fleetwood 400fc8397e Rename combobox_change() parameter to combo_type_changed
"Type" was rather a generic name.  Use "combo_type_changed" which makes
it clear that the boolean parameter indicates whether a change to
combo_type or one of the other ComboBoxes triggered this callback.
2021-03-04 16:55:06 +00:00
Mike Fleetwood e91db19e30 Fix crash in Create New Partition dialog when changing type (#101)
On an MSDOS partitioned drive, open the Create New Partition dialog and
change "created as" from Primary Partition to Extended Partition and
back to Primary Partition.  On Fedora and RHEL/CentOS 8, which builds
packages with FORTIFY_SOURCE [1][2] and GLIBXX_Assertions [3][4]
enabled, GParted will crash.

Run GParted built with the default compilation options under valgrind
and repeat the test.  Multiple out of bounds reads are reported like
this:
  # valgrind --track-origins=yes ./gpartedbin
  ...
  ==232613== Invalid read of size 8
  ==232613==    at 0x441AF6: GParted::Dialog_Partition_New::combobox_changed(bool) (Dialog_Partition_New.cc:354)
  ==232613==    by 0x443DBD: sigc::bound_mem_functor1<void, GParted::Dialog_Partition_New, bool>::operator()(bool const&) const (mem_fun.h:2066)

Coming from Dialog_Partition_New.cc:
  328  void Dialog_Partition_New::combobox_changed(bool type)
  329  {
  ...
  351      // combo_filesystem and combo_alignment
  352      if ( ! type )
  353      {
> 354          fs = FILESYSTEMS[combo_filesystem.get_active_row_number()];

When the partition type is changed to Extended the file system is forced
to be "Extended" too.  This is done in ::combobox_changed() method by
modifying combo_filesystem to add "Extended", making that the selected
item and setting the widget as inactive.

Then when the partition type is changed back to primary the file system
combobox is returned to it's previous state.  This is done by first
removing the last "Extended" item, making the widget active and setting
the selected item.  However as "Extended" is the currently selected
item, removing it forces their to be no selected item and triggers a
change to combo_filesystem triggering a recursive call to
::combobox_changed() where combo_filesystem.get_active_row_number()
returns -1 (no selection) [5] and on line 354 the code accesses item -1
of the FILESYSTEMS[] vector.

Fix by setting the new combo_filesystem selection before removing the
currently selected "Extended" item.  This has the added benefit of only
triggering a change to combo_filesystem once when the default item is
selected rather than twice when the currently "Extended" item is removed
and again when the default item is selected.

[1] [Fedora] Security Features, Compile Time Buffer Checks
    (FORTIFY_SOURCE)
    https://fedoraproject.org/wiki/Security_Features#Compile_Time_Buffer_Checks_.28FORTIFY_SOURCE.29

[2] Enhance application security with FORTIFY_SOURCE
    https://access.redhat.com/blogs/766093/posts/1976213

[3] Security Features Matrix (GLIBXX_Assertions)
    https://fedoraproject.org/wiki/Security_Features_Matrix

[4] GParted 1.2.0-1.fc33 package build.log for Fedora 33
    https://kojipkgs.fedoraproject.org/packages/gparted/1.2.0/1.fc33/data/logs/x86_64/build.log
    CXXFLAGS='-O2 -g ... -Wp,-D_FORTIFY_SOURCE=2
    -Wp,-D_GLIBCXX_ASSERTIONS ...'

[5] gtkmm: Gtk::ComboBox Class Reference, get_active_row_number()
    https://developer.gnome.org/gtkmm/stable/classGtk_1_1ComboBox.html#a53531bc041b5a460826babb8496c363b

Closes #101 - Crash changing Partition type in "Create new partition"
              dialog
2021-03-04 16:55:06 +00:00
Mike Fleetwood 58fb230fb0 Also rename FS.filesystem member to fstype (!52)
Closes !52 - Rename members and variables currently named 'filesystem'
2019-12-04 07:37:19 +00:00
Mike Fleetwood 7c94b7d920 Snap partition boundaries before dialogs update FS usage (#48)
Move snap_to_*() method calls from the point when all operations are
added to the list, to earlier when Resize/Move, Paste (into new) and
Create New dialogs are composing the new partition objects.  In
particular for the Resize/Move operation, to just before updating the
file system usage.

This change finally resolves this bug.

Because of the dialog call chains into Dialog_Base_Partition,
snap_to_alignment() must be added into:
* Dialog_Base_Partition::prepare_new_partition() for the Resize/Move and
  Paste (into new) dialogs; and
* Dialog_Partition_New::Get_New_Partition() for the Create New dialog.

Closes #48 - Error when moving locked LUKS-encrypted partition
2019-06-11 15:55:02 +00:00
Mike Fleetwood 3222c8dd1a Pass the current device down to Dialog_Base_Partition class (#48)
The current device has to be passed to the dialog constructors and then
on to the Dialog_Base_Constructor.  Note that the Dialog_Partition_New
constructor is already passed the current device, however it still needs
to pass it on to Dialog_Base_Constructor.

This is ready so that snap_to_*() methods can access the current device
when they are called from within these dialogs.

* Pass Parameter to Base Class Constructor while creating Derived class
  Object
  https://stackoverflow.com/questions/16585856/pass-parameter-to-base-class-constructor-while-creating-derived-class-object

Closes #48 - Error when moving locked LUKS-encrypted partition
2019-06-11 15:55:02 +00:00
Luca Bacci 90b3e99554 Use Gtk::Grid for Dialog_Partition_New (!25)
Gtk::Table was deprecated in Gtk 3.4.0 [1].  Replace with Gtk::Grid.
Note that the meaning of the attachment parameters changed between
Gtk::Table::attach() [2] from left, right, top, bottom and
Gtk::Grid::attach() [3] to left, top, width, height.

This commit makes the change for Dialog_Base_Partition.

[1] Gtkmm 3.4 NEWS file (actually first included in gtkmm 3.3.2
    unstable)
    https://gitlab.gnome.org/GNOME/gtkmm/blob/3.4.0/NEWS#L162
        * Deprecate Gtk::Table in favour of Gtk::Grid.

[2] Gtkmm 3.4 Gtk::Table Class Reference, attach() method
    https://developer.gnome.org/gtkmm/3.4/classGtk_1_1Table.html#a28b6926e68337a51ba29f2b4dd69f087
        Deprecated: 3.4: Use Gtk::Grid::attach() with Gtk:Grid.  Note
        that the attach argument differ between those two function.

[3] Gtkmm 3.4 Gtk::Grid Class Reference, attach() method
    https://developer.gnome.org/gtkmm/3.4/classGtk_1_1Grid.html#a9c425e95660daff60a77fc0cafc18115

Closes !25 - Modern Gtk3 - part 1
2019-04-27 12:03:05 +01:00
Luca Bacci 74bb981ed2 Use Gdk::RGBA (!25)
The Gdk::RGBA data type was introduced to replace Gdk::Color in
Gtkmm 3.0 [1], with Gdk::Color being deprecated in Gtkmm 3.10 [2].

With this commit we make the change to Gdk::RGBA data type which is the
modern replacement to Gdk::Color.  Gdk::RGBA can be used almost as a
drop in replacement because it keeps most of the Gdk::Color interface.

Also, this commit removes the C Gtk call introduced during the
port-to-gtk3 patchset by commit:
    5379352766
    repare-for-gtk3: Prepare for removal of Gtk::Widget::modify_fg() (#7)

[1] Gtkmm 3.0.1 NEWS file
    https://gitlab.gnome.org/GNOME/gtkmm/blob/3.0.1/NEWS#L48
        * RGBA replaces Color, though Color still exists because it is
          used by TextView.  We hope to deprecated Color completely in
          gtkmm 3.2.

[2] Gtkmm 3.10.0 NEWS file
    https://gitlab.gnome.org/GNOME/gtkmm/blob/3.10.0/NEWS#L127
        Gdk:
        * Deprecate Color.

Closes !25 - Modern Gtk3 - part 1
2019-04-27 12:03:04 +01:00
Mike Fleetwood e55b3c8544 Replace String::ucompose() with Glibmm equivalent (#46)
Glibmm has implemented a ustring::compose() set of methods [1] since
Glibmm 2.16, circa 2008.  So replace String::ucompose().  Note that
GParted already requires glibmm >= 2.32 as set in configure.ac.

This commit just replaces all the method calls.  Edit created by:
    sed -i 's|String::ucompose *|Glib::ustring::compose|' src/*.cc

[1] Glibmm Reference Manual, Glib::ustring Class, compose() method
    https://developer.gnome.org/glibmm/2.32/classGlib_1_1ustring.html#a64ff7ac3d9e9899c2910f1d831f8d500

Closes #46 - Drop compose subdir
2019-03-27 16:45:22 +00:00
Luca Bacci 892f5542a4 Work around Gtk3 Gtk-CRITICAL messages when closing some dialogs (#7)
There is a bug affecting Gtk+ 3.22.8 to 3.22.30 in which destroying a
GtkComboBox when it is not hidden results in this message:

    Gtk-CRITICAL **: gtk_widget_is_drawable: assertion 'GTK_IS_WIDGET (widget)' failed

This happens in GParted when some dialogs are closed, for example the
Create New Partition and Create Partition Table dialogs.  To work around
the issue we call Gtk::Dialog::hide() in the destructors of our dialog
classes.

The issue was fixed in Gtk 3.24.0.

 * Gtk 3.22.8 was released in February 2017.
 * Gtk 3.24.0 was released in September 2018.

References:

[1] Gtk Issue - GtkComboBox::private::popup_window can be NULL
    https://gitlab.gnome.org/GNOME/gtk/issues/125

[2] Gtk commit - combobox: popdown() the menu during unmap()
    7401794de6

[3] Gtk commit - Check for NULL priv->popup_window in
    gtk_combo_box_popdown()
    aa5d926c84

Closes #7 - Port to Gtk3
2019-02-11 08:57:18 +00:00
Mike Fleetwood 2bbe7fcc45 Strip unnecessary scope from GParted::TYPE_* (!20)
The code inconsistently uses GParted:: scope in front of TYPE_*.

    $ fgrep 'GParted::TYPE_' src/*.cc | wc -l
    35
    $ egrep '[^:]TYPE_' src/*.cc | wc -l
    83

GParted:: scope resolution is unnecessary as all the code is inside the
GParted scope, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood e0b6d2c65b Strip unnecessary scope from GParted::FS_* (!20)
The code inconsistently uses GParted:: scope in front of FS_*.

    $ fgrep 'GParted::FS_' src/*.cc | wc -l
    41
    $ egrep '[^:]FS_' src/*.cc | wc -l
    441

GParted:: scope resolution is unnecessary as all the code is inside the
GParted namespace, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood 7f23761964 Strip unnecessary scope from GParted::FS::* (!20)
The code inconsistency uses GParted::FS::* and FS::*.

    $ fgrep 'GParted::FS::' src/*.cc | wc -l
    97
    $ egrep '[^:]FS::' src/*.cc | wc -l
    152

GParted:: scope resolution is unnecessary as all the code is inside the
GParted namespace, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Luca Bacci d17d129044 modern-gtk2: Use Cairo for drawing the partition resizer (!17)
GdkGC has been deprecated in the underlying C / GTK+ 2.22 library.  It
is less clearly stated but Gdk::GC is also deprecated in C++ / gtkmm.
Cairo based rendering should be used instead.
https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html
https://gitlab.gnome.org/GNOME/gtk/blob/2.22.0/NEWS#L124
https://developer.gnome.org/gtkmm/2.24/classGdk_1_1GC.html

First commit in a series to convert Gdk::GC based drawing to Cairo based
drawing.  This specific commit makes the transition for the graphical
partition resizing widget that is used in the "Create New Partition",
"Paste" creating new partition and "Resize/Move" dialogs.

Cairo is not pixel based but instead uses a continuous coordinate space.
To draw in a pixel aligned way follow the guidance in the Cairo FAQ.
https://www.cairographics.org/FAQ/#sharp_lines

Additional references:
https://developer.gnome.org/gdk2/stable/gdk2-Drawing-Primitives.html#gdk-draw-line
https://developer.gnome.org/gdk2/stable/gdk2-Drawing-Primitives.html#gdk-draw-rectangle

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 6bfa95d427 modern-gtk2: Rename callback after OptionComboBox class switch (!17)
Final part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit renames the signal handler callback to match the
previously renamed combobox widget variable names.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 48d2fd2120 modern-gtk2: Use OptionComboBox class for file system combobox (!17)
Third part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about file system combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci cf5e9c863f modern-gtk2: Use OptionComboBox class for partition type combobox (!17)
Second part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about partition type combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 83b98885f6 modern-gtk2: Use OptionComboBox class for alignment combobox (!17)
First part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about partition alignment combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Mike Fleetwood a3b47ca14a Move struct FS and FS_Limits into FileSystem.h
Struct FS and struct FS_Limits are strongly related to the FileSystem
class, both being return values from members and associated with storing
file system attributes.  Move their definitions from Utils.h into
FileSystem.h.
2018-01-28 10:09:35 -07:00
Mike Fleetwood 175d27c55d Rename enum FILESYSTEM to FSType
There are too many different types of things named "filesystem" in the
GParted code with the potential to cause confusion.  Namely:

    std::vector<FS> FILESYSTEMS
                              Vector of file system capabilities.

    class FileSystem          Base class interfacing to file system
                              specific executables for querying and
                              modification.

    enum FILESYSTEM           Symbolic constants representing each file
                              system type.

Many recent written or re-written functions already used a variable
named fstype.  Rename enum FILESYSTEM to enum FSType to clearly
distinguish it from the other things with very similar names.  Only
changing the name of the enumeration, not the name of variables of that
type too because that is a lot more lines of code and those can be
changed when the relevant code is re-written.
2018-01-28 10:09:35 -07:00
Mike Fleetwood 46bf5a383e Extract common code into GParted_Core::get_filesystem_limits() (#787204)
There are multiple repetitions of the same code getting a FileSystem
object, checking for NULL and then calling the file system specific
get_filesystem_limits().  Extract that into a common function.

GParted_Core::get_filesystem_limits() can't use the file system from the
passed Partition object because that is the current file system which
will be different from the intended file system for new and format
operations.  So would look up the wrong derived FileSystem specific
object and call the wrong get_filesystem_limits().  Hence still needing
fstype as a separate parameter to pass the intended file system.

Bug 787204 - Minimum and maximum size of the UDF partition/disk
2018-01-28 10:09:35 -07:00
Mike Fleetwood 668957c0a4 Pass Partition object to get_filesystem_limits() (#787204)
As described in the previous commit, this is so that file system
specific implementations can dynamically determine size limits based on
Partition object attributes: such as the device sector size and the file
system block size.  (Assuming set_used_sectors() sets
partition.fs_block_size for the type of file system in question).

Bug 787204 - Minimum and maximum size of the UDF partition/disk
2018-01-28 10:09:35 -07:00
Mike Fleetwood 4fa262d7e3 Switch to using struct FS_Limits inside Dialog_Partition_New (#787204)
Change Dialog_Partition_New to use a fs_limits rather than struct FS
and .MIN and .MAX.  No passing of struct FS_Limits required.  Just use
the FILESYSTEMS vector of struct FS to provide the file system type and
look up it's size limits each time the selection changes.

Bug 787204 - Minimum and maximum size of the UDF partition/disk
2018-01-28 10:09:35 -07:00
Mike Fleetwood ea269cc929 Switch from whole_device flag to TYPE_UNPARTITIONED (#788308)
Remove whole_device flag and replace with new partition type
TYPE_UNPARTITIONED.  Minimally adapt the remaining code to compile and
run.

Bug 788308 - Remove whole_device partition flag
2017-10-03 08:22:19 -06:00
Mike Fleetwood 8979913a3f Remove "../include/" from GParted header #includes
It made the code look a little messy, is easily resolved in the build
system and made the dependencies more complicated than needed.  Each
GParted header was tracked via multiple different names (different
numbers of "../include/" prefixes).  For example just looking at how
DialogFeatures.o depends on Utils.h:

    $ cd src
    $ make DialogFeatures.o
    $ egrep ' [^ ]*Utils.h' .deps/DialogFeatures.Po
     ../include/DialogFeatures.h ../include/../include/Utils.h \
     ../include/../include/../include/../include/../include/../include/Utils.h \
     ../include/../include/../include/Utils.h \

After removing "../include/" from the GParted header #includes, just
need to add "-I../include" to the compile command via the AM_CPPFLAGS in
src/Makefile.am.  Now the dependencies on GParted header files are
tracked under a single name (with a single "../include/" prefix).  Now
DialogFeatures.o only depends on a single name to Utils.h:

    $ make DialogFeatures.o
    $ egrep ' [^ ]*Utils.h' .deps/DialogFeatures.Po
     ../include/DialogFeatures.h ../include/Utils.h ../include/i18n.h \
2016-12-12 13:15:34 -07:00
Mike Fleetwood e86e7b91b2 Prevent crypt-luks appearing in the Create New dialog and Format menu (#760080)
This patchset is adding read-only LUKS support.  Creation of LUKS is
planned to be a tick box adding encryption in the Create New Partition
dialog.  Therefore remove the greyed out crypt-luks entry in the Create
New Partition dialog and the Format menu.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:40 -07:00
Mike Fleetwood 24fa553385 Remove unnecessary sector_size parameter from Get_New_Partition methods
The sector_size parameter is unnecessary as the value can be retrieved
from the sector size of the selected Partition object on which the
create new, copy & paste or resize/move operation is being performed.

For the create new and resize/move operations it is trivial as the
existing unallocated or in use Partition object on which the operation
is being perform already contains the correct sector size.  For the copy
& paste operation, which can copy across disk devices of different
sector sizes, we merely have to use the sector size of the existing
selected (destination) Partition object rather than copied (source)
Partition object.  Hence these relevant lines in the new code:

    Dialog_Partition_Copy::set_data(selected_partition, copied_partition)
        new_partition = copied_partition.clone();
        ...
        new_partition->sector_size = selected_partition.sector_size;
2016-01-26 10:11:35 -07:00
Mike Fleetwood 320e166c03 Implement and use virtual Partition copy constructor clone() (#759726)
Final step for full polymorphic handling of Partition objects is to
implement a virtual copy constructor.  C++ doesn't directly support
virtual copy constructors, so instead use the virtual copy constructor
idiom [1].  (Just a virtual method called clone() which is implemented
in every polymorphic class and creates a clone of the current object and
returns a pointer to it).

Then replace all calls to the (monomorphic) Partition object copy
constructor throughout the code, except in the clone() implementation
itself, with calls to the new virtual clone() method "virtual copy
constructor".

Also have to make the Partition destructor virtual too [2][3] so that
the derived class destructor is called when deleting using a base class
pointer.  C++ supports this directly.

[1] Wikibooks: More C++ Idioms / Virtual Constructor
    https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Virtual_Constructor

[2] When to use virtual destructors?
    http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors

[3] Virtuality
    Guideline #4: A base class destructor should be either public and
    virtual, or protected and nonvirtual
    http://www.gotw.ca/publications/mill18.htm

Bug 759726 - Implement Partition object polymorphism

SQUASH: When first using pointers to Partition and calling delete
2016-01-26 10:11:35 -07:00
Mike Fleetwood 4a6cbcd0f1 Use pointer to Partition in Dialog_Base_Partition and derived classes (#759726)
Now use a pointer to the Partition object in Dialog_Base_Partition class
and derived classes, Dialog_Partition_{Copy,New,Resize_Move}.  This is
equivalent to how the Partition objects are managed in the Operation and
derived classes.

The Partition object is allocated and copy constructed in each derived
classes' set_data() method, called from each constructor and deallocated
in the destructors.  Considering the remaining Big 3, these classes are
never copy constructed or copy assigned so provide private definitions
and no implementations so the compiler enforces this.

Bug 759726 - Implement Partition object polymorphism
2016-01-26 10:11:35 -07:00
Mike Fleetwood f6b45a0429 Use Partition pointer adoption everywhere when adding items into a PartitionVector (#759726)
Replace all the current code which uses push_back() and insert() of a
local Partition object and gets it copy constructed into a
PartitionVector.  Instead allocate a Partition object on the heap and
adopt a pointer into the PartitionVector using push_back_adopt() and
insert_adopt().

Bug 759726 - Implement Partition object polymorphism
2016-01-26 10:11:35 -07:00
Mike Fleetwood 48d898ebfd Include Partition.h header everywhere it's used
Lots of files which use the Partition class relied on the declaration
being included via other header files.  This is bad practice.

Add #include "Partition.h" into every file which uses the Partition
class which doesn't already include it.  Header file #include guards are
specifically to allow this.
2016-01-26 10:11:35 -07:00
Mike Fleetwood c249b7286d Fix temporary path name of new partitions (#759488)
In the UI new partitions were being named "unallocated" instead of
"New Partition #1", etc.  Also deleting a new partition not yet created
deletes all new partitions from the operation list because it matches
by name only and they were all named "unallocated".  Broken by this
recent commit:

    762cd1094a
    Return class member from Dialog_Partition_New::Get_New_Partition() (#757671)

Prior to this commit in the create new partition dialog code did these
relevant steps:
    Dialog_Partition_New::Get_New_Partition()
        Partition part_temp;
        ...
        part_temp.Set(..., "New Partition #%1", ...);

Create local Partition object using default constructor which calls
Partition::Reset() and clears the paths vector.  It then calls Set()
which appends the new name making the vector:
    paths = ["New Partition #%1"]

After the above commit the code did these steps:
    Dialog_Partition_New::Dialog_Partition_New(..., selected_partition, ...)
        set_data(..., selected_partition, ...);
            new_partition = selected_partition;

    Dialog_Partition_New::Get_New_Partition(...)
        new_partition.Set(..., "New Partition #%1", ...);

New_partition is copied from the selected unallocated partition in which
the new partition will be created.  So new_partition is now named
"unallocated".  Then the Set() call appends the new name making the
vector:
    paths = ["unallocated", "New Partition #%1"]

As get_path() returns the first name in the paths vector the path name
changed from "New Partition #%1" to "unallocated" causing this bug.

Fix by resetting the new_partition object to clear all vestiges of it
being a copy of the selected unallocated partition, Reset() call, before
then calling Set().  This then appends the new name to an empty vector
making it contain just the required new name:
    paths = ["New Partition #%1"]

Bug 759488 - Pending create partitions are all getting named
             "unallocated"
2015-12-18 09:35:28 -07:00
Mike Fleetwood 2c4df87a2c Return reference from Get_New_Partition() (#757671)
Return newly constructed partition object by reference rather than by
copy from the Copy, Resize/Move and New dialog classes.  This is another
case of stopping copying partition objects in preparation for using
polymorphic Partition objects.  In C++ polymorphism has to use pass by
pointer and reference and not pass by value, copying, to avoid object
slicing.

The returned reference to the partition is only valid until the dialog
object containing the new_partition member is destroyed.  This is okay
because in all three cases the returned referenced partition is copied
into a context with new lifetime expectations before the dialog object
is destroyed.

Case 1: GParted_Core::activate_paste()
    Referenced new_partition is copied in the OperationCopy constructor
    before the dialog object goes out of scope.

    Operation * operation = new OperationCopy( ...,
                                               dialog.Get_New_Partition( ... ),
                                               ... );

Case 2: GParted_Core::activate_new()
    Referenced new_partition is copied in the OperationCreate
    constructor before the dialog object goes out of scope.

    Operation * operation = new OperationCreate( ...,
                                                 dialog.Get_New_Partition( ... ) );

Case 3: GParted_Core::activate_resize()
    Temporary partition object is copied from the referenced
    new_partition before the dialog object goes out of scope.

    Partition part_temp = dialog.Get_New_Partition( ... );

Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
2015-11-11 10:12:18 -07:00
Mike Fleetwood 762cd1094a Return class member from Dialog_Partition_New::Get_New_Partition() (#757671)
Replace the use of local Partition variable with class member in
preparation for Dialog_Partition_New::Get_New_Partition() being changed
to return the new partition object by reference instead of by value.
    part_temp -> new_partition

Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
2015-11-11 10:12:18 -07:00
Mike Fleetwood c86b258475 Create unallocated space within new extended partition after aligning boundaries (#757671)
When creating a new extended partition, the unallocated space within it
was being created before adjusting the partition boundaries for
alignment reasons.  This must be wrong.  Move creation of the
unallocated space to after adjusting the partition boundaries for
alignment reasons.  First introduced by this commit:

    a30f991ca5
    Fix size reduced by 1 MiB when created after cylinder aligned partition

Also added a big FIXME comment explaining how further adjustments are
still made by snap_to_alignment() to the partition boundaries including
a test case where this too late adjustment causes overlapping boundaries
and apply to fail.

Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
2015-11-11 10:12:18 -07:00
Mike Fleetwood 451c2eac43 Rename parameter to selected_partition in Dialog_Partition_New methods (#757671)
This is just to make the parameter name in the Dialog_Partition_New
constructor and set_data() method match the name of the equivalent
parameter in the Dialog_Partition_Copy and Dialog_Partition_Resize_Move
classes.  (All three classes inherit from Dialog_Base_Partition and have
similar interfaces).

Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
2015-11-11 10:12:18 -07:00
Mike Fleetwood 7a4a375ed6 Remove Set_Data() from the copy, resize/move and new dialog class APIs
The copy, resize/move and new dialog classes (Dialog_Partition_Copy,
Dialog_Partition_Resize_Move and Dialog_Partition_New respectively) had
to be used like this:

    construct dialog object passing some parameters
    call Set_Data() to pass more parameters
    run() dialog
    call Get_New_Partition()

There is nothing in the classes which forces Set_Data() to be called,
but it must be called for the dialogs to work and prevent GParted from
crashing.

Make these class APIs safer by making it impossible to program
incorrectly in this regard.  Move all the additional parameters from
each Set_Data() method to each constructor.  The constructors just call
the now private set_data() methods.
2015-06-10 10:44:33 -06:00
Mike Fleetwood 32a5ace156 Rename Dialog_Base_Partition member to new_partition
The member variable was named selected_partition.  It is assigned from
Win_GParted::selected_partition_ptr (which is a pointer to a const
partition object so is never updated).  This gives connotations that it
won't be modified.

However it is updated freely as the new resultant partition object is
prepared before being returned from the dialog, most notable in the
Get_New_Partition() methods.

Therefore rename from selected_partition to new_partition.
2015-06-10 10:44:33 -06:00
Mike Fleetwood 5fd7c92671 Add partition name to Create New Partition dialog (#746214)
Add a partition name entry box to the Create New Partition dialog.  The
entry box is greyed out (not sensitive) for partition table types which
don't support partition naming.  Currently only supported for GPTs.  See
Utils::get_max_partition_name_length() for details.

There was a slightly wider gap between the file system combobox row and
the label entry row when there were only three widgets on the right hand
side of the dialog.  This has been removed now that there are four
widgets so that they are all evenly spaced and they line up with the
four widgets on the left hand side.

So far the partition name can be entered and previewed, but isn't yet
applied to the disk.

Bug 746214 - Partition naming enhancements
2015-03-25 10:02:43 -06:00
Mike Fleetwood 6a9a06af0e Pass Device object when setting up Dialog_Partition_New (#746214)
Adding a partition name entry to the Create New Partition dialog will
need access to these two Device methods: partition_naming_supported()
and get_max_partition_length().  The Set_Data() function already takes
two parameters, only_unformatted and disktype, taken from Device member
variables.

Rather than add two more parameters to the Set_Data() function pass the
Device object instead, replacing the current only_unformatted and
disktype parameters.

Bug 746214 - Partition name enhancements
2015-03-25 10:02:43 -06:00
Mike Fleetwood 650f4c7f20 Remove redundant Gtk::Entry calls in Create New Partition dialog
This is a small tidy-up to remove Gtk::Entry method calls on the file
system label entry box in the Create New Partition dialog which serve no
purpose.

filesystem_label_entry.set_activates_default( true );
    It trying to make the Create New Partition dialog automatically
    close  when Enter is pressed with focus in the label entry box.
    However this doesn't work, presumably because the default widget for
    the dialog is not the Add button.  Remove.

filesystem_label_entry.set_text( partition.get_filesystem_label() );
    Initialises the text in the entry box with the file system label
    from the passed partition object.  The label is blank and the entry
    box defaults to blank.  Achieves nothing.  Remove.

filesystem_label_entry.select_region( 0, filesystem_label_entry.get_text_length() );
    Highlights the empty text in the entry box.  Achieves nothing.
    Remove.

NOTE:
The same set of Gtk::Entry method calls in Dialog_FileSystem_Label() and
Dialog_Partition_Name, which are editing the existing file system label
and partition name respectively, do work and have a useful effect so
shouldn't be removed.
2015-03-25 10:02:43 -06:00
Mike Fleetwood fc599270c2 Rename member object to filesystem_label_entry (#746214)
Rename Gtk::Entry object entry -> filesystem_label_entry in the
Dialog_Partition_New class.  This is in preparation for the introduction
of the partition name entry box in the Create New Partition dialog.

Bug 746214 - Partition name enhancements
2015-03-25 10:02:43 -06:00
Mike Fleetwood 5098744f9a Add whole_device flag to the partition object (#743181)
Need to be able to take different actions in the GParted_Core partition
manipulation methods and in Win_GParted UI methods to deal with
libparted supported partitions or whole disk devices without a partition
table.  Add boolean whole_device to the partition object and set
appropriately to allow for this.

Bug 743181 - Add unpartitioned drive read-write support
2015-03-09 11:04:13 -06:00
Mike Fleetwood 63aeb150ac Rename member variables and methods in Partition class (#741424)
class Partition:
    have_label    -> have_filesystem_label
    label         -> filesystem_label
    label_known() -> filesystem_label_known()
    get_label()   -> get_filesystem_label()
    set_label()   -> set_filesystem_label()

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood 6220a35dac Rework population of the create new partition file system list
Simplify how the list of file system types is populated in the Create
New Partition dialog.  Change from copying everything and removing
unwanted items to only copying required items.  Makes the code simpler
and therefore easier to understand.
2014-10-30 09:55:01 -06:00