diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-11-19 18:22:36 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-11-19 18:22:36 +0200 |
commit | 1bc1ae8cd09851faa05345f5a6b105b02fe75dd2 (patch) | |
tree | 4fd33c0f8c79157031defd9f87f0dee4331b85de /src/session | |
parent | Remove updater (diff) | |
download | smolbote-1bc1ae8cd09851faa05345f5a6b105b02fe75dd2.tar.xz |
Drop args.hxx dependency
Replace args.hxx with QCommandLineParser.
Diffstat (limited to 'src/session')
-rw-r--r-- | src/session/builtin.cpp | 61 | ||||
-rw-r--r-- | src/session/meson.build | 1 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/session/builtin.cpp b/src/session/builtin.cpp new file mode 100644 index 0000000..0359b42 --- /dev/null +++ b/src/session/builtin.cpp @@ -0,0 +1,61 @@ +/* + * 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 <QCommandLineParser> +#include <variant> + +namespace builtins +{ +int sub_session(const QStringList &args, Browser &app) +{ + const auto default_profile = []() { + Configuration conf; + return conf.value<QString>("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; +} +} diff --git a/src/session/meson.build b/src/session/meson.build new file mode 100644 index 0000000..5ba8ffd --- /dev/null +++ b/src/session/meson.build @@ -0,0 +1 @@ +poi_sourceset.add(files('builtin.cpp')) |