From 36dce3fd26194cdf6dbf1ba52cc27cfa1daae389 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 27 Aug 2018 16:42:51 +0200 Subject: PluginEditor: implement add plugin action --- plugins/ProfileEditor/CMakeLists.txt | 3 + plugins/ProfileEditor/forms/newprofiledialog.cpp | 19 ++++++ plugins/ProfileEditor/forms/newprofiledialog.h | 24 +++++++ plugins/ProfileEditor/forms/newprofiledialog.ui | 78 ++++++++++++++++++++++ .../ProfileEditor/forms/profilemanagerdialog.cpp | 26 ++++++-- plugins/ProfileEditor/forms/profilemanagerdialog.h | 7 ++ .../ProfileEditor/forms/profilemanagerdialog.ui | 3 - plugins/ProfileEditor/forms/profileview.cpp | 15 ++++- plugins/ProfileEditor/forms/profileview.h | 9 ++- plugins/ProfileEditor/profileeditorplugin.cpp | 5 ++ plugins/interfaces.h | 2 + 11 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 plugins/ProfileEditor/forms/newprofiledialog.cpp create mode 100644 plugins/ProfileEditor/forms/newprofiledialog.h create mode 100644 plugins/ProfileEditor/forms/newprofiledialog.ui (limited to 'plugins') diff --git a/plugins/ProfileEditor/CMakeLists.txt b/plugins/ProfileEditor/CMakeLists.txt index be65d8e..f294c30 100644 --- a/plugins/ProfileEditor/CMakeLists.txt +++ b/plugins/ProfileEditor/CMakeLists.txt @@ -14,6 +14,9 @@ add_library(ProfileEditorPlugin SHARED forms/profilemanagerdialog.cpp forms/profilemanagerdialog.h forms/profilemanagerdialog.ui + forms/newprofiledialog.cpp + forms/newprofiledialog.h + forms/newprofiledialog.ui ) target_include_directories(ProfileEditorPlugin diff --git a/plugins/ProfileEditor/forms/newprofiledialog.cpp b/plugins/ProfileEditor/forms/newprofiledialog.cpp new file mode 100644 index 0000000..04415de --- /dev/null +++ b/plugins/ProfileEditor/forms/newprofiledialog.cpp @@ -0,0 +1,19 @@ +#include "newprofiledialog.h" +#include "ui_newprofiledialog.h" + +NewProfileDialog::NewProfileDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewProfileDialog) +{ + ui->setupUi(this); +} + +NewProfileDialog::~NewProfileDialog() +{ + delete ui; +} + +const QString NewProfileDialog::getId() const +{ + return ui->id_lineEdit->text(); +} diff --git a/plugins/ProfileEditor/forms/newprofiledialog.h b/plugins/ProfileEditor/forms/newprofiledialog.h new file mode 100644 index 0000000..6fa0a27 --- /dev/null +++ b/plugins/ProfileEditor/forms/newprofiledialog.h @@ -0,0 +1,24 @@ +#ifndef NEWPROFILEDIALOG_H +#define NEWPROFILEDIALOG_H + +#include + +namespace Ui { +class NewProfileDialog; +} + +class NewProfileDialog : public QDialog +{ + Q_OBJECT + +public: + explicit NewProfileDialog(QWidget *parent = nullptr); + ~NewProfileDialog(); + + const QString getId() const; + +private: + Ui::NewProfileDialog *ui; +}; + +#endif // NEWPROFILEDIALOG_H diff --git a/plugins/ProfileEditor/forms/newprofiledialog.ui b/plugins/ProfileEditor/forms/newprofiledialog.ui new file mode 100644 index 0000000..c46c3b3 --- /dev/null +++ b/plugins/ProfileEditor/forms/newprofiledialog.ui @@ -0,0 +1,78 @@ + + + NewProfileDialog + + + + 0 + 0 + 320 + 78 + + + + New Profile + + + + + + + + ID + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + NewProfileDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewProfileDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index 427330a..dac4a61 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "newprofiledialog.h" ProfileManagerDialog::ProfileManagerDialog(const QVector &profiles, QWidget *parent) : QDialog(parent) @@ -14,16 +15,20 @@ ProfileManagerDialog::ProfileManagerDialog(const QVector &profiles connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showProfile); showProfile(nullptr); + connect(ui->new_pushButton, &QPushButton::clicked, this, [=]() { + auto *profileDlg = new NewProfileDialog(this); + if(profileDlg->exec() == QDialog::Accepted) { + emit createProfile(profileDlg->getId()); + } + delete profileDlg; + }); + 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)); + addProfile(profile); } } @@ -32,6 +37,17 @@ ProfileManagerDialog::~ProfileManagerDialog() delete ui; } +void ProfileManagerDialog::addProfile(WebProfile *profile) +{ + Q_CHECK_PTR(profile); + + auto *item = new QListWidgetItem(ui->listWidget); + item->setText(profile->name()); + + auto pointer = QPointer(profile); + item->setData(Qt::UserRole, QVariant::fromValue(pointer)); +} + void ProfileManagerDialog::showProfile(QListWidgetItem *item) { // clear out groupbox layout diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index e182799..4f468c5 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -19,6 +19,13 @@ public: explicit ProfileManagerDialog(const QVector &profiles, QWidget *parent = 0); ~ProfileManagerDialog(); +signals: + void createProfile(const QString &id); + void updateProfile(const QString &id); + +public slots: + void addProfile(WebProfile *profile); + private slots: void showProfile(QListWidgetItem *item); void deleteProfile(QListWidgetItem *item); diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.ui b/plugins/ProfileEditor/forms/profilemanagerdialog.ui index f7acdec..f41b1b0 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.ui +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.ui @@ -43,9 +43,6 @@ - - false - New diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 87546e5..85dde12 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -13,10 +13,11 @@ #include #include -inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) +void ProfileView::connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) { checkBox->setChecked(settings->testAttribute(attr)); - QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked) { + connect(checkBox, &QCheckBox::clicked, [this, settings, attr](bool checked) { + this->m_isChanged = true; settings->setAttribute(attr, checked); }); } @@ -37,26 +38,31 @@ ProfileView::ProfileView(WebProfile *profile, QWidget *parent) // http tab ui->userAgent->setPlainText(m_profile->httpUserAgent()); connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() { + this->m_isChanged = true; profile->setHttpUserAgent(ui->userAgent->toPlainText()); }); ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [=]() { + this->m_isChanged = true; profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); }); ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); connect(ui->cacheType, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { + this->m_isChanged = true; profile->setHttpCacheType(static_cast(index)); }); ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize())); connect(ui->cacheSize, &QLineEdit::textChanged, profile, [=](const QString &text) { + this->m_isChanged = true; profile->setHttpCacheMaximumSize(text.toInt()); }); ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); connect(ui->cookiePolicy, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { + this->m_isChanged = true; profile->setPersistentCookiesPolicy(static_cast(index)); }); @@ -81,6 +87,11 @@ ProfileView::~ProfileView() delete ui; } +bool ProfileView::isChanged() const +{ + return m_isChanged; +} + void ProfileView::loadSettings(QWebEngineSettings *settings) { // settings diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index 6aa7c34..6c77982 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -11,6 +11,7 @@ #include #include +#include namespace Ui { @@ -18,8 +19,9 @@ class ProfileView; } class WebProfile; -class QWebEngineSettings; class QWebEngineCookieStore; +class QCheckBox; + class ProfileView : public QWidget { Q_OBJECT @@ -28,6 +30,8 @@ public: explicit ProfileView(WebProfile *profile, QWidget *parent = nullptr); ~ProfileView() override; + bool isChanged() const; + private slots: void loadSettings(QWebEngineSettings *settings); void loadCookies(QWebEngineCookieStore *store); @@ -38,6 +42,9 @@ private slots: private: Ui::ProfileView *ui; WebProfile *m_profile; + bool m_isChanged = false; + + void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr); }; #endif // PROFILEDIALOG_H diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index 5d5c18a..32b0b8d 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -28,5 +28,10 @@ QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) Q_CHECK_PTR(browser); auto *widget = new ProfileManagerDialog(browser->profiles(), parent); widget->setAttribute(Qt::WA_DeleteOnClose, true); + + connect(widget, &ProfileManagerDialog::createProfile, this, [=](const QString &id) { + auto newProfile = browser->loadProfile(id); + widget->addProfile(newProfile.second); + }); return widget; } diff --git a/plugins/interfaces.h b/plugins/interfaces.h index fc8eac8..fe25ed3 100644 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -24,6 +24,8 @@ class BrowserInterface { public: virtual Configuration *getConfiguration() const = 0; + + virtual QPair loadProfile(const QString &id) = 0; virtual const QVector profiles() const = 0; }; -- cgit v1.2.1