#include "profilemanagerdialog.h" #include "profileview.h" #include "ui_profilemanagerdialog.h" #include #include #include ProfileManagerDialog::ProfileManagerDialog(const QVector &profiles, QWidget *parent) : QDialog(parent) , ui(new Ui::ProfileManagerDialog) { ui->setupUi(this); connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showProfile); showProfile(nullptr); connect(ui->delete_pushButton, &QPushButton::clicked, this, [=]() { deleteProfile(ui->listWidget->currentItem()); }); for(auto *profile : profiles) { auto *item = new QListWidgetItem(ui->listWidget); item->setText(profile->name()); auto pointer = QPointer(profile); item->setData(Qt::UserRole, QVariant::fromValue(pointer)); } } ProfileManagerDialog::~ProfileManagerDialog() { delete ui; } void ProfileManagerDialog::showProfile(QListWidgetItem *item) { // clear out groupbox layout QLayoutItem *i; while((i = ui->groupBox->layout()->takeAt(0)) != nullptr) { delete i->widget(); delete i; } if(item == nullptr) { ui->groupBox->setVisible(false); return; } ui->groupBox->setVisible(true); auto profile = item->data(Qt::UserRole).value>(); auto *v = new ProfileView(profile.data(), this); ui->groupBox->layout()->addWidget(v); v->adjustSize(); } void ProfileManagerDialog::deleteProfile(QListWidgetItem *item) { if(item == nullptr) return; // clear out groupbox layout QLayoutItem *i; while((i = ui->groupBox->layout()->takeAt(0)) != nullptr) { delete i->widget(); delete i; } auto profile = item->data(Qt::UserRole).value>(); Q_ASSERT(!profile.isNull()); qDebug("deleting profile %s", qUtf8Printable(profile->name())); qDebug("deleting %s: %s", qUtf8Printable(profile->configurationPath()), QFile(profile->configurationPath()).remove() ? "okay" : "failed"); qDebug("deleting %s: %s", qUtf8Printable(profile->persistentStoragePath()), QDir(profile->persistentStoragePath()).removeRecursively() ? "okay" : "failed"); qDebug("deleting %s: %s", qUtf8Printable(profile->cachePath()), QDir(profile->cachePath()).removeRecursively() ? "okay" : "failed"); delete item; delete profile.data(); }