File indexing completed on 2024-04-28 04:45:42

0001 #include <QApplication>
0002 #include <QQmlApplicationEngine>
0003 #include <QCommandLineParser>
0004 #include <QQmlContext>
0005 #include <QIcon>
0006 
0007 #include <MauiKit3/Core/mauiapp.h>
0008 #include <MauiKit3/Terminal/moduleinfo.h>
0009 
0010 #include <KI18n/KLocalizedString>
0011 #include <KAboutData>
0012 
0013 #include "helpers/keyshelper.h"
0014 #include "helpers/commandsmodel.h"
0015 #include "helpers/station.h"
0016 #include "helpers/fonts.h"
0017 
0018 #include "server/server.h"
0019 
0020 #include "../station_version.h"
0021 
0022 #define STATION_URI "org.maui.station"
0023 
0024 int main(int argc, char *argv[])
0025 {
0026     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0027     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0028 
0029     QApplication app(argc, argv);
0030 
0031     app.setOrganizationName("Maui");
0032     app.setWindowIcon(QIcon(":/station/station.svg"));
0033 
0034     KLocalizedString::setApplicationDomain("station");
0035     KAboutData about(QStringLiteral("station"),
0036                      i18n("Station"),
0037                      STATION_VERSION_STRING,
0038                      i18n("Convergent terminal emulator."),
0039                      KAboutLicense::LGPL_V3,
0040                      i18n("© 2019-2023 Maui Development Team"),
0041                      QString(GIT_BRANCH) + "/" + QString(GIT_COMMIT_HASH));
0042     about.addAuthor(i18n("Camilo Higuita"), i18n("Developer"), QStringLiteral("milo.h@aol.com"));
0043     about.setHomepage("https://mauikit.org");
0044     about.setProductName("maui/station");
0045     about.setBugAddress("https://invent.kde.org/maui/station/-/issues");
0046     about.setOrganizationDomain(STATION_URI);
0047     about.setProgramLogo(app.windowIcon());
0048 
0049     const auto TData = MauiKitTerminal::aboutData();
0050     about.addComponent(TData.name(), MauiKitTerminal::buildVersion(), TData.version(), TData.webAddress());
0051 
0052     about.addCredit("QMLTermWidget");
0053     about.addCredit("UBPorts Terminal");
0054     about.addCredit("Cutefish Terminal");
0055 
0056     KAboutData::setApplicationData(about);
0057 
0058     MauiApp::instance()->setIconName("qrc:/station/station.svg");
0059 
0060     QCommandLineParser parser;
0061 
0062     about.setupCommandLine(&parser);
0063     parser.process(app);
0064 
0065     about.processCommandLine(&parser);
0066     const QStringList args = parser.positionalArguments();
0067 
0068     QStringList paths;
0069     if (!args.isEmpty())
0070     {
0071         for(const auto &path : args)
0072             paths << QUrl::fromUserInput(path).toString();
0073     }
0074 
0075     if (AppInstance::attachToExistingInstance(QUrl::fromStringList(paths), false))
0076     {
0077         // Successfully attached to existing instance of Nota
0078         return 0;
0079     }
0080 
0081     AppInstance::registerService();
0082     auto server = std::make_unique<Server>();
0083 
0084     QQmlApplicationEngine engine;
0085     const QUrl url(QStringLiteral("qrc:/main.qml"));
0086     QObject::connect(
0087                 &engine,
0088                 &QQmlApplicationEngine::objectCreated,
0089                 &app,
0090                 [url, args, &server](QObject *obj, const QUrl &objUrl) {
0091         if (!obj && url == objUrl)
0092             QCoreApplication::exit(-1);
0093 
0094         server->setQmlObject(obj);
0095         if (!args.isEmpty())
0096             server->openTabs(args, false);
0097         else
0098         {
0099             server->openTabs({"$PWD"}, false);
0100         }
0101 
0102     },
0103     Qt::QueuedConnection);
0104 
0105     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0106 
0107     qmlRegisterAnonymousType<Key> (STATION_URI, 1);
0108     qmlRegisterType<KeysHelper> (STATION_URI, 1, 0, "KeysModel");
0109     qmlRegisterType<CommandsModel> (STATION_URI, 1, 0, "CommandsModel");
0110     qmlRegisterSingletonInstance<Station>(STATION_URI, 1, 0, "Station", Station::instance());
0111     qmlRegisterSingletonType<Fonts>(STATION_URI, 1, 0, "Fonts", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
0112         Q_UNUSED(engine)
0113         Q_UNUSED(scriptEngine)
0114         return new Fonts;
0115     });
0116 
0117     engine.load(url);
0118 
0119     return app.exec();
0120 }