diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-03 00:18:10 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-03 00:20:41 +0200 |
commit | f3a4607d6a722a862af0eb9747a15dcdf624b6fb (patch) | |
tree | 9885709cdff55a865be6c03c591a9757680b0396 /src/main.cpp | |
parent | Change spdlog from makedepends to depends (diff) | |
download | smolbote-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/main.cpp')
-rw-r--r-- | src/main.cpp | 98 |
1 files changed, 38 insertions, 60 deletions
diff --git a/src/main.cpp b/src/main.cpp index 02a1168..c6f4120 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,15 +15,15 @@ #include "util.h" #include "version.h" #include <QFile> -#include <QLibraryInfo> #include <QPluginLoader> -#include <QTranslator> #include <args.hxx> #include <iostream> #include <memory> #include <plugininterface.h> #include <pluginloader.h> #include <spdlog/spdlog.h> +#include "conf.hpp" +#include <QStandardPaths> typedef std::function<void(const std::string &, std::vector<std::string>::const_iterator, std::vector<std::string>::const_iterator)> subcommand_func; typedef std::unordered_map<std::string, subcommand_func> command_map; @@ -42,24 +42,6 @@ inline std::string join_keys(const command_map &map, const std::string sep = ", return k; } -#include <QStandardPaths> -inline std::string defaultUserConfigLocation() -{ -#ifdef CONFIG_PATH_CONFIG - return CONFIG_PATH_CONFIG; -#else - // try to locate an existing config - QString path = QStandardPaths::locate(QStandardPaths::ConfigLocation, "smolbote/smolbote.cfg"); - - // it's possible there is no config, so set the path properly - if(path.isEmpty()) - path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/smolbote/smolbote.cfg"; - - return path.toStdString(); -#endif -} - -#include "config.h" #if defined(CONFIG_USEPLASMA) && !defined(PLASMA) #error "You have enabled Plasma integration, but Frameworks was not found." #endif @@ -94,7 +76,7 @@ int main(int argc, char **argv) args::PositionalList<std::string> cmd_args(parser, "URL(s)", "List of URLs to open"); try { - auto next = parser.ParseArgs(args); + /*auto next = */parser.ParseArgs(args); if(cmd_version) return builtins::version(); @@ -121,52 +103,48 @@ int main(int argc, char **argv) // create and load configuration const std::string config_path = [&]() { + std::string path; if(cmd_config) - return args::get(cmd_config); + path = args::get(cmd_config); else - return defaultUserConfigLocation(); + path = std::string(CONFIG_POI_CFG_PATH); + + if(path.front() == '~') + path.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()); + + return path; }(); - std::unique_ptr<Configuration> config = std::make_unique<Configuration>(argc, argv, config_path); - QTranslator translator; - if(config->exists("browser.translation")) { - translator.load(config->value<QString>("browser.translation").value()); - } + spdlog::debug("Opening config file {}", config_path); + init_conf(config_path); + QVector<QPluginLoader *> plugins; CommandHash_t pluginCommands; // Load plugins - for(const QString &path : Util::files(config->value<QString>("plugins.path").value(), { "*.so", "*.dll" })) { - auto *loader = new PluginLoader(path); - const bool loaded = loader->load(); - spdlog::info("{} plugin {}", loaded ? "Loaded" : "Failed to load", qUtf8Printable(path)); - - if(loaded) { - plugins.append(loader); - auto *plugin = qobject_cast<PluginInterface *>(loader->instance()); - pluginCommands.unite(plugin->commands()); - } else { - spdlog::warn("{}", qUtf8Printable(loader->errorString())); - delete loader; - } + [&]() { + Configuration conf; + spdlog::debug("plugins.path={}", conf.value<std::string>("plugins.path").value()); + for(const QString &path : Util::files(conf.value<QString>("plugins.path").value(), { "*.so", "*.dll" })) { + auto *loader = new PluginLoader(path); + const bool loaded = loader->load(); + spdlog::info("{} plugin {}", loaded ? "Loaded" : "Failed to load", qUtf8Printable(path)); + + if(loaded) { + plugins.append(loader); + auto *plugin = qobject_cast<PluginInterface *>(loader->instance()); + pluginCommands.unite(plugin->commands()); + } else { + spdlog::warn("{}", qUtf8Printable(loader->errorString())); + delete loader; + } } + }(); // argc, argv, allowSecondary Browser app(argc, argv); // set this, otherwise the webview becomes black when using a stylesheet app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); - app.installTranslator(&translator); - if(config->exists("browser.locale")) { - auto *locale = new QTranslator(&app); - if(locale->load("qt_" + config->value<QString>("browser.locale").value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(locale); - else - delete locale; - } - - if(auto iconTheme = config->value<QString>("browser.iconTheme")) { - QIcon::setThemeName(iconTheme.value()); - } #ifdef CONFIG_USEBREAKPAD const std::string crashpath = config->value<std::string>("browser.crash.path").value_or("/tmp"); @@ -186,14 +164,14 @@ int main(int argc, char **argv) // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd google_breakpad::ExceptionHandler eh(descriptor, nullptr, CrashHandler::dumpCallback, &ctx, true, -1); -#ifdef QT_DEBUG - spdlog::info("Installed breakpad exception handler (path {})", crashpath); -#endif + spdlog::debug("Installed breakpad exception handler (path {})", crashpath); #endif // CONFIG_USEBREAKPAD - const auto profile = config->value<QString>("profile.default"); + const auto profile = [](){ + Configuration c; + return c.value<QString>("profile.default").value(); + }(); - app.setConfiguration(config); // app takes ownership of config app.setup(plugins); QStringList urls; @@ -225,7 +203,7 @@ int main(int argc, char **argv) if(const auto pick = dlg->pickSession()) sessionData = pick.value(); else - sessionData = Session::fromCommandLine(profile.value(), urls); + sessionData = Session::fromCommandLine(profile, urls); } else if(cmd_session) { QFile sessionJson(QString::fromStdString(args::get(cmd_session))); if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -233,7 +211,7 @@ int main(int argc, char **argv) sessionJson.close(); } } else { - sessionData = Session::fromCommandLine(profile.value(), urls); + sessionData = Session::fromCommandLine(profile, urls); } if(app.isPrimary() || cmd_noRemote) { |