[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [partitionmanager/raid-support] src/gui: Load partitions for RAID in CreateVolumeGroupDialog.
From:       Caio Carvalho <null () kde ! org>
Date:       2018-07-31 19:36:55
Message-ID: E1fkaRz-0007qF-LE () code ! kde ! org
[Download RAW message or body]

Git commit a87f042468eae5467d4336ef03de7ec92de6179e by Caio Carvalho.
Committed on 31/07/2018 at 19:34.
Pushed by cdelimacarvalho into branch 'raid-support'.

Load partitions for RAID in CreateVolumeGroupDialog.

M  +59   -39   src/gui/createvolumegroupdialog.cpp
M  +1    -0    src/gui/createvolumegroupdialog.h
M  +5    -0    src/gui/listphysicalvolumes.cpp
M  +2    -0    src/gui/listphysicalvolumes.h
M  +3    -1    src/gui/mainwindow.cpp
M  +20   -8    src/gui/volumegroupdialog.cpp
M  +3    -0    src/gui/volumegroupdialog.h

https://commits.kde.org/partitionmanager/a87f042468eae5467d4336ef03de7ec92de6179e

diff --git a/src/gui/createvolumegroupdialog.cpp b/src/gui/createvolumegroupdialog.cpp
index b4c0ed2..25f303b 100644
--- a/src/gui/createvolumegroupdialog.cpp
+++ b/src/gui/createvolumegroupdialog.cpp
@@ -49,7 +49,7 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam
     setupConnections();
 
     // disable volume type and PE size for now, until the features are implemented.
-    dialogWidget().volumeType().setEnabled(false);
+    dialogWidget().volumeType().setEnabled(true);
 
     KConfigGroup kcg(KSharedConfig::openConfig(), "createVolumeDialog");
     restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
@@ -57,58 +57,78 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam
 
 void CreateVolumeGroupDialog::setupDialog()
 {
-    for (const auto &p : qAsConst(LVM::pvList::list())) {
-        bool toBeDeleted = false;
+    updatePartitionList();
+}
 
-        // Ignore partitions that are going to be deleted
-        for (const auto &o : qAsConst(m_PendingOps)) {
-            if (dynamic_cast<DeleteOperation *>(o) && o->targets(*p.partition())) {
-                toBeDeleted = true;
-                break;
-            }
-        }
+void CreateVolumeGroupDialog::setupConnections()
+{
+    connect(&dialogWidget().vgName(), &QLineEdit::textChanged, this, \
&CreateVolumeGroupDialog::onVGNameChanged); +    connect(&dialogWidget().spinPESize(), \
qOverload<int>(&QSpinBox::valueChanged), this, &CreateVolumeGroupDialog::onSpinPESizeChanged); +}
+
+void CreateVolumeGroupDialog::updatePartitionList()
+{
+    if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
+        dialogWidget().listPV().clear();
 
-        if (toBeDeleted)
-            continue;
+        for (const auto &p : qAsConst(LVM::pvList::list())) {
+            bool toBeDeleted = false;
 
-        if (!p.isLuks() && p.vgName() == QString() && !LvmDevice::s_DirtyPVs.contains(p.partition()))
-            dialogWidget().listPV().addPartition(*p.partition(), false);
-    }
+            // Ignore partitions that are going to be deleted
+            for (const auto &o : qAsConst(m_PendingOps)) {
+                if (dynamic_cast<DeleteOperation *>(o) && o->targets(*p.partition())) {
+                    toBeDeleted = true;
+                    break;
+                }
+            }
 
-    for (const Device *d : qAsConst(m_Devices)) {
-        if (d->partitionTable() != nullptr) {
-            for (const Partition *p : qAsConst(d->partitionTable()->children())) {
-                // Looking if there is another VG creation that contains this partition
-                if (LvmDevice::s_DirtyPVs.contains(p))
-                    continue;
+            if (toBeDeleted)
+                continue;
 
-                // Including new LVM PVs (that are currently in OperationStack and that aren't at other \
                VG creation)
-                if (p->state() == Partition::State::New) {
-                    if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
-                        dialogWidget().listPV().addPartition(*p, false);
-                    else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() \
                == FileSystem::Type::Luks2) {
-                        FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS();
+            if (!p.isLuks() && p.vgName() == QString() && \
!LvmDevice::s_DirtyPVs.contains(p.partition())) +                \
dialogWidget().listPV().addPartition(*p.partition(), false); +        }
 
-                        if (fs->type() == FileSystem::Type::Lvm2_PV)
+        for (const Device *d : qAsConst(m_Devices)) {
+            if (d->partitionTable() != nullptr) {
+                for (const Partition *p : qAsConst(d->partitionTable()->children())) {
+                    // Looking if there is another VG creation that contains this partition
+                    if (LvmDevice::s_DirtyPVs.contains(p))
+                        continue;
+
+                    // Including new LVM PVs (that are currently in OperationStack and that aren't at \
other VG creation) +                    if (p->state() == Partition::State::New) {
+                        if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
                             dialogWidget().listPV().addPartition(*p, false);
+                        else if (p->fileSystem().type() == FileSystem::Type::Luks || \
p->fileSystem().type() == FileSystem::Type::Luks2) { +                            FileSystem *fs = \
static_cast<const FS::luks *>(&p->fileSystem())->innerFS(); +
+                            if (fs->type() == FileSystem::Type::Lvm2_PV)
+                                dialogWidget().listPV().addPartition(*p, false);
+                        }
                     }
                 }
             }
         }
-    }
-
-    for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs))
-        if (!LvmDevice::s_DirtyPVs.contains(p))
-            dialogWidget().listPV().addPartition(*p, false);
-}
 
