From 694ee824fde63f0091dfec4eb2ad09def23b069c Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Tue, 15 Aug 2023 20:49:49 +1000 Subject: [PATCH] Add LVs to VG view --- application/lvm/volumegrouppage.cpp | 18 +++++ application/lvm/volumegrouppage.h | 2 + application/lvm/volumegrouppage.ui | 75 ++++++++++++++++++++ application/translations/ar_SA.ts | 15 ++++ application/translations/da.ts | 15 ++++ application/translations/en_US.ts | 15 ++++ application/translations/he_IL.ts | 15 ++++ application/translations/ja.ts | 15 ++++ application/translations/pt_BR.ts | 15 ++++ application/translations/tr.ts | 15 ++++ application/translations/vi.ts | 15 ++++ libthefrisbee/CMakeLists.txt | 1 + libthefrisbee/DriveObjects/logicalvolume.cpp | 30 ++++++++ libthefrisbee/DriveObjects/logicalvolume.h | 5 ++ libthefrisbee/DriveObjects/volumegroup.cpp | 13 ++++ libthefrisbee/DriveObjects/volumegroup.h | 6 ++ libthefrisbee/driveobjectmanager.cpp | 5 +- libthefrisbee/translations/cs.ts | 8 +++ libthefrisbee/translations/cs_CZ.ts | 8 +++ libthefrisbee/translations/da.ts | 8 +++ libthefrisbee/translations/de.ts | 8 +++ libthefrisbee/translations/en_US.ts | 8 +++ libthefrisbee/translations/he_IL.ts | 8 +++ libthefrisbee/translations/ru.ts | 8 +++ libthefrisbee/translations/vi_VN.ts | 8 +++ libthefrisbee/volumegrouplvmodel.cpp | 63 ++++++++++++++++ libthefrisbee/volumegrouplvmodel.h | 31 ++++++++ 27 files changed, 431 insertions(+), 2 deletions(-) create mode 100644 libthefrisbee/volumegrouplvmodel.cpp create mode 100644 libthefrisbee/volumegrouplvmodel.h diff --git a/application/lvm/volumegrouppage.cpp b/application/lvm/volumegrouppage.cpp index ff50263..5a63a3b 100644 --- a/application/lvm/volumegrouppage.cpp +++ b/application/lvm/volumegrouppage.cpp @@ -2,8 +2,11 @@ #include "ui_volumegrouppage.h" #include +#include struct VolumeGroupPagePrivate { + VolumeGroup* vg; + VolumeGroupLvModel* lvModel; }; VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) : @@ -11,7 +14,16 @@ VolumeGroupPage::VolumeGroupPage(VolumeGroup* vg, QWidget* parent) : ui(new Ui::VolumeGroupPage) { ui->setupUi(this); d = new VolumeGroupPagePrivate(); + d->vg = vg; ui->titleLabel->setText(vg->name()); + ui->disbandButton->setProperty("type", "destructive"); + + 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()); } VolumeGroupPage::~VolumeGroupPage() { @@ -27,3 +39,9 @@ void VolumeGroupPage::setTopPadding(int padding) { void VolumeGroupPage::on_titleLabel_backButtonClicked() { emit done(); } + +void VolumeGroupPage::on_disbandButton_clicked() +{ + +} + diff --git a/application/lvm/volumegrouppage.h b/application/lvm/volumegrouppage.h index 4107213..7e478d9 100644 --- a/application/lvm/volumegrouppage.h +++ b/application/lvm/volumegrouppage.h @@ -24,6 +24,8 @@ class VolumeGroupPage : public QWidget { private slots: void on_titleLabel_backButtonClicked(); + void on_disbandButton_clicked(); + private: Ui::VolumeGroupPage* ui; VolumeGroupPagePrivate* d; diff --git a/application/lvm/volumegrouppage.ui b/application/lvm/volumegrouppage.ui index a1c152c..3cd4ea9 100644 --- a/application/lvm/volumegrouppage.ui +++ b/application/lvm/volumegrouppage.ui @@ -71,6 +71,76 @@ 535 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Logical Volumes + + + 9 + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + + Physical Volumes + + + 9 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Disband Volume Group + + + + @@ -111,6 +181,11 @@ backButtonClicked() + + tSubtitleLabel + QLabel +
tsubtitlelabel.h
+
diff --git a/application/translations/ar_SA.ts b/application/translations/ar_SA.ts index c10732b..b051cf1 100644 --- a/application/translations/ar_SA.ts +++ b/application/translations/ar_SA.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/da.ts b/application/translations/da.ts index ba52c17..d93ed05 100644 --- a/application/translations/da.ts +++ b/application/translations/da.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/en_US.ts b/application/translations/en_US.ts index a96dbd7..19100e1 100644 --- a/application/translations/en_US.ts +++ b/application/translations/en_US.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/he_IL.ts b/application/translations/he_IL.ts index e5e808a..5072772 100644 --- a/application/translations/he_IL.ts +++ b/application/translations/he_IL.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/ja.ts b/application/translations/ja.ts index b0ca195..2f4ad31 100644 --- a/application/translations/ja.ts +++ b/application/translations/ja.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/pt_BR.ts b/application/translations/pt_BR.ts index 08b9efc..5a80f88 100644 --- a/application/translations/pt_BR.ts +++ b/application/translations/pt_BR.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/tr.ts b/application/translations/tr.ts index 34d1704..d37b68e 100644 --- a/application/translations/tr.ts +++ b/application/translations/tr.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/application/translations/vi.ts b/application/translations/vi.ts index 85d8748..6bce947 100644 --- a/application/translations/vi.ts +++ b/application/translations/vi.ts @@ -557,6 +557,21 @@ Form + + + Logical Volumes + + + + + Physical Volumes + + + + + Disband Volume Group + + main diff --git a/libthefrisbee/CMakeLists.txt b/libthefrisbee/CMakeLists.txt index 788bc9c..7ac7a59 100644 --- a/libthefrisbee/CMakeLists.txt +++ b/libthefrisbee/CMakeLists.txt @@ -51,6 +51,7 @@ set(SOURCES structures/private/smartattribute.h structures/private/smartattribute.cpp structures/formattedsmartattribute.cpp volumegroupmodel.h volumegroupmodel.cpp + volumegrouplvmodel.h volumegrouplvmodel.cpp ) set(STRUCTURES_HEADERS diff --git a/libthefrisbee/DriveObjects/logicalvolume.cpp b/libthefrisbee/DriveObjects/logicalvolume.cpp index 93314c4..b8edab0 100644 --- a/libthefrisbee/DriveObjects/logicalvolume.cpp +++ b/libthefrisbee/DriveObjects/logicalvolume.cpp @@ -1,11 +1,26 @@ #include "logicalvolume.h" +#include "driveobjectmanager.h" + struct LogicalVolumePrivate { + QDBusObjectPath vg; + QDBusObjectPath block; + QString name; }; LogicalVolume::LogicalVolume(QDBusObjectPath path, QObject* parent) : UdisksInterface{path, interfaceName(), parent} { d = new LogicalVolumePrivate(); + + bindPropertyUpdater("Name", [this](QVariant value) { + d->name = value.toString(); + }); + bindPropertyUpdater("VolumeGroup", [this](QVariant value) { + d->vg = value.value(); + }); + bindPropertyUpdater("BlockDevice", [this](QVariant value) { + d->block = value.value(); + }); } LogicalVolume::~LogicalVolume() { @@ -15,3 +30,18 @@ LogicalVolume::~LogicalVolume() { QString LogicalVolume::interfaceName() { return QStringLiteral("org.freedesktop.UDisks2.LogicalVolume"); } + +QString LogicalVolume::name() +{ + return d->name; +} + +VolumeGroup *LogicalVolume::vg() +{ + return DriveObjectManager::volumeGroupForPath(d->vg); +} + +DiskObject *LogicalVolume::block() +{ + return DriveObjectManager::diskForPath(d->block); +} diff --git a/libthefrisbee/DriveObjects/logicalvolume.h b/libthefrisbee/DriveObjects/logicalvolume.h index 237c0a0..ae8f56f 100644 --- a/libthefrisbee/DriveObjects/logicalvolume.h +++ b/libthefrisbee/DriveObjects/logicalvolume.h @@ -4,6 +4,7 @@ #include "udisksinterface.h" struct LogicalVolumePrivate; +class VolumeGroup; class LogicalVolume : public UdisksInterface { Q_OBJECT public: @@ -12,6 +13,10 @@ class LogicalVolume : public UdisksInterface { static QString interfaceName(); + QString name(); + VolumeGroup* vg(); + DiskObject* block(); + private: LogicalVolumePrivate* d; }; diff --git a/libthefrisbee/DriveObjects/volumegroup.cpp b/libthefrisbee/DriveObjects/volumegroup.cpp index 9d7c322..3dcdc2f 100644 --- a/libthefrisbee/DriveObjects/volumegroup.cpp +++ b/libthefrisbee/DriveObjects/volumegroup.cpp @@ -1,4 +1,7 @@ #include "volumegroup.h" +#include "logicalvolume.h" + +#include "driveobjectmanager.h" struct VolumeGroupPrivate { QString name; @@ -11,6 +14,9 @@ VolumeGroup::VolumeGroup(QDBusObjectPath path, QObject* parent) : bindPropertyUpdater("Name", [this](QVariant value) { d->name = value.toString(); }); + + connect(DriveObjectManager::instance(), &DriveObjectManager::logicalVolumeAdded, this, &VolumeGroup::lvsChanged); + connect(DriveObjectManager::instance(), &DriveObjectManager::logicalVolumeRemoved, this, &VolumeGroup::lvsChanged); } VolumeGroup::~VolumeGroup() { @@ -21,6 +27,13 @@ QString VolumeGroup::interfaceName() { return QStringLiteral("org.freedesktop.UDisks2.VolumeGroup"); } +tRange VolumeGroup::lvs() +{ + return tRange(DriveObjectManager::logicalVolumes()).filter([this](LogicalVolume* lv) { + return lv->vg() == this; + }); +} + QString VolumeGroup::name() { return d->name; } diff --git a/libthefrisbee/DriveObjects/volumegroup.h b/libthefrisbee/DriveObjects/volumegroup.h index 5b9d340..39bd644 100644 --- a/libthefrisbee/DriveObjects/volumegroup.h +++ b/libthefrisbee/DriveObjects/volumegroup.h @@ -2,8 +2,10 @@ #define VOLUMEGROUP_H #include "udisksinterface.h" +#include struct VolumeGroupPrivate; +class LogicalVolume; class VolumeGroup : public UdisksInterface { Q_OBJECT public: @@ -11,9 +13,13 @@ class VolumeGroup : public UdisksInterface { ~VolumeGroup(); static QString interfaceName(); + tRange lvs(); QString name(); + signals: + void lvsChanged(); + private: VolumeGroupPrivate* d; }; diff --git a/libthefrisbee/driveobjectmanager.cpp b/libthefrisbee/driveobjectmanager.cpp index 0c1bdb0..a9fc96f 100644 --- a/libthefrisbee/driveobjectmanager.cpp +++ b/libthefrisbee/driveobjectmanager.cpp @@ -65,7 +65,8 @@ DriveObjectManager::DriveObjectManager(QObject* parent) : QDBusConnection::systemBus().connect("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", this, SLOT(updateInterfaces())); QDBusConnection::systemBus().connect("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", this, SLOT(updateInterfaces())); - updateInterfaces(); + + QTimer::singleShot(0, this, &DriveObjectManager::updateInterfaces); } DriveObjectManager* DriveObjectManager::instance() { @@ -310,7 +311,7 @@ void DriveObjectManager::updateInterfaces() { emit logicalVolumeAdded(lv); }); } - lv->updateProperties(interfaces.value(VolumeGroup::interfaceName())); + lv->updateProperties(interfaces.value(LogicalVolume::interfaceName())); } } } diff --git a/libthefrisbee/translations/cs.ts b/libthefrisbee/translations/cs.ts index f153269..71a326d 100644 --- a/libthefrisbee/translations/cs.ts +++ b/libthefrisbee/translations/cs.ts @@ -1058,6 +1058,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/cs_CZ.ts b/libthefrisbee/translations/cs_CZ.ts index f153269..71a326d 100644 --- a/libthefrisbee/translations/cs_CZ.ts +++ b/libthefrisbee/translations/cs_CZ.ts @@ -1058,6 +1058,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/da.ts b/libthefrisbee/translations/da.ts index ffdaed7..f275716 100644 --- a/libthefrisbee/translations/da.ts +++ b/libthefrisbee/translations/da.ts @@ -1116,6 +1116,14 @@ Når disken i drevet er formateret, vil alt data på den være væk for evigt.Et medie kan ikke gendannes til sig selv. Vælg et andet medie at gendanne. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/de.ts b/libthefrisbee/translations/de.ts index 5a9b220..d3fe084 100644 --- a/libthefrisbee/translations/de.ts +++ b/libthefrisbee/translations/de.ts @@ -1062,6 +1062,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/en_US.ts b/libthefrisbee/translations/en_US.ts index 14a3d47..e1fa5d7 100644 --- a/libthefrisbee/translations/en_US.ts +++ b/libthefrisbee/translations/en_US.ts @@ -1058,6 +1058,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/he_IL.ts b/libthefrisbee/translations/he_IL.ts index 0b0e6e4..7e864ca 100644 --- a/libthefrisbee/translations/he_IL.ts +++ b/libthefrisbee/translations/he_IL.ts @@ -1111,6 +1111,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever.לא ניתן לשחזר מדיום מעצמו. בחר מדיום אחר לשחזר. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/ru.ts b/libthefrisbee/translations/ru.ts index 5b5f125..fb35e9c 100644 --- a/libthefrisbee/translations/ru.ts +++ b/libthefrisbee/translations/ru.ts @@ -1066,6 +1066,14 @@ Once the disc in the drive is erased, all the data on it will be gone forever. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/translations/vi_VN.ts b/libthefrisbee/translations/vi_VN.ts index c400213..ae8fbb3 100644 --- a/libthefrisbee/translations/vi_VN.ts +++ b/libthefrisbee/translations/vi_VN.ts @@ -1108,6 +1108,14 @@ Sau khi đĩa trong ổ bị xóa, các tệp trên nó sẽ bị mất mãi mã Một phương tiện không thể bị khôi phục lại vào chính nó. Vui lòng chọn một phương tiện khác để khôi phục. + + VolumeGroupLvModel + + + New Logical Volume + + + VolumeGroupModel diff --git a/libthefrisbee/volumegrouplvmodel.cpp b/libthefrisbee/volumegrouplvmodel.cpp new file mode 100644 index 0000000..22bfc49 --- /dev/null +++ b/libthefrisbee/volumegrouplvmodel.cpp @@ -0,0 +1,63 @@ +#include "volumegrouplvmodel.h" + +#include "DriveObjects/logicalvolume.h" +#include "DriveObjects/volumegroup.h" + +struct VolumeGroupLvModelPrivate { + VolumeGroup* vg; + QList lvs; + bool showAddLvItem = true; +}; + +VolumeGroupLvModel::VolumeGroupLvModel(VolumeGroup *vg, QObject *parent) + : QAbstractListModel(parent) +{ + d = new VolumeGroupLvModelPrivate(); + d->vg = vg; + this->updateLvs(); +} + +VolumeGroupLvModel::~VolumeGroupLvModel() +{ + delete d; +} + +int VolumeGroupLvModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) return 0; + + return d->lvs.count() + (d->showAddLvItem ? 1 : 0); +} + +QVariant VolumeGroupLvModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return {}; + + if (d->lvs.count() == index.row() && d->showAddLvItem) { + switch (role) { + case Qt::DisplayRole: + return tr("New Logical Volume"); + case Qt::DecorationRole: + return QIcon::fromTheme("list-add"); + } + return {}; + } + + auto lv = d->lvs.at(index.row()); + switch (role) { + case Qt::DisplayRole: + return lv->name(); + case LvRole: + return QVariant::fromValue(lv); + } + + return {}; +} + +void VolumeGroupLvModel::updateLvs() +{ + this->beginResetModel(); + d->lvs = d->vg->lvs().toList(); + this->endResetModel(); +} diff --git a/libthefrisbee/volumegrouplvmodel.h b/libthefrisbee/volumegrouplvmodel.h new file mode 100644 index 0000000..f0d8246 --- /dev/null +++ b/libthefrisbee/volumegrouplvmodel.h @@ -0,0 +1,31 @@ +#ifndef VOLUMEGROUPLVMODEL_H +#define VOLUMEGROUPLVMODEL_H + +#include + +class VolumeGroup; +struct VolumeGroupLvModelPrivate; +class VolumeGroupLvModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit VolumeGroupLvModel(VolumeGroup* vg, QObject *parent = nullptr); + ~VolumeGroupLvModel(); + + enum Roles { + LvRole = Qt::UserRole + }; + + // Basic functionality: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +private: + VolumeGroupLvModelPrivate* d; + + void updateLvs(); +}; + +#endif // VOLUMEGROUPLVMODEL_H