summaryrefslogtreecommitdiff
path: root/ui/qt5/main.cc
blob: 22ef39ec24d526b3a2f557e65291223d1814744f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * main.cc - Implementation of the main routine
 * horizon-qt5, the Qt 5 user interface for
 * Project Horizon
 *
 * Copyright (c) 2019 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#include <QApplication>
#include <QCommandLineParser>
#include <QDialog>
#include <QIcon>
#include <QLabel>
#include <QLibraryInfo>
#include <QTranslator>
#include <QVBoxLayout>

#include "horizonwizard.hh"

class WaitDialog : public QDialog {
public:
    WaitDialog(QWidget *parent = nullptr);
    void accept() override;
    void reject() override;
};

WaitDialog::WaitDialog(QWidget *parent) : QDialog(parent,
                                                  Qt::FramelessWindowHint) {
   setWindowTitle(tr("Loading..."));
   QVBoxLayout *layout = new QVBoxLayout;
   QLabel *descLabel = new QLabel(tr("System Installation is loading.\n\n"
                                     "Please wait a moment."));
   descLabel->setAlignment(Qt::AlignCenter);
   layout->addWidget(descLabel);
   setLayout(layout);
}

/* Prevents the user from interacting in any way. */
void WaitDialog::accept() { return; }
void WaitDialog::reject() { return; }

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    app.setOrganizationName("Adélie Linux");
    app.setApplicationName("Horizon Qt UI");
    app.setApplicationVersion(VERSTR);

    QString translatorFileName = QLatin1String("qt_");
    translatorFileName += QLocale::system().name();
    QTranslator *translator = new QTranslator(&app);
    if(translator->load(translatorFileName,
                        QLibraryInfo::location(
                                QLibraryInfo::TranslationsPath
                        ))) {
        app.installTranslator(translator);
    }

    WaitDialog d;
    d.show();
    app.setOverrideCursor(Qt::WaitCursor);
    app.processEvents(QEventLoop::AllEvents, 1000);

    app.setWindowIcon(QIcon(":/horizon-256.png"));

    QCommandLineParser parser;
    parser.setApplicationDescription(app.tr("Guides the user through creation of a HorizonScript."));
    QCommandLineOption help = parser.addHelpOption();
    QCommandLineOption version = parser.addVersionOption();

    if(!parser.parse(app.arguments())) {
        parser.showHelp(1);
        return 1;
    }

    if(parser.isSet(help)) {
        parser.showHelp();
        return 0;
    }

    if(parser.isSet(version)) {
        parser.showVersion();
        return 0;
    }

    HorizonWizard wizard;
    d.hide();
    app.restoreOverrideCursor();
    wizard.show();

    return app.exec();
}