-void CreateVolumeGroupDialog::setupConnections()
-{
-    connect(&dialogWidget().vgName(), &QLineEdit::textChanged, this, \
                &CreateVolumeGroupDialog::onVGNameChanged);
-    connect(&dialogWidget().spinPESize(), qOverload<int>(&QSpinBox::valueChanged), this, \
&CreateVolumeGroupDialog::onSpinPESizeChanged); +        for (const Partition *p : \
qAsConst(LvmDevice::s_OrphanPVs)) +            if (!LvmDevice::s_DirtyPVs.contains(p))
+                dialogWidget().listPV().addPartition(*p, false);
+    }
+    else if (dialogWidget().volumeType().currentText() == QStringLiteral("RAID")) {
+        for (const Device *d : qAsConst(m_Devices)) {
+            if (d->type() != Device::Type::SoftwareRAID_Device && d->partitionTable() != nullptr) {
+                for (const Partition *p : qAsConst(d->partitionTable()->children())) {
+                    if (p->fileSystem().type() != FileSystem::Type::LinuxRaidMember &&
+                            !p->roles().has(PartitionRole::Role::Unallocated))
+                        dialogWidget().listPV().addPartition(*p, false);
+                }
+            }
+        }
+    }
 }
 
-void  CreateVolumeGroupDialog::accept()
+void CreateVolumeGroupDialog::accept()
 {
     QString& tname = targetName();
     tname = dialogWidget().vgName().text();
diff --git a/src/gui/createvolumegroupdialog.h b/src/gui/createvolumegroupdialog.h
index 4dcf2dc..a613a92 100644
--- a/src/gui/createvolumegroupdialog.h
+++ b/src/gui/createvolumegroupdialog.h
@@ -37,6 +37,7 @@ protected:
     void accept() override;
     void setupDialog() override;
     void setupConnections() override;
+    void updatePartitionList() override;
 
 protected:
     virtual void updateOkButtonStatus() override;
diff --git a/src/gui/listphysicalvolumes.cpp b/src/gui/listphysicalvolumes.cpp
index 8b4d8bb..e07c7a9 100644
--- a/src/gui/listphysicalvolumes.cpp
+++ b/src/gui/listphysicalvolumes.cpp
@@ -35,6 +35,11 @@ void ListPhysicalVolumes::addPartition(const Partition& p, bool checked)
     listPhysicalVolumes().addItem(item);
 }
 
