From 0492a063806b6d63e4f378908b809de104a24820 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 25 Apr 2020 22:09:13 +0300 Subject: Update ProfileEditor plugin ProfileEditor: - add tests - disable read-only settings on otr profiles Add WebProfile::setHeaders and WebProfile::setCookies --- plugins/ProfileEditor/ProfileEditor.json | 5 +- .../ProfileEditor/forms/newhttpheaderdialog.cpp | 32 -- plugins/ProfileEditor/forms/newhttpheaderdialog.h | 33 -- plugins/ProfileEditor/forms/newhttpheaderdialog.ui | 84 ---- plugins/ProfileEditor/forms/newprofiledialog.cpp | 32 -- plugins/ProfileEditor/forms/newprofiledialog.h | 33 -- plugins/ProfileEditor/forms/newprofiledialog.ui | 81 ---- .../ProfileEditor/forms/profilemanagerdialog.cpp | 30 +- plugins/ProfileEditor/forms/profilemanagerdialog.h | 18 +- .../ProfileEditor/forms/profilemanagerdialog.ui | 24 +- plugins/ProfileEditor/forms/profileview.cpp | 153 ++---- plugins/ProfileEditor/forms/profileview.h | 12 +- plugins/ProfileEditor/forms/profileview.ui | 535 ++++++++++----------- plugins/ProfileEditor/forms/settingstable.cpp | 90 ++++ plugins/ProfileEditor/forms/settingstable.h | 31 ++ plugins/ProfileEditor/meson.build | 17 +- plugins/ProfileEditor/profileeditorplugin.cpp | 36 -- plugins/ProfileEditor/profileeditorplugin.h | 7 +- plugins/ProfileEditor/test/main.cpp | 22 + 19 files changed, 514 insertions(+), 761 deletions(-) delete mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.cpp delete mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.h delete mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.ui delete mode 100644 plugins/ProfileEditor/forms/newprofiledialog.cpp delete mode 100644 plugins/ProfileEditor/forms/newprofiledialog.h delete mode 100644 plugins/ProfileEditor/forms/newprofiledialog.ui create mode 100644 plugins/ProfileEditor/forms/settingstable.cpp create mode 100644 plugins/ProfileEditor/forms/settingstable.h create mode 100644 plugins/ProfileEditor/test/main.cpp (limited to 'plugins/ProfileEditor') diff --git a/plugins/ProfileEditor/ProfileEditor.json b/plugins/ProfileEditor/ProfileEditor.json index 8381e9a..afa0a1f 100644 --- a/plugins/ProfileEditor/ProfileEditor.json +++ b/plugins/ProfileEditor/ProfileEditor.json @@ -1,5 +1,6 @@ { "name": "Profile Editor", - "author": "Aqua-sama", - "shortcut": "Ctrl+Shift+E" + "author": "aqua@", + "shortcut": "Ctrl+Shift+E", + "license": "GPL3" } diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp b/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp deleted file mode 100644 index 3978c4e..0000000 --- a/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp +++ /dev/null @@ -1,32 +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: GPL-3.0 - */ - -#include "newhttpheaderdialog.h" -#include "ui_newhttpheaderdialog.h" - -NewHttpHeaderDialog::NewHttpHeaderDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::NewHttpHeaderDialog) -{ - ui->setupUi(this); -} - -NewHttpHeaderDialog::~NewHttpHeaderDialog() -{ - delete ui; -} - -QString NewHttpHeaderDialog::header() const -{ - return ui->header->text(); -} - -QString NewHttpHeaderDialog::value() const -{ - return ui->value->text(); -} diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.h b/plugins/ProfileEditor/forms/newhttpheaderdialog.h deleted file mode 100644 index 53a2a80..0000000 --- a/plugins/ProfileEditor/forms/newhttpheaderdialog.h +++ /dev/null @@ -1,33 +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: GPL-3.0 - */ - -#ifndef NEWHTTPHEADERDIALOG_H -#define NEWHTTPHEADERDIALOG_H - -#include - -namespace Ui { -class NewHttpHeaderDialog; -} - -class NewHttpHeaderDialog : public QDialog -{ - Q_OBJECT - -public: - explicit NewHttpHeaderDialog(QWidget *parent = nullptr); - ~NewHttpHeaderDialog(); - - QString header() const; - QString value() const; - -private: - Ui::NewHttpHeaderDialog *ui; -}; - -#endif // NEWHTTPHEADERDIALOG_H diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.ui b/plugins/ProfileEditor/forms/newhttpheaderdialog.ui deleted file mode 100644 index a457ba6..0000000 --- a/plugins/ProfileEditor/forms/newhttpheaderdialog.ui +++ /dev/null @@ -1,84 +0,0 @@ - - - NewHttpHeaderDialog - - - - 0 - 0 - 320 - 108 - - - - Dialog - - - - - - Header - - - - - - - - - - Value - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - NewHttpHeaderDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - NewHttpHeaderDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/plugins/ProfileEditor/forms/newprofiledialog.cpp b/plugins/ProfileEditor/forms/newprofiledialog.cpp deleted file mode 100644 index 3ed61d8..0000000 --- a/plugins/ProfileEditor/forms/newprofiledialog.cpp +++ /dev/null @@ -1,32 +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: GPL-3.0 - */ - -#include "newprofiledialog.h" -#include "ui_newprofiledialog.h" - -NewProfileDialog::NewProfileDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::NewProfileDialog) -{ - ui->setupUi(this); -} - -NewProfileDialog::~NewProfileDialog() -{ - delete ui; -} - -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 deleted file mode 100644 index dd9aa4e..0000000 --- a/plugins/ProfileEditor/forms/newprofiledialog.h +++ /dev/null @@ -1,33 +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: GPL-3.0 - */ - -#ifndef NEWPROFILEDIALOG_H -#define NEWPROFILEDIALOG_H - -#include - -namespace Ui { -class NewProfileDialog; -} - -class NewProfileDialog : public QDialog -{ - Q_OBJECT - -public: - explicit NewProfileDialog(QWidget *parent = nullptr); - ~NewProfileDialog(); - - const QString getId() const; - bool getOtr() const; - -private: - Ui::NewProfileDialog *ui; -}; - -#endif // NEWPROFILEDIALOG_H diff --git a/plugins/ProfileEditor/forms/newprofiledialog.ui b/plugins/ProfileEditor/forms/newprofiledialog.ui deleted file mode 100644 index 8b4888d..0000000 --- a/plugins/ProfileEditor/forms/newprofiledialog.ui +++ /dev/null @@ -1,81 +0,0 @@ - - - NewProfileDialog - - - - 0 - 0 - 320 - 112 - - - - New Profile - - - - - - ID - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Off the record - - - - - - - - - buttonBox - accepted() - NewProfileDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - NewProfileDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index f5a17b1..6cbc806 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -10,15 +10,14 @@ #include "profileview.h" #include #include +#include "ui_profilemanagerdialog.h" ProfileManagerDialog::ProfileManagerDialog(QWidget *parent) - : QDialog(parent) + : ProfileDialog(parent) , ui(new Ui::ProfileManagerDialog) { ui->setupUi(this); - - connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showProfile); - showProfile(nullptr); + connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showItem); } ProfileManagerDialog::~ProfileManagerDialog() @@ -26,17 +25,26 @@ ProfileManagerDialog::~ProfileManagerDialog() delete ui; } -void ProfileManagerDialog::addProfile(const QString &id, Profile *profile) +int ProfileManagerDialog::addProfile(const QString &id, const QString name, QWebEngineProfile *profile, QSettings *settings) { Q_CHECK_PTR(profile); auto *item = new QListWidgetItem(id, ui->listWidget); - auto pointer = QPointer(profile); - item->setData(Qt::UserRole, QVariant::fromValue(pointer)); + item->setData(Qt::UserRole, name); + item->setData(Qt::UserRole+1, QVariant::fromValue(QPointer(profile))); + item->setData(Qt::UserRole+2, QVariant::fromValue(QPointer(settings))); + + return ui->listWidget->count() - 1; +} + +void ProfileManagerDialog::showProfile(int index) +{ + auto *item = ui->listWidget->item(index); + showItem(item); } -void ProfileManagerDialog::showProfile(QListWidgetItem *item) +void ProfileManagerDialog::showItem(QListWidgetItem *item) { // clear out groupbox layout QLayoutItem *i; @@ -51,8 +59,10 @@ void ProfileManagerDialog::showProfile(QListWidgetItem *item) } ui->groupBox->setVisible(true); - auto profile = item->data(Qt::UserRole).value>(); - auto *v = new ProfileView(profile.data(), this); + const auto name = item->data(Qt::UserRole).value(); + auto profile = item->data(Qt::UserRole+1).value>(); + auto settings = item->data(Qt::UserRole+2).value>(); + auto *v = new ProfileView(name, profile.data(), settings.data(), this); ui->groupBox->layout()->addWidget(v); v->adjustSize(); } diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index fe91948..8dd307e 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -11,12 +11,15 @@ #include #include -#include -#include "ui_profilemanagerdialog.h" +#include +#include + +namespace Ui { + class ProfileManagerDialog; +} -class WebProfile; class QListWidgetItem; -class ProfileManagerDialog : public QDialog +class ProfileManagerDialog : public ProfileDialog { Q_OBJECT @@ -27,10 +30,9 @@ public: ~ProfileManagerDialog() override; public slots: - void addProfile(const QString &id, Profile *profile); - -private slots: - void showProfile(QListWidgetItem *item); + int addProfile(const QString &id, const QString name, QWebEngineProfile *profile, QSettings *settings) override; + void showProfile(int index) override; + void showItem(QListWidgetItem *item); private: Ui::ProfileManagerDialog *ui; diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.ui b/plugins/ProfileEditor/forms/profilemanagerdialog.ui index f41b1b0..b715b86 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.ui +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 918 + 600 @@ -34,6 +34,12 @@ 0 + + + 640 + 0 + + @@ -41,20 +47,6 @@ - - - - New - - - - - - - Delete - - - diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 9a19cfc..992364c 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -1,29 +1,26 @@ /* * 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 + * location: https://neueland.iserlohn-fortress.net/cgit/smolbote * * SPDX-License-Identifier: GPL-3.0 */ #include "profileview.h" #include "ui_profileview.h" -#include -#include -#include #include -#include "newhttpheaderdialog.h" +#include +#include -inline void connectSetting(QCheckBox *checkBox, Profile *profile, QWebEngineSettings::WebAttribute attr) +inline void connectSetting(QCheckBox *checkBox, QWebEngineProfile *profile, QWebEngineSettings::WebAttribute attr) { checkBox->setChecked(profile->settings()->testAttribute(attr)); QObject::connect(checkBox, &QCheckBox::clicked, [profile, attr](bool checked) { profile->settings()->setAttribute(attr, checked); - emit profile->attributeChanged(attr, checked); }); } -ProfileView::ProfileView(Profile *profile, QWidget *parent) +ProfileView::ProfileView(const QString &name, QWebEngineProfile *profile, QSettings *settings, QWidget *parent) : QWidget(parent) , ui(new Ui::ProfileView) { @@ -32,52 +29,37 @@ ProfileView::ProfileView(Profile *profile, QWidget *parent) ui->setupUi(this); // general tab - ui->name->setText(profile->name()); - connect(ui->name, &QLineEdit::editingFinished, profile, [=]() { - profile->setName(ui->name->text()); - }); - + ui->name->setText(name); ui->offTheRecord->setChecked(profile->isOffTheRecord()); - ui->homepage->setText(profile->homepage().toString()); - connect(ui->homepage, &QLineEdit::editingFinished, profile, [=]() { - profile->setHomepage(QUrl::fromUserInput(ui->homepage->text())); - }); - - ui->newtab->setText(profile->newtab().toString()); - connect(ui->newtab, &QLineEdit::editingFinished, profile, [=]() { - profile->setNewtab(QUrl::fromUserInput(ui->newtab->text())); - }); - - ui->search->setText(profile->search()); - connect(ui->search, &QLineEdit::editingFinished, profile, [=]() { - profile->setSearch(ui->search->text()); - }); + ui->settings_table->connect(settings); // http tab ui->userAgent->setPlainText(m_profile->httpUserAgent()); - connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() { + connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [this, profile]() { profile->setHttpUserAgent(ui->userAgent->toPlainText()); }); ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); - connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [=]() { + connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [this, profile]() { profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); }); + ui->headers_table->connect(settings, "headers"); + ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); - connect(ui->cacheType, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { - profile->setHttpCacheType(index); + connect(ui->cacheType, QOverload::of(&QComboBox::currentIndexChanged), profile, [profile](int index) { + profile->setHttpCacheType(static_cast(index)); }); ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize())); - connect(ui->cacheSize, &QLineEdit::textChanged, profile, [=](const QString &text) { + connect(ui->cacheSize, &QLineEdit::textChanged, profile, [profile](const QString &text) { profile->setHttpCacheMaximumSize(text.toInt()); }); ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); - connect(ui->cookiePolicy, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { - profile->setPersistentCookiesPolicy(index); + connect(ui->cookiePolicy, QOverload::of(&QComboBox::currentIndexChanged), profile, [profile](int index) { + profile->setPersistentCookiesPolicy(static_cast(index)); }); connect(ui->clearCache_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearHttpCache); @@ -86,28 +68,13 @@ ProfileView::ProfileView(Profile *profile, QWidget *parent) ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); ui->cachePath_lineEdit->setText(m_profile->cachePath()); - // headers tab - for(auto i = m_profile->headers().constBegin(); i != m_profile->headers().constEnd(); ++i) { - //ui->httpHeaders->addItem(); - headerChanged(i.key(), i.value()); + if(profile->isOffTheRecord()) { + ui->cacheType->setEnabled(false); + ui->cacheSize->setEnabled(false); + ui->storagePath_lineEdit->setEnabled(false); + ui->cachePath_lineEdit->setEnabled(false); + ui->cookiePolicy->setEnabled(false); } - 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) { - m_profile->setHttpHeader(dlg->header(), dlg->value()); - } - delete dlg; - }); - connect(ui->headers_delete, &QPushButton::clicked, m_profile, [this]() { - for(auto &list : ui->httpHeaders->selectedRanges()) { - for(int i = list.bottomRow(); i >= list.topRow(); --i) { - m_profile->removeHttpHeader(ui->httpHeaders->item(i, 0)->text()); - } - } - }); - // settings tab connectSetting(ui->autoloadImages, m_profile, QWebEngineSettings::AutoLoadImages); connectSetting(ui->autoloadIcons, m_profile, QWebEngineSettings::AutoLoadIconsForPage); @@ -144,62 +111,39 @@ ProfileView::ProfileView(Profile *profile, QWidget *parent) connectSetting(ui->printElementBackgrounds, m_profile, QWebEngineSettings::PrintElementBackgrounds); // cookies tab - loadCookies(profile->cookieStore()); - for(const auto &c : profile->cookies()) { - cookieAdded(c); + for(const auto &data : profile->property("cookies").toList()) { + for(const auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) { + cookieAdded(cookie); + } } -} -ProfileView::~ProfileView() -{ - delete ui; -} + connect(profile->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded); + connect(profile->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved); -void ProfileView::loadCookies(QWebEngineCookieStore *store) -{ - // - connect(store, &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded); - connect(store, &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved); + connect(ui->cookies_deleteSession, &QPushButton::clicked, profile->cookieStore(), &QWebEngineCookieStore::deleteSessionCookies); + connect(ui->cookies_deleteAll, &QPushButton::clicked, profile->cookieStore(), &QWebEngineCookieStore::deleteAllCookies); - connect(ui->cookies_reload, &QPushButton::clicked, store, [=]() { - ui->cookies->clearContents(); - ui->cookies->setRowCount(0); - store->loadAllCookies(); - }); - - connect(ui->cookies_delete, &QPushButton::clicked, store, [=]() { + connect(ui->cookies_delete, &QPushButton::clicked, [this, profile]() { for(auto &list : ui->cookies->selectedRanges()) { for(int i = list.bottomRow(); i >= list.topRow(); --i) { auto cookie = ui->cookies->item(i, 0)->data(Qt::UserRole).value(); - store->deleteCookie(cookie); + profile->cookieStore()->deleteCookie(cookie); } } }); - connect(ui->cookies_deleteSession, &QPushButton::clicked, store, &QWebEngineCookieStore::deleteSessionCookies); - connect(ui->cookies_deleteAll, &QPushButton::clicked, store, &QWebEngineCookieStore::deleteAllCookies); -} -void ProfileView::headerChanged(const QString &name, const QString &value) -{ - const auto items = ui->httpHeaders->findItems(name, Qt::MatchExactly); - if(!items.isEmpty()) { - QTableWidgetItem *valueItem = ui->httpHeaders->item(items.constFirst()->row(), 1); - valueItem->setText(value); - } else { - // new header - const int index = ui->httpHeaders->rowCount(); - ui->httpHeaders->setRowCount(index + 1); - ui->httpHeaders->setItem(index, 0, new QTableWidgetItem(name)); - ui->httpHeaders->setItem(index, 1, new QTableWidgetItem(value)); - } + connect(ui->cookies_reload, &QPushButton::clicked, [this, profile]() { + ui->cookies->clearContents(); + ui->cookies->setRowCount(0); + qDebug("loadAllCookies called!"); + profile->cookieStore()->loadAllCookies(); + }); + } -void ProfileView::headerRemoved(const QString& name) +ProfileView::~ProfileView() { - const auto items = ui->httpHeaders->findItems(name, Qt::MatchExactly); - if(!items.isEmpty()) { - ui->httpHeaders->removeRow(items.constFirst()->row()); - } + delete ui; } void ProfileView::cookieAdded(const QNetworkCookie &cookie) @@ -212,21 +156,24 @@ void ProfileView::cookieAdded(const QNetworkCookie &cookie) ui->cookies->setItem(index, 0, item); ui->cookies->setItem(index, 1, new QTableWidgetItem(cookie.domain())); ui->cookies->setItem(index, 2, new QTableWidgetItem(cookie.path())); - if(cookie.isSessionCookie()) + if(cookie.isSessionCookie()) { ui->cookies->setItem(index, 3, new QTableWidgetItem(tr("session"))); - else + } else { ui->cookies->setItem(index, 3, new QTableWidgetItem(cookie.expirationDate().toString(Qt::RFC2822Date))); + } } void ProfileView::cookieRemoved(const QNetworkCookie &cookie) { + qDebug("cookieRemoved called"); + for(int i = 0; i < ui->cookies->rowCount(); ++i) { auto *item = ui->cookies->item(i, 0); - if(item->data(Qt::UserRole).value() == cookie) { - //qDebug("removing cookie on row %i", i); + if(item->data(Qt::UserRole).value().hasSameIdentifier(cookie)) { + qDebug("removing cookie on row %i", i); ui->cookies->removeRow(i); - break; + return; } + qDebug("cookie on row %i doesn't have the same identifier", i); } } - diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index 7f3e738..9b4506a 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -12,13 +12,14 @@ #include #include #include +#include +#include namespace Ui { class ProfileView; } -class Profile; class QWebEngineCookieStore; class QCheckBox; @@ -27,21 +28,16 @@ class ProfileView : public QWidget Q_OBJECT public: - explicit ProfileView(Profile *profile, QWidget *parent = nullptr); + explicit ProfileView(const QString &name, QWebEngineProfile *profile, QSettings *settings, QWidget *parent = nullptr); ~ProfileView() override; private slots: - void loadCookies(QWebEngineCookieStore *store); - - void headerChanged(const QString &name, const QString &value); - void headerRemoved(const QString &name); - void cookieAdded(const QNetworkCookie &cookie); void cookieRemoved(const QNetworkCookie &cookie); private: Ui::ProfileView *ui; - Profile *m_profile; + QWebEngineProfile *m_profile; }; #endif // PROFILEDIALOG_H diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui index 630e53d..46e0a68 100644 --- a/plugins/ProfileEditor/forms/profileview.ui +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -7,7 +7,7 @@ 0 0 640 - 504 + 510 @@ -19,7 +19,7 @@ Profile - + @@ -29,76 +29,58 @@ General - - - - - Name - - - - - - - - - - false - - - Off-the-record - - - - - - - false - - + + + + + + + + + + + + + + false + + + Off-the-record + + + + - - - + + + Configuration - - - - - - Homepage - - - - - - - New tab page - - - - - - - Search - - - - - - - - - - - - - - - - Qt::Horizontal + + true + + + + + true + + + false + + + + Key + + + + + Value + + + + + @@ -125,176 +107,150 @@ - - - - Cache Type - + + + + + + + true + + + false + + + + Key + + + + + Value + + - + - Cache Size + Headers - - + + + + + Storage + + + + + + Cache Type + + - - + + - - Memory Cache - + + + + Memory Cache + + + + + Disk Cache + + + + + Disabled + + + - - Disk Cache - + + + Qt::Horizontal + + + + 40 + 20 + + + - - Disabled - + + + Clear Cache + + - - - - + - - + + - Storage Path + Cache Size - - - - false - - + + - + Cache Path - + false - - + + - Clear Cache + Storage Path - - - - Cookies + + + + false - - - - - No Persistent Cookies - - - - - Allow Persistent Cookies - - - - - Force Persistent Cookies - - - - - + Clear History - - - - - Headers - - - - - - 200 - - - 100 - - - true - - - false - - - - Name - - - - - Value - - - - - - - - - - Insert - - - - - - - Delete - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + Qt::Vertical + + + + 20 + 40 + + + @@ -313,7 +269,7 @@ 0 0 - 584 + 273 797 @@ -559,94 +515,128 @@ Cookies - + - - - QAbstractScrollArea::AdjustToContents - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SelectRows - - - false - - - false - - - true - - - false - - - - Name - - - - - Domain - - - - - Path - - - - - Expires - - - - - - - - + + + - Reload + Cookies - - - - Delete - + + + + + No Persistent Cookies + + + + + Allow Persistent Cookies + + + + + Force Persistent Cookies + + + + + + - - - Delete Session + + + QAbstractScrollArea::AdjustToContents - - - - - - Delete All + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + false + + + false + + + true + + + false + + + + Name + + + + + Domain + + + + + Path + + + + + Expires + + - - - Qt::Vertical - - - - 20 - 40 - - - + + + + + Reload + + + + + + + Delete + + + + + + + Delete Session + + + + + + + Delete All + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -656,6 +646,13 @@ + + + SettingsTable + QTableWidget +
forms/settingstable.h
+
+
diff --git a/plugins/ProfileEditor/forms/settingstable.cpp b/plugins/ProfileEditor/forms/settingstable.cpp new file mode 100644 index 0000000..6cfe144 --- /dev/null +++ b/plugins/ProfileEditor/forms/settingstable.cpp @@ -0,0 +1,90 @@ +/* + * 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/cgit/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "settingstable.h" +#include +#include +#include + +SettingsTable::SettingsTable(QWidget *parent) + : QTableWidget(parent) +{ + QObject::connect(this, &QTableWidget::currentCellChanged, [this](int currentRow, int currentColumn, int /*previousRow*/, int /*previousColumn*/) { + if(currentColumn == 0) { + const auto key = item(currentRow, currentColumn)->text(); + m_selectedKey = key; + } + }); + + addBtn = new QToolButton(this); + addBtn->setText("Add"); + removeBtn = new QToolButton(this); + removeBtn->setText("Remove"); +} + +void SettingsTable::connect(QSettings *settings, const QString §ion) +{ + settings->beginGroup(section); + if(settings != nullptr) { + const auto keys = settings->childKeys(); + setRowCount(keys.count()); + for(int i = 0; i < keys.count(); ++i) { + setItem(i, 0, new QTableWidgetItem(keys[i])); + setItem(i, 1, new QTableWidgetItem(settings->value(keys[i]).toString())); + } + } + settings->endGroup(); + + QObject::connect(addBtn, &QToolButton::clicked, [this]() { + const auto row = rowCount(); + setRowCount(row + 1); + setItem(row, 0, new QTableWidgetItem("key")); + setItem(row, 1, new QTableWidgetItem("value")); + }); + + QObject::connect(removeBtn, &QToolButton::clicked, [this, settings, section]() { + settings->beginGroup(section); + + const int row = currentRow(); + const auto key = item(row, 0)->text(); + + removeRow(row); + qDebug("remove key: %s", qUtf8Printable(key)); + settings->remove(key); + + settings->endGroup(); + }); + + QObject::connect(this, &QTableWidget::cellChanged, [this, settings, section](int row, int column) { + // no value has been created yet + if(item(row, 1) == nullptr) { + return; + } + + settings->beginGroup(section); + + if(column == 0) { + qDebug("remove old key: %s", qUtf8Printable(m_selectedKey)); + settings->remove(m_selectedKey); + } + + const auto key = item(row, 0)->text(); + const auto val = item(row, 1)->text(); + qDebug("set: [%s]=[%s]", qUtf8Printable(key), qUtf8Printable(val)); + settings->setValue(key, val); + + settings->endGroup(); + }); +} + +void SettingsTable::resizeEvent(QResizeEvent *event) +{ + QTableWidget::resizeEvent(event); + addBtn->move(width() - addBtn->width() - removeBtn->width(), 0); + removeBtn->move(width() - removeBtn->width(), 0); +} diff --git a/plugins/ProfileEditor/forms/settingstable.h b/plugins/ProfileEditor/forms/settingstable.h new file mode 100644 index 0000000..80e76f0 --- /dev/null +++ b/plugins/ProfileEditor/forms/settingstable.h @@ -0,0 +1,31 @@ +/* + * 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/cgit/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef SETTINGS_TREE +#define SETTINGS_TREE + +#include + +class QSettings; +class QToolButton; +class SettingsTable : public QTableWidget +{ +public: + SettingsTable(QWidget *parent = nullptr); + + void connect(QSettings *settings, const QString §ion = QString()); + +protected: + void resizeEvent(QResizeEvent *event); + +private: + QString m_selectedKey; + QToolButton *addBtn = nullptr, *removeBtn = nullptr; +}; + +#endif // SETTINGS_TREE diff --git a/plugins/ProfileEditor/meson.build b/plugins/ProfileEditor/meson.build index caa3a75..47a1c17 100644 --- a/plugins/ProfileEditor/meson.build +++ b/plugins/ProfileEditor/meson.build @@ -1,15 +1,14 @@ ProfileEditorPlugin_moc = mod_qt5.preprocess( - include_directories: include, - moc_headers: ['profileeditorplugin.h', 'forms/profilemanagerdialog.h', 'forms/profileview.h', 'forms/newprofiledialog.h', 'forms/newhttpheaderdialog.h'], - ui_files: ['forms/profilemanagerdialog.ui', 'forms/profileview.ui', 'forms/newprofiledialog.ui', 'forms/newhttpheaderdialog.ui'], - dependencies: dep_qt5 + include_directories: plugininterfaces_include, + moc_headers: [ 'profileeditorplugin.h', 'forms/profilemanagerdialog.h', 'forms/profileview.h' ], + ui_files: [ 'forms/profilemanagerdialog.ui', 'forms/profileview.ui' ], ) -ProfileEditorPlugin_lib = shared_library('ProfileEditorPlugin', - [interfaces_moc, ProfileEditorPlugin_moc, 'profileeditorplugin.cpp', 'forms/profilemanagerdialog.cpp', 'forms/profileview.cpp', 'forms/newprofiledialog.cpp', 'forms/newhttpheaderdialog.cpp'], - dependencies: dep_qt5, - include_directories: include, - install: true, install_dir: join_paths(get_option('libdir'), 'smolbote/plugins') +ProfileEditorPlugin = shared_library('ProfileEditorPlugin', + [ ProfileEditorPlugin_moc, 'profileeditorplugin.cpp', 'forms/profilemanagerdialog.cpp', 'forms/profileview.cpp', 'forms/settingstable.cpp' ], + include_directories: plugininterfaces_include, + dependencies: [ dep_qt5 ], + install: true, install_dir: join_paths(get_option('libdir'), 'smolbote/plugins') ) test('run', executable('ProfileEditor', 'test/main.cpp', diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index d480392..6d1fc6a 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -8,48 +8,12 @@ #include "profileeditorplugin.h" #include "forms/profilemanagerdialog.h" -#include "forms/newprofiledialog.h" - -QHash> ProfileEditorPlugin::commands() -{ - QHash> hash; - - hash.insert("edit-profiles-ui", [this]() -> int { - auto *dialog = createWidget(nullptr); - return dialog->exec(); - }); - return hash; -} QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) const { - auto *app = browser(); - Q_CHECK_PTR(app); auto *widget = new ProfileManagerDialog(parent); widget->setAttribute(Qt::WA_DeleteOnClose, true); - 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->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 a673436..13f6d90 100644 --- a/plugins/ProfileEditor/profileeditorplugin.h +++ b/plugins/ProfileEditor/profileeditorplugin.h @@ -9,7 +9,7 @@ #ifndef PROFILEEDITOR_PLUGIN_H #define PROFILEEDITOR_PLUGIN_H -#include +#include class QDialog; class ProfileEditorPlugin : public QObject, public PluginInterface @@ -19,10 +19,7 @@ class ProfileEditorPlugin : public QObject, public PluginInterface Q_INTERFACES(PluginInterface) public: - // PluginInterface - QHash> commands() override; - - // ProfileInterface + ~ProfileEditorPlugin() override = default; QDialog *createWidget(QWidget *parent) const override; }; diff --git a/plugins/ProfileEditor/test/main.cpp b/plugins/ProfileEditor/test/main.cpp new file mode 100644 index 0000000..40b563c --- /dev/null +++ b/plugins/ProfileEditor/test/main.cpp @@ -0,0 +1,22 @@ +#include +#include "profileeditorplugin.h" +#include +#include +#include + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + ProfileEditorPlugin plugin; + + auto *dlg = dynamic_cast(plugin.createWidget(nullptr)); + const auto i = dlg->addProfile("id", "testing", new QWebEngineProfile, new QSettings(QString(), QSettings::IniFormat, &app)); + dlg->show(); + + if(qEnvironmentVariableIsSet("autoclose")) { + dlg->showProfile(i); + QTimer::singleShot(200, dlg, &QDialog::accept); + } + + return app.exec(); +} -- cgit v1.2.1