diff --git a/src/gui/newdialog.cpp b/src/gui/newdialog.cpp index ea1d6ab..d97b8ee 100644 --- a/src/gui/newdialog.cpp +++ b/src/gui/newdialog.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -49,8 +48,7 @@ NewDialog::NewDialog(QWidget* parent, Device& device, Partition& unallocatedPartition, PartitionRole::Roles r) : SizeDialogBase(parent, device, unallocatedPartition, unallocatedPartition.firstSector(), unallocatedPartition.lastSector()), m_PartitionRoles(r), - m_IsValidPassword(true), - m_IsValidLVName(true) + m_IsValidPassword(true) { setWindowTitle(xi18nc("@title:window", "Create a new partition")); @@ -103,27 +101,6 @@ void NewDialog::setupDialog() dialogWidget().checkBoxEncrypt().hide(); dialogWidget().editPassphrase().hide(); - if (device().type() == Device::Disk_Device) { - dialogWidget().lvName().hide(); - dialogWidget().textLVName().hide(); - } - - if (device().type() == Device::LVM_Device) { - dialogWidget().hideBeforeAndAfter(); - detailsWidget().checkAlign().setChecked(false); - detailsWidget().checkAlign().setEnabled(false); - detailsButton->hide(); - dialogWidget().comboFileSystem().removeItem(dialogWidget().comboFileSystem().findText(QStringLiteral("lvm2 pv"))); - m_IsValidLVName = false; - - /* LVM logical volume name can consist of: letters numbers _ . - + - * It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/ - * QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */ - QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)")); - QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this); - dialogWidget().lvName().setValidator(validator); - } - dialogWidget().editPassphrase().setMinimumPasswordLength(1); dialogWidget().editPassphrase().setMaximumPasswordLength(512); // cryptsetup does not support longer passwords @@ -148,7 +125,6 @@ void NewDialog::setupConnections() connect(&dialogWidget().label(), &QLineEdit::textChanged, this, &NewDialog::onLabelChanged); // listen to password status updates connect(&dialogWidget().editPassphrase(), &KNewPasswordWidget::passwordStatusChanged, this, &NewDialog::slotPasswordStatusChanged); - connect(&dialogWidget().lvName(), &QLineEdit::textChanged, this, &NewDialog::onLVNameChanged); SizeDialogBase::setupConnections(); } @@ -265,20 +241,6 @@ void NewDialog::slotPasswordStatusChanged() updateOkButtonStatus(); } -void NewDialog::onLVNameChanged(const QString& newName) -{ - partition().setPartitionPath(device().deviceNode() + QStringLiteral("/") + newName.trimmed()); - if ((dialogWidget().lvName().isVisible() && - dialogWidget().lvName().text().isEmpty()) || - (device().type() == Device::LVM_Device && - dynamic_cast(device()).partitionNodes().contains(partition().partitionPath())) ) { - m_IsValidLVName = false; - } else { - m_IsValidLVName = true; - } - updateOkButtonStatus(); -} - void NewDialog::updateHideAndShow() { // this is mostly copy'n'pasted from PartPropsDialog::updateHideAndShow() diff --git a/src/gui/newdialog.h b/src/gui/newdialog.h index 7f5a027..dadd311 100644 --- a/src/gui/newdialog.h +++ b/src/gui/newdialog.h @@ -44,13 +44,12 @@ protected: void onRoleChanged(bool); void onFilesystemChanged(int); void onLabelChanged(const QString& newLabel); - void onLVNameChanged(const QString& newName); void setupConnections() override; void setupDialog() override; void slotPasswordStatusChanged(); void updateHideAndShow(); - void updateOkButtonStatus(); + void updateOkButtonStatus() override; void updateFileSystem(FileSystem::Type t); PartitionRole::Roles partitionRoles() const { return m_PartitionRoles; @@ -66,14 +65,10 @@ protected: bool isValidPassword() const { return m_IsValidPassword; } - bool isValidLVName() const { - return m_IsValidLVName; - } private: PartitionRole::Roles m_PartitionRoles; bool m_IsValidPassword; - bool m_IsValidLVName; }; #endif diff --git a/src/gui/sizedialogbase.cpp b/src/gui/sizedialogbase.cpp index 4d4c663..bc9d9b3 100644 --- a/src/gui/sizedialogbase.cpp +++ b/src/gui/sizedialogbase.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -56,7 +57,8 @@ SizeDialogBase::SizeDialogBase(QWidget* parent, Device& d, Partition& part, qint m_MinimumFirstSector(minFirst), m_MaximumLastSector(maxLast), m_MinimumLength(-1), - m_MaximumLength(-1) + m_MaximumLength(-1), + m_IsValidLVName(true) { QVBoxLayout *mainLayout = new QVBoxLayout(this); setLayout(mainLayout); @@ -102,6 +104,26 @@ void SizeDialogBase::setupDialog() else dialogWidget().partResizerWidget().init(device(), partition(), minimumFirstSector(), maximumLastSector(), true, canMove()); dialogWidget().partResizerWidget().setAlign(Config::alignDefault()); + + if (device().type() == Device::Disk_Device) { + dialogWidget().lvName().hide(); + dialogWidget().textLVName().hide(); + } + if (device().type() == Device::LVM_Device) { + dialogWidget().hideBeforeAndAfter(); + detailsWidget().checkAlign().setChecked(false); + detailsWidget().checkAlign().setEnabled(false); + detailsButton->hide(); + dialogWidget().comboFileSystem().removeItem(dialogWidget().comboFileSystem().findText(QStringLiteral("lvm2 pv"))); + m_IsValidLVName = false; + + /* LVM logical volume name can consist of: letters numbers _ . - + + * It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/ + * QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */ + QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)")); + QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this); + dialogWidget().lvName().setValidator(validator); + } } void SizeDialogBase::setupConstraints() @@ -158,6 +180,8 @@ void SizeDialogBase::setupConnections() connect(&detailsWidget().spinFirstSector(), qOverload(&QDoubleSpinBox::valueChanged), this, &SizeDialogBase::onSpinFirstSectorChanged); connect(&detailsWidget().spinLastSector(), qOverload(&QDoubleSpinBox::valueChanged), this, &SizeDialogBase::onSpinLastSectorChanged); connect(&detailsWidget().checkAlign(), &QCheckBox::toggled, this, &SizeDialogBase::onAlignToggled); + + connect(&dialogWidget().lvName(), &QLineEdit::textChanged, this, &SizeDialogBase::onLVNameChanged); } void SizeDialogBase::toggleDetails() @@ -352,6 +376,25 @@ void SizeDialogBase::onAlignToggled(bool align) } } +void SizeDialogBase::onLVNameChanged(const QString& newName) +{ + partition().setPartitionPath(device().deviceNode() + QStringLiteral("/") + newName.trimmed()); + if ((dialogWidget().lvName().isVisible() && + dialogWidget().lvName().text().isEmpty()) || + (device().type() == Device::LVM_Device && + dynamic_cast(device()).partitionNodes().contains(partition().partitionPath())) ) { + m_IsValidLVName = false; + } else { + m_IsValidLVName = true; + } + updateOkButtonStatus(); +} + +void SizeDialogBase::updateOkButtonStatus() +{ + okButton->setEnabled(isValidLVName()); +} + void SizeDialogBase::updateSpinFreeBefore(qint64 sectorsFreeBefore) { const bool signalState = dialogWidget().spinFreeBefore().blockSignals(true); diff --git a/src/gui/sizedialogbase.h b/src/gui/sizedialogbase.h index 487143a..83d86d8 100644 --- a/src/gui/sizedialogbase.h +++ b/src/gui/sizedialogbase.h @@ -114,6 +114,10 @@ protected: m_MaximumLength = s; } + bool isValidLVName() const { + return m_IsValidLVName; + } + protected: void onResizerWidgetFirstSectorChanged(qint64 newFirst); void onResizerWidgetLastSectorChanged(qint64 newLast); @@ -126,6 +130,9 @@ protected: void onSpinLastSectorChanged(qint64 newLast); void onAlignToggled(bool); + void onLVNameChanged(const QString& newName); + virtual void updateOkButtonStatus(); + void toggleDetails(); SizeDialogWidget* m_SizeDialogWidget; @@ -136,6 +143,7 @@ protected: qint64 m_MaximumLastSector; qint64 m_MinimumLength; qint64 m_MaximumLength; + bool m_IsValidLVName; public: QPushButton* okButton;