From 2660fff9e6191808aa83197639a663b73a27bbfa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 15 Jan 2018 00:35:58 +0100 Subject: Moved ProfileView to ProfileEditorPlugin --- src/browser.cpp | 41 ++++--- src/browser.h | 8 +- src/forms/profileview.cpp | 132 ---------------------- src/forms/profileview.h | 42 ------- src/forms/profileview.ui | 230 -------------------------------------- src/mainwindow.cpp | 39 +++---- src/mainwindow.h | 5 +- src/widgets/mainwindowmenubar.cpp | 13 +-- 8 files changed, 50 insertions(+), 460 deletions(-) delete mode 100644 src/forms/profileview.cpp delete mode 100644 src/forms/profileview.h delete mode 100644 src/forms/profileview.ui (limited to 'src') diff --git a/src/browser.cpp b/src/browser.cpp index 542465b..43cee5f 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -13,9 +13,6 @@ #include #include -#include -#include - Browser::Browser(int &argc, char *argv[]) : SingleApplication(argc, argv) { @@ -29,33 +26,38 @@ Browser::~Browser() { if(m_config) { QtConcurrent::run(QThreadPool::globalInstance(), m_config.get(), &Configuration::writeIfNeeded); - //m_config->writeIfNeeded(); } if(m_bookmarksManager) { QtConcurrent::run(QThreadPool::globalInstance(), m_bookmarksManager.get(), &BookmarksWidget::save); - //m_bookmarksManager->save(); } - qDebug("Waiting for threads to wind down: %s", QThreadPool::globalInstance()->waitForDone() ? "done" : "failed"); - - qDeleteAll(m_plugins); + qDebug("Waiting for threads to wind down..."); + qDebug("Thread pool is done: %s", QThreadPool::globalInstance()->waitForDone() ? "okay" : "failed"); } void Browser::setConfiguration(std::shared_ptr &config) { m_config = config; - // plugin loader - QPluginLoader loader("plugins/ProfileEditor/libProfileEditorPlugin.so"); - qDebug("Trying to load %s: %s", qUtf8Printable(loader.fileName()), loader.load() ? "ok" : "failed"); - if(!loader.isLoaded()) { - qDebug("Error: %s", qUtf8Printable(loader.errorString())); - } else { - PluginInterface *plugin = qobject_cast(loader.instance()); - m_plugins.append(plugin); - //qDebug("author: %s", qUtf8Printable(loader.metaData()["MetaData"].toObject()["author"].toString())); + QDir pluginsDir(QString::fromStdString(m_config->value("plugins.path").value())); + if(pluginsDir.exists()) { + const QStringList entries = pluginsDir.entryList(QDir::Files | QDir::Readable); + for (const QString &name : entries) { + QPluginLoader loader(pluginsDir.absoluteFilePath(name)); + qDebug("Loading plugin %s: %s", qUtf8Printable(name), loader.load() ? "ok" : "failed"); + if (!loader.isLoaded()) { + qDebug("Error: %s", qUtf8Printable(loader.errorString())); + } else { + Plugin d; + d.meta = loader.metaData()["MetaData"].toObject(); + d.pointer = loader.instance(); + d.pointer->setParent(this); + m_plugins.append(d); + } + } } + m_bookmarksManager = std::make_shared(QString::fromStdString(m_config->value("bookmarks.path").value())); m_downloadManager = std::make_shared(QString::fromStdString(m_config->value("downloads.path").value())); @@ -141,8 +143,3 @@ std::shared_ptr Browser::profile(const QString storageName) return _profile; } - -QStringList Browser::profiles() const -{ - return m_profiles.keys(); -} diff --git a/src/browser.h b/src/browser.h index 236b0fb..5b1a760 100644 --- a/src/browser.h +++ b/src/browser.h @@ -26,6 +26,11 @@ class Browser : public SingleApplication Q_OBJECT public: + struct Plugin { + QJsonObject meta; + QObject *pointer; + }; + explicit Browser(int &argc, char *argv[]); ~Browser() final; Q_DISABLE_COPY(Browser) @@ -33,7 +38,6 @@ public: void setConfiguration(std::shared_ptr &config); std::shared_ptr profile(const QString storageName); - QStringList profiles() const; public slots: MainWindow *createSession(const QString &profileName, bool newWindow, const QStringList &urls); @@ -44,7 +48,7 @@ private: std::shared_ptr m_config; QVector m_windows; - QVector m_plugins; + QVector m_plugins; QHash> m_profiles; std::shared_ptr m_defaultProfile; diff --git a/src/forms/profileview.cpp b/src/forms/profileview.cpp deleted file mode 100644 index 3d85963..0000000 --- a/src/forms/profileview.cpp +++ /dev/null @@ -1,132 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "profileview.h" -#include "ui_profileview.h" - -#include "forms/cookiesform.h" -#include "webengine/webengineprofile.h" -#include -#include -#include -#include - -#include - -#include - -ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) - : QDialog(parent) - , ui(new Ui::ProfileView) -{ - ui->setupUi(this); - setProfile(profile); - - // actions - connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { - this->m_profile->clearHttpCache(); - }); - connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { - this->m_profile->clearAllVisitedLinks(); - }); - - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ProfileView::updateProfile); - connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProfileView::close); -} - -ProfileView::~ProfileView() -{ - delete ui; -} - -void ProfileView::setProfile(WebEngineProfile *profile) -{ - Q_CHECK_PTR(profile); - - m_profile = profile; - setWindowTitle(m_profile->name()); - - m_cookiesForm = new CookiesForm(m_profile->cookieStore(), this); - //ui->tabWidget->addTab(m_cookiesForm, m_cookiesForm->windowTitle()); - - // general - ui->homepage_lineEdit->setText(m_profile->homepage().toString()); - ui->newtab_lineEdit->setText(m_profile->newtab().toString()); - - // 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()); - - // policy - ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); - - //ui->formLayout_3->addWidget(m_cookiesForm); - ui->verticalLayout_3->addWidget(m_cookiesForm); -} - -void ProfileView::showProfile() -{ - ui->tabWidget->setCurrentIndex(0); - show(); -} - -void ProfileView::showCookies() -{ - ui->tabWidget->setCurrentIndex(2); - show(); -} - -void ProfileView::updateProfile() -{ - qDebug("Updating profile [%s]...", qUtf8Printable(m_profile->name())); - - // general - m_profile->setHomepage(QUrl::fromUserInput(ui->homepage_lineEdit->text())); - m_profile->setNewtab(QUrl::fromUserInput(ui->newtab_lineEdit->text())); - - // http - m_profile->setHttpUserAgent(ui->userAgent->toPlainText()); - m_profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); - switch(ui->cacheType->currentIndex()) { - case 0: - m_profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); - break; - case 1: - m_profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); - break; - case 2: - m_profile->setHttpCacheType(QWebEngineProfile::NoCache); - break; - default: - break; - } - m_profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); - - // policy - switch(ui->cookiePolicy->currentIndex()) { - case 0: - m_profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); - break; - case 1: - m_profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); - break; - case 2: - m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); - break; - default: - break; - } - - m_profile->saveProfile(); -} diff --git a/src/forms/profileview.h b/src/forms/profileview.h deleted file mode 100644 index bf44346..0000000 --- a/src/forms/profileview.h +++ /dev/null @@ -1,42 +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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef PROFILEDIALOG_H -#define PROFILEDIALOG_H - -#include - -namespace Ui -{ -class ProfileView; -} - -class WebEngineProfile; -class CookiesForm; -class ProfileView : public QDialog -{ - Q_OBJECT - -public: - explicit ProfileView(WebEngineProfile *profile, QWidget *parent = nullptr); - ~ProfileView(); - - void setProfile(WebEngineProfile *profile); - -public slots: - void showProfile(); - void showCookies(); - void updateProfile(); - -private: - Ui::ProfileView *ui; - WebEngineProfile *m_profile; - CookiesForm *m_cookiesForm; -}; - -#endif // PROFILEDIALOG_H diff --git a/src/forms/profileview.ui b/src/forms/profileview.ui deleted file mode 100644 index 7590e87..0000000 --- a/src/forms/profileview.ui +++ /dev/null @@ -1,230 +0,0 @@ - - - ProfileView - - - - 0 - 0 - 480 - 640 - - - - - 200 - 0 - - - - Profile - - - - - - 0 - - - - General - - - - - - Homepage - - - - - - - - - - Newtab - - - - - - - - - - - HTTP - - - - - - User Agent - - - - - - - - - - Accept Language - - - - - - - Cache Type - - - - - - - Cache Size - - - - - - - - - - - Memory Cache - - - - - Disk Cache - - - - - Disabled - - - - - - - - - - - Storage Path - - - - - - - false - - - - - - - Cache Path - - - - - - - false - - - - - - - Clear Cache - - - - - - - - Cookies - - - - - - - - Cookies - - - - - - - - No Persistent Cookies - - - - - Allow Persistent Cookies - - - - - Force Persistent Cookies - - - - - - - - - - - History - - - - - - Clear History - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - QDialogButtonBox::Close|QDialogButtonBox::Save - - - - - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 913885d..4306afd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -308,24 +308,25 @@ void MainWindow::handleTitleUpdated(const QString &title) //setWindowTitle(browser->settings()->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name())); } -void MainWindow::addPlugins(QVector &plugins) { - for(PluginInterface *plugin : plugins) { - ProfileInterface *profilePlugin = dynamic_cast(plugin); - QWidget *w = profilePlugin->createWidget(m_profile.get(), this); - - QAction *profileAction = new QAction(this); - profileAction->setText("Profile Action"); - ui->navigationToolBar->addAction(profileAction); - connect(profileAction, &QAction::triggered, this, [this, w]() { - w->setVisible(!w->isVisible()); - if(w->isVisible()) { - w->adjustSize(); - QPoint pos = ui->navigationToolBar->pos(); - pos.setX(pos.x() + ui->navigationToolBar->width() - w->width()); - pos.setY(pos.y() + ui->navigationToolBar->height()); - w->move(mapToGlobal(pos)); - w->show(); - } - }); +void MainWindow::addPlugins(const QVector &plugins) +{ + for(const Browser::Plugin &plugin : plugins) { + ProfileInterface *iProfilePlugin = qobject_cast(plugin.pointer); + if(iProfilePlugin) { + QWidget *w = iProfilePlugin->createWidget(m_profile.get(), this); + + auto *profileAction = new QAction(tr("Profile Action"), this); + ui->navigationToolBar->addAction(profileAction); + connect(profileAction, &QAction::triggered, this, [this, w]() { + w->setVisible(!w->isVisible()); + if(w->isVisible()) { + QPoint pos = ui->navigationToolBar->pos(); + pos.setX(pos.x() + ui->navigationToolBar->width() - w->width()); + pos.setY(pos.y() + ui->navigationToolBar->height()); + w->move(mapToGlobal(pos)); + w->show(); + } + }); + } } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 6d1e190..79773d3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -9,14 +9,15 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include "browser.h" #include "lib/navigation/navigationbutton.h" #include "webengine/webengineprofile.h" #include "widgets/loadingbar.h" #include "widgets/mainwindowtabbar.h" #include #include -#include #include +#include namespace Ui { @@ -60,7 +61,7 @@ public slots: void setBookmarksWidget(std::shared_ptr &widget); void setDownloadsWidget(std::shared_ptr &widget); - void addPlugins(QVector &plugins); + void addPlugins(const QVector &plugins); void toggleFullscreen(); diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index c0bea4f..f8275c0 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -7,14 +7,9 @@ */ #include "mainwindowmenubar.h" -#include "forms/profileview.h" +#include "downloads/downloadswidget.h" #include "mainwindow.h" -#include #include -#include - -#include "browser.h" -#include "downloads/downloadswidget.h" MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr config, MainWindow *parent) : QMenuBar(parent) @@ -69,11 +64,7 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr config, Main // Profile menu QMenu *profileMenu = addMenu(tr("Profile")); m_profileAction = profileMenu->addAction(tr("Current profile")); - connect(m_profileAction, &QAction::triggered, this, [parent]() { - ProfileView *dlg = new ProfileView(parent->profile(), parent); - dlg->exec(); - delete dlg; - }); + m_profileAction->setEnabled(false); QMenu *loadMenu = profileMenu->addMenu(tr("Load")); loadMenu->setEnabled(false); -- cgit v1.2.1