cool-retro-term

Форк
0
/
main.cpp 
126 строк · 4.7 Кб
1
#include <QtQml/QQmlApplicationEngine>
2
#include <QtGui/QGuiApplication>
3

4
#include <QQmlContext>
5
#include <QStringList>
6

7
#include <QtWidgets/QApplication>
8
#include <QIcon>
9
#include <QQuickStyle>
10

11
#include <QDebug>
12
#include <stdlib.h>
13

14
#include <QFontDatabase>
15
#include <QLoggingCategory>
16

17
#include <fileio.h>
18
#include <monospacefontmanager.h>
19

20
QString getNamedArgument(QStringList args, QString name, QString defaultName)
21
{
22
    int index = args.indexOf(name);
23
    return (index != -1) ? args[index + 1] : QString(defaultName);
24
}
25

26
QString getNamedArgument(QStringList args, QString name)
27
{
28
    return getNamedArgument(args, name, "");
29
}
30

31
int main(int argc, char *argv[])
32
{
33
    // Some environmental variable are necessary on certain platforms.
34

35
    // This disables QT appmenu under Ubuntu, which is not working with QML apps.
36
    setenv("QT_QPA_PLATFORMTHEME", "", 1);
37

38
    // Disable Connections slot warnings
39
    QLoggingCategory::setFilterRules("qt.qml.connections.warning=false");
40

41
#if defined (Q_OS_LINUX)
42
    setenv("QSG_RENDER_LOOP", "threaded", 0);
43
#endif
44

45
#if defined(Q_OS_MAC)
46
    // This allows UTF-8 characters usage in OSX.
47
    setenv("LC_CTYPE", "UTF-8", 1);
48
#endif
49

50
    if (argc>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help"))) {
51
        QTextStream cout(stdout, QIODevice::WriteOnly);
52
        cout << "Usage: " << argv[0] << " [--default-settings] [--workdir <dir>] [--program <prog>] [-p|--profile <prof>] [--fullscreen] [-h|--help]" << endl;
53
        cout << "  --default-settings  Run cool-retro-term with the default settings" << endl;
54
        cout << "  --workdir <dir>     Change working directory to 'dir'" << endl;
55
        cout << "  -e <cmd>            Command to execute. This option will catch all following arguments, so use it as the last option." << endl;
56
        cout << "  -T <title>          Set window title to 'title'." << endl;
57
        cout << "  --fullscreen        Run cool-retro-term in fullscreen." << endl;
58
        cout << "  -p|--profile <prof> Run cool-retro-term with the given profile." << endl;
59
        cout << "  -h|--help           Print this help." << endl;
60
        cout << "  --verbose           Print additional information such as profiles and settings." << endl;
61
        return 0;
62
    }
63

64
    QString appVersion("1.2.0");
65

66
    if (argc>1 && (!strcmp(argv[1],"-v") || !strcmp(argv[1],"--version"))) {
67
        QTextStream cout(stdout, QIODevice::WriteOnly);
68
        cout << "cool-retro-term " << appVersion << endl;
69
        return 0;
70
    }
71

72
    QApplication app(argc, argv);
73
    app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
74

75
    QQmlApplicationEngine engine;
76
    FileIO fileIO;
77
    MonospaceFontManager monospaceFontManager;
78

79
#if !defined(Q_OS_MAC)
80
    app.setWindowIcon(QIcon::fromTheme("cool-retro-term", QIcon(":../icons/32x32/cool-retro-term.png")));
81
#else
82
    app.setWindowIcon(QIcon(":../icons/32x32/cool-retro-term.png"));
83
#endif
84

85
    app.setOrganizationName("cool-retro-term");
86
    app.setOrganizationDomain("cool-retro-term");
87

88
    // Manage command line arguments from the cpp side
89
    QStringList args = app.arguments();
90

91
    // Manage default command
92
    QStringList cmdList;
93
    if (args.contains("-e")) {
94
        cmdList << args.mid(args.indexOf("-e") + 1);
95
    }
96
    QVariant command(cmdList.empty() ? QVariant() : cmdList[0]);
97
    QVariant commandArgs(cmdList.size() <= 1 ? QVariant() : QVariant(cmdList.mid(1)));
98
    engine.rootContext()->setContextProperty("appVersion", appVersion);
99
    engine.rootContext()->setContextProperty("defaultCmd", command);
100
    engine.rootContext()->setContextProperty("defaultCmdArgs", commandArgs);
101

102
    engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir", "$HOME"));
103
    engine.rootContext()->setContextProperty("fileIO", &fileIO);
104
    engine.rootContext()->setContextProperty("monospaceSystemFonts", monospaceFontManager.retrieveMonospaceFonts());
105

106
    engine.rootContext()->setContextProperty("devicePixelRatio", app.devicePixelRatio());
107

108
    // Manage import paths for Linux and OSX.
109
    QStringList importPathList = engine.importPathList();
110
    importPathList.prepend(QCoreApplication::applicationDirPath() + "/qmltermwidget");
111
    importPathList.prepend(QCoreApplication::applicationDirPath() + "/../PlugIns");
112
    importPathList.prepend(QCoreApplication::applicationDirPath() + "/../../../qmltermwidget");
113
    engine.setImportPathList(importPathList);
114

115
    engine.load(QUrl(QStringLiteral ("qrc:/main.qml")));
116

117
    if (engine.rootObjects().isEmpty()) {
118
        qDebug() << "Cannot load QML interface";
119
        return EXIT_FAILURE;
120
    }
121

122
    // Quit the application when the engine closes.
123
    QObject::connect((QObject*) &engine, SIGNAL(quit()), (QObject*) &app, SLOT(quit()));
124

125
    return app.exec();
126
}
127

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.