aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-07 13:11:58 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-07 13:11:58 +0200
commit4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc (patch)
treee3f89c1db2aaaa605f0cbd4d752479a611fb5aac /src
parentSome cppcheck fixes (diff)
downloadsmolbote-4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc.tar.xz
Move ProfileManager to libweb
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/browser.cpp5
-rw-r--r--src/browser.h2
-rw-r--r--src/profilemanager.cpp102
-rw-r--r--src/profilemanager.h50
5 files changed, 7 insertions, 154 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4549155..5db6e36 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,8 +13,6 @@ set(poi_SRC
browser.h
session.cpp
session.h
- profilemanager.cpp
- profilemanager.h
../data/resources.qrc
# main window
diff --git a/src/browser.cpp b/src/browser.cpp
index 0af050f..1e2ad25 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -73,6 +73,11 @@ Configuration *Browser::getConfiguration() const
return m_config.get();
}
+const ProfileManager *Browser::getProfileManager() const
+{
+ return const_cast<ProfileManager *>(ProfileManager::instance());
+}
+
void Browser::registerPlugin(const Plugin &plugin)
{
Q_ASSERT(m_config);
diff --git a/src/browser.h b/src/browser.h
index ff84c32..6969087 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -38,6 +38,8 @@ public slots:
public:
// interface
Configuration *getConfiguration() const override;
+
+ const ProfileManager *getProfileManager() const override;
const QVector<WebProfile *> profiles() const override;
QPair<QString, WebProfile *> loadProfile(const QString &id) override;
diff --git a/src/profilemanager.cpp b/src/profilemanager.cpp
deleted file mode 100644
index 5b0f76e..0000000
--- a/src/profilemanager.cpp
+++ /dev/null
@@ -1,102 +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: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "profilemanager.h"
-#include <web/webprofile.h>
-#include <QSettings>
-#include <QFileInfo>
-#include <QWebEngineSettings>
-
-ProfileManager *ProfileManager::s_instance = nullptr;
-
-ProfileManager::ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent) : QObject(parent)
- , defaults(profileSection)
-{
-}
-
-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
- qDebug("==> Reading profile config : %s", qUtf8Printable(path));
-#endif
-
- const QString id = QFileInfo(path).baseName();
- QSettings config(path, QSettings::IniFormat);
-
- if(config.value("otr", true).toBool()) {
- profile = new WebProfile(config.value("name", id).toString(), path, nullptr);
- } else {
- profile = new WebProfile(id, config.value("name", id).toString(), path, nullptr);
- }
-
- Q_CHECK_PTR(profile);
- profiles.insert(id, profile);
-
- profile->setSearch(config.value("search", defaults.value("profile.search")).toString());
- profile->setHomepage(config.value("homepage", defaults.value("profile.homepage")).toUrl());
- profile->setNewtab(config.value("newtab", defaults.value("profile.newtab")).toUrl());
-
- config.beginGroup("properties");
- {
- const auto keys = config.childKeys();
- for(const QString &key : keys) {
-#ifdef QT_DEBUG
- qDebug("- set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
-#endif
- profile->setProperty(qUtf8Printable(key), config.value(key));
- }
- }
- config.endGroup(); // properties
-
- config.beginGroup("attributes");
- {
- const auto keys = config.childKeys();
- auto *settings = profile->settings();
- for(const QString &key : keys) {
-#ifdef QT_DEBUG
- qDebug("- set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
-#endif
- auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
- settings->setAttribute(attribute, config.value(key).toBool());
- }
- }
- config.endGroup();
-
- return profile;
-}
-
-const QString ProfileManager::id(WebProfile *profile)
-{
- return profiles.key(profile);
-}
-
-WebProfile *ProfileManager::profile(const QString &id)
-{
- if(profiles.contains(id))
- return profiles.value(id);
- else
- return nullptr;
-}
-
-const QMap<QString, WebProfile *> &ProfileManager::profileList()
-{
- return profiles;
-}
diff --git a/src/profilemanager.h b/src/profilemanager.h
deleted file mode 100644
index 5ece510..0000000
--- a/src/profilemanager.h
+++ /dev/null
@@ -1,50 +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: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_PROFILEMANAGER_H
-#define SMOLBOTE_PROFILEMANAGER_H
-
-#include <QObject>
-#include <QMap>
-#include <webprofile.h>
-
-typedef QMapIterator<QString, WebProfile *> ProfileIterator;
-
-#define profileManager ProfileManager::instance()
-
-class WebProfile;
-class ProfileManager : public QObject
-{
- Q_OBJECT
-public:
-
- 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();
-
- WebProfile *loadProfile(const QString &path);
-
- const QString id(WebProfile *profile);
- WebProfile *profile(const QString &id);
- const QMap<QString, WebProfile *>& profileList();
-
-private:
- QMap<QString, WebProfile *> profiles;
-
- static ProfileManager *s_instance;
- const QHash<QString, QString> defaults;
-};
-
-#endif // SMOLBOTE_PROFILEMANAGER_H