Skip to content

Commit

Permalink
List PVs in VG
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Aug 15, 2023
1 parent 694ee82 commit aeef36d
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 20 deletions.
45 changes: 39 additions & 6 deletions application/lvm/volumegrouppage.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include "volumegrouppage.h"
#include "ui_volumegrouppage.h"

#include "diskpane.h"
#include <DriveObjects/diskobject.h>
#include <DriveObjects/logicalvolume.h>
#include <DriveObjects/volumegroup.h>
#include <volumegrouplvmodel.h>
#include <volumegrouppvmodel.h>

struct VolumeGroupPagePrivate {
VolumeGroup* vg;
VolumeGroupLvModel* lvModel;
VolumeGroup* vg;
VolumeGroupLvModel* lvModel;
VolumeGroupPvModel* pvModel;
};

VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) :
Expand All @@ -17,13 +22,44 @@ 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] {
ui->lvsView->setFixedHeight(ui->lvsView->sizeHintForRow(0) * d->lvModel->rowCount());
});
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<LogicalVolume*>();
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<DiskObject*>();
if (pv) {
DiskPane* disk = new DiskPane(pv);
ui->stackedWidget->addWidget(disk);
ui->stackedWidget->setCurrentWidget(disk);
}
});
}

VolumeGroupPage::~VolumeGroupPage() {
Expand All @@ -40,8 +76,5 @@ void VolumeGroupPage::on_titleLabel_backButtonClicked() {
emit done();
}

void VolumeGroupPage::on_disbandButton_clicked()
{

void VolumeGroupPage::on_disbandButton_clicked() {
}

21 changes: 17 additions & 4 deletions application/lvm/volumegrouppage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
</property>
</widget>
</item>
<item>
<widget class="QListView" name="pvsView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -163,16 +170,22 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
<widget class="tStackedWidget" name="stackedWidget"/>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>tStackedWidget</class>
<extends>QStackedWidget</extends>
<header location="global">tstackedwidget.h</header>
<container>1</container>
<slots>
<signal>switchingFrame(int)</signal>
</slots>
</customwidget>
<customwidget>
<class>tTitleLabel</class>
<extends>QLabel</extends>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/ar_SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/he_IL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion application/translations/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../lvm/volumegrouppage.ui" line="139"/>
<location filename="../lvm/volumegrouppage.ui" line="146"/>
<source>Disband Volume Group</source>
<translation type="unfinished"></translation>
</message>
Expand Down
1 change: 1 addition & 0 deletions libthefrisbee/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(SOURCES
structures/formattedsmartattribute.cpp
volumegroupmodel.h volumegroupmodel.cpp
volumegrouplvmodel.h volumegrouplvmodel.cpp
volumegrouppvmodel.h volumegrouppvmodel.cpp
)

set(STRUCTURES_HEADERS
Expand Down
13 changes: 11 additions & 2 deletions libthefrisbee/DriveObjects/volumegroup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "volumegroup.h"
#include "logicalvolume.h"

#include "DriveObjects/diskobject.h"
#include "DriveObjects/physicalvolumeinterface.h"
#include "driveobjectmanager.h"

struct VolumeGroupPrivate {
Expand All @@ -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() {
Expand All @@ -27,13 +31,18 @@ QString VolumeGroup::interfaceName() {
return QStringLiteral("org.freedesktop.UDisks2.VolumeGroup");
}

tRange<LogicalVolume *> VolumeGroup::lvs()
{
tRange<LogicalVolume*> VolumeGroup::lvs() {
return tRange(DriveObjectManager::logicalVolumes()).filter([this](LogicalVolume* lv) {
return lv->vg() == this;
});
}

tRange<DiskObject*> VolumeGroup::pvs() {
return DriveObjectManager::lvmPhysicalVolumeDisks().filter([this](DiskObject* obj) {
return obj->interface<PhysicalVolumeInterface>()->volumeGroup() == this;
});
}

QString VolumeGroup::name() {
return d->name;
}
3 changes: 3 additions & 0 deletions libthefrisbee/DriveObjects/volumegroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

struct VolumeGroupPrivate;
class LogicalVolume;
class DiskObject;
class VolumeGroup : public UdisksInterface {
Q_OBJECT
public:
Expand All @@ -14,11 +15,13 @@ class VolumeGroup : public UdisksInterface {

static QString interfaceName();
tRange<LogicalVolume*> lvs();
tRange<DiskObject*> pvs();

QString name();

signals:
void lvsChanged();
void pvsChanged();

private:
VolumeGroupPrivate* d;
Expand Down
10 changes: 10 additions & 0 deletions libthefrisbee/driveobjectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QCoroDBusPendingCall>
#include <QDebug>
Expand Down Expand Up @@ -175,6 +176,15 @@ QList<DiskObject*> DriveObjectManager::opticalDisks() {
return disks;
}

tRange<DiskObject*> DriveObjectManager::lvmPhysicalVolumeDisks() {
return tRange(instance()->d->objects.values()).filter([](DiskObject* obj) {
return obj->isInterfaceAvailable(DiskInterface::PhysicalVolume);
})
.filter([](DiskObject* obj) {
return obj->interface<PhysicalVolumeInterface>()->volumeGroup() != nullptr;
});
}

QList<VolumeGroup*> DriveObjectManager::volumeGroups() {
return instance()->d->volumeGroups.values();
}
Expand Down
2 changes: 2 additions & 0 deletions libthefrisbee/driveobjectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDBusObjectPath>
#include <QDBusUnixFileDescriptor>
#include <QObject>
#include <ranges/trange.h>
#include <tpromise.h>

struct DriveObjectManagerPrivate;
Expand All @@ -42,6 +43,7 @@ class LIBTHEFRISBEE_EXPORT DriveObjectManager : public QObject {
static QList<DiskObject*> filesystemDisks();
static QList<DiskObject*> encryptedDisks();
static QList<DiskObject*> opticalDisks();
static tRange<DiskObject*> lvmPhysicalVolumeDisks();
static QList<DriveInterface*> drives();

static QList<VolumeGroup*> volumeGroups();
Expand Down
50 changes: 50 additions & 0 deletions libthefrisbee/volumegrouppvmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "volumegrouppvmodel.h"

#include "DriveObjects/diskobject.h"
#include "DriveObjects/volumegroup.h"

struct VolumeGroupPvModelPrivate {
VolumeGroup* vg;
QList<DiskObject*> 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();
}
29 changes: 29 additions & 0 deletions libthefrisbee/volumegrouppvmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef VOLUMEGROUPPVMODEL_H
#define VOLUMEGROUPPVMODEL_H

#include <QAbstractListModel>

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

0 comments on commit aeef36d

Please sign in to comment.