aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp58
-rw-r--r--src/browser.h1
-rw-r--r--src/mainwindow/mainwindow.cpp1
-rw-r--r--src/session.cpp3
-rw-r--r--src/subwindow/subwindow.cpp1
-rw-r--r--src/webengine/webview.cpp2
6 files changed, 29 insertions, 37 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 6cdfdab..e93123c 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -16,16 +16,16 @@
#include <QFileInfo>
#include <QFileInfoList>
#include <QJsonArray>
+#include <QJsonDocument>
#include <QPluginLoader>
+#include <QTimer>
#include <about/aboutdialog.h>
#include <bookmarks/bookmarkswidget.h>
#include <configuration/configuration.h>
#include <downloads/downloadswidget.h>
#include <version.h>
-#include <web/webprofile.h>
#include <web/profilemanager.h>
-#include <QJsonDocument>
-#include <QTimer>
+#include <web/webprofile.h>
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
@@ -55,11 +55,11 @@ void Browser::about()
QPair<QString, WebProfile *> Browser::loadProfile(const QString &id)
{
- WebProfile *profile = profileManager->loadProfile(id);
+ WebProfile *profile = m_profileManager->loadProfile(id);
connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
profile->setRequestInterceptor(m_urlFilter.get());
- return QPair<QString, WebProfile *>(profileManager->id(profile), profile);
+ return QPair<QString, WebProfile *>(m_profileManager->id(profile), profile);
}
void Browser::setConfiguration(std::unique_ptr<Configuration> &config)
@@ -76,27 +76,24 @@ Configuration *Browser::getConfiguration() const
ProfileManager *Browser::getProfileManager()
{
- return ProfileManager::instance();
+ return m_profileManager;
}
void Browser::registerPlugin(const Plugin &plugin)
{
Q_ASSERT(m_config);
-
auto *p = qobject_cast<PluginInterface *>(plugin.instance);
- Q_CHECK_PTR(p);
- p->setBrowserInterface(this);
-
- m_plugins.append(plugin);
+ if(p != nullptr) {
+ p->setBrowserInterface(this);
+ m_plugins.append(plugin);
+ }
}
void Browser::setup(const QString &defaultProfile)
{
Q_ASSERT(m_config);
- ProfileManager::setInstance(new ProfileManager(m_config->section("profile"), this));
-
auto stylesheet = m_config->value<QString>("browser.stylesheet");
if(stylesheet) {
QFile f(stylesheet.value());
@@ -113,25 +110,15 @@ void Browser::setup(const QString &defaultProfile)
// cookie request filter
// 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, QDir::Time);
-
- for(const QFileInfo &f : entries) {
- loadProfile(f.absoluteFilePath());
- }
- }
-
- // set default profile
- if(profileManager->profile(defaultProfile) == nullptr) {
- // if this profile has not been added, it doesn't have a path
- loadProfile(QString());
- }
- WebProfile::setDefaultProfile(profileManager->profile(defaultProfile));
+ m_profileManager = new ProfileManager(m_config->section("profile"), defaultProfile, this);
+ // connect profiles
+ for(const QString &id : m_profileManager->idList()) {
+ auto *profile = m_profileManager->profile(id);
+ connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
+ profile->setRequestInterceptor(m_urlFilter.get());
}
+ // set default profile
+ WebProfile::setDefaultProfile(m_profileManager->profile(defaultProfile));
// bookmarks
m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
@@ -142,7 +129,7 @@ void Browser::setup(const QString &defaultProfile)
auto *timer = new QTimer(this);
connect(timer, &QTimer::timeout, m_bookmarks.get(), &BookmarksWidget::save);
// 5min * 60sec * 1000ms
- timer->start(5*60*1000);
+ timer->start(5 * 60 * 1000);
}
void Browser::createSession(const QJsonObject &object)
@@ -158,7 +145,7 @@ void Browser::createSession(const QJsonObject &object)
for(const QJsonValue &s : subwindows) {
const QJsonObject subwindow = s.toObject();
const QString profileId = subwindow.value("profile").toString();
- WebProfile *profile = profileManager->profile(profileId);
+ WebProfile *profile = m_profileManager->profile(profileId);
if(profile == nullptr)
profile = WebProfile::defaultProfile();
Q_CHECK_PTR(profile);
@@ -180,7 +167,7 @@ void Browser::createSession(const QJsonObject &object)
for(const QJsonValue &t : subwindow.value("tabs").toArray()) {
const QJsonObject tab = t.toObject();
const QUrl url = QUrl::fromUserInput(tab.value("url").toString());
- WebProfile *p = profileManager->profile(tab.value("profile").toString());
+ WebProfile *p = m_profileManager->profile(tab.value("profile").toString());
window->addTab(url, p);
}
}
@@ -190,7 +177,7 @@ void Browser::createSession(const QJsonObject &object)
MainWindow *Browser::createWindow()
{
// the window will delete itself when it closes, so we don't need to delete it
- MainWindow *window = new MainWindow(m_config);
+ auto *window = new MainWindow(m_config);
connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search);
connect(window, &MainWindow::createBookmark, m_bookmarks.get(), &BookmarksWidget::addBookmark);
@@ -231,7 +218,6 @@ MainWindow *Browser::createWindow()
plugin->createWidget(window)->exec();
});
window->addAction(MainWindow::ToolsMenu, pluginAction);
-
}
m_windows.append(window);
diff --git a/src/browser.h b/src/browser.h
index 007b0a1..bf91cc8 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -63,6 +63,7 @@ private:
std::unique_ptr<Configuration> m_config;
std::shared_ptr<BookmarksWidget> m_bookmarks;
std::unique_ptr<DownloadsWidget> m_downloads;
+ ProfileManager *m_profileManager;
std::unique_ptr<UrlRequestInterceptor> m_urlFilter;
QVector<MainWindow *> m_windows;
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index e1b8fd8..8a33e23 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -390,6 +390,7 @@ void MainWindow::updatePageLoadProfileMenu()
if(currentView == nullptr)
return;
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
pageLoadProfileMenu->addActions(profileManager->createProfileMenu([this](WebProfile *profile) {
this->currentView->setProfile(profile);
},
diff --git a/src/session.cpp b/src/session.cpp
index 70e1deb..3c40a2a 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -13,7 +13,7 @@
#include <QJsonArray>
#include "webengine/webview.h"
#include <web/profilemanager.h>
-
+#include "browser.h"
QJsonObject Session::session(QVector<MainWindow *> windows)
{
@@ -31,6 +31,7 @@ QJsonObject Session::session(QVector<MainWindow *> windows)
QJsonObject Session::window(const MainWindow *window)
{
QJsonObject obj;
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
QJsonArray subwindows;
for(const SubWindow *subwindow : window->subWindows()) {
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp
index 7dc1cdf..44ac1b1 100644
--- a/src/subwindow/subwindow.cpp
+++ b/src/subwindow/subwindow.cpp
@@ -50,6 +50,7 @@ SubWindow::SubWindow(const std::unique_ptr<Configuration> &config, QWidget *pare
Browser *browser = qobject_cast<Browser *>(qApp);
Q_CHECK_PTR(browser);
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
loadProfile_menu->addActions(profileManager->createProfileMenu([this, profileName_action](WebProfile *profile) {
this->setProfile(profile);
profileName_action->setText(tr("Profile: %1").arg(profile->name()));
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index c2c0f75..f8be48e 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -22,6 +22,7 @@
#include <QWidgetAction>
#include <web/profilemanager.h>
#include <web/webprofile.h>
+#include "browser.h"
inline QAction *historyAction(QWebEngineView *view, const QWebEngineHistoryItem &item)
{
@@ -243,6 +244,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
createWindow(QWebEnginePage::WebBrowserTab)->load(ctxdata.linkUrl());
});
+ auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
QMenu *newTabMenu = profileManager->createProfileMenu([this, ctxdata](WebProfile *profile) {
auto *view = this->createWindow(QWebEnginePage::WebBrowserTab);
view->setProfile(profile);