aboutsummaryrefslogtreecommitdiff
path: root/plugins/ProfileEditor
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/ProfileEditor
parentCreate .profile file when adding a new profile (diff)
downloadsmolbote-3639d5789259561c531a3481d7061a0cb492c644.tar.xz
Unlink plugins from lib/ libraries
Diffstat (limited to 'plugins/ProfileEditor')
-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
10 files changed, 91 insertions, 116 deletions
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