Skip to content

Commit

Permalink
Implement VG Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Aug 15, 2023
1 parent 637d22f commit ff59e24
Show file tree
Hide file tree
Showing 26 changed files with 901 additions and 223 deletions.
2 changes: 2 additions & 0 deletions application/diskPanes/lvmdiskpane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <DriveObjects/partitiontableinterface.h>
#include <DriveObjects/physicalvolumeinterface.h>
#include <DriveObjects/volumegroup.h>
#include <diskoperationmanager.h>
#include <partitioninformation.h>

struct LvmDiskPanePrivate {
Expand Down Expand Up @@ -65,4 +66,5 @@ int LvmDiskPane::order() const {
}

void LvmDiskPane::on_attachVgButton_clicked() {
DiskOperationManager::showDiskOperationUi(this->window(), DiskOperationManager::AttachPv, d->disk);
}
4 changes: 1 addition & 3 deletions application/lvm/lvmpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LvmPage::LvmPage(QWidget* parent) :

d = new LvmPagePrivate();
d->vgModel = new VolumeGroupModel(this);
d->vgModel->setShowAddButton(true);
d->vgModel->setShowAddButton(false);
ui->listView->setModel(d->vgModel);

ui->stackedWidget->setCurrentAnimation(tStackedWidget::Fade);
Expand All @@ -44,7 +44,5 @@ void LvmPage::on_listView_clicked(const QModelIndex& index) {
});
ui->stackedWidget_2->addWidget(vgPage);
ui->stackedWidget_2->setCurrentWidget(vgPage);
} else {
// Create a new VG
}
}
4 changes: 2 additions & 2 deletions application/translations/ar_SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/he_IL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a volume group.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions application/translations/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="51"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="52"/>
<source>This block is part of the %1 volume group.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../diskPanes/lvmdiskpane.cpp" line="56"/>
<location filename="../diskPanes/lvmdiskpane.cpp" line="57"/>
<source>This block is not part of a 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 @@ -53,6 +53,7 @@ set(SOURCES
volumegroupmodel.h volumegroupmodel.cpp
volumegrouplvmodel.h volumegrouplvmodel.cpp
volumegrouppvmodel.h volumegrouppvmodel.cpp
operations/attachpvpopover.h operations/attachpvpopover.cpp operations/attachpvpopover.ui
)

set(STRUCTURES_HEADERS
Expand Down
21 changes: 19 additions & 2 deletions libthefrisbee/diskoperationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <tpopover.h>
#include <ttoast.h>

#include <operations/attachpvpopover.h>
#include <operations/eraseopticalpopover.h>
#include <operations/erasepartitionpopover.h>
#include <operations/erasepartitiontablepopover.h>
Expand All @@ -48,14 +49,16 @@ QMap<DiskOperationManager::DiskOperation, QString> OperationManagerPrivate::oper
{DiskOperationManager::Erase, "erase" },
{DiskOperationManager::Image, "image" },
{DiskOperationManager::Restore, "restore" },
{DiskOperationManager::Partition, "partition"}
{DiskOperationManager::Partition, "partition"},
{DiskOperationManager::AttachPv, "attachPv" }
};

QMap<DiskOperationManager::DiskOperation, QString> OperationManagerPrivate::operationDescriptions = {
{DiskOperationManager::Erase, DiskOperationManager::tr("Erase a block device") },
{DiskOperationManager::Image, DiskOperationManager::tr("Create an image of a block device") },
{DiskOperationManager::Restore, DiskOperationManager::tr("Restore an image back to a block device or disc")},
{DiskOperationManager::Partition, DiskOperationManager::tr("Edit partitions on a filesystem") }
{DiskOperationManager::Partition, DiskOperationManager::tr("Edit partitions on a filesystem") },
{DiskOperationManager::AttachPv, DiskOperationManager::tr("Attach a Physical Volume to a Volume Group") }
};

DiskOperationManager::DiskOperation DiskOperationManager::operationForString(QString operationString) {
Expand Down Expand Up @@ -87,6 +90,9 @@ void DiskOperationManager::showDiskOperationUi(QWidget* parent, DiskOperation op
break;
case DiskOperationManager::Partition:
showPartitionOperationUi(parent, disk);
break;
case DiskOperationManager::AttachPv:
showAttachPvOperationUi(parent, disk);
}
}

Expand Down Expand Up @@ -270,6 +276,17 @@ void DiskOperationManager::showPartitionOperationUi(QWidget* parent, DiskObject*
popover->show(parent->window());
}

void DiskOperationManager::showAttachPvOperationUi(QWidget* parent, DiskObject* disk) {
auto* jp = new AttachPvPopover(disk);
tPopover* popover = new tPopover(jp);
popover->setPopoverWidth(-200);
popover->setPopoverSide(tPopover::Bottom);
connect(jp, &AttachPvPopover::done, popover, &tPopover::dismiss);
connect(popover, &tPopover::dismissed, popover, &tPopover::deleteLater);
connect(popover, &tPopover::dismissed, jp, &AttachPvPopover::deleteLater);
popover->show(parent->window());
}

