Don't allow creating a new partition table on a device with currently mounted

partitions.

svn path=/trunk/playground/sysadmin/partitionmanager/; revision=868375
This commit is contained in:
Volker Lanz 2008-10-06 07:31:11 +00:00
parent acb8634d81
commit 26d914e7c8
6 changed files with 24 additions and 11 deletions

View File

@ -239,16 +239,7 @@ bool Partition::hasChildren() const
/** Sets an extended Partition to mounted if any of its children are mounted */
void Partition::checkChildrenMounted()
{
bool isBusy = false;
foreach (const Partition* child, children())
if (child->isMounted())
{
isBusy = true;
break;
}
setMounted(isBusy);
setMounted(isChildMounted());
}
/** @return true if this Partition can be mounted */

View File

@ -205,3 +205,13 @@ qint32 PartitionNode::highestMountedChild() const
return result;
}
/** @return true if any of the partition's children are mounted */
bool PartitionNode::isChildMounted() const
{
foreach (const Partition* child, children())
if (child->isMounted() || child->hasChildren() && child->isChildMounted())
return true;
return false;
}

View File

@ -68,6 +68,7 @@ class PartitionNode : public QObject
virtual const Partitions& children() const = 0;
virtual void append(Partition* p) = 0;
virtual qint32 highestMountedChild() const;
virtual bool isChildMounted() const;
protected:
virtual void clearChildren();

View File

@ -381,7 +381,7 @@ void MainWindow::setupDevicesList()
void MainWindow::enableActions()
{
actionCollection()->action("createNewPartitionTable")->setEnabled(selectedDevice() != NULL);
actionCollection()->action("createNewPartitionTable")->setEnabled(CreatePartitionTableOperation::canCreate(selectedDevice()));
const Partition* part = selectedPartition();

View File

@ -67,6 +67,15 @@ bool CreatePartitionTableOperation::execute(Report& parent)
return Operation::execute(parent);
}
/** Can a new partition table be created on a device?
@param device pointer to the device, can be NULL
@return true if a new partition table can be created on @p device
*/
bool CreatePartitionTableOperation::canCreate(const Device* device)
{
return device != NULL && !device->partitionTable().isChildMounted();
}
QString CreatePartitionTableOperation::description() const
{
return QString(i18nc("@info/plain", "Create a new partition table on <filename>%1</filename>", targetDevice().deviceNode()));

View File

@ -47,6 +47,8 @@ class CreatePartitionTableOperation : public Operation
void undo();
bool execute(Report& parent);
static bool canCreate(const Device* device);
protected:
Device& targetDevice() { return m_TargetDevice; }
const Device& targetDevice() const { return m_TargetDevice; }