aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-11-03 00:18:10 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2019-11-03 00:20:41 +0200
commitf3a4607d6a722a862af0eb9747a15dcdf624b6fb (patch)
tree9885709cdff55a865be6c03c591a9757680b0396 /src/browser.cpp
parentChange spdlog from makedepends to depends (diff)
downloadsmolbote-f3a4607d6a722a862af0eb9747a15dcdf624b6fb.tar.xz
Drop boost dependency
- wrote not-invented-here config file parser and conf class - spent obscene amount of time plugging in said conf class
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp91
1 files changed, 46 insertions, 45 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 0b076ca..d677997 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -9,9 +9,9 @@
#include "browser.h"
#include "aboutdialog.h"
#include "aboutplugin.h"
-#include "addressbar.h"
+#include "mainwindow/addressbar.h"
#include "bookmarkswidget.h"
-#include "config.h"
+#include "conf.hpp"
#include "configuration.h"
#include "downloadswidget.h"
#include "mainwindow/mainwindow.h"
@@ -39,6 +39,8 @@
#include "hostlist/hostlist.h"
#include <spdlog/spdlog.h>
#include <pluginloader.h>
+#include <QLibraryInfo>
+#include <QTranslator>
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
@@ -46,6 +48,29 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
setApplicationName(CONFIG_POI_NAME);
setWindowIcon(QIcon(CONFIG_POI_ICON));
setApplicationVersion(QVersionNumber::fromString(QLatin1String(poi_Version)).toString());
+
+ Configuration conf;
+
+ if(const auto _translation = conf.value<QString>("browser.translation")) {
+ auto *translator = new QTranslator(this);
+ if(translator->load(_translation.value()))
+ installTranslator(translator);
+ else
+ delete translator;
+ }
+
+ if(const auto _locale = conf.value<QString>("browser.locale")) {
+ auto *locale = new QTranslator(this);
+ if(locale->load("qt_" + _locale.value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ installTranslator(locale);
+ else
+ delete locale;
+ }
+
+ if(auto iconTheme = conf.value<QString>("browser.iconTheme")) {
+ QIcon::setThemeName(iconTheme.value());
+ }
+
}
Browser::~Browser()
@@ -66,25 +91,6 @@ void Browser::about()
dlg->exec();
}
-const QStringList Browser::configurationOptions() const
-{
- QStringList options;
- for(const auto &option : m_config->description().options()) {
- options.append(QString::fromStdString(option->long_name()));
- }
- return options;
-}
-
-const QString Browser::configuration(const QString &key) const
-{
- return m_config->value<QString>(qUtf8Printable(key)).value_or(QString());
-}
-
-void Browser::setConfiguration(const QString &key, const QString &value)
-{
- m_config->setValue(qUtf8Printable(key), value);
-}
-
const QList<QPair<QString, Profile *>> Browser::profileList() const
{
QList<QPair<QString, Profile *>> profiles;
@@ -96,6 +102,8 @@ const QList<QPair<QString, Profile *>> Browser::profileList() const
QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheRecord)
{
+ Configuration conf;
+
const QString _id = [id](){
// if id contains a separator, it should be a path
if(id.contains(QDir::separator())) {
@@ -112,7 +120,7 @@ QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheR
for(UrlFilter *filter : m_filters) {
interceptor->addFilter(filter);
}
- const auto headers = m_config->value<QStringList>("filter.header").value_or(QStringList());
+ const auto headers = conf.value<QStringList>("filter.header").value_or(QStringList());
for(const QString &header : headers) {
const auto h = header.split(QLatin1Literal(":"));
if(h.length() == 2)
@@ -129,18 +137,6 @@ void Browser::removeProfile(const QString &id)
m_profileManager->deleteProfile(id);
}
-void Browser::setConfiguration(std::unique_ptr<Configuration> &config)
-{
- Q_ASSERT(config);
- m_config = std::move(config);
-}
-
-Configuration *Browser::getConfiguration() const
-{
- Q_ASSERT(m_config);
- return m_config.get();
-}
-
WebProfileManager *Browser::getProfileManager()
{
return m_profileManager;
@@ -172,13 +168,13 @@ QPluginLoader *Browser::addPlugin(const QString &path)
void Browser::setup(QVector<QPluginLoader *> plugins)
{
- Q_ASSERT(m_config);
+ Configuration conf;
+
for(QPluginLoader *loader : plugins) {
m_plugins.append(new PluginInfo(loader));
}
- auto stylesheet = m_config->value<QString>("browser.stylesheet");
- if(stylesheet) {
+ if(auto stylesheet = conf.value<QString>("browser.stylesheet")) {
QFile f(stylesheet.value());
if(f.open(QIODevice::ReadOnly)) {
setStyleSheet(f.readAll());
@@ -187,16 +183,17 @@ void Browser::setup(QVector<QPluginLoader *> plugins)
}
// downloads
- m_downloads = std::make_unique<DownloadsWidget>(m_config->value<QString>("downloads.path").value());
+ m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads.path").value());
+
// url request filter
- for(const QString &hostlist : Util::files(m_config->value<QString>("filter.hosts").value_or(QString()))) {
+ for(const QString &hostlist : Util::files(conf.value<QString>("filter.hosts").value_or(QString()))) {
QFile f(hostlist);
if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_filters.append(new HostList(&f));
f.close();
}
}
- for(const QString &adblock : Util::files(m_config->value<QString>("filter.adblock").value_or(QString()))) {
+ for(const QString &adblock : Util::files(conf.value<QString>("filter.adblock").value_or(QString()))) {
QFile f(adblock);
if(f.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_filters.append(new AdBlockList(&f));
@@ -206,14 +203,18 @@ void Browser::setup(QVector<QPluginLoader *> plugins)
// cookie request filter
// load profiles
- m_profileManager = new WebProfileManager(m_config->section("profile"), this);
- for(const QString &profilePath : Util::files(m_config->value<QString>("profile.path").value(), { "*.profile" })) {
+ ProfileDefault_t p;
+ p.search = conf.value<QString>("profile.search").value();
+ p.homepage = conf.value<QString>("profile.homepage").value();
+ p.newtab = conf.value<QString>("profile.newtab").value();
+ m_profileManager = new WebProfileManager(p, this);
+ for(const QString &profilePath : Util::files(conf.value<QString>("profile.path").value(), { "*.profile" })) {
this->loadProfile(profilePath);
}
// set default profile
{
- const QString id = m_config->value<QString>("profile.default").value();
+ const QString id = conf.value<QString>("profile.default").value();
auto *profile = m_profileManager->profile(id);
if(profile == nullptr) {
profile = qobject_cast<WebProfile *>(loadProfile(id).second);
@@ -223,7 +224,7 @@ void Browser::setup(QVector<QPluginLoader *> plugins)
}
// bookmarks
- m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
+ m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value()));
connect(m_bookmarks.get(), &BookmarksWidget::showContextMenu, this, [this](const QUrl &url, const QPoint &pos) {
auto *subwindow = m_windows.last()->currentSubWindow();
if(subwindow == nullptr)
@@ -276,7 +277,7 @@ void Browser::showWidget(QWidget *widget, MainWindow *where) const
MainWindow *Browser::createWindow()
{
// the window will delete itself when it closes, so we don't need to delete it
- auto *window = new MainWindow(m_config);
+ auto *window = new MainWindow();
connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search);
for(auto *info : m_plugins) {