bool DiskOperationManager::ensureOpticalUtilitiesInstalled(QWidget* parent) {
if (QStandardPaths::findExecutable("cdrecord").isEmpty()) {
QMessageBox* box = new QMessageBox();
Expand Down
6 changes: 4 additions & 2 deletions libthefrisbee/diskoperationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#ifndef DISKOPERATIONMANAGER_H
#define DISKOPERATIONMANAGER_H

#include <QWidget>
#include <DriveObjects/diskobject.h>
#include "libthefrisbee_global.h"
#include <DriveObjects/diskobject.h>
#include <QWidget>

class LIBTHEFRISBEE_EXPORT DiskOperationManager : public QObject {
Q_OBJECT
Expand All @@ -34,6 +34,7 @@ class LIBTHEFRISBEE_EXPORT DiskOperationManager : public QObject {
Restore,
Image,
Partition,
AttachPv,
LastOperation = Partition
};

Expand All @@ -51,6 +52,7 @@ class LIBTHEFRISBEE_EXPORT DiskOperationManager : public QObject {
static void showRestoreOperationUi(QWidget* parent, DiskObject* disk);
static void showImageOperationUi(QWidget* parent, DiskObject* disk);
static void showPartitionOperationUi(QWidget* parent, DiskObject* disk);
static void showAttachPvOperationUi(QWidget* parent, DiskObject* disk);
};

#endif // DISKOPERATIONMANAGER_H
16 changes: 16 additions & 0 deletions libthefrisbee/driveobjectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ QCoro::Task<QDBusObjectPath> DriveObjectManager::loopSetup(QDBusUnixFileDescript
}
}

QCoro::Task<QDBusObjectPath> DriveObjectManager::volumeGroupCreate(QString name, QList<DiskObject*> blocks, QVariantMap options) {
QDBusMessage vgCreate = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2/Manager", "org.freedesktop.UDisks2.Manager.LVM2", "VolumeGroupCreate");
vgCreate.setArguments({name, QVariant::fromValue(tRange(blocks).map<QDBusObjectPath>([](DiskObject* obj) {
return obj->path();
})
.toList()),
options});
auto call = QDBusConnection::systemBus().asyncCall(vgCreate);
auto reply = co_await call;
if (call.isError()) {
throw FrisbeeException(call.error().message());
} else {
co_return reply.arguments().first().value<QDBusObjectPath>();
}
}

void DriveObjectManager::updateInterfaces() {
d->rootDisks.clear();
d->filesystemDisks.clear();
Expand Down
1 change: 1 addition & 0 deletions libthefrisbee/driveobjectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class LIBTHEFRISBEE_EXPORT DriveObjectManager : public QObject {
static QStringList supportedFilesystems();

static QCoro::Task<QDBusObjectPath> loopSetup(QDBusUnixFileDescriptor fd, QVariantMap options);
static QCoro::Task<QDBusObjectPath> volumeGroupCreate(QString name, QList<DiskObject*> blocks, QVariantMap options);

public slots:
void updateInterfaces();
Expand Down
60 changes: 60 additions & 0 deletions libthefrisbee/operations/attachpvpopover.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "attachpvpopover.h"
#include "ui_attachpvpopover.h"

#include <DriveObjects/volumegroup.h>
#include <driveobjectmanager.h>
#include <tcontentsizer.h>
#include <terrorflash.h>
#include <volumegroupmodel.h>

struct AttachPvPopoverPrivate {
DiskObject* disk;
VolumeGroupModel* vgModel;
};

AttachPvPopover::AttachPvPopover(DiskObject* disk, QWidget* parent) :
QWidget(parent),
ui(new Ui::AttachPvPopover) {
ui->setupUi(this);
d = new AttachPvPopoverPrivate();
d->disk = disk;

new tContentSizer(ui->optionsWidget);
new tContentSizer(ui->newVgOptionsWidget);
ui->stackedWidget->setCurrentAnimation(tStackedWidget::SlideHorizontal);

d->vgModel = new VolumeGroupModel(this);
d->vgModel->setShowAddButton(true);
ui->vgList->setModel(d->vgModel);
}

AttachPvPopover::~AttachPvPopover() {
delete d;
delete ui;
}

void AttachPvPopover::on_titleLabel_backButtonClicked() {
emit done();
}

void AttachPvPopover::on_vgList_activated(const QModelIndex& index) {
auto vg = index.data(VolumeGroupModel::VolumeGroupRole).value<VolumeGroup*>();
if (!vg) {
ui->stackedWidget->setCurrentWidget(ui->addVgPage);
}
}

void AttachPvPopover::on_titleLabel_2_backButtonClicked() {
ui->stackedWidget->setCurrentWidget(ui->selectVgPage);
}

void AttachPvPopover::on_attachToNewVgButton_clicked() {
auto vgName = ui->newVgName->text();
if (vgName.isEmpty()) {
tErrorFlash::flashError(ui->newVgName);
return;
}

DriveObjectManager::volumeGroupCreate(ui->newVgName->text(), {d->disk}, {});
emit done();
}
36 changes: 36 additions & 0 deletions libthefrisbee/operations/attachpvpopover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef ATTACHPVPOPOVER_H
#define ATTACHPVPOPOVER_H

#include <QWidget>

namespace Ui {
class AttachPvPopover;
}

class DiskObject;
struct AttachPvPopoverPrivate;
class AttachPvPopover : public QWidget {
Q_OBJECT

public:
explicit AttachPvPopover(DiskObject* disk, QWidget* parent = nullptr);
~AttachPvPopover();

signals:
void done();

private slots:
void on_titleLabel_backButtonClicked();

void on_vgList_activated(const QModelIndex& index);

void on_titleLabel_2_backButtonClicked();

void on_attachToNewVgButton_clicked();

private:
Ui::AttachPvPopover* ui;
AttachPvPopoverPrivate* d;
};

#endif // ATTACHPVPOPOVER_H
Loading

0 comments on commit ff59e24

Please sign in to comment.