aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-09 12:05:28 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-09 12:05:28 +0200
commit3639d5789259561c531a3481d7061a0cb492c644 (patch)
treec9c7ff04022b62cf5be4d4ea31bf28d966ccefda /plugins
parentCreate .profile file when adding a new profile (diff)
downloadsmolbote-3639d5789259561c531a3481d7061a0cb492c644.tar.xz
Unlink plugins from lib/ libraries
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ConfigurationEditor/CMakeLists.txt8
-rw-r--r--plugins/ConfigurationEditor/configurationeditorplugin.cpp27
-rw-r--r--plugins/ConfigurationEditor/configurationeditorplugin.h12
-rw-r--r--plugins/ConfigurationEditor/forms/configurationdialog.cpp65
-rw-r--r--plugins/ConfigurationEditor/forms/configurationdialog.h23
-rw-r--r--plugins/ProfileEditor/CMakeLists.txt38
-rw-r--r--plugins/ProfileEditor/forms/newprofiledialog.cpp5
-rw-r--r--plugins/ProfileEditor/forms/newprofiledialog.h1
-rw-r--r--plugins/ProfileEditor/forms/newprofiledialog.ui35
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.cpp50
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.h19
-rw-r--r--plugins/ProfileEditor/forms/profileview.cpp11
-rw-r--r--plugins/ProfileEditor/forms/profileview.h6
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.cpp36
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.h6
-rw-r--r--plugins/interfaces.h62
16 files changed, 183 insertions, 221 deletions
diff --git a/plugins/ConfigurationEditor/CMakeLists.txt b/plugins/ConfigurationEditor/CMakeLists.txt
index 22ef3d3..699366e 100644
--- a/plugins/ConfigurationEditor/CMakeLists.txt
+++ b/plugins/ConfigurationEditor/CMakeLists.txt
@@ -5,6 +5,9 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
add_library(ConfigurationEditorPlugin SHARED
+ ${CMAKE_SOURCE_DIR}/include/plugininterface.h
+ ${CMAKE_SOURCE_DIR}/include/browserinterface.h
+
configurationeditorplugin.cpp
configurationeditorplugin.h
forms/configurationdialog.cpp
@@ -13,14 +16,11 @@ add_library(ConfigurationEditorPlugin SHARED
)
target_include_directories(ConfigurationEditorPlugin
- PRIVATE ${CMAKE_SOURCE_DIR}/plugins
- PRIVATE ${CMAKE_SOURCE_DIR}/lib/configuration
- PRIVATE ${Boost_INCLUDE_DIRS}
+ PRIVATE ${CMAKE_SOURCE_DIR}/include
)
target_link_libraries(ConfigurationEditorPlugin
PRIVATE Qt5::Widgets
- PRIVATE configuration
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.cpp b/plugins/ConfigurationEditor/configurationeditorplugin.cpp
index bf8a90d..1f60cc0 100644
--- a/plugins/ConfigurationEditor/configurationeditorplugin.cpp
+++ b/plugins/ConfigurationEditor/configurationeditorplugin.cpp
@@ -1,8 +1,15 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
#include "configurationeditorplugin.h"
#include "forms/configurationdialog.h"
#include <QDialog>
#include <QHash>
-#include <configuration.h>
CommandHash_t ConfigurationEditorPlugin::commands()
{
@@ -16,9 +23,23 @@ CommandHash_t ConfigurationEditorPlugin::commands()
return hash;
}
-QDialog *ConfigurationEditorPlugin::createWidget(QWidget *parent)
+QDialog *ConfigurationEditorPlugin::createWidget(QWidget *parent) const
{
- auto *dlg = new ConfigurationDialog(browser->getConfiguration(), parent);
+ auto *app = browser();
+ Q_CHECK_PTR(app);
+
+ auto *dlg = new ConfigurationDialog(parent);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
+
+ for(const QString &key : app->configurationOptions()) {
+ dlg->addOption(key, app->configuration(key));
+ }
+ dlg->ui->settings_treeWidget->resizeColumnToContents(0);
+ dlg->ui->shortcuts_treeWidget->resizeColumnToContents(0);
+
+ connect(dlg, &ConfigurationDialog::configurationChanged, dlg, [app](const QString &key, const QString &value) {
+ app->setConfiguration(key, value);
+ });
+
return dlg;
}
diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.h b/plugins/ConfigurationEditor/configurationeditorplugin.h
index 5e70ab7..7e7ebc6 100644
--- a/plugins/ConfigurationEditor/configurationeditorplugin.h
+++ b/plugins/ConfigurationEditor/configurationeditorplugin.h
@@ -1,8 +1,16 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
#ifndef CONFIGURATIONEDITOR_PLUGIN_H
#define CONFIGURATIONEDITOR_PLUGIN_H
#include <QVector>
-#include <interfaces.h>
+#include <plugininterface.h>
class QDialog;
class ConfigurationEditorPlugin : public QObject, public PluginInterface
@@ -14,7 +22,7 @@ class ConfigurationEditorPlugin : public QObject, public PluginInterface
public:
// PluginInterface
CommandHash_t commands() override;
- QDialog *createWidget(QWidget *parent = nullptr) override;
+ QDialog *createWidget(QWidget *parent = nullptr) const override;
};
#endif // CONFIGURATIONEDITOR_PLUGIN_H
diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.cpp b/plugins/ConfigurationEditor/forms/configurationdialog.cpp
index ffe7f9c..f433d70 100644
--- a/plugins/ConfigurationEditor/forms/configurationdialog.cpp
+++ b/plugins/ConfigurationEditor/forms/configurationdialog.cpp
@@ -1,41 +1,50 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
#include "configurationdialog.h"
-#include "ui_configurationdialog.h"
-#include <configuration.h>
#include <QKeySequenceEdit>
+#include <QLineEdit>
-ConfigurationDialog::ConfigurationDialog(Configuration *conf, QWidget *parent) :
+ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigurationDialog)
{
ui->setupUi(this);
- Q_CHECK_PTR(conf);
-
- for(const auto &option : conf->options()) {
- auto path = QString::fromStdString(option->long_name());
- auto value = QString::fromStdString(conf->value<std::string>(option->long_name().c_str()).value_or(""));
-
- QTreeWidgetItem *item = nullptr;
- if(path.contains("shortcut")) {
- item = new QTreeWidgetItem(ui->shortcuts_treeWidget);
- auto *edit = new QKeySequenceEdit(value);
- connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [=](const QKeySequence &keySequqnce) {
- conf->setValue(qUtf8Printable(path), keySequqnce.toString());
- });
- ui->shortcuts_treeWidget->setItemWidget(item, 1, edit);
- } else {
- item = new QTreeWidgetItem(ui->settings_treeWidget);
- item->setText(1, value);
- }
-
- item->setText(0, path);
-
- }
-
- ui->settings_treeWidget->resizeColumnToContents(0);
- ui->shortcuts_treeWidget->resizeColumnToContents(0);
}
ConfigurationDialog::~ConfigurationDialog()
{
delete ui;
}
+
+void ConfigurationDialog::addOption(const QString &key, const QString &value)
+{
+ QTreeWidgetItem *item = nullptr;
+
+ if(key.contains(QLatin1Literal("shortcut"))) {
+ item = new QTreeWidgetItem(ui->shortcuts_treeWidget);
+
+ auto *edit = new QKeySequenceEdit(value);
+ ui->shortcuts_treeWidget->setItemWidget(item, 1, edit);
+
+ connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [this, key](const QKeySequence &keySequence) {
+ emit configurationChanged(key, keySequence.toString());
+ });
+
+ } else {
+ item = new QTreeWidgetItem(ui->settings_treeWidget);
+
+ auto *edit = new QLineEdit(value);
+ ui->settings_treeWidget->setItemWidget(item, 1, edit);
+
+ connect(edit, &QLineEdit::editingFinished, this, [this, key, edit]() {
+ emit configurationChanged(key, edit->text());
+ });
+ }
+ item->setText(0, key);
+}
diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.h b/plugins/ConfigurationEditor/forms/configurationdialog.h
index 9d86f2d..fd07aa8 100644
--- a/plugins/ConfigurationEditor/forms/configurationdialog.h
+++ b/plugins/ConfigurationEditor/forms/configurationdialog.h
@@ -1,21 +1,32 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
#ifndef CONFIGURATIONDIALOG_H
#define CONFIGURATIONDIALOG_H
#include <QDialog>
+#include "ui_configurationdialog.h"
-namespace Ui {
-class ConfigurationDialog;
-}
-
-class Configuration;
class ConfigurationDialog : public QDialog
{
Q_OBJECT
+ friend class ConfigurationEditorPlugin;
+
public:
- explicit ConfigurationDialog(Configuration *conf, QWidget *parent = nullptr);
+ explicit ConfigurationDialog(QWidget *parent = nullptr);
~ConfigurationDialog();
+ void addOption(const QString &key, const QString &value);
+
+signals:
+ void configurationChanged(const QString &key, const QString &value);
+
private:
Ui::ConfigurationDialog *ui;
};
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 @@
<x>0</x>
<y>0</y>
<width>320</width>
- <height>78</height>
+ <height>112</height>
</rect>
</property>
<property name="windowTitle">
<string>New Profile</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="id_label">
- <property name="text">
- <string>ID</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="id_lineEdit"/>
- </item>
- </layout>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="id_label">
+ <property name="text">
+ <string>ID</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="id_lineEdit"/>
</item>
- <item>
+ <item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -38,6 +34,13 @@
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="offTheRecord">
+ <property name="text">
+ <string>Off the record</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
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 <webprofile.h>
#include <QDir>
#include <QPointer>
-#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<WebProfile>(profile);
+ auto pointer = QPointer<Profile>(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<QPointer<WebProfile>>();
+ auto profile = item->data(Qt::UserRole).value<QPointer<Profile>>();
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<QPointer<WebProfile>>();
- 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 <QDialog>
#include <QVector>
-#include <profilemanager.h>
-
-namespace Ui
-{
-class ProfileManagerDialog;
-}
+#include <profileinterface.h>
+#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 <webprofile.h>
-#include <profilemanager.h>
+#include <profileinterface.h>
#include <QWebEngineSettings>
#include <QWebEngineCookieStore>
#include <QDateTime>
#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 <QVector>
-#include <webprofile.h>
+#include "forms/newprofiledialog.h"
QHash<QString, std::function<int()>> ProfileEditorPlugin::commands()
{
@@ -23,20 +21,34 @@ QHash<QString, std::function<int()>> 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 <QVector>
-#include <interfaces.h>
+#include <plugininterface.h>
-class QWebEngineProfile;
class QDialog;
class ProfileEditorPlugin : public QObject, public PluginInterface
{
@@ -25,7 +23,7 @@ public:
QHash<QString, std::function<int()>> commands() override;
// ProfileInterface
- QDialog *createWidget(QWidget *parent) override;
+ QDialog *createWidget(QWidget *parent) const override;
};
#endif //PROFILEEDITOR_PLUGIN_H
diff --git a/plugins/interfaces.h b/plugins/interfaces.h
deleted file mode 100644
index ea8c9d6..0000000
--- a/plugins/interfaces.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef SMOLBOTE_PLUGIN_INTERFACES_H
-#define SMOLBOTE_PLUGIN_INTERFACES_H
-
-#include <QtPlugin>
-#include <QKeySequence>
-#include <memory>
-#include <functional>
-
-class QString;
-class QAction;
-class QDialog;
-class WebProfile;
-class Configuration;
-
-class ProfileManager;
-class BrowserInterface
-{
-public:
- virtual Configuration *getConfiguration() const = 0;
-
- virtual QPair<QString, WebProfile *> loadProfile(const QString &id) = 0;
- virtual ProfileManager *getProfileManager() = 0;
-};
-
-struct Plugin
-{
- QString name;
- QString author;
- QKeySequence shortcut;
- QObject *instance;
-};
-
-typedef QHash<QString, std::function<int()>> CommandHash_t;
-
-class PluginInterface
-{
-public:
- virtual ~PluginInterface() = default;
- virtual CommandHash_t commands() = 0;
- virtual QDialog *createWidget(QWidget *parent = nullptr) = 0;
-
- void setBrowserInterface(BrowserInterface *browser)
- {
- this->browser = browser;
- }
-
-protected:
- BrowserInterface *browser = nullptr;
-};
-
-#define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface"
-Q_DECLARE_INTERFACE(PluginInterface, PluginInterfaceIid)
-
-#endif // SMOLBOTE_PLUGIN_INTERFACES_H