bool PartResizerWidget::checkConstraints(qint64 first, qint64 last) const { return (maximumFirstSector() == -1 || first <= maximumFirstSector()) && (minimumFirstSector() == 0 || first >= minimumFirstSector()) && (minimumLastSector() == -1 || last >= minimumLastSector()) && (maximumLastSector() == 0 || last <= maximumLastSector()); }
void SizeDialogBase::setupConstraints() { setMinimumLength(!canShrink() ? partition().length() : qMax(partition().sectorsUsed(), partition().minimumSectors())); setMaximumLength(!canGrow() ? partition().length() : qMin(maximumLastSector() - minimumFirstSector() + 1, partition().maximumSectors())); dialogWidget().partResizerWidget().setMinimumLength(minimumLength()); dialogWidget().partResizerWidget().setMaximumLength(maximumLength()); dialogWidget().labelMinSize().setText(Capacity::formatByteSize(minimumLength() * device().logicalSectorSize())); dialogWidget().labelMaxSize().setText(Capacity::formatByteSize(maximumLength() * device().logicalSectorSize())); dialogWidget().spinCapacity().setEnabled(canShrink() || canGrow()); dialogWidget().partResizerWidget().setMaximumFirstSector(maximumFirstSector()); dialogWidget().partResizerWidget().setMinimumLastSector(minimumLastSector()); const qint64 totalCapacity = sectorsToDialogUnit(device(), maximumLastSector() - minimumFirstSector() + 1); const qint64 minCapacity = sectorsToDialogUnit(device(), minimumLength()); const qint64 maxCapacity = sectorsToDialogUnit(device(), maximumLength()); dialogWidget().spinCapacity().setRange(minCapacity, maxCapacity); const qint64 maxFree = totalCapacity - minCapacity; dialogWidget().spinFreeBefore().setRange(0, maxFree); dialogWidget().spinFreeAfter().setRange(0, maxFree); detailsWidget().spinFirstSector().setRange(minimumFirstSector(), maximumLastSector()); detailsWidget().spinLastSector().setRange(minimumFirstSector(), maximumLastSector()); onAlignToggled(align()); }
bool PartResizerWidget::updateLastSector(qint64 newLastSector) { if (minimumLastSector(align()) > -1 && newLastSector < minimumLastSector(align())) newLastSector = minimumLastSector(align()); if (maximumLastSector(align()) > 0 && newLastSector > maximumLastSector(align())) newLastSector = maximumLastSector(align()); const qint64 newLength = newLastSector - partition().firstSector() + 1; if (newLength < minimumLength()) newLastSector += minimumLength() - newLength; if (newLength > maximumLength()) newLastSector -= newLength - maximumLength(); if (align()) newLastSector = PartitionAlignment::alignedLastSector(device(), partition(), newLastSector, minimumLastSector(align()), maximumLastSector(align()), minimumLength(), maximumLength()); if (newLastSector != partition().lastSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().last(), partition().lastSector() - newLastSector))) { const qint64 deltaLast = newLastSector - partition().lastSector(); partition().setLastSector(newLastSector); partition().fileSystem().setLastSector(newLastSector); resizeLogicals(0, deltaLast); updatePositions(); emit lastSectorChanged(partition().lastSector()); return true; } return false; }
void SizeDialogBase::onSpinCapacityChanged(double newCapacity) { bool success = false; qint64 newLength = qBound( minimumLength(), dialogUnitToSectors(device(), newCapacity), qMin(maximumLastSector() - minimumFirstSector() + 1, maximumLength()) ); if (newLength == partition().length()) return; qint64 delta = newLength - partition().length(); qint64 tmp = qMin(delta, maximumLastSector() - partition().lastSector()); delta -= tmp; const bool signalState = dialogWidget().partResizerWidget().blockSignals(true); if (tmp != 0) { qint64 newLastSector = partition().lastSector() + tmp; if (align()) newLastSector = PartitionAlignment::alignedLastSector(device(), partition(), newLastSector, minimumLastSector(), maximumLastSector(), minimumLength(), maximumLength()); if (dialogWidget().partResizerWidget().updateLastSector(newLastSector)) { success = true; updateSpinFreeAfter(maximumLastSector() - newLastSector); updateSpinLastSector(newLastSector); } } tmp = qMin(delta, partition().firstSector() - minimumFirstSector()); delta -= tmp; if (tmp != 0) { qint64 newFirstSector = partition().firstSector() - tmp; if (align()) newFirstSector = PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector, minimumFirstSector(), maximumFirstSector(), minimumLength(), maximumLength()); if (dialogWidget().partResizerWidget().updateFirstSector(newFirstSector)) { success = true; updateSpinFreeBefore(newFirstSector - minimumFirstSector()); updateSpinFirstSector(newFirstSector); } } dialogWidget().partResizerWidget().blockSignals(signalState); if (success) setDirty(); }
bool PartResizerWidget::movePartition(qint64 newFirstSector) { const qint64 originalLength = partition().length(); const bool isLengthAligned = PartitionAlignment::isLengthAligned(device(), partition()); if (maximumFirstSector(align()) > -1 && newFirstSector > maximumFirstSector(align())) newFirstSector = maximumFirstSector(align()); if (minimumFirstSector(align()) > 0 && newFirstSector < minimumFirstSector(align())) newFirstSector = minimumFirstSector(align()); if (align()) newFirstSector = PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector, minimumFirstSector(align()), maximumFirstSector(align()), -1, -1); qint64 delta = newFirstSector - partition().firstSector(); if (delta == 0) return false; qint64 newLastSector = partition().lastSector() + delta; if (minimumLastSector(align()) > -1 && newLastSector < minimumLastSector(align())) { const qint64 deltaLast = minimumLastSector(align()) - newLastSector; newFirstSector += deltaLast; newLastSector += deltaLast; } if (maximumLastSector(align()) > 0 && newLastSector > maximumLastSector(align())) { const qint64 deltaLast = newLastSector - maximumLastSector(align()); newFirstSector -= deltaLast; newLastSector -= deltaLast; } if (align()) newLastSector = PartitionAlignment::alignedLastSector(device(), partition(), newLastSector, minimumLastSector(align()), maximumLastSector(align()), -1, -1, originalLength, isLengthAligned); if (newLastSector == partition().lastSector()) return false; if (isLengthAligned && newLastSector - newFirstSector + 1 != partition().length()) { qDebug() << "length changes while trying to move partition " << partition().deviceNode() << ". new first: " << newFirstSector << ", new last: " << newLastSector << ", old length: " << partition().length() << ", new length: " << newLastSector - newFirstSector + 1; return false; } if (!checkConstraints(newFirstSector, newLastSector)) { qDebug() << "constraints not satisfied while trying to move partition " << partition().deviceNode() << ". new first: " << newFirstSector << ", new last: " << newLastSector; return false; } if (align() && !PartitionAlignment::isAligned(device(), partition(), newFirstSector, newLastSector, true)) { qDebug() << "partition " << partition().deviceNode() << " not aligned but supposed to be. new first: " << newFirstSector << " delta: " << PartitionAlignment::firstDelta(device(), partition(), newFirstSector) << ", new last: " << newLastSector << ", delta: " << PartitionAlignment::lastDelta(device(), partition(), newLastSector); return false; } if (partition().children().size() > 0 && (!checkAlignment(*partition().children().first(), partition().firstSector() - newFirstSector) || !checkAlignment(*partition().children().last(), partition().lastSector() - newLastSector))) { qDebug() << "cannot align children while trying to move partition " << partition().deviceNode(); return false; } partition().setFirstSector(newFirstSector); partition().fileSystem().setFirstSector(newFirstSector); partition().setLastSector(newLastSector); partition().fileSystem().setLastSector(newLastSector); updatePositions(); emit firstSectorChanged(partition().firstSector()); emit lastSectorChanged(partition().lastSector()); return true; }