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()); }
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 VolumeGroupDialog::setupConnections() { connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &VolumeGroupDialog::accept); connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &VolumeGroupDialog::reject); connect(&dialogWidget().volumeType(), static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &VolumeGroupDialog::onVolumeTypeChanged); connect(&dialogWidget().listPV().listPhysicalVolumes(), &QListWidget::itemChanged, this, [=] ( QListWidgetItem*) { updateSizeInfos(); }); }
void VolumeGroupDialog::updateSectorInfos() { qint32 totalSectors = 0; // we can't use LvmDevice mothod here because pv that is not in any VG will return 0 m_ExtentSize = dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); if (m_ExtentSize > 0) { totalSectors = m_TotalSize / m_ExtentSize; } dialogWidget().totalSectors().setText(QString::number(totalSectors)); }
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(); }
void VolumeGroupDialog::updateSizeInfos() { QStringList checkedPartitions = dialogWidget().listPV().checkedItems(); m_TotalSize = FS::lvm2_pv::getPVSize(checkedPartitions); dialogWidget().totalSize().setText(Capacity::formatByteSize(m_TotalSize)); //Probably a bad design for updating state here; the state should be changed inside the update button function. m_IsValidSize = m_TotalSize > m_TotalUsedSize; updateSectorInfos(); updateOkButtonStatus(); }
void VolumeGroupDialog::updateOkButtonStatus() { bool enable = isValidSize(); if (dialogWidget().vgName().text().isEmpty() || !isValidName()) { enable = false; } if (dialogWidget().spinPESize().value() <= 0) { enable = false; } okButton->setEnabled(enable); }
void SizeDialogBase::setupConnections() { connect(&dialogWidget().partResizerWidget(), SIGNAL(firstSectorChanged(qint64)), SLOT(onResizerWidgetFirstSectorChanged(qint64))); connect(&dialogWidget().partResizerWidget(), SIGNAL(lastSectorChanged(qint64)), SLOT(onResizerWidgetLastSectorChanged(qint64))); connect(&dialogWidget().spinFreeBefore(), SIGNAL(valueChanged(double)), SLOT(onSpinFreeBeforeChanged(double))); connect(&dialogWidget().spinFreeAfter(), SIGNAL(valueChanged(double)), SLOT(onSpinFreeAfterChanged(double))); connect(&dialogWidget().spinCapacity(), SIGNAL(valueChanged(double)), SLOT(onSpinCapacityChanged(double))); connect(&detailsWidget().spinFirstSector(), SIGNAL(valueChanged(double)), SLOT(onSpinFirstSectorChanged(double))); connect(&detailsWidget().spinLastSector(), SIGNAL(valueChanged(double)), SLOT(onSpinLastSectorChanged(double))); connect(&detailsWidget().checkAlign(), SIGNAL(toggled(bool)), SLOT(onAlignToggled(bool))); }
void VolumeGroupDialog::updateSizeInfos() { const QList <const Partition *> checkedPartitions = dialogWidget().listPV().checkedItems(); m_TotalSize = 0; for (const auto &p : checkedPartitions) m_TotalSize += p->capacity() - p->capacity() % (dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Byte, Capacity::MiB)); // subtract space which is too small to hold PE dialogWidget().totalSize().setText(Capacity::formatByteSize(m_TotalSize)); //Probably a bad design for updating state here; the state should be changed inside the update button function. m_IsValidSize = m_TotalSize >= m_TotalUsedSize; updateSectorInfos(); updateOkButtonStatus(); }
/** Creates a new VolumeGroupDialog @param parent pointer to the parent widget @param vgName Volume Group name @param pvList List of LVM Physical Volumes used to create Volume Group */ VolumeGroupDialog::VolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& pvList) : QDialog(parent), m_DialogWidget(new VolumeGroupWidget(this)), m_TargetName(vgName), m_TargetPVList(pvList), m_IsValidSize(false), m_IsValidName(true), m_TotalSize(0), m_TotalUsedSize(0), m_ExtentSize(0) { mainLayout = new QVBoxLayout(this); setLayout(mainLayout); mainLayout->addWidget(&dialogWidget()); dialogButtonBox = new QDialogButtonBox; okButton = dialogButtonBox->addButton(QDialogButtonBox::Ok); cancelButton = dialogButtonBox->addButton(QDialogButtonBox::Cancel); mainLayout->addWidget(dialogButtonBox); cancelButton->setFocus(); cancelButton->setDefault(true); setupDialog(); setupConstraints(); setupConnections(); }
SizeDialogBase::SizeDialogBase(QWidget* parent, Device& d, Partition& part, qint64 minFirst, qint64 maxLast) : QDialog(parent), m_SizeDialogWidget(new SizeDialogWidget(this)), m_SizeDetailsWidget(new SizeDetailsWidget(this)), m_Device(d), m_Partition(part), m_MinimumFirstSector(minFirst), m_MaximumLastSector(maxLast), m_MinimumLength(-1), m_MaximumLength(-1) { QVBoxLayout *mainLayout = new QVBoxLayout(this); setLayout(mainLayout); mainLayout->addWidget(&dialogWidget()); QFrame* detailsBox = new QFrame(this); mainLayout->addWidget(detailsBox); QVBoxLayout *detailsLayout = new QVBoxLayout(detailsBox); detailsLayout->addWidget(&detailsWidget()); detailsWidget().hide(); QDialogButtonBox* dialogButtonBox = new QDialogButtonBox; detailsButton = new QPushButton; okButton = dialogButtonBox->addButton(QDialogButtonBox::Ok); cancelButton = dialogButtonBox->addButton(QDialogButtonBox::Cancel); detailsButton->setText(i18nc("@item:button advanced settings button", "Advanced") + QStringLiteral(" >>")); dialogButtonBox->addButton(detailsButton, QDialogButtonBox::ActionRole); mainLayout->setSizeConstraint(QLayout::SetFixedSize); mainLayout->addWidget(dialogButtonBox); connect(dialogButtonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(dialogButtonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(detailsButton, SIGNAL(clicked()), this, SLOT(toggleDetails())); }
void SizeDialogBase::onSpinLastSectorChanged(double newLast) { if (newLast <= maximumLastSector() && dialogWidget().partResizerWidget().updateLastSector(newLast)) setDirty(); else // TODO: this is not the best solution: we should prevent the user from entering // illegal values with a validator updateSpinLastSector(partition().lastSector()); }
/** Creates a new ProgressDialog @param parent pointer to the parent widget @param orunner the OperationRunner whose progress this dialog is showing */ ApplyProgressDialog::ApplyProgressDialog(QWidget* parent, OperationRunner& orunner) : QDialog(parent), m_ProgressDialogWidget(new ApplyProgressDialogWidget(this)), m_ProgressDetailsWidget(new ApplyProgressDetailsWidget(this)), m_OperationRunner(orunner), m_Report(NULL), m_SavedParentTitle(mainWindow(this)->windowTitle()), m_Timer(this), m_Time(), m_CurrentOpItem(NULL), m_CurrentJobItem(NULL), m_LastReportUpdate(0) { QVBoxLayout *mainLayout = new QVBoxLayout(this); setLayout(mainLayout); mainLayout->addWidget(&dialogWidget()); QFrame* detailsBox = new QFrame( this ); mainLayout->addWidget(detailsBox); QVBoxLayout *detailsLayout = new QVBoxLayout(detailsBox); detailsLayout->addWidget(&detailsWidget()); detailsWidget().hide(); setAttribute(Qt::WA_ShowModal, true); dialogButtonBox = new QDialogButtonBox; okButton = dialogButtonBox->addButton( QDialogButtonBox::Ok ); cancelButton = dialogButtonBox->addButton( QDialogButtonBox::Cancel ); detailsButton = new QPushButton; detailsButton->setText(i18n("&Details") + QStringLiteral(" >>")); detailsButton->setIcon(QIcon::fromTheme(QStringLiteral("help-about"))); dialogButtonBox->addButton(detailsButton, QDialogButtonBox::ActionRole); mainLayout->addWidget(dialogButtonBox); dialogWidget().treeTasks().setColumnWidth(0, width() * 0.8); detailsWidget().buttonBrowser().setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); detailsWidget().buttonSave().setIcon(QIcon::fromTheme(QStringLiteral("document-save"))); setupConnections(); KConfigGroup kcg(KSharedConfig::openConfig(), "applyProgressDialog"); restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray())); }
/** Creates a new InsertDialog instance. @param parent the parent widget @param device the Device the Partition to insert is on @param insertedPartition the Partition to insert @param destpartition the Partition the new one is to be inserted to */ InsertDialog::InsertDialog(QWidget* parent, Device& device, Partition& insertedPartition, const Partition& destpartition) : SizeDialogBase(parent, device, insertedPartition, destpartition.firstSector(), destpartition.lastSector()), m_DestPartition(destpartition) { setWindowTitle(i18nc("@title:window", "Insert a partition")); partition().move(destPartition().firstSector()); partition().fileSystem().move(destPartition().fileSystem().firstSector()); dialogWidget().hideRole(); dialogWidget().hideFileSystem(); dialogWidget().hideLabel(); setupDialog(); setupConstraints(); setupConnections(); KConfigGroup kcg(KSharedConfig::openConfig(), "insertDialog"); restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray())); }
void FileSystemSupportDialog::setupDialog() { QIcon yes = QIcon::fromTheme(QStringLiteral("dialog-ok")).pixmap(IconSize(KIconLoader::Toolbar)); QIcon no = QIcon::fromTheme(QStringLiteral("dialog-error")).pixmap(IconSize(KIconLoader::Toolbar)); dialogWidget().tree().clear(); foreach(const FileSystem * fs, FileSystemFactory::map()) { if (fs->type() == FileSystem::Unknown || fs->type() == FileSystem::Extended) continue; QTreeWidgetItem* item = new QTreeWidgetItem(); int i = 0; item->setText(i++, fs->name()); item->setIcon(i++, fs->supportCreate() ? yes : no); item->setIcon(i++, fs->supportGrow() ? yes : no); item->setIcon(i++, fs->supportShrink() ? yes : no); item->setIcon(i++, fs->supportMove() ? yes : no); item->setIcon(i++, fs->supportCopy() ? yes : no); item->setIcon(i++, fs->supportCheck() ? yes : no); item->setIcon(i++, fs->supportGetLabel() ? yes : no); item->setIcon(i++, fs->supportSetLabel() ? yes : no); item->setIcon(i++, fs->supportGetUsed() ? yes : no); item->setIcon(i++, fs->supportBackup() ? yes : no); // there is no FileSystem::supportRestore(), because we currently can't tell // if a file is an image of a supported or unsupported (or even invalid) filesystem item->setIcon(i++, yes); item->setText(i++, fs->supportToolName().name.isEmpty() ? QStringLiteral("---") : fs->supportToolName().name); dialogWidget().tree().addTopLevelItem(item); } for (int i = 0; i < dialogWidget().tree().columnCount(); i++) dialogWidget().tree().resizeColumnToContents(i); dialogWidget().tree().sortItems(0, Qt::AscendingOrder); }
void SizeDialogBase::onAlignToggled(bool align) { dialogWidget().partResizerWidget().setAlign(align); detailsWidget().spinFirstSector().setSingleStep(align ? PartitionAlignment::sectorAlignment(device()) : 1); detailsWidget().spinLastSector().setSingleStep(align ? PartitionAlignment::sectorAlignment(device()) : 1); const double capacityStep = align ? sectorsToDialogUnit(device(), PartitionAlignment::sectorAlignment(device())) : 1; dialogWidget().spinFreeBefore().setSingleStep(capacityStep); dialogWidget().spinFreeBefore().setSingleStep(capacityStep); dialogWidget().spinCapacity().setSingleStep(capacityStep); // if align is on, turn off keyboard tracking for all spin boxes to avoid the two clashing foreach(QAbstractSpinBox * box, dialogWidget().findChildren<QAbstractSpinBox*>() + detailsWidget().findChildren<QAbstractSpinBox*>()) box->setKeyboardTracking(!align); if (align) { onSpinFirstSectorChanged(partition().firstSector()); onSpinLastSectorChanged(partition().lastSector()); } }
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)); }
void VolumeGroupDialog::setupDialog() { QRegExp re(QStringLiteral("[\\w-.+]+")); QRegExpValidator *validator = new QRegExpValidator(re, this); dialogWidget().vgName().setValidator(validator); dialogWidget().vgName().setText(targetName()); dialogWidget().volumeType().addItem(QStringLiteral("LVM")); dialogWidget().volumeType().addItem(QStringLiteral("RAID")); dialogWidget().volumeType().setCurrentIndex(0); setMinimumSize(dialogWidget().size()); resize(dialogWidget().size()); }
void SizeDialogBase::setupDialog() { dialogWidget().spinFreeBefore().setValue(sectorsToDialogUnit(device(), partition().firstSector() - minimumFirstSector())); dialogWidget().spinFreeAfter().setValue(sectorsToDialogUnit(device(), maximumLastSector() - partition().lastSector())); dialogWidget().spinCapacity().setValue(Capacity(partition().capacity()).toDouble(preferredUnit())); dialogWidget().spinFreeBefore().setSuffix(QStringLiteral(" ") + Capacity::unitName(preferredUnit())); dialogWidget().spinFreeAfter().setSuffix(QStringLiteral(" ") + Capacity::unitName(preferredUnit())); dialogWidget().spinCapacity().setSuffix(QStringLiteral(" ") + Capacity::unitName(preferredUnit())); detailsWidget().spinFirstSector().setValue(partition().firstSector()); detailsWidget().spinLastSector().setValue(partition().lastSector()); detailsWidget().checkAlign().setChecked(Config::alignDefault()); if (canGrow() || canShrink()) dialogWidget().partResizerWidget().init(device(), partition(), minimumFirstSector(), maximumLastSector(), false, canMove()); else dialogWidget().partResizerWidget().init(device(), partition(), minimumFirstSector(), maximumLastSector(), true, canMove()); dialogWidget().partResizerWidget().setAlign(Config::alignDefault()); }
/** Creates a new FileSystemSupportDialog @param parent the parent object */ FileSystemSupportDialog::FileSystemSupportDialog(QWidget* parent) : QDialog(parent), m_FileSystemSupportDialogWidget(new FileSystemSupportDialogWidget(this)) { QVBoxLayout *mainLayout = new QVBoxLayout(this); setLayout(mainLayout); mainLayout->addWidget(&dialogWidget()); setWindowTitle(i18nc("@title:window", "File System Support")); dialogButtonBox = new QDialogButtonBox(this); dialogButtonBox -> setStandardButtons(QDialogButtonBox::Ok); mainLayout->addWidget(dialogButtonBox); setupDialog(); setupConnections(); KConfigGroup kcg(KSharedConfig::openConfig(), "fileSystemSupportDialog"); restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray())); }
void VolumeGroupDialog::setupDialog() { dialogWidget().vgName().setText(targetName()); dialogWidget().volumeType().addItem(QStringLiteral("LVM")); dialogWidget().volumeType().addItem(QStringLiteral("RAID")); dialogWidget().volumeType().setCurrentIndex(0); //update used size and LV infos qint32 totalLV = 0; QString vgname = dialogWidget().vgName().text(); if (!vgname.isEmpty()) { m_TotalUsedSize = LvmDevice::getAllocatedPE(vgname) * LvmDevice::getPeSize(vgname); QStringList lvlist = LvmDevice::getLVs(vgname); if (!lvlist.isEmpty() ) { totalLV = lvlist.count(); } } dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize)); dialogWidget().totalLV().setText(QString::number(totalLV)); setMinimumSize(dialogWidget().size()); resize(dialogWidget().size()); }
DialogCode ConfigurationDialog::exec(bool saveOnAccept, bool doLoad) { if (doLoad) Load(); MythDialog *dialog = dialogWidget( GetMythMainWindow(), "Configuration Dialog"); dialog->Show(); DialogCode ret = dialog->exec(); if ((QDialog::Accepted == ret) && saveOnAccept) Save(); clear_widgets(cfgChildren, childwidget); dialog->deleteLater(); dialog = NULL; return ret; }
void SizeDialogBase::updateSpinFreeAfter(qint64 sectorsFreeAfter) { const bool signalState = dialogWidget().spinFreeAfter().blockSignals(true); dialogWidget().spinFreeAfter().setValue(sectorsToDialogUnit(device(), sectorsFreeAfter)); dialogWidget().spinFreeAfter().blockSignals(signalState); }
void SizeDialogBase::updateSpinCapacity(qint64 newLengthInSectors) { bool state = dialogWidget().spinCapacity().blockSignals(true); dialogWidget().spinCapacity().setValue(sectorsToDialogUnit(device(), newLengthInSectors)); dialogWidget().spinCapacity().blockSignals(state); }
void FileSystemSupportDialog::setupConnections() { connect(dialogButtonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(close())); connect(&dialogWidget().buttonRescan(), SIGNAL(clicked()), SLOT(onButtonRescanClicked())); }