From 1bc1ae8cd09851faa05345f5a6b105b02fe75dd2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 19 Nov 2020 18:22:36 +0200 Subject: Drop args.hxx dependency Replace args.hxx with QCommandLineParser. --- src/browser.cpp | 112 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 44 deletions(-) (limited to 'src/browser.cpp') 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("poi.name").value()); + //setApplicationName(conf.value("poi.name").value()); + setApplicationName("smolbote"); setWindowIcon(Util::icon()); 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("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("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("browser.locale")) { + if(const auto _locale = m_conf->value("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("browser.iconTheme")) { + if(auto iconTheme = m_conf->value("browser.iconTheme")) { QIcon::setThemeName(iconTheme.value()); } - if(auto stylesheet = conf.value("browser.stylesheet")) { + if(auto stylesheet = m_conf->value("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("smolblok.plugins.hostlist")) { + if(const auto hostlist_plugin = m_conf->value("smolblok.plugins.hostlist")) { content_filter.registerFormatPlugin("hostlist", hostlist_plugin.value()); } - if(const auto adblock_plugin = conf.value("smolblok.plugins.adblock")) { + if(const auto adblock_plugin = m_conf->value("smolblok.plugins.adblock")) { content_filter.registerFormatPlugin("adblock", adblock_plugin.value()); } // load profiles { - const auto profiles = Util::files(conf.value("profile.path").value(), { "*.profile" }); - const auto search = conf.value("profile.search").value(); - const auto homepage = QUrl::fromUserInput(conf.value("profile.homepage").value()); - const auto newtab = QUrl::fromUserInput(conf.value("profile.newtab").value()); - const auto default_id = conf.value("profile.default").value(); + const auto profiles = Util::files(m_conf->value("profile.path").value(), { "*.profile" }); + const auto search = m_conf->value("profile.search").value(); + const auto homepage = QUrl::fromUserInput(m_conf->value("profile.homepage").value()); + const auto newtab = QUrl::fromUserInput(m_conf->value("profile.newtab").value()); + const auto default_id = m_conf->value("profile.default").value(); m_profileManager = std::make_unique>(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(conf.value("downloads.path").value()); + m_downloads = std::make_unique(m_conf->value("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(QString::fromStdString(conf.value("bookmarks.path").value())); + m_bookmarks = std::make_shared(m_conf->value("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(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(); -- cgit v1.2.1