aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-02 12:38:21 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-02 12:38:21 +0200
commitde6225509a584df31be1b28146e73d8ecf72c7eb (patch)
tree853f04d227e47f3685d156d0d4fb43a51723dba7 /src/browser.cpp
parentPluginEditor: implement add plugin action (diff)
downloadsmolbote-de6225509a584df31be1b28146e73d8ecf72c7eb.tar.xz
Clean up ProfileManager
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 46e55d2..0af050f 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -54,14 +54,11 @@ void Browser::about()
QPair<QString, WebProfile *> Browser::loadProfile(const QString &id)
{
- Q_ASSERT(m_config);
- const QDir profilesDir(m_config->value<QString>("profile.path").value());
-
- auto *profile = ProfileManager::loadProfile(profilesDir.absoluteFilePath(id + ".profile"), m_config->section("profile"));
+ WebProfile *profile = profileManager->loadProfile(id);
connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
profile->setRequestInterceptor(m_urlFilter.get());
- return QPair<QString, WebProfile *>(id, profile);
+ return QPair<QString, WebProfile *>(profileManager->id(profile), profile);
}
void Browser::setConfiguration(std::unique_ptr<Configuration> &config)
@@ -90,7 +87,9 @@ void Browser::registerPlugin(const Plugin &plugin)
void Browser::setup(const QString &defaultProfile)
{
- Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set");
+ Q_ASSERT(m_config);
+
+ ProfileManager::setInstance(new ProfileManager(m_config->section("profile"), this));
auto stylesheet = m_config->value<QString>("browser.stylesheet");
if(stylesheet) {
@@ -116,20 +115,16 @@ void Browser::setup(const QString &defaultProfile)
const auto entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable, QDir::Time);
for(const QFileInfo &f : entries) {
- auto *profile = ProfileManager::loadProfile(f.absoluteFilePath(), defaults);
- connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
- profile->setRequestInterceptor(m_urlFilter.get());
+ loadProfile(f.absoluteFilePath());
}
}
// set default profile
- if(ProfileManager::profile(defaultProfile) == nullptr) {
+ if(profileManager->profile(defaultProfile) == nullptr) {
// if this profile has not been added, it doesn't have a path
- auto *profile = ProfileManager::loadProfile(QString(), defaults);
- connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
- profile->setRequestInterceptor(m_urlFilter.get());
+ loadProfile(QString());
}
- WebProfile::setDefaultProfile(ProfileManager::profile(defaultProfile));
+ WebProfile::setDefaultProfile(profileManager->profile(defaultProfile));
}
// bookmarks
@@ -141,7 +136,7 @@ void Browser::setup(const QString &defaultProfile)
const QVector<WebProfile *> Browser::profiles() const
{
- const QMap<QString, WebProfile *> profileList = ProfileManager::profileList();
+ const QMap<QString, WebProfile *> profileList = profileManager->profileList();
return QVector<WebProfile *>::fromList(profileList.values());
}
@@ -158,7 +153,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 = profileManager->profile(profileId);
if(profile == nullptr)
profile = WebProfile::defaultProfile();
Q_CHECK_PTR(profile);
@@ -180,7 +175,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 = profileManager->profile(tab.value("profile").toString());
window->addTab(url, p);
}
}