From 3639d5789259561c531a3481d7061a0cb492c644 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 9 Oct 2018 12:05:28 +0200 Subject: Unlink plugins from lib/ libraries --- plugins/ProfileEditor/CMakeLists.txt | 38 ++++++++-------- plugins/ProfileEditor/forms/newprofiledialog.cpp | 5 +++ plugins/ProfileEditor/forms/newprofiledialog.h | 1 + plugins/ProfileEditor/forms/newprofiledialog.ui | 35 ++++++++------- .../ProfileEditor/forms/profilemanagerdialog.cpp | 50 +++------------------- plugins/ProfileEditor/forms/profilemanagerdialog.h | 19 +++----- plugins/ProfileEditor/forms/profileview.cpp | 11 +++-- plugins/ProfileEditor/forms/profileview.h | 6 +-- plugins/ProfileEditor/profileeditorplugin.cpp | 36 ++++++++++------ plugins/ProfileEditor/profileeditorplugin.h | 6 +-- 10 files changed, 91 insertions(+), 116 deletions(-) (limited to 'plugins/ProfileEditor') diff --git a/plugins/ProfileEditor/CMakeLists.txt b/plugins/ProfileEditor/CMakeLists.txt index 7c9a774..5bcfcce 100644 --- a/plugins/ProfileEditor/CMakeLists.txt +++ b/plugins/ProfileEditor/CMakeLists.txt @@ -9,31 +9,35 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) add_library(ProfileEditorPlugin SHARED - profileeditorplugin.cpp - profileeditorplugin.h - forms/profileview.cpp - forms/profileview.h - forms/profileview.ui - forms/profilemanagerdialog.cpp - forms/profilemanagerdialog.h - forms/profilemanagerdialog.ui - forms/newprofiledialog.cpp - forms/newprofiledialog.h - forms/newprofiledialog.ui - forms/newhttpheaderdialog.cpp - forms/newhttpheaderdialog.h - forms/newhttpheaderdialog.ui + ${CMAKE_SOURCE_DIR}/include/profileinterface.h + ${CMAKE_SOURCE_DIR}/include/browserinterface.h + ${CMAKE_SOURCE_DIR}/include/plugininterface.h + + profileeditorplugin.cpp + profileeditorplugin.h + + forms/profilemanagerdialog.cpp + forms/profilemanagerdialog.h + forms/profilemanagerdialog.ui + forms/profileview.cpp + forms/profileview.h + forms/profileview.ui + + forms/newprofiledialog.cpp + forms/newprofiledialog.h + forms/newprofiledialog.ui + forms/newhttpheaderdialog.cpp + forms/newhttpheaderdialog.h + forms/newhttpheaderdialog.ui ) target_include_directories(ProfileEditorPlugin - PRIVATE ${CMAKE_SOURCE_DIR}/plugins - PRIVATE ${CMAKE_SOURCE_DIR}/lib/web + PRIVATE ${CMAKE_SOURCE_DIR}/include ) target_link_libraries(ProfileEditorPlugin PRIVATE Qt5::Widgets PRIVATE Qt5::WebEngineWidgets - PRIVATE web ) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/plugins/ProfileEditor/forms/newprofiledialog.cpp b/plugins/ProfileEditor/forms/newprofiledialog.cpp index 13c46f8..3ed61d8 100644 --- a/plugins/ProfileEditor/forms/newprofiledialog.cpp +++ b/plugins/ProfileEditor/forms/newprofiledialog.cpp @@ -25,3 +25,8 @@ const QString NewProfileDialog::getId() const { return ui->id_lineEdit->text(); } + +bool NewProfileDialog::getOtr() const +{ + return ui->offTheRecord->isChecked(); +} diff --git a/plugins/ProfileEditor/forms/newprofiledialog.h b/plugins/ProfileEditor/forms/newprofiledialog.h index 84626fa..dd9aa4e 100644 --- a/plugins/ProfileEditor/forms/newprofiledialog.h +++ b/plugins/ProfileEditor/forms/newprofiledialog.h @@ -24,6 +24,7 @@ public: ~NewProfileDialog(); const QString getId() const; + bool getOtr() const; private: Ui::NewProfileDialog *ui; diff --git a/plugins/ProfileEditor/forms/newprofiledialog.ui b/plugins/ProfileEditor/forms/newprofiledialog.ui index c46c3b3..8b4888d 100644 --- a/plugins/ProfileEditor/forms/newprofiledialog.ui +++ b/plugins/ProfileEditor/forms/newprofiledialog.ui @@ -7,28 +7,24 @@ 0 0 320 - 78 + 112 New Profile - - - - - - - ID - - - - - - - + + + + + ID + + + + + - + Qt::Horizontal @@ -38,6 +34,13 @@ + + + + Off the record + + + diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index b6c1c7e..f5a17b1 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -8,13 +8,10 @@ #include "profilemanagerdialog.h" #include "profileview.h" -#include "ui_profilemanagerdialog.h" -#include #include #include -#include "newprofiledialog.h" -ProfileManagerDialog::ProfileManagerDialog(const ProfileManager *profiles, QWidget *parent) +ProfileManagerDialog::ProfileManagerDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::ProfileManagerDialog) { @@ -22,22 +19,6 @@ ProfileManagerDialog::ProfileManagerDialog(const ProfileManager *profiles, QWidg 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(const QString &profileId : profiles->idList()) { - addProfile(profiles->profile(profileId)); - } } ProfileManagerDialog::~ProfileManagerDialog() @@ -45,14 +26,13 @@ ProfileManagerDialog::~ProfileManagerDialog() delete ui; } -void ProfileManagerDialog::addProfile(WebProfile *profile) +void ProfileManagerDialog::addProfile(const QString &id, Profile *profile) { Q_CHECK_PTR(profile); - auto *item = new QListWidgetItem(ui->listWidget); - item->setText(profile->name()); + auto *item = new QListWidgetItem(id, ui->listWidget); - auto pointer = QPointer(profile); + auto pointer = QPointer(profile); item->setData(Qt::UserRole, QVariant::fromValue(pointer)); } @@ -71,28 +51,8 @@ void ProfileManagerDialog::showProfile(QListWidgetItem *item) } ui->groupBox->setVisible(true); - auto profile = item->data(Qt::UserRole).value>(); + 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()); - - emit removeProfile(profile); - - delete item; -} diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index 35c2111..fe91948 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -11,12 +11,8 @@ #include #include -#include - -namespace Ui -{ -class ProfileManagerDialog; -} +#include +#include "ui_profilemanagerdialog.h" class WebProfile; class QListWidgetItem; @@ -24,20 +20,17 @@ class ProfileManagerDialog : public QDialog { Q_OBJECT + friend class ProfileEditorPlugin; + public: - explicit ProfileManagerDialog(const ProfileManager *profiles, QWidget *parent = 0); + explicit ProfileManagerDialog(QWidget *parent = 0); ~ProfileManagerDialog() override; -signals: - void createProfile(const QString &id); - void removeProfile(const WebProfile *profile); - public slots: - void addProfile(WebProfile *profile); + void addProfile(const QString &id, Profile *profile); private slots: void showProfile(QListWidgetItem *item); - void deleteProfile(QListWidgetItem *item); private: Ui::ProfileManagerDialog *ui; diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 4a89af6..9a19cfc 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -8,14 +8,13 @@ #include "profileview.h" #include "ui_profileview.h" -#include -#include +#include #include #include #include #include "newhttpheaderdialog.h" -inline void connectSetting(QCheckBox *checkBox, WebProfile *profile, QWebEngineSettings::WebAttribute attr) +inline void connectSetting(QCheckBox *checkBox, Profile *profile, QWebEngineSettings::WebAttribute attr) { checkBox->setChecked(profile->settings()->testAttribute(attr)); QObject::connect(checkBox, &QCheckBox::clicked, [profile, attr](bool checked) { @@ -24,7 +23,7 @@ inline void connectSetting(QCheckBox *checkBox, WebProfile *profile, QWebEngineS }); } -ProfileView::ProfileView(WebProfile *profile, QWidget *parent) +ProfileView::ProfileView(Profile *profile, QWidget *parent) : QWidget(parent) , ui(new Ui::ProfileView) { @@ -92,8 +91,8 @@ ProfileView::ProfileView(WebProfile *profile, QWidget *parent) //ui->httpHeaders->addItem(); headerChanged(i.key(), i.value()); } - connect(m_profile, &WebProfile::headerChanged, this, &ProfileView::headerChanged); - connect(m_profile, &WebProfile::headerRemoved, this, &ProfileView::headerRemoved); + connect(m_profile, &Profile::headerChanged, this, &ProfileView::headerChanged); + connect(m_profile, &Profile::headerRemoved, this, &ProfileView::headerRemoved); connect(ui->headers_insert, &QPushButton::clicked, m_profile, [this]() { auto *dlg = new NewHttpHeaderDialog(this); if(dlg->exec() == QDialog::Accepted) { diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index d05b0f1..7f3e738 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -18,7 +18,7 @@ namespace Ui class ProfileView; } -class WebProfile; +class Profile; class QWebEngineCookieStore; class QCheckBox; @@ -27,7 +27,7 @@ class ProfileView : public QWidget Q_OBJECT public: - explicit ProfileView(WebProfile *profile, QWidget *parent = nullptr); + explicit ProfileView(Profile *profile, QWidget *parent = nullptr); ~ProfileView() override; private slots: @@ -41,7 +41,7 @@ private slots: private: Ui::ProfileView *ui; - WebProfile *m_profile; + Profile *m_profile; }; #endif // PROFILEDIALOG_H diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index 1eb7b28..d480392 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -8,9 +8,7 @@ #include "profileeditorplugin.h" #include "forms/profilemanagerdialog.h" -#include "forms/profileview.h" -#include -#include +#include "forms/newprofiledialog.h" QHash> ProfileEditorPlugin::commands() { @@ -23,20 +21,34 @@ QHash> ProfileEditorPlugin::commands() return hash; } -QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) +QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) const { - Q_CHECK_PTR(browser); - auto *widget = new ProfileManagerDialog(browser->getProfileManager(), parent); + auto *app = browser(); + Q_CHECK_PTR(app); + auto *widget = new ProfileManagerDialog(parent); widget->setAttribute(Qt::WA_DeleteOnClose, true); - connect(widget, &ProfileManagerDialog::createProfile, this, [=](const QString &id) { - auto newProfile = browser->loadProfile(id); - widget->addProfile(newProfile.second); + for(const auto &pair : app->profileList()) { + widget->addProfile(pair.first, pair.second); + } + + connect(widget->ui->new_pushButton, &QPushButton::clicked, widget, [=]() { + auto *newProfileDlg = new NewProfileDialog(widget); + if(newProfileDlg->exec() == QDialog::Accepted) { + const auto pair = app->loadProfile(newProfileDlg->getId(), newProfileDlg->getOtr()); + widget->addProfile(pair.first, pair.second); + } + delete newProfileDlg; }); - connect(widget, &ProfileManagerDialog::removeProfile, this, [this](const WebProfile *profile) { - const QString id = browser->getProfileManager()->id(profile); - browser->getProfileManager()->deleteProfile(id); + connect(widget->ui->delete_pushButton, &QPushButton::clicked, widget, [=]() { + auto *item = widget->ui->listWidget->currentItem(); + if(item != nullptr) { + // there is a selected widget + const QString id = item->text(); + widget->showProfile(nullptr); + app->removeProfile(id); + } }); return widget; diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h index 70f077d..a673436 100644 --- a/plugins/ProfileEditor/profileeditorplugin.h +++ b/plugins/ProfileEditor/profileeditorplugin.h @@ -9,10 +9,8 @@ #ifndef PROFILEEDITOR_PLUGIN_H #define PROFILEEDITOR_PLUGIN_H -#include -#include +#include -class QWebEngineProfile; class QDialog; class ProfileEditorPlugin : public QObject, public PluginInterface { @@ -25,7 +23,7 @@ public: QHash> commands() override; // ProfileInterface - QDialog *createWidget(QWidget *parent) override; + QDialog *createWidget(QWidget *parent) const override; }; #endif //PROFILEEDITOR_PLUGIN_H -- cgit v1.2.1