+void ListPhysicalVolumes::clear()
+{
+    listPhysicalVolumes().clear();
+}
+
 QVector<const Partition *> ListPhysicalVolumes::checkedItems()
 {
     QVector<const Partition *> partitionList;
diff --git a/src/gui/listphysicalvolumes.h b/src/gui/listphysicalvolumes.h
index 7060c75..89c6b8e 100644
--- a/src/gui/listphysicalvolumes.h
+++ b/src/gui/listphysicalvolumes.h
@@ -50,6 +50,8 @@ public:
 
     void addPartition(const Partition& p, bool checked);
 
+    void clear();
+
     QVector<const Partition *> checkedItems();
 
     QListWidget& listPhysicalVolumes() {
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index 404150e..d40afab 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -1111,7 +1111,9 @@ void MainWindow::onCreateNewVolumeGroup()
     QVector<const Partition*> pvList;
     qint32 peSize = 4;
     // *NOTE*: vgName & pvList will be modified and validated by the dialog
-    QPointer<CreateVolumeGroupDialog> dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, \
operationStack().previewDevices(), operationStack().operations()); +    QPointer<CreateVolumeGroupDialog> \
dlg = new CreateVolumeGroupDialog(this, vgName, pvList, +                                                 \
peSize, operationStack().previewDevices(), +                                                              \
operationStack().operations());  if (dlg->exec() == QDialog::Accepted)
         operationStack().push(new CreateVolumeGroupOperation(vgName, pvList, peSize));
 
diff --git a/src/gui/volumegroupdialog.cpp b/src/gui/volumegroupdialog.cpp
index 70edf02..dc01ad4 100644
--- a/src/gui/volumegroupdialog.cpp
+++ b/src/gui/volumegroupdialog.cpp
@@ -76,18 +76,12 @@ VolumeGroupDialog::~VolumeGroupDialog()
 
 void VolumeGroupDialog::setupDialog()
 {
-    /* LVM Volume group 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().vgName().setValidator(validator);
-    dialogWidget().vgName().setText(targetName());
-
     dialogWidget().volumeType().addItem(QStringLiteral("LVM"));
     dialogWidget().volumeType().addItem(QStringLiteral("RAID"));
     dialogWidget().volumeType().setCurrentIndex(0);
 
+    updateNameValidator();
+
     setMinimumSize(dialogWidget().size());
     resize(dialogWidget().size());
 }
@@ -153,6 +147,23 @@ void VolumeGroupDialog::updatePartitionList()
 {
 }
 
+void VolumeGroupDialog::updateNameValidator()
+{
+    if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
+        /* LVM Volume group 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().vgName().setValidator(validator);
+        dialogWidget().vgName().setText(targetName());
+    }
+    else if (dialogWidget().volumeType().currentText() == QStringLiteral("RAID")) {
+        // TODO: See how Software RAID names should be validated.
+    }
+}
+
 void VolumeGroupDialog::onPartitionListChanged()
 {
 }
@@ -160,5 +171,6 @@ void VolumeGroupDialog::onPartitionListChanged()
 void VolumeGroupDialog::onVolumeTypeChanged(int index)
 {
     Q_UNUSED(index)
+    updateNameValidator();
     updatePartitionList();
 }
diff --git a/src/gui/volumegroupdialog.h b/src/gui/volumegroupdialog.h
index b5ff3eb..e9660f1 100644
--- a/src/gui/volumegroupdialog.h
+++ b/src/gui/volumegroupdialog.h
@@ -86,6 +86,9 @@ protected:
 protected:
     virtual void onPartitionListChanged();
 
+private:
+    virtual void updateNameValidator();
+
 protected:
     VolumeGroupWidget* m_DialogWidget;
     QString& m_TargetName;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic