From 1efd63efaf435db81cf5bfd0ca6b0534d8c1c36c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 14 Jun 2018 18:09:01 +0200 Subject: ProfileEditor: add delete button --- lib/web/webprofile.cpp | 12 +++--- lib/web/webprofile.h | 9 +++- .../ProfileEditor/forms/profilemanagerdialog.cpp | 29 +++++++++++++ plugins/ProfileEditor/forms/profilemanagerdialog.h | 1 + .../ProfileEditor/forms/profilemanagerdialog.ui | 50 ++++++++++++++++++---- plugins/ProfileEditor/forms/profileview.cpp | 2 +- plugins/ProfileEditor/forms/profileview.h | 4 +- plugins/ProfileEditor/forms/profileview.ui | 2 +- 8 files changed, 90 insertions(+), 19 deletions(-) diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index 67671a0..dca639b 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -24,15 +24,15 @@ WebProfile* loadProfile(const QString &name, const QHash &defa if(name.isEmpty()) { // a default otr profile - profile = new WebProfile(QObject::tr("Off-the-record"), nullptr); + profile = new WebProfile(QObject::tr("Off-the-record"), path, nullptr); } else if(config.value("otr").toBool()) { // a named otr profile - profile = new WebProfile(config.value("name", name).toString(), nullptr); + profile = new WebProfile(config.value("name", name).toString(), path, nullptr); } else { // a named profile - profile = new WebProfile(name, config.value("name", name).toString(), nullptr); + profile = new WebProfile(name, config.value("name", name).toString(), path, nullptr); } Q_CHECK_PTR(profile); @@ -70,20 +70,22 @@ WebProfile* loadProfile(const QString &name, const QHash &defa return profile; } -WebProfile::WebProfile(const QString &name, QObject *parent) +WebProfile::WebProfile(const QString &name, const QString &configPath, QObject *parent) : QWebEngineProfile(parent) { m_name = name; + m_configPath = configPath; #ifdef QT_DEBUG qDebug("Creating otr profile %s", qUtf8Printable(m_name)); #endif } -WebProfile::WebProfile(const QString &storageName, const QString &name, QObject *parent) +WebProfile::WebProfile(const QString &storageName, const QString &name, const QString &configPath, QObject *parent) : QWebEngineProfile(storageName, parent) { m_name = name; + m_configPath = configPath; #ifdef QT_DEBUG qDebug("Creating profile %s", qUtf8Printable(m_name)); diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index a421359..7a747a3 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -34,9 +34,9 @@ class WebProfile : public QWebEngineProfile public: // off-the-record constructor - explicit WebProfile(const QString &name, QObject *parent = nullptr); + explicit WebProfile(const QString &name, const QString &configPath, QObject *parent = nullptr); // default constructor - explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr); + explicit WebProfile(const QString &storageName, const QString &name, const QString &configPath, QObject *parent = nullptr); ~WebProfile() = default; @@ -55,6 +55,10 @@ public: { return m_name; } + QString configurationPath() const + { + return m_configPath; + } // search url QString search() const; @@ -102,6 +106,7 @@ signals: private: static WebProfile *profile; + QString m_configPath; QString m_name; QString m_search = QString("about:blank"); QUrl m_homepage = QUrl("about:blank"); diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index d05b480..2f0f4a2 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -2,6 +2,7 @@ #include "profileview.h" #include "ui_profilemanagerdialog.h" #include +#include ProfileManagerDialog::ProfileManagerDialog(QHash *profiles, QWidget *parent) : QDialog(parent) @@ -13,6 +14,10 @@ ProfileManagerDialog::ProfileManagerDialog(QHash *profile 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()); } @@ -42,3 +47,27 @@ void ProfileManagerDialog::showProfile(QListWidgetItem *item) 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; +} diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index ba315ce..a4b6f83 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -21,6 +21,7 @@ public: private slots: void showProfile(QListWidgetItem *item); + void deleteProfile(QListWidgetItem *item); private: Ui::ProfileManagerDialog *ui; diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.ui b/plugins/ProfileEditor/forms/profilemanagerdialog.ui index ae3829a..f7acdec 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.ui +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.ui @@ -40,14 +40,48 @@ - - - Qt::Horizontal - - - QDialogButtonBox::Close - - + + + + + false + + + New + + + + + + + Delete + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index b723a61..2d96d43 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -18,7 +18,7 @@ inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QW } ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) - : QDialog(parent) + : QWidget(parent) , ui(new Ui::ProfileView) { Q_CHECK_PTR(profile); diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index a264cc0..6a8e8ab 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -9,7 +9,7 @@ #ifndef PROFILEDIALOG_H #define PROFILEDIALOG_H -#include +#include #include namespace Ui @@ -17,7 +17,7 @@ namespace Ui class ProfileView; } -class ProfileView : public QDialog +class ProfileView : public QWidget { Q_OBJECT diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui index f0ea24c..2f6c889 100644 --- a/plugins/ProfileEditor/forms/profileview.ui +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -1,7 +1,7 @@ ProfileView - + 0 -- cgit v1.2.1