From b27e55b0bbba9a1678159abe44280e173374f971 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 16 Jun 2018 13:55:35 +0200 Subject: Sort .profile by time Remove ProfileInterface::setProfiles ProfileView: Add General tab ProfileView: some cleanup ProfileView: Add Cookies tab --- plugins/ProfileEditor/CMakeLists.txt | 1 + .../ProfileEditor/forms/profilemanagerdialog.cpp | 21 ++-- plugins/ProfileEditor/forms/profilemanagerdialog.h | 5 +- plugins/ProfileEditor/forms/profileview.cpp | 127 ++++++++++++--------- plugins/ProfileEditor/forms/profileview.h | 17 ++- plugins/ProfileEditor/forms/profileview.ui | 109 +++++++++++++++++- plugins/ProfileEditor/profileeditorplugin.cpp | 17 ++- plugins/ProfileEditor/profileeditorplugin.h | 8 +- plugins/interfaces.h | 3 +- 9 files changed, 227 insertions(+), 81 deletions(-) (limited to 'plugins') diff --git a/plugins/ProfileEditor/CMakeLists.txt b/plugins/ProfileEditor/CMakeLists.txt index 7ded842..fc7cf96 100644 --- a/plugins/ProfileEditor/CMakeLists.txt +++ b/plugins/ProfileEditor/CMakeLists.txt @@ -23,6 +23,7 @@ target_include_directories(ProfileEditorPlugin target_link_libraries(ProfileEditorPlugin PRIVATE Qt5::Widgets PRIVATE Qt5::WebEngineWidgets + PRIVATE web ) if(WIN32) diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp index 2f0f4a2..427330a 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -3,11 +3,11 @@ #include "ui_profilemanagerdialog.h" #include #include +#include -ProfileManagerDialog::ProfileManagerDialog(QHash *profiles, QWidget *parent) +ProfileManagerDialog::ProfileManagerDialog(const QVector &profiles, QWidget *parent) : QDialog(parent) , ui(new Ui::ProfileManagerDialog) - , profiles(profiles) { ui->setupUi(this); @@ -18,8 +18,12 @@ ProfileManagerDialog::ProfileManagerDialog(QHash *profile deleteProfile(ui->listWidget->currentItem()); }); - for(auto i = profiles->constBegin(); i != profiles->constEnd(); ++i) { - ui->listWidget->addItem(i.key()); + for(auto *profile : profiles) { + auto *item = new QListWidgetItem(ui->listWidget); + item->setText(profile->name()); + + auto pointer = QPointer(profile); + item->setData(Qt::UserRole, QVariant::fromValue(pointer)); } } @@ -43,7 +47,8 @@ void ProfileManagerDialog::showProfile(QListWidgetItem *item) } ui->groupBox->setVisible(true); - auto *v = new ProfileView(profiles->value(item->text()), this); + auto profile = item->data(Qt::UserRole).value>(); + auto *v = new ProfileView(profile.data(), this); ui->groupBox->layout()->addWidget(v); v->adjustSize(); } @@ -60,8 +65,8 @@ void ProfileManagerDialog::deleteProfile(QListWidgetItem *item) delete i; } - auto *profile = profiles->value(item->text()); - Q_CHECK_PTR(profile); + auto profile = item->data(Qt::UserRole).value>(); + Q_ASSERT(!profile.isNull()); qDebug("deleting profile %s", qUtf8Printable(profile->name())); qDebug("deleting %s: %s", qUtf8Printable(profile->configurationPath()), QFile(profile->configurationPath()).remove() ? "okay" : "failed"); @@ -69,5 +74,5 @@ void ProfileManagerDialog::deleteProfile(QListWidgetItem *item) qDebug("deleting %s: %s", qUtf8Printable(profile->cachePath()), QDir(profile->cachePath()).removeRecursively() ? "okay" : "failed"); delete item; - delete profile; + delete profile.data(); } diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h index a4b6f83..e182799 100644 --- a/plugins/ProfileEditor/forms/profilemanagerdialog.h +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -2,7 +2,7 @@ #define PROFILEMANAGERDIALOG_H #include -#include +#include namespace Ui { @@ -16,7 +16,7 @@ class ProfileManagerDialog : public QDialog Q_OBJECT public: - explicit ProfileManagerDialog(QHash *profiles, QWidget *parent = 0); + explicit ProfileManagerDialog(const QVector &profiles, QWidget *parent = 0); ~ProfileManagerDialog(); private slots: @@ -25,7 +25,6 @@ private slots: private: Ui::ProfileManagerDialog *ui; - const QHash *profiles; }; #endif // PROFILEMANAGERDIALOG_H diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 2d96d43..f2e74ad 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -8,16 +8,20 @@ #include "profileview.h" #include "ui_profileview.h" +#include #include +#include +#include inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) { + checkBox->setChecked(settings->testAttribute(attr)); QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked) { settings->setAttribute(attr, checked); }); } -ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) +ProfileView::ProfileView(WebProfile *profile, QWidget *parent) : QWidget(parent) , ui(new Ui::ProfileView) { @@ -25,28 +29,58 @@ ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) m_profile = profile; ui->setupUi(this); - loadProfile(); + // general tab + ui->name->setText(profile->name()); + ui->offTheRecord->setChecked(profile->isOffTheRecord()); + ui->configurationPath->setText(profile->configurationPath()); // http tab + ui->userAgent->setPlainText(m_profile->httpUserAgent()); connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() { profile->setHttpUserAgent(ui->userAgent->toPlainText()); }); + + ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [=]() { profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); }); + + ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); connect(ui->cacheType, QOverload::of(&QComboBox::currentIndexChanged), 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) { profile->setHttpCacheMaximumSize(text.toInt()); }); + + ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); connect(ui->cookiePolicy, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { profile->setPersistentCookiesPolicy(static_cast(index)); }); + connect(ui->clearCache_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearHttpCache); connect(ui->clearHistory_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearAllVisitedLinks); - QWebEngineSettings *settings = m_profile->settings(); + ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); + ui->cachePath_lineEdit->setText(m_profile->cachePath()); + + // settings tab + loadSettings(profile->settings()); + + // cookies tab + loadCookies(profile->cookieStore()); +} + +ProfileView::~ProfileView() +{ + delete ui; +} + +void ProfileView::loadSettings(QWebEngineSettings *settings) +{ + // settings connectSetting(ui->autoloadImages, settings, QWebEngineSettings::AutoLoadImages); connectSetting(ui->autoloadIcons, settings, QWebEngineSettings::AutoLoadIconsForPage); @@ -82,57 +116,48 @@ ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) connectSetting(ui->printElementBackgrounds, settings, QWebEngineSettings::PrintElementBackgrounds); } -ProfileView::~ProfileView() +void ProfileView::loadCookies(QWebEngineCookieStore *store) { - delete ui; -} + // + connect(store, &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded); + connect(store, &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved); + + connect(ui->cookies_reload, &QPushButton::clicked, store, [=]() { + ui->cookies->clearContents(); + ui->cookies->setRowCount(0); + store->loadAllCookies(); + }); -void ProfileView::loadProfile() -{ - if(m_profile->storageName().isEmpty()) - setWindowTitle(tr("Off-the-record")); - else - setWindowTitle(m_profile->storageName()); + connect(ui->cookies_delete, &QPushButton::clicked, store, [=]() { + auto index = ui->cookies->currentRow(); + auto cookie = ui->cookies->item(index, 0)->data(Qt::UserRole).value(); + store->deleteCookie(cookie); + }); - // http - ui->userAgent->setPlainText(m_profile->httpUserAgent()); - ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); - ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); - ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize())); +} - // path - ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); - ui->cachePath_lineEdit->setText(m_profile->cachePath()); +void ProfileView::cookieAdded(const QNetworkCookie &cookie) +{ + auto index = ui->cookies->rowCount(); + ui->cookies->setRowCount(index + 1); + + auto *item = new QTableWidgetItem(QString(cookie.name())); + item->setData(Qt::UserRole, QVariant::fromValue(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())); + ui->cookies->setItem(index, 3, new QTableWidgetItem(cookie.expirationDate().toString(Qt::RFC2822Date))); +} - // settings - QWebEngineSettings *settings = m_profile->settings(); - ui->autoloadImages->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadImages)); - ui->javascriptEnabled->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptEnabled)); - ui->javascriptCanOpenWindows->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows)); - ui->javascriptCanAccessClipboard->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard)); - ui->linksIncludedInFocusChain->setChecked(settings->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain)); - ui->localStorageEnabled->setChecked(settings->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - ui->localContentCanAccessRemoteUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls)); - ui->xssAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::XSSAuditingEnabled)); - ui->spatialNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::SpatialNavigationEnabled)); - ui->localContentCanAccessFileUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls)); - ui->hyperlinkAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled)); - ui->scrollAnimatorEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled)); - ui->errorPagesEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)); - ui->ppapiPluginsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::PluginsEnabled)); - ui->fullscreenSupportEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FullScreenSupportEnabled)); - ui->screenCaptureEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScreenCaptureEnabled)); - ui->webglEnabled->setChecked(settings->testAttribute(QWebEngineSettings::WebGLEnabled)); - ui->canvasEnabled->setChecked(settings->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled)); - ui->autoloadIcons->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadIconsForPage)); - ui->touchIconsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::TouchIconsEnabled)); - ui->focusOnNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled)); - ui->printElementBackgrounds->setChecked(settings->testAttribute(QWebEngineSettings::PrintElementBackgrounds)); - ui->allowRunningInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowRunningInsecureContent)); - ui->allowGeolocationOnInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins)); - ui->javascriptCanActivateWindows->setChecked(settings->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript)); - ui->showScrollBars->setChecked(settings->testAttribute(QWebEngineSettings::ShowScrollBars)); - - // policy - ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); +void ProfileView::cookieRemoved(const QNetworkCookie &cookie) +{ + 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); + ui->cookies->removeRow(i); + break; + } + } } + diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index 6a8e8ab..6aa7c34 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -10,27 +10,34 @@ #define PROFILEDIALOG_H #include -#include +#include namespace Ui { class ProfileView; } +class WebProfile; +class QWebEngineSettings; +class QWebEngineCookieStore; class ProfileView : public QWidget { Q_OBJECT public: - explicit ProfileView(QWebEngineProfile *profile, QWidget *parent = nullptr); + explicit ProfileView(WebProfile *profile, QWidget *parent = nullptr); ~ProfileView() override; -public slots: - void loadProfile(); +private slots: + void loadSettings(QWebEngineSettings *settings); + void loadCookies(QWebEngineCookieStore *store); + + void cookieAdded(const QNetworkCookie &cookie); + void cookieRemoved(const QNetworkCookie &cookie); private: Ui::ProfileView *ui; - QWebEngineProfile *m_profile; + WebProfile *m_profile; }; #endif // PROFILEDIALOG_H diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui index 2f6c889..c1507db 100644 --- a/plugins/ProfileEditor/forms/profileview.ui +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -25,6 +25,51 @@ 0 + + + General + + + + + + Name + + + + + + + false + + + + + + + false + + + Off-the-record + + + + + + + false + + + + + + + Configuration + + + + + HTTP @@ -171,7 +216,7 @@ 0 0 - 276 + 584 855 @@ -413,6 +458,68 @@ + + + Cookies + + + + + + + Name + + + + + Domain + + + + + Path + + + + + Expires + + + + + + + + + + Reload + + + + + + + Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index 2e7b261..d13e819 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -9,7 +9,7 @@ #include "profileeditorplugin.h" #include "forms/profilemanagerdialog.h" #include "forms/profileview.h" -#include +#include #include QHash> ProfileEditorPlugin::commands() @@ -22,23 +22,22 @@ QHash> ProfileEditorPlugin::commands() }); hash.insert("list-profiles", [this]() -> int { - for(auto i = profiles->constBegin(); i != profiles->constEnd(); ++i) { - qDebug(" - %s", qUtf8Printable(i.key())); + for(const WebProfile *profile : qAsConst(profiles)) { + qDebug(" - %s", qUtf8Printable(profile->name())); } return 0; }); return hash; } -void ProfileEditorPlugin::setProfiles(QHash *profiles) -{ - Q_CHECK_PTR(profiles); - this->profiles = profiles; -} - QDialog *ProfileEditorPlugin::createWidget(QWidget *parent) { auto *widget = new ProfileManagerDialog(profiles, parent); widget->setAttribute(Qt::WA_DeleteOnClose, true); return widget; } + +void ProfileEditorPlugin::registerProfile(WebProfile *profile) +{ + profiles.append(profile); +} diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h index db82cfb..bc95708 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 #include class QWebEngineProfile; @@ -25,11 +25,13 @@ public: QHash> commands() override; // ProfileInterface - void setProfiles(QHash *profiles) override; QDialog *createWidget(QWidget *parent) override; +public slots: + void registerProfile(WebProfile *profile) override; + private: - QHash *profiles; + QVector profiles; }; #endif //PROFILEEDITOR_PLUGIN_H diff --git a/plugins/interfaces.h b/plugins/interfaces.h index 1b653cd..67cd3c6 100644 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -38,8 +38,9 @@ class ProfileInterface { public: virtual ~ProfileInterface() = default; - virtual void setProfiles(QHash *profiles) = 0; virtual QDialog *createWidget(QWidget *parent = nullptr) = 0; + + virtual void registerProfile(WebProfile *profile) = 0; }; #define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface" -- cgit v1.2.1