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()); }
BytevectorCell* BytevectorCell::fromAppended(World &world, const std::list<const BytevectorCell*> &byteVectors) { if (byteVectors.size() == 1) { // This allows implicit data sharing while the below always allocates return byteVectors.front()->copy(world); } std::uint64_t totalLength = 0; for(auto byteVector : byteVectors) { totalLength += byteVector->length(); } if (totalLength > maximumLength()) { return nullptr; } SharedByteArray *newByteArray = SharedByteArray::createInstance(totalLength); std::uint8_t *copyPtr = newByteArray->data(); for(auto byteVector : byteVectors) { memcpy(copyPtr, byteVector->byteArray()->data(), byteVector->length()); copyPtr += byteVector->length(); } return BytevectorCell::withByteArray(world, newByteArray, totalLength); }
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::updateFirstSector(qint64 newFirstSector) { if (maximumFirstSector(align()) > -1 && newFirstSector > maximumFirstSector(align())) newFirstSector = maximumFirstSector(align()); if (minimumFirstSector(align()) > 0 && newFirstSector < minimumFirstSector(align())) newFirstSector = minimumFirstSector(align()); const qint64 newLength = partition().lastSector() - newFirstSector + 1; if (newLength < minimumLength()) newFirstSector -= minimumLength() - newLength; if (newLength > maximumLength()) newFirstSector -= newLength - maximumLength(); if (align()) newFirstSector = PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector, minimumFirstSector(align()), maximumFirstSector(align()), minimumLength(), maximumLength()); if (newFirstSector != partition().firstSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().first(), partition().firstSector() - newFirstSector))) { const qint64 deltaFirst = partition().firstSector() - newFirstSector; partition().setFirstSector(newFirstSector); partition().fileSystem().setFirstSector(newFirstSector); resizeLogicals(deltaFirst, 0); updatePositions(); emit firstSectorChanged(partition().firstSector()); return true; } return false; }
void SizeDialogBase::onSpinFreeAfterChanged(double newAfter) { bool success = false; const double oldAfter = sectorsToDialogUnit(device(), maximumLastSector() - partition().lastSector()); const qint64 newLastSector = maximumLastSector() - dialogUnitToSectors(device(), newAfter); const qint64 deltaCorrection = newAfter > oldAfter ? PartitionAlignment::lastDelta(device(), partition(), newLastSector) : 0; // see onSpinFreeBeforeChanged on why this is as complicated as it is qint64 alignedLastSector = align() ? PartitionAlignment::alignedLastSector(device(), partition(), newLastSector - deltaCorrection, -1, maximumLastSector(), -1, -1) : newLastSector; if (dialogWidget().partResizerWidget().movePartition(alignedLastSector - partition().length() + 1)) success = true; else { alignedLastSector = align() ? PartitionAlignment::alignedLastSector(device(), partition(), newLastSector - deltaCorrection, -1, maximumLastSector(), minimumLength(), maximumLength()) : newLastSector; success = dialogWidget().partResizerWidget().updateLastSector(alignedLastSector); } if (success) setDirty(); else // TODO: this is not the best solution: we should prevent the user from entering // illegal values with a validator updateSpinFreeAfter(dialogUnitToSectors(device(), oldAfter)); }
void SizeDialogBase::onSpinFreeBeforeChanged(double newBefore) { bool success = false; const double oldBefore = sectorsToDialogUnit(device(), partition().firstSector() - minimumFirstSector()); const qint64 newFirstSector = minimumFirstSector() + dialogUnitToSectors(device(), newBefore); const qint64 deltaCorrection = newBefore > oldBefore ? PartitionAlignment::firstDelta(device(), partition(), newFirstSector) : 0; // We need different alignFirstSector parameters for moving the first sector (which // has to take into account min and max length of the partition) and for moving // the whole partition (which must NOT take min and max length into account since // the length is fixed in this case anyway) qint64 alignedFirstSector = align() ? PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector + deltaCorrection, minimumFirstSector(), -1, -1, -1) : newFirstSector; if (dialogWidget().partResizerWidget().movePartition(alignedFirstSector)) success = true; else { alignedFirstSector = align() ? PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector + deltaCorrection, minimumFirstSector(), -1, minimumLength(), maximumLength()) : newFirstSector; success = dialogWidget().partResizerWidget().updateFirstSector(alignedFirstSector); } if (success) setDirty(); else // TODO: this is not the best solution: we should prevent the user from entering // illegal values with a validator updateSpinFreeBefore(dialogUnitToSectors(device(), oldBefore)); }