/* * 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/cgit/smolbote * * SPDX-License-Identifier: GPL-3.0 */ #include "browser.h" #include "configuration.h" #include "session/sessiondialog.h" #include "session_json.hpp" #include #include namespace builtins { int sub_session(const QStringList &args, Browser &app) { const auto default_profile = []() { Configuration conf; return conf.value("profile.default").value(); }(); const auto session = args.count() == 0 ? JsonSession(default_profile, args) : [&]() { const QCommandLineOption profile({ "p", "profile" }, "Create session with specified profile.", "profile-id", default_profile); const QCommandLineOption pick("pick", "Show all available sessions and select which one to open."); const QCommandLineOption open({ "o", "open" }, "Open the specified session.", "file"); QCommandLineParser parser; parser.setApplicationDescription("session"); parser.addHelpOption(); parser.addOptions({ pick, open, profile }); parser.process(args); if(parser.isSet(pick)) { SessionDialog dlg; if(const auto s = dlg.pickSession()) { return JsonSession(s.value()); } } else if(parser.isSet(open)) { QFile sessionJson(parser.value(open)); if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { return JsonSession(sessionJson.readAll()); } } return JsonSession(parser.isSet(profile) ? parser.value(profile) : default_profile, args); }(); if(app.isPrimary() || !app.remoteEnabled()) { app.open(session.get()); return app.exec(); } app.sendMessage(session.serialize()); return 0; } }