diff options
-rw-r--r-- | plugins/ProfileEditor/forms/profilemanagerdialog.cpp | 20 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profilemanagerdialog.h | 9 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.cpp | 2 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.cpp | 22 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.h | 7 | ||||
-rw-r--r-- | plugins/interfaces.h | 3 | ||||
-rw-r--r-- | src/browser.cpp | 28 |
7 files changed, 48 insertions, 43 deletions
diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index c5fec2b..fbf7ad4 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -1,17 +1,21 @@ #include "profilemanagerdialog.h" +#include "profileview.h" #include "ui_profilemanagerdialog.h" #include <QWebEngineProfile> -#include <QLabel> -#include "profileview.h" -ProfileManagerDialog::ProfileManagerDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ProfileManagerDialog) +ProfileManagerDialog::ProfileManagerDialog(QHash<QString, QWebEngineProfile *> &profiles, QWidget *parent) + : QDialog(parent) + , ui(new Ui::ProfileManagerDialog) + , profiles(profiles) { ui->setupUi(this); connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showProfile); showProfile(nullptr); + + for(const QString &name : profiles.keys()) { + ui->listWidget->addItem(name); + } } ProfileManagerDialog::~ProfileManagerDialog() @@ -19,12 +23,6 @@ ProfileManagerDialog::~ProfileManagerDialog() delete ui; } -void ProfileManagerDialog::addProfile(const QString &name, QWebEngineProfile *profile) -{ - profiles.insert(name, profile); - ui->listWidget->addItem(name); -} - void ProfileManagerDialog::showProfile(QListWidgetItem *item) { // clear out groupbox layout diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index ed79824..9ce177d 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -4,7 +4,8 @@ #include <QDialog> #include <QHash> -namespace Ui { +namespace Ui +{ class ProfileManagerDialog; } @@ -15,17 +16,15 @@ class ProfileManagerDialog : public QDialog Q_OBJECT public: - explicit ProfileManagerDialog(QWidget *parent = 0); + explicit ProfileManagerDialog(QHash<QString, QWebEngineProfile *> &profiles, QWidget *parent = 0); ~ProfileManagerDialog(); - void addProfile(const QString &name, QWebEngineProfile *profile); - private slots: void showProfile(QListWidgetItem *item); private: Ui::ProfileManagerDialog *ui; - QHash<QString, QWebEngineProfile *> profiles; + const QHash<QString, QWebEngineProfile *> profiles; }; #endif // PROFILEMANAGERDIALOG_H diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index e073dbb..b53cc7d 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -12,7 +12,7 @@ inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) { - QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked){ + QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked) { settings->setAttribute(attr, checked); }); } diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index 041dbe7..d0341b9 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -7,26 +7,34 @@ */ #include "profileeditorplugin.h" -#include "forms/profileview.h" #include "forms/profilemanagerdialog.h" +#include "forms/profileview.h" #include <QHash> -QHash<QString, std::function<int ()> > ProfileEditorPlugin::commands() +QHash<QString, std::function<int()>> ProfileEditorPlugin::commands() { QHash<QString, std::function<int()>> hash; hash.insert("profileEditor:about", []() -> int { qDebug("ProfileEditor for smolbote"); return 0; }); + + hash.insert("profileEditor:edit", [this]() -> int { + auto *dialog = createWidget(nullptr); + return dialog->exec(); + }); return hash; } -QDialog *ProfileEditorPlugin::createWidget(QHash<QString, QWebEngineProfile *> profiles, QWidget *parent) +void ProfileEditorPlugin::addProfile(const QString &name, QWebEngineProfile *profile) +{ + Q_CHECK_PTR(profile); + profiles.insert(name, profile); +} + +QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) { - auto *widget = new ProfileManagerDialog(parent); - for(const QString &name : profiles.keys()) { - widget->addProfile(name, profiles.value(name)); - } + auto *widget = new ProfileManagerDialog(profiles, parent); widget->setAttribute(Qt::WA_DeleteOnClose, true); return widget; } diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h index e026bbe..7ae0a57 100644 --- a/plugins/ProfileEditor/profileeditorplugin.h +++ b/plugins/ProfileEditor/profileeditorplugin.h @@ -9,6 +9,7 @@ #ifndef PROFILEEDITOR_PLUGIN_H #define PROFILEEDITOR_PLUGIN_H +#include <QHash> #include <interfaces.h> class QWebEngineProfile; @@ -24,7 +25,11 @@ public: QHash<QString, std::function<int()>> commands() override; // ProfileInterface - QDialog *createWidget(QHash<QString, QWebEngineProfile *> profiles, QWidget *parent) override; + void addProfile(const QString &name, QWebEngineProfile *profile) override; + QDialog *createWidget(QWidget *parent) override; + +private: + QHash<QString, QWebEngineProfile *> profiles; }; #endif //PROFILEEDITOR_PLUGIN_H diff --git a/plugins/interfaces.h b/plugins/interfaces.h index 4e361ab..d6bff54 100644 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -34,7 +34,8 @@ class ProfileInterface { public: virtual ~ProfileInterface() = default; - virtual QDialog *createWidget(QHash<QString, QWebEngineProfile *> profiles, QWidget *parent) = 0; + virtual void addProfile(const QString &name, QWebEngineProfile *profile) = 0; + virtual QDialog *createWidget(QWidget *parent = nullptr) = 0; }; #define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface" diff --git a/src/browser.cpp b/src/browser.cpp index be9d6b5..3442d66 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -118,20 +118,19 @@ void Browser::setup(const QString &defaultProfile) // register commands for(Plugin p : m_plugins) { - auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); - if(plugin) { - m_commands.unite(plugin->commands()); - } + if(p.instance->inherits("ProfileInterface")) { auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); - m_commands.insert("profileEditor:edit", [this, profileEditor]() -> int { - QHash<QString,QWebEngineProfile *> p; - for(const QString &key : m_profiles.keys()) { - p.insert(key, m_profiles.value(key)); - } - return profileEditor->createWidget(p, nullptr)->exec(); - }); + + for(const QString &name : m_profiles.keys()) { + profileEditor->addProfile(name, qobject_cast<QWebEngineProfile*>(m_profiles.value(name))); + } + } + + auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); + if(plugin) { + m_commands.unite(plugin->commands()); } } @@ -234,12 +233,7 @@ MainWindow *Browser::createWindow() if(profileEditor) { auto *profileAction = new QAction(tr("Profile"), window); connect(profileAction, &QAction::triggered, window, [this, profileEditor]() { - QHash<QString,QWebEngineProfile *> p; - for(const QString &key : m_profiles.keys()) { - p.insert(key, m_profiles.value(key)); - } - profileEditor->createWidget(p, nullptr)->show(); - //profileEditor->createWidget(WebProfile::defaultProfile(), nullptr)->show(); + profileEditor->createWidget(nullptr)->show(); }); window->addAction(MainWindow::ToolsMenu, profileAction); } |