1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "profilemanagerdialog.h"
#include "profileview.h"
#include "ui_profilemanagerdialog.h"
#include <webprofile.h>
#include <QDir>
ProfileManagerDialog::ProfileManagerDialog(QHash<QString, WebProfile *> *profiles, QWidget *parent)
: QDialog(parent)
, ui(new Ui::ProfileManagerDialog)
, profiles(profiles)
{
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 i = profiles->constBegin(); i != profiles->constEnd(); ++i) {
ui->listWidget->addItem(i.key());
}
}
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 *v = new ProfileView(profiles->value(item->text()), 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 = profiles->value(item->text());
Q_CHECK_PTR(profile);
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;
}
|