aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-01 17:27:58 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-01 17:27:58 +0200
commit329e8de84fc8e0a2e4a04fbaf85ab0e1632c6084 (patch)
tree864df8426b543d6817d6e364be4889bc6e20d640 /plugins
parentMiddle mouse button closes tab (diff)
downloadsmolbote-329e8de84fc8e0a2e4a04fbaf85ab0e1632c6084.tar.xz
Only add profiles to profile manager at init
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.cpp20
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.h9
-rw-r--r--plugins/ProfileEditor/forms/profileview.cpp2
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.cpp22
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.h7
-rw-r--r--plugins/interfaces.h3
6 files changed, 37 insertions, 26 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"