2023-01-26 17:31:16 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QCommandLineParser>
|
2024-02-26 10:36:25 +00:00
|
|
|
#include <QMessageBox>
|
2023-01-26 17:31:16 +00:00
|
|
|
|
2023-06-20 12:20:47 +00:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2023-01-26 17:31:16 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
2023-07-03 14:49:06 +00:00
|
|
|
QCoreApplication::setOrganizationName("QtProject"_L1);
|
|
|
|
QCoreApplication::setApplicationName("DocumentViewer"_L1);
|
|
|
|
QCoreApplication::setApplicationVersion("1.0"_L1);
|
2023-01-26 17:31:16 +00:00
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(QApplication::translate("main",
|
|
|
|
"A viewer for JSON, PDF and text files"));
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
2023-06-20 12:20:47 +00:00
|
|
|
parser.addPositionalArgument("File"_L1, QApplication::translate("main",
|
|
|
|
"JSON, PDF or text file to open"));
|
2023-01-26 17:31:16 +00:00
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
const QStringList &positionalArguments = parser.positionalArguments();
|
|
|
|
const QString &fileName = (positionalArguments.count() > 0) ? positionalArguments.at(0)
|
|
|
|
: QString();
|
|
|
|
|
|
|
|
MainWindow w;
|
2024-02-26 10:36:25 +00:00
|
|
|
|
|
|
|
// Start application only if plugins are available
|
|
|
|
if (!w.hasPlugins()) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
"No viewer plugins found"_L1,
|
|
|
|
"Unable to load viewer plugins. Exiting application."_L1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-01-26 17:31:16 +00:00
|
|
|
w.show();
|
|
|
|
if (!fileName.isEmpty())
|
|
|
|
w.openFile(fileName);
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|