/* * 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 "browser.h" #include "src/mainwindow/mainwindow.h" #include "version.h" #include #include #include #include // startup time measuring #ifdef QT_DEBUG #include #endif int main(int argc, char **argv) { // Create application object Browser instance(argc, argv); instance.setApplicationVersion(SMOLBOTE_VERSION); #ifdef QT_DEBUG QElapsedTimer timer; timer.start(); #endif QCommandLineParser parser; parser.setApplicationDescription("yet another no-frills browser"); parser.addHelpOption(); parser.addVersionOption(); // user config, ~/.config/smolbote/smolbote.cfg or empty if there is none QCommandLineOption configOption({ "c", "config" }, "Set configuration file.", "path"); { // try to locate an existing config QString path = QStandardPaths::locate(QStandardPaths::AppConfigLocation, "smolbote.cfg"); // it's possible there is no config, so set the path properly if(path.isEmpty()) path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/smolbote.cfg"; configOption.setDefaultValue(path); } parser.addOption(configOption); // default config, :/poi.cfg QCommandLineOption defaultConfigOption("default-config", "Set the default configuration file.", "path"); defaultConfigOption.setDefaultValue(":/poi.cfg"); parser.addOption(defaultConfigOption); QCommandLineOption profileOption({ "p", "profile" }, "Use this profile.", "PROFILE"); profileOption.setDefaultValue(""); parser.addOption(profileOption); QCommandLineOption socketOption("socket", "Set socket to use for IPC, leave blank for default, 'none' to disable.", "name"); socketOption.setDefaultValue(""); parser.addOption(socketOption); QCommandLineOption newWindowOption("in-new-window", "Open URL in new window"); parser.addOption(newWindowOption); parser.addPositionalArgument("URL", "URL(s) to open"); parser.process(instance); #ifdef QT_DEBUG qDebug("config=%s", qUtf8Printable(parser.value(configOption))); qDebug("default-config=%s", qUtf8Printable(parser.value(defaultConfigOption))); qDebug("socket=%s", qUtf8Printable(parser.value(socketOption))); qDebug("profile=%s", qUtf8Printable(parser.value(profileOption))); #endif std::shared_ptr config = std::make_shared( parser.value(configOption).toStdString(), QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()); // first load the default configuration config->read(parser.value(defaultConfigOption)); // then load in the user configuration, which will overwrite it config->read(parser.value(configOption)); // check for other instances // if we socket hasn't been disabled (socket is not none) if(parser.value(socketOption) != "none") { bool bindOk = instance.bindLocalSocket(parser.value(socketOption)); if(bindOk) { qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName())); } else { // pass arguments to new instance return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments()); } } instance.setConfiguration(config); if(parser.isSet(profileOption)) instance.createSession(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments()); else instance.createSession(QString::fromStdString(config->value("browser.profile").value()), parser.isSet(newWindowOption), parser.positionalArguments()); #ifdef QT_DEBUG qDebug("Startup complete in %lldms", timer.elapsed()); #endif // Normally we'd use //return instance.exec(); // but, Call to "exec" is ambiguous return static_cast(&instance)->exec(); }