aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-29 14:56:39 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-29 14:56:39 +0200
commit9abf7a9690163737d3e70b3b52d814135858d0d5 (patch)
tree037b1d3a12115221182cb283c14736229c52a8d8 /src/browser.cpp
parentUpdate repository path in license headers (diff)
downloadsmolbote-9abf7a9690163737d3e70b3b52d814135858d0d5.tar.xz
ProfileManager: move initial profile loading to ProfileManager
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp58
1 files changed, 22 insertions, 36 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);