aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp29
-rw-r--r--src/mainwindow/mainwindow.cpp2
-rw-r--r--src/profilemanager.cpp19
-rw-r--r--src/profilemanager.h27
-rw-r--r--src/session.cpp4
-rw-r--r--src/subwindow/subwindow.cpp2
-rw-r--r--src/webengine/webview.cpp2
7 files changed, 54 insertions, 31 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);
}
}
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index ccc5f1e..91e820a 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -382,7 +382,7 @@ void MainWindow::updatePageLoadProfileMenu()
auto *browser = qobject_cast<Browser *>(qApp);
Q_CHECK_PTR(browser);
- ProfileIterator it(ProfileManager::profileList());
+ ProfileIterator it(profileManager->profileList());
while(it.hasNext()) {
it.next();
auto *profile = it.value();
diff --git a/src/profilemanager.cpp b/src/profilemanager.cpp
index 1038598..5b0f76e 100644
--- a/src/profilemanager.cpp
+++ b/src/profilemanager.cpp
@@ -12,13 +12,26 @@
#include <QFileInfo>
#include <QWebEngineSettings>
-QMap<QString, WebProfile *> ProfileManager::profiles;
+ProfileManager *ProfileManager::s_instance = nullptr;
-ProfileManager::ProfileManager(QObject *parent) : QObject(parent)
+ProfileManager::ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent) : QObject(parent)
+ , defaults(profileSection)
{
}
-WebProfile *ProfileManager::loadProfile(const QString &path, const QHash<QString, QString> &defaults)
+void ProfileManager::setInstance(ProfileManager *instance)
+{
+ Q_CHECK_PTR(instance);
+ s_instance = instance;
+}
+
+ProfileManager *ProfileManager::instance()
+{
+ Q_CHECK_PTR(s_instance);
+ return s_instance;
+}
+
+WebProfile *ProfileManager::loadProfile(const QString &path)
{
WebProfile *profile = nullptr;
#ifdef QT_DEBUG
diff --git a/src/profilemanager.h b/src/profilemanager.h
index b2509a1..5ece510 100644
--- a/src/profilemanager.h
+++ b/src/profilemanager.h
@@ -15,21 +15,36 @@
typedef QMapIterator<QString, WebProfile *> ProfileIterator;
+#define profileManager ProfileManager::instance()
+
class WebProfile;
class ProfileManager : public QObject
{
Q_OBJECT
public:
- explicit ProfileManager(QObject *parent = nullptr);
- static WebProfile *loadProfile(const QString &path, const QHash<QString, QString> &defaults);
+ struct Profile
+ {
+ QString id;
+ WebProfile *profile = nullptr;
+ };
+
+ explicit ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent = nullptr);
+
+ static void setInstance(ProfileManager *instance);
+ static ProfileManager *instance();
- static const QString id(WebProfile *profile);
- static WebProfile *profile(const QString &id);
- static const QMap<QString, WebProfile *>& profileList();
+ WebProfile *loadProfile(const QString &path);
+
+ const QString id(WebProfile *profile);
+ WebProfile *profile(const QString &id);
+ const QMap<QString, WebProfile *>& profileList();
private:
- static QMap<QString, WebProfile *> profiles;
+ QMap<QString, WebProfile *> profiles;
+
+ static ProfileManager *s_instance;
+ const QHash<QString, QString> defaults;
};
#endif // SMOLBOTE_PROFILEMANAGER_H
diff --git a/src/session.cpp b/src/session.cpp
index 0781cd7..414e8aa 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -25,13 +25,13 @@ QJsonObject Session::toJsonObject(MainWindow *window)
QJsonArray subwindows;
for(const SubWindow *subwindow : window->subWindows()) {
QJsonObject window;
- window.insert("profile", ProfileManager::id(subwindow->profile()));
+ window.insert("profile", profileManager->id(subwindow->profile()));
QJsonArray tabs;
for(int i = 0; i < subwindow->tabCount(); ++i) {
QJsonObject tab;
tab.insert("url", subwindow->view(i)->url().toString());
- tab.insert("profile", ProfileManager::id(subwindow->view(i)->profile()));
+ tab.insert("profile", profileManager->id(subwindow->view(i)->profile()));
tabs.append(tab);
}
window.insert("tabs", tabs);
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp
index 56bf821..4e79a03 100644
--- a/src/subwindow/subwindow.cpp
+++ b/src/subwindow/subwindow.cpp
@@ -50,7 +50,7 @@ SubWindow::SubWindow(const std::unique_ptr<Configuration> &config, QWidget *pare
Browser *browser = qobject_cast<Browser *>(qApp);
Q_CHECK_PTR(browser);
- ProfileIterator it(ProfileManager::profileList());
+ ProfileIterator it(profileManager->profileList());
while(it.hasNext()) {
it.next();
auto *profile = it.value();
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index d7281e9..94f73bc 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -244,7 +244,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
});
auto *newTabMenu = new QMenu(tr("Open link in new tab with profile"), this);
- ProfileIterator it(ProfileManager::profileList());
+ ProfileIterator it(profileManager->profileList());
while(it.hasNext()) {
it.next();
connect(newTabMenu->addAction(it.key()), &QAction::triggered, this, [this, ctxdata, it]() {