aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp112
1 files changed, 68 insertions, 44 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index aec3ad1..894216e 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -1,7 +1,7 @@
/*
* 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/gitea/aqua/smolbote
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
*
* SPDX-License-Identifier: GPL-3.0
*/
@@ -16,6 +16,8 @@
#include "mainwindow/addressbar.h"
#include "mainwindow/mainwindow.h"
#include "mainwindow/menubar.h"
+#include "session_json.hpp"
+#include "settings.h"
#include "smolbote/plugininterface.hpp"
#include "subwindow/subwindow.h"
#include "util.h"
@@ -35,13 +37,46 @@
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
{
- Configuration conf;
-
- setApplicationName(conf.value<QString>("poi.name").value());
+ //setApplicationName(conf.value<QString>("poi.name").value());
+ setApplicationName("smolbote");
setWindowIcon(Util::icon<Util::AppWindowIcon>());
setApplicationVersion(QVersionNumber::fromString(QLatin1String(poi_Version)).toString());
+}
+
+Browser::~Browser()
+{
+ if(m_bookmarks)
+ m_bookmarks->save();
+
+ for(auto *info : qAsConst(m_plugins))
+ delete info;
+
+ qDeleteAll(m_windows);
+ m_windows.clear();
+}
+
+void Browser::about()
+{
+ auto *dlg = new AboutDialog(activeWindow());
+ dlg->show();
+}
- if(const auto _translation = conf.value<QString>("browser.translation")) {
+void Browser::aboutPlugins()
+{
+ auto *dlg = new AboutPluginDialog;
+ for(auto *info : qAsConst(m_plugins)) {
+ dlg->add(info->loader);
+ }
+ dlg->exec();
+}
+
+void Browser::loadConfiguration(const QString &path)
+{
+ auto ctx = init_conf(path.toStdString());
+ spdlog::info("Using configuration [{}]: {}", ctx.path, ctx.ptr->make_global() ? "okay" : "failed");
+ m_conf = std::move(ctx.ptr);
+
+ if(const auto _translation = m_conf->value<QString>("browser.translation")) {
auto *translator = new QTranslator(this);
if(translator->load(_translation.value()))
installTranslator(translator);
@@ -49,7 +84,7 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
delete translator;
}
- if(const auto _locale = conf.value<QString>("browser.locale")) {
+ if(const auto _locale = m_conf->value<QString>("browser.locale")) {
auto *locale = new QTranslator(this);
if(locale->load("qt_" + _locale.value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
installTranslator(locale);
@@ -57,11 +92,11 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
delete locale;
}
- if(auto iconTheme = conf.value<QString>("browser.iconTheme")) {
+ if(auto iconTheme = m_conf->value<QString>("browser.iconTheme")) {
QIcon::setThemeName(iconTheme.value());
}
- if(auto stylesheet = conf.value<QString>("browser.stylesheet")) {
+ if(auto stylesheet = m_conf->value<QString>("browser.stylesheet")) {
QFile f(stylesheet.value());
if(f.open(QIODevice::ReadOnly)) {
setStyleSheet(f.readAll());
@@ -70,20 +105,20 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
}
// content filter - register format plugins
- if(const auto hostlist_plugin = conf.value<QString>("smolblok.plugins.hostlist")) {
+ if(const auto hostlist_plugin = m_conf->value<QString>("smolblok.plugins.hostlist")) {
content_filter.registerFormatPlugin("hostlist", hostlist_plugin.value());
}
- if(const auto adblock_plugin = conf.value<QString>("smolblok.plugins.adblock")) {
+ if(const auto adblock_plugin = m_conf->value<QString>("smolblok.plugins.adblock")) {
content_filter.registerFormatPlugin("adblock", adblock_plugin.value());
}
// load profiles
{
- const auto profiles = Util::files(conf.value<QString>("profile.path").value(), { "*.profile" });
- const auto search = conf.value<QString>("profile.search").value();
- const auto homepage = QUrl::fromUserInput(conf.value<QString>("profile.homepage").value());
- const auto newtab = QUrl::fromUserInput(conf.value<QString>("profile.newtab").value());
- const auto default_id = conf.value<QString>("profile.default").value();
+ const auto profiles = Util::files(m_conf->value<QString>("profile.path").value(), { "*.profile" });
+ const auto search = m_conf->value<QString>("profile.search").value();
+ const auto homepage = QUrl::fromUserInput(m_conf->value<QString>("profile.homepage").value());
+ const auto newtab = QUrl::fromUserInput(m_conf->value<QString>("profile.newtab").value());
+ const auto default_id = m_conf->value<QString>("profile.default").value();
m_profileManager = std::make_unique<WebProfileManager<false>>(profiles, default_id, search, homepage, newtab);
m_profileManager->make_global();
@@ -97,14 +132,14 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
}
// downloads
- m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads.path").value());
+ m_downloads = std::make_unique<DownloadsWidget>(m_conf->value<QString>("downloads.path").value());
m_profileManager->walk([this](const QString &, WebProfile *profile, QSettings *) {
profile->setUrlRequestInterceptor(content_filter.interceptor());
connect(profile, &QWebEngineProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
});
// bookmarks
- m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value()));
+ m_bookmarks = std::make_shared<BookmarksWidget>(m_conf->value<QString>("bookmarks.path").value());
connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) {
m_windows.last()->createTab(url);
});
@@ -114,33 +149,6 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
timer->start(5 * 60 * 1000); // 5min * 60sec * 1000ms
}
-Browser::~Browser()
-{
- if(m_bookmarks)
- m_bookmarks->save();
-
- for(auto *info : qAsConst(m_plugins))
- delete info;
-
- qDeleteAll(m_windows);
- m_windows.clear();
-}
-
-void Browser::about()
-{
- auto *dlg = new AboutDialog(activeWindow());
- dlg->show();
-}
-
-void Browser::aboutPlugins()
-{
- auto *dlg = new AboutPluginDialog;
- for(auto *info : qAsConst(m_plugins)) {
- dlg->add(info->loader);
- }
- dlg->exec();
-}
-
bool Browser::loadPlugin(const QString &path)
{
if(path.isEmpty()) {
@@ -167,6 +175,22 @@ bool Browser::loadPlugin(const QString &path)
return true;
}
+void Browser::enableRemote(bool toggle)
+{
+ if(static_cast<bool>(remoteConnection) == toggle)
+ return;
+
+ if(!toggle) {
+ disconnect(remoteConnection);
+ return;
+ }
+
+ remoteConnection = connect(this, &Browser::receivedMessage, this, [this](quint32, const QByteArray &message) {
+ JsonSession s(message);
+ this->open(s.get());
+ });
+}
+
void Browser::showWidget(QWidget *widget, MainWindow *where) const
{
bool wasVisible = widget->isVisible();