diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-16 13:55:35 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-16 13:55:35 +0200 |
commit | b27e55b0bbba9a1678159abe44280e173374f971 (patch) | |
tree | a7a5bb75ad9b4dc3fc31b39b5ab2fe860b55a27e | |
parent | Add extra-cmake-modules to make depends (diff) | |
download | smolbote-b27e55b0bbba9a1678159abe44280e173374f971.tar.xz |
Sort .profile by time
Remove ProfileInterface::setProfiles
ProfileView: Add General tab
ProfileView: some cleanup
ProfileView: Add Cookies tab
-rw-r--r-- | lib/web/webprofile.cpp | 8 | ||||
-rw-r--r-- | lib/web/webprofile.h | 2 | ||||
-rw-r--r-- | linux/makepkg/PKGBUILD | 4 | ||||
-rw-r--r-- | plugins/ProfileEditor/CMakeLists.txt | 1 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profilemanagerdialog.cpp | 21 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profilemanagerdialog.h | 5 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.cpp | 127 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.h | 17 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.ui | 109 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.cpp | 17 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.h | 8 | ||||
-rw-r--r-- | plugins/interfaces.h | 3 | ||||
-rw-r--r-- | src/browser.cpp | 59 | ||||
-rw-r--r-- | src/browser.h | 3 |
14 files changed, 274 insertions, 110 deletions
diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index dca639b..37338b9 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -14,7 +14,7 @@ WebProfile *WebProfile::profile = nullptr; -WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defaults, const QString &path) +WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defaults, const QString &path, QObject *parent) { WebProfile *profile = nullptr; #ifdef QT_DEBUG @@ -24,15 +24,15 @@ WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defa if(name.isEmpty()) { // a default otr profile - profile = new WebProfile(QObject::tr("Off-the-record"), path, nullptr); + profile = new WebProfile(QObject::tr("Off-the-record"), path, parent); } else if(config.value("otr").toBool()) { // a named otr profile - profile = new WebProfile(config.value("name", name).toString(), path, nullptr); + profile = new WebProfile(config.value("name", name).toString(), path, parent); } else { // a named profile - profile = new WebProfile(name, config.value("name", name).toString(), path, nullptr); + profile = new WebProfile(name, config.value("name", name).toString(), path, parent); } Q_CHECK_PTR(profile); diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index f4d31e6..9e9fd3e 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -105,7 +105,7 @@ private: QUrl m_newtab = QUrl("about:blank"); }; -WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defaults, const QString &path = QString()); +WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defaults, const QString &path = QString(), QObject *parent = nullptr); //WebProfile *saveProfile(WebProfile *profile, const QString &path); #endif // SMOLBOTE_WEBENGINEPROFILE_H diff --git a/linux/makepkg/PKGBUILD b/linux/makepkg/PKGBUILD index 9544732..e1ce4c8 100644 --- a/linux/makepkg/PKGBUILD +++ b/linux/makepkg/PKGBUILD @@ -13,7 +13,7 @@ license=('GPL3') replaces=('smolbote-git') depends=('qt5-webengine>=5.10.1' 'boost-libs>=1.66.0') -makedepends=('mercurial' 'cmake' 'pkg-config' 'ninja' 'extra-cmake-modules') +makedepends=('mercurial' 'cmake' 'pkg-config' 'ninja') # this is the central repository source=("smolbote-hg::hg+https://neueland.iserlohn-fortress.net/smolbote.hg") @@ -70,7 +70,7 @@ build() { # Flavour: add some KF5 effects # this requires 'extra-cmake-modules' - _cmake_options="$_cmake_options -DPlasma=On" + #_cmake_options="$_cmake_options -DPlasma=On" # Build System # Flavour: I use ninja, but you can comment this out, or set your own 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 <webprofile.h> #include <QDir> +#include <QPointer> -ProfileManagerDialog::ProfileManagerDialog(QHash<QString, WebProfile *> *profiles, QWidget *parent) +ProfileManagerDialog::ProfileManagerDialog(const QVector<WebProfile *> &profiles, QWidget *parent) : QDialog(parent) , ui(new Ui::ProfileManagerDialog) - , profiles(profiles) { ui->setupUi(this); @@ -18,8 +18,12 @@ ProfileManagerDialog::ProfileManagerDialog(QHash<QString, WebProfile *> *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<WebProfile>(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<QPointer<WebProfile>>(); + 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<QPointer<WebProfile>>(); + 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 <QDialog> -#include <QHash> +#include <QVector> namespace Ui { @@ -16,7 +16,7 @@ class ProfileManagerDialog : public QDialog Q_OBJECT public: - explicit ProfileManagerDialog(QHash<QString, WebProfile *> *profiles, QWidget *parent = 0); + explicit ProfileManagerDialog(const QVector<WebProfile *> &profiles, QWidget *parent = 0); ~ProfileManagerDialog(); private slots: @@ -25,7 +25,6 @@ private slots: private: Ui::ProfileManagerDialog *ui; - const QHash<QString, WebProfile *> *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 <webprofile.h> #include <QWebEngineSettings> +#include <QWebEngineCookieStore> +#include <QDateTime> 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<int>::of(&QComboBox::currentIndexChanged), profile, [=](int index) { profile->setHttpCacheType(static_cast<QWebEngineProfile::HttpCacheType>(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<int>::of(&QComboBox::currentIndexChanged), profile, [=](int index) { profile->setPersistentCookiesPolicy(static_cast<QWebEngineProfile::PersistentCookiesPolicy>(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<QNetworkCookie>(); + 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<QNetworkCookie>() == 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 <QWidget> -#include <QWebEngineProfile> +#include <QNetworkCookie> 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 @@ <property name="currentIndex"> <number>0</number> </property> + <widget class="QWidget" name="generalTab"> + <attribute name="title"> + <string>General</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="name_label"> + <property name="text"> + <string>Name</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="name"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QCheckBox" name="offTheRecord"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Off-the-record</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="configurationPath"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="configurationPath_label"> + <property name="text"> + <string>Configuration</string> + </property> + </widget> + </item> + </layout> + </widget> <widget class="QWidget" name="httpTab"> <attribute name="title"> <string>HTTP</string> @@ -171,7 +216,7 @@ <rect> <x>0</x> <y>0</y> - <width>276</width> + <width>584</width> <height>855</height> </rect> </property> @@ -413,6 +458,68 @@ </item> </layout> </widget> + <widget class="QWidget" name="cookiesTab"> + <attribute name="title"> + <string>Cookies</string> + </attribute> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTableWidget" name="cookies"> + <column> + <property name="text"> + <string>Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Domain</string> + </property> + </column> + <column> + <property name="text"> + <string>Path</string> + </property> + </column> + <column> + <property name="text"> + <string>Expires</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QPushButton" name="cookies_reload"> + <property name="text"> + <string>Reload</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cookies_delete"> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> </widget> </item> </layout> 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 <QHash> +#include <QVector> #include <webprofile.h> QHash<QString, std::function<int()>> ProfileEditorPlugin::commands() @@ -22,23 +22,22 @@ QHash<QString, std::function<int()>> 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<QString, WebProfile *> *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 <QHash> +#include <QVector> #include <interfaces.h> class QWebEngineProfile; @@ -25,11 +25,13 @@ public: QHash<QString, std::function<int()>> commands() override; // ProfileInterface - void setProfiles(QHash<QString, WebProfile *> *profiles) override; QDialog *createWidget(QWidget *parent) override; +public slots: + void registerProfile(WebProfile *profile) override; + private: - QHash<QString, WebProfile *> *profiles; + QVector<WebProfile *> 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<QString, WebProfile *> *profiles) = 0; virtual QDialog *createWidget(QWidget *parent = nullptr) = 0; + + virtual void registerProfile(WebProfile *profile) = 0; }; #define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface" diff --git a/src/browser.cpp b/src/browser.cpp index 4c6549c..e3857dc 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -43,6 +43,7 @@ inline Plugin loadPluginFromPath(const QString &path) #ifdef QT_DEBUG } else { qDebug("Loading pluing: %s [failed]", qUtf8Printable(path)); + qDebug("%s", qUtf8Printable(loader.errorString())); #endif } @@ -99,7 +100,7 @@ Browser::~Browser() //qDeleteAll(m_plugins); m_plugins.clear(); - qDeleteAll(m_profiles); + } void Browser::setConfiguration(std::shared_ptr<Configuration> &config) @@ -112,24 +113,55 @@ void Browser::setup(const QString &defaultProfile) { Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); + // load plugins first + m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value()))); + + // register commands + for(const Plugin &p : qAsConst(m_plugins)) { + + if(p.instance->inherits("ProfileInterface")) { + auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); + Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); + + connect(this, &Browser::registerProfile, [=](WebProfile *profile) { + profileEditor->registerProfile(profile); + }); + } + + auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); + if(plugin) { + m_commands.unite(plugin->commands()); + } + } + // load profiles { const auto defaults = m_config->section("profile"); const QDir profilesDir(m_config->value<QString>("profile.path").value()); if(profilesDir.exists()) { - const auto entries = profilesDir.entryInfoList({"*.profile"}, QDir::Files | QDir::Readable); + const auto entries = profilesDir.entryInfoList({"*.profile"}, QDir::Files | QDir::Readable, QDir::Time); for(const QFileInfo &f : entries) { - auto *profile = loadProfile(f.baseName(), defaults, f.absoluteFilePath()); - m_profiles.insert(f.baseName(), profile); + auto name = f.baseName(); + auto *profile = loadProfile(name, defaults, f.absoluteFilePath(), this); + m_profiles.insert(name, profile); + connect(profile, &WebProfile::destroyed, this, [=]() { + m_profiles.remove(name); + }); + emit registerProfile(profile); } } // set default profile if(!m_profiles.contains(defaultProfile)) { // if this profile has not been added, it doesn't have a path - m_profiles.insert(defaultProfile, loadProfile(defaultProfile, defaults)); + auto *profile = loadProfile(defaultProfile, defaults, QString(), this); + m_profiles.insert(defaultProfile, profile); + connect(profile, &WebProfile::destroyed, this, [=]() { + m_profiles.remove(defaultProfile); + }); + emit registerProfile(profile); } WebProfile::setDefaultProfile(m_profiles.value(defaultProfile)); } @@ -150,24 +182,7 @@ void Browser::setup(const QString &defaultProfile) m_downloads = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); - // load plugins last - m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value()))); - // register commands - for(const Plugin &p : qAsConst(m_plugins)) { - - if(p.instance->inherits("ProfileInterface")) { - auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); - Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); - - profileEditor->setProfiles(&m_profiles); - } - - auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); - if(plugin) { - m_commands.unite(plugin->commands()); - } - } } diff --git a/src/browser.h b/src/browser.h index 8148e99..9e606dd 100644 --- a/src/browser.h +++ b/src/browser.h @@ -58,6 +58,9 @@ public: return m_plugins; } +signals: + void registerProfile(WebProfile *profile); + public slots: void createSession(const QString &profileName, bool newWindow, const QStringList &urls); MainWindow *createWindow(); |