diff --git a/application/lvm/volumegrouppage.cpp b/application/lvm/volumegrouppage.cpp index 5a63a3b..d9da9e5 100644 --- a/application/lvm/volumegrouppage.cpp +++ b/application/lvm/volumegrouppage.cpp @@ -1,12 +1,17 @@ #include "volumegrouppage.h" #include "ui_volumegrouppage.h" +#include "diskpane.h" +#include +#include #include #include +#include struct VolumeGroupPagePrivate { - VolumeGroup* vg; - VolumeGroupLvModel* lvModel; + VolumeGroup* vg; + VolumeGroupLvModel* lvModel; + VolumeGroupPvModel* pvModel; }; VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) : @@ -17,6 +22,8 @@ VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) : d->vg = vg; ui->titleLabel->setText(vg->name()); ui->disbandButton->setProperty("type", "destructive"); + ui->stackedWidget->setCurrentAnimation(tStackedWidget::Lift); + ui->leftWidget->setFixedWidth(400); d->lvModel = new VolumeGroupLvModel(d->vg); connect(d->lvModel, &VolumeGroupLvModel::modelReset, this, [this] { @@ -24,6 +31,35 @@ VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) : }); ui->lvsView->setModel(d->lvModel); ui->lvsView->setFixedHeight(ui->lvsView->sizeHintForRow(0) * d->lvModel->rowCount()); + connect(ui->lvsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [this](QModelIndex current, QModelIndex previous) { + ui->pvsView->clearSelection(); + ui->pvsView->selectionModel()->clearCurrentIndex(); + + auto lv = current.data(VolumeGroupLvModel::LvRole).value(); + if (lv) { + DiskPane* disk = new DiskPane(lv->block()); + ui->stackedWidget->addWidget(disk); + ui->stackedWidget->setCurrentWidget(disk); + } + }); + + d->pvModel = new VolumeGroupPvModel(d->vg); + connect(d->pvModel, &VolumeGroupLvModel::modelReset, this, [this] { + ui->pvsView->setFixedHeight(ui->pvsView->sizeHintForRow(0) * d->pvModel->rowCount()); + }); + ui->pvsView->setModel(d->pvModel); + ui->pvsView->setFixedHeight(ui->lvsView->sizeHintForRow(0) * d->pvModel->rowCount()); + connect(ui->pvsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [this](QModelIndex current, QModelIndex previous) { + ui->lvsView->clearSelection(); + ui->lvsView->selectionModel()->clearCurrentIndex(); + + auto pv = current.data(VolumeGroupPvModel::PvRole).value(); + if (pv) { + DiskPane* disk = new DiskPane(pv); + ui->stackedWidget->addWidget(disk); + ui->stackedWidget->setCurrentWidget(disk); + } + }); } VolumeGroupPage::~VolumeGroupPage() { @@ -40,8 +76,5 @@ void VolumeGroupPage::on_titleLabel_backButtonClicked() { emit done(); } -void VolumeGroupPage::on_disbandButton_clicked() -{ - +void VolumeGroupPage::on_disbandButton_clicked() { } - diff --git a/application/lvm/volumegrouppage.ui b/application/lvm/volumegrouppage.ui index 3cd4ea9..918ae28 100644 --- a/application/lvm/volumegrouppage.ui +++ b/application/lvm/volumegrouppage.ui @@ -120,6 +120,13 @@ + + + + QFrame::NoFrame + + + @@ -163,16 +170,22 @@ - - - - + + + tStackedWidget + QStackedWidget +
tstackedwidget.h
+ 1 + + switchingFrame(int) + +
tTitleLabel QLabel diff --git a/application/translations/ar_SA.ts b/application/translations/ar_SA.ts index b051cf1..bf34c60 100644 --- a/application/translations/ar_SA.ts +++ b/application/translations/ar_SA.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/da.ts b/application/translations/da.ts index d93ed05..f0dd0d2 100644 --- a/application/translations/da.ts +++ b/application/translations/da.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/en_US.ts b/application/translations/en_US.ts index 19100e1..d117b85 100644 --- a/application/translations/en_US.ts +++ b/application/translations/en_US.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/he_IL.ts b/application/translations/he_IL.ts index 5072772..ac5c0ad 100644 --- a/application/translations/he_IL.ts +++ b/application/translations/he_IL.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/ja.ts b/application/translations/ja.ts index 2f4ad31..54b3874 100644 --- a/application/translations/ja.ts +++ b/application/translations/ja.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/pt_BR.ts b/application/translations/pt_BR.ts index 5a80f88..6c07538 100644 --- a/application/translations/pt_BR.ts +++ b/application/translations/pt_BR.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/tr.ts b/application/translations/tr.ts index d37b68e..b886bad 100644 --- a/application/translations/tr.ts +++ b/application/translations/tr.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/application/translations/vi.ts b/application/translations/vi.ts index 6bce947..6ce5ec6 100644 --- a/application/translations/vi.ts +++ b/application/translations/vi.ts @@ -568,7 +568,7 @@ - + Disband Volume Group diff --git a/libthefrisbee/CMakeLists.txt b/libthefrisbee/CMakeLists.txt index 7ac7a59..8625d91 100644 --- a/libthefrisbee/CMakeLists.txt +++ b/libthefrisbee/CMakeLists.txt @@ -52,6 +52,7 @@ set(SOURCES structures/formattedsmartattribute.cpp volumegroupmodel.h volumegroupmodel.cpp volumegrouplvmodel.h volumegrouplvmodel.cpp + volumegrouppvmodel.h volumegrouppvmodel.cpp ) set(STRUCTURES_HEADERS diff --git a/libthefrisbee/DriveObjects/volumegroup.cpp b/libthefrisbee/DriveObjects/volumegroup.cpp index 3dcdc2f..25b5852 100644 --- a/libthefrisbee/DriveObjects/volumegroup.cpp +++ b/libthefrisbee/DriveObjects/volumegroup.cpp @@ -1,6 +1,8 @@ #include "volumegroup.h" #include "logicalvolume.h" +#include "DriveObjects/diskobject.h" +#include "DriveObjects/physicalvolumeinterface.h" #include "driveobjectmanager.h" struct VolumeGroupPrivate { @@ -17,6 +19,8 @@ VolumeGroup::VolumeGroup(QDBusObjectPath path, QObject* parent) : connect(DriveObjectManager::instance(), &DriveObjectManager::logicalVolumeAdded, this, &VolumeGroup::lvsChanged); connect(DriveObjectManager::instance(), &DriveObjectManager::logicalVolumeRemoved, this, &VolumeGroup::lvsChanged); + connect(DriveObjectManager::instance(), &DriveObjectManager::diskAdded, this, &VolumeGroup::pvsChanged); + connect(DriveObjectManager::instance(), &DriveObjectManager::diskRemoved, this, &VolumeGroup::pvsChanged); } VolumeGroup::~VolumeGroup() { @@ -27,13 +31,18 @@ QString VolumeGroup::interfaceName() { return QStringLiteral("org.freedesktop.UDisks2.VolumeGroup"); } -tRange VolumeGroup::lvs() -{ +tRange VolumeGroup::lvs() { return tRange(DriveObjectManager::logicalVolumes()).filter([this](LogicalVolume* lv) { return lv->vg() == this; }); } +tRange VolumeGroup::pvs() { + return DriveObjectManager::lvmPhysicalVolumeDisks().filter([this](DiskObject* obj) { + return obj->interface()->volumeGroup() == this; + }); +} + QString VolumeGroup::name() { return d->name; } diff --git a/libthefrisbee/DriveObjects/volumegroup.h b/libthefrisbee/DriveObjects/volumegroup.h index 39bd644..8bae717 100644 --- a/libthefrisbee/DriveObjects/volumegroup.h +++ b/libthefrisbee/DriveObjects/volumegroup.h @@ -6,6 +6,7 @@ struct VolumeGroupPrivate; class LogicalVolume; +class DiskObject; class VolumeGroup : public UdisksInterface { Q_OBJECT public: @@ -14,11 +15,13 @@ class VolumeGroup : public UdisksInterface { static QString interfaceName(); tRange lvs(); + tRange pvs(); QString name(); signals: void lvsChanged(); + void pvsChanged(); private: VolumeGroupPrivate* d; diff --git a/libthefrisbee/driveobjectmanager.cpp b/libthefrisbee/driveobjectmanager.cpp index a9fc96f..4b05133 100644 --- a/libthefrisbee/driveobjectmanager.cpp +++ b/libthefrisbee/driveobjectmanager.cpp @@ -29,6 +29,7 @@ #include "DriveObjects/logicalvolume.h" #include "DriveObjects/loopinterface.h" #include "DriveObjects/partitiontableinterface.h" +#include "DriveObjects/physicalvolumeinterface.h" #include "DriveObjects/volumegroup.h" #include #include @@ -175,6 +176,15 @@ QList DriveObjectManager::opticalDisks() { return disks; } +tRange DriveObjectManager::lvmPhysicalVolumeDisks() { + return tRange(instance()->d->objects.values()).filter([](DiskObject* obj) { + return obj->isInterfaceAvailable(DiskInterface::PhysicalVolume); + }) + .filter([](DiskObject* obj) { + return obj->interface()->volumeGroup() != nullptr; + }); +} + QList DriveObjectManager::volumeGroups() { return instance()->d->volumeGroups.values(); } diff --git a/libthefrisbee/driveobjectmanager.h b/libthefrisbee/driveobjectmanager.h index e8845bc..66d34f5 100644 --- a/libthefrisbee/driveobjectmanager.h +++ b/libthefrisbee/driveobjectmanager.h @@ -25,6 +25,7 @@ #include #include #include +#include #include struct DriveObjectManagerPrivate; @@ -42,6 +43,7 @@ class LIBTHEFRISBEE_EXPORT DriveObjectManager : public QObject { static QList filesystemDisks(); static QList encryptedDisks(); static QList opticalDisks(); + static tRange lvmPhysicalVolumeDisks(); static QList drives(); static QList volumeGroups(); diff --git a/libthefrisbee/volumegrouppvmodel.cpp b/libthefrisbee/volumegrouppvmodel.cpp new file mode 100644 index 0000000..692b12d --- /dev/null +++ b/libthefrisbee/volumegrouppvmodel.cpp @@ -0,0 +1,50 @@ +#include "volumegrouppvmodel.h" + +#include "DriveObjects/diskobject.h" +#include "DriveObjects/volumegroup.h" + +struct VolumeGroupPvModelPrivate { + VolumeGroup* vg; + QList pvs; +}; + +VolumeGroupPvModel::VolumeGroupPvModel(VolumeGroup* vg, QObject* parent) : + QAbstractListModel(parent) { + d = new VolumeGroupPvModelPrivate(); + d->vg = vg; + + connect(vg, &VolumeGroup::pvsChanged, this, &VolumeGroupPvModel::updatePvs); + this->updatePvs(); +} + +VolumeGroupPvModel::~VolumeGroupPvModel() { + delete d; +} + +int VolumeGroupPvModel::rowCount(const QModelIndex& parent) const { + if (parent.isValid()) + return 0; + + return d->pvs.count(); +} + +QVariant VolumeGroupPvModel::data(const QModelIndex& index, int role) const { + if (!index.isValid()) + return {}; + + auto pv = d->pvs.at(index.row()); + switch (role) { + case Qt::DisplayRole: + return pv->displayName(); + case PvRole: + return QVariant::fromValue(pv); + } + + return {}; +} + +void VolumeGroupPvModel::updatePvs() { + this->beginResetModel(); + d->pvs = d->vg->pvs().toList(); + this->endResetModel(); +} diff --git a/libthefrisbee/volumegrouppvmodel.h b/libthefrisbee/volumegrouppvmodel.h new file mode 100644 index 0000000..8abea53 --- /dev/null +++ b/libthefrisbee/volumegrouppvmodel.h @@ -0,0 +1,29 @@ +#ifndef VOLUMEGROUPPVMODEL_H +#define VOLUMEGROUPPVMODEL_H + +#include + +class VolumeGroup; +struct VolumeGroupPvModelPrivate; +class VolumeGroupPvModel : public QAbstractListModel { + Q_OBJECT + + public: + explicit VolumeGroupPvModel(VolumeGroup* vg, QObject* parent = nullptr); + ~VolumeGroupPvModel(); + + enum Roles { + PvRole = Qt::UserRole + }; + + // Basic functionality: + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + + private: + VolumeGroupPvModelPrivate* d; + void updatePvs(); +}; + +#endif // VOLUMEGROUPPVMODEL_H