2013-01-23 17:28:19 +00:00
|
|
|
# Disk resizing dialog
|
|
|
|
#
|
2014-04-07 12:38:09 +00:00
|
|
|
# Copyright (C) 2012-2013 Red Hat, Inc.
|
2013-01-23 17:28:19 +00:00
|
|
|
#
|
|
|
|
# This copyrighted material is made available to anyone wishing to use,
|
|
|
|
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
|
|
# the GNU General Public License v.2, or (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
# Public License for more details. You should have received a copy of the
|
|
|
|
# GNU General Public License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
|
|
# source code or documentation are not subject to the GNU General Public
|
|
|
|
# License and may only be used or replicated with the express permission of
|
|
|
|
# Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# Red Hat Author(s): Chris Lumens <clumens@redhat.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
from __future__ import division
|
2014-04-07 12:38:09 +00:00
|
|
|
from collections import namedtuple
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
from gi.repository import Gdk, Gtk
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
from pyanaconda.i18n import _, C_, N_, P_
|
2013-01-23 17:28:19 +00:00
|
|
|
from pyanaconda.ui.gui import GUIObject
|
2015-05-30 11:20:59 +00:00
|
|
|
from pyanaconda.ui.gui.utils import blockedHandler, escape_markup, timed_action
|
2014-04-07 12:38:09 +00:00
|
|
|
from blivet.size import Size
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
__all__ = ["ResizeDialog"]
|
|
|
|
|
|
|
|
DEVICE_ID_COL = 0
|
|
|
|
DESCRIPTION_COL = 1
|
|
|
|
FILESYSTEM_COL = 2
|
|
|
|
RECLAIMABLE_COL = 3
|
2014-04-07 12:38:09 +00:00
|
|
|
ACTION_COL = 4
|
|
|
|
EDITABLE_COL = 5
|
2015-03-23 11:36:12 +00:00
|
|
|
TYPE_COL = 6
|
|
|
|
TOOLTIP_COL = 7
|
|
|
|
RESIZE_TARGET_COL = 8
|
|
|
|
NAME_COL = 9
|
|
|
|
|
|
|
|
TY_NORMAL = 0
|
|
|
|
TY_FREE_SPACE = 1
|
|
|
|
TY_PROTECTED = 2
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
PartStoreRow = namedtuple("PartStoreRow", ["id", "desc", "fs", "reclaimable",
|
2015-03-23 11:36:12 +00:00
|
|
|
"action", "editable", "ty",
|
|
|
|
"tooltip", "target", "name"])
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
PRESERVE = N_("Preserve")
|
|
|
|
SHRINK = N_("Shrink")
|
|
|
|
DELETE = N_("Delete")
|
2015-03-23 11:36:12 +00:00
|
|
|
NOTHING = ""
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
class ResizeDialog(GUIObject):
|
2014-04-07 12:38:09 +00:00
|
|
|
builderObjects = ["actionStore", "diskStore", "resizeDialog", "resizeAdjustment"]
|
2013-01-23 17:28:19 +00:00
|
|
|
mainWidgetName = "resizeDialog"
|
|
|
|
uiFile = "spokes/lib/resize.glade"
|
|
|
|
|
|
|
|
def __init__(self, data, storage, payload):
|
|
|
|
GUIObject.__init__(self, data)
|
|
|
|
self.storage = storage
|
|
|
|
self.payload = payload
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
self._initialFreeSpace = Size(0)
|
2015-03-23 11:36:12 +00:00
|
|
|
self._selectedReclaimableSpace = Size(0)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
self._actionStore = self.builder.get_object("actionStore")
|
|
|
|
self._diskStore = self.builder.get_object("diskStore")
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
self._selection = self.builder.get_object("diskView-selection")
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
self._view = self.builder.get_object("diskView")
|
|
|
|
self._diskStore = self.builder.get_object("diskStore")
|
|
|
|
self._reclaimable_label = self.builder.get_object("reclaimableSpaceLabel")
|
|
|
|
self._selected_label = self.builder.get_object("selectedSpaceLabel")
|
|
|
|
|
|
|
|
self._required_label = self.builder.get_object("requiredSpaceLabel")
|
|
|
|
markup = self._required_label.get_label()
|
2015-03-23 11:36:12 +00:00
|
|
|
self._required_label.set_markup(markup % escape_markup(str(self.payload.spaceRequired)))
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
self._reclaimDescLabel = self.builder.get_object("reclaimDescLabel")
|
|
|
|
|
|
|
|
self._resizeButton = self.builder.get_object("resizeButton")
|
|
|
|
|
|
|
|
self._preserveButton = self.builder.get_object("preserveButton")
|
2014-04-07 12:38:09 +00:00
|
|
|
self._shrinkButton = self.builder.get_object("shrinkButton")
|
2013-01-23 17:28:19 +00:00
|
|
|
self._deleteButton = self.builder.get_object("deleteButton")
|
2014-04-07 12:38:09 +00:00
|
|
|
self._resizeSlider = self.builder.get_object("resizeSlider")
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
def _description(self, part):
|
|
|
|
# First, try to find the partition in some known Root. If we find
|
|
|
|
# it, return the mountpoint as the description.
|
|
|
|
for root in self.storage.roots:
|
2015-05-30 11:20:59 +00:00
|
|
|
for (mount, device) in root.mounts.items():
|
2013-01-23 17:28:19 +00:00
|
|
|
if device == part:
|
|
|
|
return "%s (%s)" % (mount, root.name)
|
|
|
|
|
|
|
|
# Otherwise, fall back on increasingly vague information.
|
|
|
|
if not part.isleaf:
|
|
|
|
return self.storage.devicetree.getChildren(part)[0].name
|
|
|
|
if getattr(part.format, "label", None):
|
|
|
|
return part.format.label
|
|
|
|
elif getattr(part.format, "name", None):
|
|
|
|
return part.format.name
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def _get_tooltip(self, device):
|
|
|
|
if device.protected:
|
|
|
|
return _("This device contains the installation source.")
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def populate(self, disks):
|
|
|
|
totalDisks = 0
|
2015-03-23 11:36:12 +00:00
|
|
|
totalReclaimableSpace = Size(0)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
self._initialFreeSpace = Size(0)
|
2015-03-23 11:36:12 +00:00
|
|
|
self._selectedReclaimableSpace = Size(0)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
canShrinkSomething = False
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
free_space = self.storage.getFreeSpace(disks=disks)
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
for disk in disks:
|
|
|
|
# First add the disk itself.
|
2014-04-07 12:38:09 +00:00
|
|
|
editable = not disk.protected
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
if disk.partitioned:
|
|
|
|
fstype = ""
|
2015-03-23 11:36:12 +00:00
|
|
|
diskReclaimableSpace = Size(0)
|
2013-01-23 17:28:19 +00:00
|
|
|
else:
|
2015-03-23 11:36:12 +00:00
|
|
|
fstype = disk.format.name
|
2013-01-23 17:28:19 +00:00
|
|
|
diskReclaimableSpace = disk.size
|
|
|
|
|
|
|
|
itr = self._diskStore.append(None, [disk.id,
|
2015-03-23 11:36:12 +00:00
|
|
|
"%s %s" % (disk.size.humanReadable(max_places=1), disk.description),
|
2013-01-23 17:28:19 +00:00
|
|
|
fstype,
|
|
|
|
"<span foreground='grey' style='italic'>%s total</span>",
|
|
|
|
_(PRESERVE),
|
|
|
|
editable,
|
2015-03-23 11:36:12 +00:00
|
|
|
TY_NORMAL,
|
2014-04-07 12:38:09 +00:00
|
|
|
self._get_tooltip(disk),
|
|
|
|
int(disk.size),
|
|
|
|
disk.name])
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
if disk.partitioned:
|
|
|
|
# Then add all its partitions.
|
|
|
|
for dev in self.storage.devicetree.getChildren(disk):
|
|
|
|
if dev.isExtended and disk.format.logicalPartitions:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Devices that are not resizable are still deletable.
|
|
|
|
if dev.resizable:
|
|
|
|
freeSize = dev.size - dev.minSize
|
2014-04-07 12:38:09 +00:00
|
|
|
resizeString = _("%(freeSize)s of %(devSize)s") \
|
2015-03-23 11:36:12 +00:00
|
|
|
% {"freeSize": freeSize.humanReadable(max_places=1), "devSize": dev.size.humanReadable(max_places=1)}
|
2013-01-23 17:28:19 +00:00
|
|
|
if not dev.protected:
|
|
|
|
canShrinkSomething = True
|
|
|
|
else:
|
|
|
|
freeSize = dev.size
|
2015-03-23 11:36:12 +00:00
|
|
|
resizeString = "<span foreground='grey'>%s</span>" % \
|
|
|
|
escape_markup(_("Not resizeable"))
|
|
|
|
|
|
|
|
if dev.protected:
|
|
|
|
ty = TY_PROTECTED
|
|
|
|
else:
|
|
|
|
ty = TY_NORMAL
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
self._diskStore.append(itr, [dev.id,
|
|
|
|
self._description(dev),
|
2015-03-23 11:36:12 +00:00
|
|
|
dev.format.name,
|
2014-04-07 12:38:09 +00:00
|
|
|
resizeString,
|
2013-01-23 17:28:19 +00:00
|
|
|
_(PRESERVE),
|
|
|
|
not dev.protected,
|
2015-03-23 11:36:12 +00:00
|
|
|
ty,
|
2014-04-07 12:38:09 +00:00
|
|
|
self._get_tooltip(dev),
|
|
|
|
int(dev.size),
|
|
|
|
dev.name])
|
2013-01-23 17:28:19 +00:00
|
|
|
diskReclaimableSpace += freeSize
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# And then add another uneditable line that lists how much space is
|
|
|
|
# already free in the disk.
|
|
|
|
diskFree = free_space[disk.name][0]
|
2015-03-23 11:36:12 +00:00
|
|
|
if diskFree >= Size("1MiB"):
|
|
|
|
freeSpaceString = "<span foreground='grey' style='italic'>%s</span>" % \
|
|
|
|
escape_markup(_("Free space"))
|
2014-04-07 12:38:09 +00:00
|
|
|
self._diskStore.append(itr, [disk.id,
|
2015-03-23 11:36:12 +00:00
|
|
|
freeSpaceString,
|
2014-04-07 12:38:09 +00:00
|
|
|
"",
|
2015-03-23 11:36:12 +00:00
|
|
|
"<span foreground='grey' style='italic'>%s</span>" % escape_markup(diskFree.humanReadable(max_places=1)),
|
|
|
|
NOTHING,
|
2014-04-07 12:38:09 +00:00
|
|
|
False,
|
2015-03-23 11:36:12 +00:00
|
|
|
TY_FREE_SPACE,
|
2014-04-07 12:38:09 +00:00
|
|
|
self._get_tooltip(disk),
|
2015-03-23 11:36:12 +00:00
|
|
|
diskFree,
|
2014-04-07 12:38:09 +00:00
|
|
|
""])
|
|
|
|
self._initialFreeSpace += diskFree
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
# And then go back and fill in the total reclaimable space for the
|
|
|
|
# disk, now that we know what each partition has reclaimable.
|
2015-03-23 11:36:12 +00:00
|
|
|
self._diskStore[itr][RECLAIMABLE_COL] = self._diskStore[itr][RECLAIMABLE_COL] % diskReclaimableSpace
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
totalDisks += 1
|
|
|
|
totalReclaimableSpace += diskReclaimableSpace
|
|
|
|
|
|
|
|
self._update_labels(totalDisks, totalReclaimableSpace, 0)
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
description = _("You can remove existing file systems you no longer need to free up space "
|
|
|
|
"for this installation. Removing a file system will permanently delete all "
|
2013-01-23 17:28:19 +00:00
|
|
|
"of the data it contains.")
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
if canShrinkSomething:
|
|
|
|
description += "\n\n"
|
2015-05-30 11:20:59 +00:00
|
|
|
description += _("There is also free space available in pre-existing file systems. "
|
2014-04-07 12:38:09 +00:00
|
|
|
"While it's risky and we recommend you back up your data first, you "
|
|
|
|
"can recover that free disk space and make it available for this "
|
|
|
|
"installation below.")
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
self._reclaimDescLabel.set_text(description)
|
2015-03-23 11:36:12 +00:00
|
|
|
self._update_reclaim_button(Size(0))
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
def _update_labels(self, nDisks=None, totalReclaimable=None, selectedReclaimable=None):
|
|
|
|
if nDisks is not None and totalReclaimable is not None:
|
2015-05-30 11:20:59 +00:00
|
|
|
text = P_("<b>%(count)s disk; %(size)s reclaimable space</b> (in file systems)",
|
|
|
|
"<b>%(count)s disks; %(size)s reclaimable space</b> (in file systems)",
|
2015-03-23 11:36:12 +00:00
|
|
|
nDisks) % {"count" : escape_markup(str(nDisks)),
|
|
|
|
"size" : escape_markup(totalReclaimable)}
|
2013-01-23 17:28:19 +00:00
|
|
|
self._reclaimable_label.set_markup(text)
|
|
|
|
|
|
|
|
if selectedReclaimable is not None:
|
2015-03-23 11:36:12 +00:00
|
|
|
text = _("Total selected space to reclaim: <b>%s</b>") % \
|
|
|
|
escape_markup(selectedReclaimable)
|
2013-01-23 17:28:19 +00:00
|
|
|
self._selected_label.set_markup(text)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def _setup_slider(self, device, value):
|
|
|
|
"""Set up the slider for this device, pulling out any previously given
|
|
|
|
shrink value as the default. This also sets up the ticks on the
|
|
|
|
slider and keyboard support. Any devices that are not resizable
|
|
|
|
will not have a slider displayed, so they do not need to be worried
|
|
|
|
with here.
|
2015-03-23 11:36:12 +00:00
|
|
|
|
|
|
|
:param device: The device
|
|
|
|
:type device: PartitionDevice
|
|
|
|
:param value: default value to set
|
|
|
|
:type value: Size
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
2015-03-23 11:36:12 +00:00
|
|
|
# Convert the Sizes to ints
|
|
|
|
minSize = int(device.minSize)
|
|
|
|
size = int(device.size)
|
|
|
|
default_value = int(value)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# The slider needs to be keyboard-accessible. We'll make small movements change in
|
|
|
|
# 1% increments, and large movements in 5% increments.
|
2015-03-23 11:36:12 +00:00
|
|
|
distance = size - minSize
|
|
|
|
onePercent = int(distance / 100)
|
|
|
|
fivePercent = int(distance / 20)
|
|
|
|
twentyPercent = int(distance / 5)
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
with blockedHandler(self._resizeSlider, self.on_resize_value_changed):
|
|
|
|
self._resizeSlider.set_range(minSize, size)
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
self._resizeSlider.set_value(default_value)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
adjustment = self.builder.get_object("resizeAdjustment")
|
2015-03-23 11:36:12 +00:00
|
|
|
adjustment.configure(default_value, minSize, size, onePercent, fivePercent, 0)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# And then the slider needs a couple tick marks for easier navigation.
|
|
|
|
self._resizeSlider.clear_marks()
|
|
|
|
for i in range(1, 5):
|
2015-03-23 11:36:12 +00:00
|
|
|
self._resizeSlider.add_mark(minSize + i * twentyPercent, Gtk.PositionType.BOTTOM, None)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# Finally, add tick marks for the ends.
|
2015-03-23 11:36:12 +00:00
|
|
|
self._resizeSlider.add_mark(minSize, Gtk.PositionType.BOTTOM, str(device.minSize))
|
|
|
|
self._resizeSlider.add_mark(size, Gtk.PositionType.BOTTOM, str(device.size))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
def _update_action_buttons(self, row):
|
|
|
|
obj = PartStoreRow(*row)
|
|
|
|
device = self.storage.devicetree.getDeviceByID(obj.id)
|
|
|
|
|
|
|
|
# Disks themselves may be editable in certain ways, but they are never
|
|
|
|
# shrinkable.
|
|
|
|
self._preserveButton.set_sensitive(obj.editable)
|
|
|
|
self._shrinkButton.set_sensitive(obj.editable and not device.isDisk)
|
|
|
|
self._deleteButton.set_sensitive(obj.editable)
|
|
|
|
self._resizeSlider.set_visible(False)
|
|
|
|
|
|
|
|
if not obj.editable:
|
2013-01-23 17:28:19 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# If the selected filesystem does not support shrinking, make that
|
|
|
|
# button insensitive.
|
2014-04-07 12:38:09 +00:00
|
|
|
self._shrinkButton.set_sensitive(device.resizable)
|
|
|
|
|
|
|
|
if device.resizable:
|
2015-03-23 11:36:12 +00:00
|
|
|
self._setup_slider(device, Size(obj.target))
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
# Then, disable the button for whatever action is currently selected.
|
|
|
|
# It doesn't make a lot of sense to allow clicking that.
|
2014-04-07 12:38:09 +00:00
|
|
|
if obj.action == _(PRESERVE):
|
2013-01-23 17:28:19 +00:00
|
|
|
self._preserveButton.set_sensitive(False)
|
2014-04-07 12:38:09 +00:00
|
|
|
elif obj.action == _(SHRINK):
|
|
|
|
self._shrinkButton.set_sensitive(False)
|
|
|
|
self._resizeSlider.set_visible(True)
|
|
|
|
elif obj.action == _(DELETE):
|
2013-01-23 17:28:19 +00:00
|
|
|
self._deleteButton.set_sensitive(False)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def _update_reclaim_button(self, got):
|
2015-03-23 11:36:12 +00:00
|
|
|
self._resizeButton.set_sensitive(got+self._initialFreeSpace >= self.payload.spaceRequired)
|
|
|
|
|
|
|
|
# pylint: disable=arguments-differ
|
2013-01-23 17:28:19 +00:00
|
|
|
def refresh(self, disks):
|
|
|
|
super(ResizeDialog, self).refresh()
|
|
|
|
|
|
|
|
# clear out the store and repopulate it from the devicetree
|
|
|
|
self._diskStore.clear()
|
|
|
|
self.populate(disks)
|
|
|
|
|
|
|
|
self._view.expand_all()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
rc = self.window.run()
|
|
|
|
self.window.destroy()
|
|
|
|
return rc
|
|
|
|
|
|
|
|
# Signal handlers.
|
2014-04-07 12:38:09 +00:00
|
|
|
def on_key_pressed(self, window, event, *args):
|
|
|
|
# Handle any keyboard events. Right now this is just delete for
|
|
|
|
# removing a partition, but it could include more later.
|
|
|
|
if not event or event and event.type != Gdk.EventType.KEY_RELEASE:
|
|
|
|
return
|
|
|
|
|
|
|
|
if event.keyval == Gdk.KEY_Delete and self._deleteButton.get_sensitive():
|
|
|
|
self._deleteButton.emit("clicked")
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def _sumReclaimableSpace(self, model, path, itr, *args):
|
2014-04-07 12:38:09 +00:00
|
|
|
obj = PartStoreRow(*model[itr])
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
device = self.storage.devicetree.getDeviceByID(obj.id)
|
|
|
|
if device.isDisk and device.partitioned:
|
2013-01-23 17:28:19 +00:00
|
|
|
return False
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
if obj.action == _(PRESERVE):
|
2013-01-23 17:28:19 +00:00
|
|
|
return False
|
2014-04-07 12:38:09 +00:00
|
|
|
if obj.action == _(SHRINK):
|
2015-03-23 11:36:12 +00:00
|
|
|
self._selectedReclaimableSpace += device.size - Size(obj.target)
|
2014-04-07 12:38:09 +00:00
|
|
|
elif obj.action == _(DELETE):
|
|
|
|
self._selectedReclaimableSpace += int(device.size)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def on_preserve_clicked(self, button):
|
2014-04-07 12:38:09 +00:00
|
|
|
itr = self._selection.get_selected()[1]
|
|
|
|
self._actionChanged(itr, PRESERVE)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
def on_shrink_clicked(self, button):
|
2014-04-07 12:38:09 +00:00
|
|
|
itr = self._selection.get_selected()[1]
|
|
|
|
self._actionChanged(itr, SHRINK)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
def on_delete_clicked(self, button):
|
2014-04-07 12:38:09 +00:00
|
|
|
itr = self._selection.get_selected()[1]
|
|
|
|
self._actionChanged(itr, DELETE)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def _actionChanged(self, itr, newAction):
|
2013-01-23 17:28:19 +00:00
|
|
|
if not itr:
|
|
|
|
return
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# Handle the row selected when a button was pressed.
|
2013-01-23 17:28:19 +00:00
|
|
|
selectedRow = self._diskStore[itr]
|
|
|
|
selectedRow[ACTION_COL] = _(newAction)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# If that row is a disk header, we need to process all the partitions
|
|
|
|
# it contains.
|
|
|
|
device = self.storage.devicetree.getDeviceByID(selectedRow[DEVICE_ID_COL])
|
|
|
|
if device.isDisk and device.partitioned:
|
|
|
|
partItr = self._diskStore.iter_children(itr)
|
|
|
|
while partItr:
|
2015-03-23 11:36:12 +00:00
|
|
|
# Immutable entries are those that we can't do anything to - like
|
|
|
|
# the free space lines. We just want to leave them in the display
|
|
|
|
# for information, but you can't choose to preserve/delete/shrink
|
|
|
|
# them.
|
|
|
|
if self._diskStore[partItr][TYPE_COL] in [TY_FREE_SPACE, TY_PROTECTED]:
|
|
|
|
partItr = self._diskStore.iter_next(partItr)
|
|
|
|
continue
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
self._diskStore[partItr][ACTION_COL] = _(newAction)
|
|
|
|
|
|
|
|
# If the user marked a whole disk for deletion, they can't go in and
|
|
|
|
# un-delete partitions under it.
|
|
|
|
if newAction == DELETE:
|
|
|
|
self._diskStore[partItr][EDITABLE_COL] = False
|
|
|
|
elif newAction == PRESERVE:
|
|
|
|
part = self.storage.devicetree.getDeviceByID(self._diskStore[partItr][DEVICE_ID_COL])
|
|
|
|
self._diskStore[partItr][EDITABLE_COL] = not part.protected
|
|
|
|
|
|
|
|
partItr = self._diskStore.iter_next(partItr)
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
# And then we're keeping a running tally of how much space the user
|
|
|
|
# has selected to reclaim, so reflect that in the UI.
|
2015-03-23 11:36:12 +00:00
|
|
|
self._selectedReclaimableSpace = Size(0)
|
2013-01-23 17:28:19 +00:00
|
|
|
self._diskStore.foreach(self._sumReclaimableSpace, None)
|
|
|
|
self._update_labels(selectedReclaimable=self._selectedReclaimableSpace)
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
self._update_reclaim_button(self._selectedReclaimableSpace)
|
2014-04-07 12:38:09 +00:00
|
|
|
self._update_action_buttons(selectedRow)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
def _recursiveRemove(self, device):
|
|
|
|
""" Remove a device, or if it has protected children, just remove the
|
|
|
|
unprotected children.
|
|
|
|
"""
|
|
|
|
if not any(d for d in self.storage.devices \
|
|
|
|
if device in d.parents and d.protected):
|
|
|
|
# No protected children, remove the device
|
|
|
|
self.storage.recursiveRemove(device)
|
|
|
|
else:
|
|
|
|
# Only remove unprotected children
|
|
|
|
unprotected = (d for d in self.storage.devices \
|
|
|
|
if device in d.parents and not d.protected)
|
|
|
|
for child in unprotected:
|
|
|
|
if child in self.storage.devices:
|
|
|
|
self.storage.recursiveRemove(child)
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def _scheduleActions(self, model, path, itr, *args):
|
2014-04-07 12:38:09 +00:00
|
|
|
obj = PartStoreRow(*model[itr])
|
|
|
|
device = self.storage.devicetree.getDeviceByID(obj.id)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
if not obj.editable:
|
2013-01-23 17:28:19 +00:00
|
|
|
return False
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
if obj.action == _(PRESERVE):
|
2013-01-23 17:28:19 +00:00
|
|
|
return False
|
2014-04-07 12:38:09 +00:00
|
|
|
elif obj.action == _(SHRINK) and int(device.size) != int(obj.target):
|
2013-01-23 17:28:19 +00:00
|
|
|
if device.resizable:
|
2015-03-23 11:36:12 +00:00
|
|
|
aligned = device.alignTargetSize(Size(obj.target))
|
|
|
|
self.storage.resizeDevice(device, aligned)
|
2013-01-23 17:28:19 +00:00
|
|
|
else:
|
2015-03-23 11:36:12 +00:00
|
|
|
self._recursiveRemove(device)
|
2014-04-07 12:38:09 +00:00
|
|
|
elif obj.action == _(DELETE):
|
2015-03-23 11:36:12 +00:00
|
|
|
self._recursiveRemove(device)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def on_resize_clicked(self, *args):
|
|
|
|
self._diskStore.foreach(self._scheduleActions, None)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def on_delete_all_clicked(self, button, *args):
|
2015-03-23 11:36:12 +00:00
|
|
|
if button.get_label() == C_("GUI|Reclaim Dialog", "Delete _all"):
|
2014-04-07 12:38:09 +00:00
|
|
|
action = DELETE
|
2015-03-23 11:36:12 +00:00
|
|
|
button.set_label(C_("GUI|Reclaim Dialog", "Preserve _all"))
|
2014-04-07 12:38:09 +00:00
|
|
|
else:
|
|
|
|
action = PRESERVE
|
2015-03-23 11:36:12 +00:00
|
|
|
button.set_label(C_("GUI|Reclaim Dialog", "Delete _all"))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
itr = self._diskStore.get_iter_first()
|
|
|
|
while itr:
|
|
|
|
obj = PartStoreRow(*self._diskStore[itr])
|
|
|
|
if not obj.editable:
|
|
|
|
itr = self._diskStore.iter_next(itr)
|
|
|
|
continue
|
|
|
|
|
|
|
|
device = self.storage.devicetree.getDeviceByID(obj.id)
|
|
|
|
if device.isDisk:
|
|
|
|
self._actionChanged(itr, action)
|
|
|
|
|
|
|
|
itr = self._diskStore.iter_next(itr)
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def on_row_clicked(self, view, path, column):
|
|
|
|
# This handles when the user clicks on a row in the view. We use it
|
|
|
|
# only for expanding/collapsing disk headers.
|
|
|
|
if view.row_expanded(path):
|
|
|
|
view.collapse_row(path)
|
|
|
|
else:
|
|
|
|
view.expand_row(path, True)
|
|
|
|
|
|
|
|
def on_selection_changed(self, selection):
|
|
|
|
# This handles when the selection changes. It's very similar to what
|
|
|
|
# on_row_clicked above does, but this handler only deals with changes in
|
|
|
|
# selection. Thus, clicking on a disk header to collapse it and then
|
|
|
|
# immediately clicking on it again to expand it would not work when
|
|
|
|
# dealt with here.
|
2014-04-07 12:38:09 +00:00
|
|
|
itr = selection.get_selected()[1]
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
if not itr:
|
|
|
|
return
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
self._update_action_buttons(self._diskStore[itr])
|
|
|
|
|
|
|
|
@timed_action(delay=200, threshold=500, busy_cursor=False)
|
|
|
|
def on_resize_value_changed(self, rng):
|
|
|
|
(model, itr) = self._selection.get_selected()
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
old_delta = Size(rng.get_adjustment().get_upper()) - int(model[itr][RESIZE_TARGET_COL])
|
2014-04-07 12:38:09 +00:00
|
|
|
self._selectedReclaimableSpace -= old_delta
|
|
|
|
|
|
|
|
# Update the target size in the store.
|
2015-03-23 11:36:12 +00:00
|
|
|
model[itr][RESIZE_TARGET_COL] = Size(rng.get_value())
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# Update the "Total selected space" label.
|
2015-03-23 11:36:12 +00:00
|
|
|
delta = Size(rng.get_adjustment().get_upper()) - int(rng.get_value())
|
2014-04-07 12:38:09 +00:00
|
|
|
self._selectedReclaimableSpace += delta
|
|
|
|
self._update_labels(selectedReclaimable=self._selectedReclaimableSpace)
|
|
|
|
|
|
|
|
# And then the reclaim button, in case they've made enough space.
|
2015-03-23 11:36:12 +00:00
|
|
|
self._update_reclaim_button(self._selectedReclaimableSpace)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
def resize_slider_format(self, scale, value):
|
|
|
|
# This makes the value displayed under the slider prettier than just a
|
|
|
|
# single number.
|
2015-03-23 11:36:12 +00:00
|
|
|
return str(Size(value))
|