/* * 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 "version.h" #include #include #include #include int main(int argc, char **argv) { // create and load configuration std::shared_ptr config = std::make_shared(); if(!config->parse(argc, argv)) { qWarning("Check --help for usage."); return -1; } if(!config->parse(config->value("config").value())) { qWarning("Error parsing config file."); } if(config->exists("help")) { std::cout << "smolbote " << SMOLBOTE_VERSION << ": yet another no-frills browser" << std::endl; std::cout << "Usage: " << argv[0] << " [options] URL(s)" << std::endl << std::endl; std::cout << "Command-line Options: " << std::endl << config->commandlineOptions() << std::endl; std::cout << "Configuration Options: " << std::endl << config->configurationOptions() << std::endl; #ifdef Q_OS_LINUX std::cout << std::endl << "For more information refer to the manual page smolbote.7" << std::endl; #endif return 0; } if(config->exists("version")) { std::cout << "smolbote " << SMOLBOTE_VERSION << std::endl; return 0; } if(config->exists("build")) { std::cout << SMOLBOTE_BRANCH << ":" << SMOLBOTE_COMMIT; return 0; } Browser app(argc, argv); // set this, otherwise the webview becomes black when using a stylesheet app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); app.setConfiguration(config); app.setup(QString::fromStdString(config->value("profile.default").value())); if(config->exists("commands")) { for(const QString &cmd : app.commands()) { std::cout << cmd.toStdString() << std::endl; } exit(0); } if(config->exists("command")) { exit(app.command(QString::fromStdString(config->value("command").value()))); } // set up socket bool isSingleInstance = app.bindLocalSocket(QString::fromStdString(config->value("socket").value())); #ifdef QT_DEBUG qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(QString::fromStdString(config->value("socket").value())), isSingleInstance ? "true" : "false"); #endif // if we are the only instance, set up the browser if(isSingleInstance) { auto stylesheet = config->value("browser.stylesheet"); if(stylesheet) { QFile f(QString::fromStdString(stylesheet.value())); if(f.open(QIODevice::ReadOnly)) { app.setStyleSheet(f.readAll()); f.close(); } } QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession); } app.sendMessage("", false, config->positionalArguments()); if(isSingleInstance) return app.exec(); else return 0; }