2023-01-19 10:33:49 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
|
2023-02-03 16:17:47 +01:00
|
|
|
|
2023-06-11 10:07:39 +02:00
|
|
|
#include "ScreenPlayWidget/CMakeVariables.h"
|
2023-02-03 17:03:10 +01:00
|
|
|
#include <QGuiApplication>
|
2018-03-08 22:03:05 +01:00
|
|
|
#include <QQmlApplicationEngine>
|
2023-06-11 10:07:39 +02:00
|
|
|
#include <QQmlExtensionPlugin>
|
2023-02-18 14:30:06 +01:00
|
|
|
#include <QString>
|
2018-03-21 18:56:58 +01:00
|
|
|
#include <QStringList>
|
2023-07-29 11:21:05 +02:00
|
|
|
#include <QtWebEngineQuick>
|
2023-02-18 14:30:06 +01:00
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
#include "ScreenPlayUtil/contenttypes.h"
|
2024-01-05 16:51:11 +01:00
|
|
|
#include "ScreenPlayUtil/exitcodes.h"
|
2023-10-29 18:10:13 +01:00
|
|
|
#include "ScreenPlayUtil/logginghandler.h"
|
2023-11-01 12:28:35 +01:00
|
|
|
#include "src/widgetwindow.h"
|
2018-03-21 18:56:58 +01:00
|
|
|
|
2022-04-23 20:15:32 +02:00
|
|
|
#if defined(Q_OS_WIN)
|
2022-02-20 17:55:26 +01:00
|
|
|
Q_IMPORT_QML_PLUGIN(ScreenPlaySysInfoPlugin)
|
2022-04-23 20:15:32 +02:00
|
|
|
#endif
|
2023-11-09 18:06:52 +01:00
|
|
|
#if defined(Q_OS_MACOS)
|
2023-02-04 17:34:59 +01:00
|
|
|
#include "ScreenPlayUtil/macutils.h"
|
|
|
|
#endif
|
2022-04-23 20:15:32 +02:00
|
|
|
|
|
|
|
Q_IMPORT_QML_PLUGIN(ScreenPlayWeatherPlugin)
|
2023-12-03 11:43:17 +01:00
|
|
|
Q_IMPORT_QML_PLUGIN(ScreenPlayUtilPlugin)
|
2022-02-20 17:55:26 +01:00
|
|
|
|
2018-03-21 18:56:58 +01:00
|
|
|
int main(int argc, char* argv[])
|
2018-03-08 22:03:05 +01:00
|
|
|
{
|
2023-01-27 11:12:45 +01:00
|
|
|
|
2024-01-05 16:51:11 +01:00
|
|
|
using namespace ScreenPlay;
|
2023-07-29 11:21:05 +02:00
|
|
|
// Lets keep using it until: https://bugreports.qt.io/browse/QTBUG-109401
|
|
|
|
QtWebEngineQuick::initialize();
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
2023-08-20 11:59:02 +02:00
|
|
|
// Workaround for Qt 6.5.1 crash https://bugreports.qt.io/browse/QTBUG-113832
|
2023-07-29 11:21:39 +02:00
|
|
|
qputenv("QT_DISABLE_HW_TEXTURES_CONVERSION", "1");
|
2023-01-28 11:02:10 +01:00
|
|
|
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
|
2023-01-27 11:12:45 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-03 16:17:47 +01:00
|
|
|
QGuiApplication app(argc, argv);
|
2023-10-29 18:10:13 +01:00
|
|
|
std::unique_ptr<const ScreenPlayUtil::LoggingHandler> logging;
|
2018-03-08 22:03:05 +01:00
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
QStringList argumentList;
|
2018-03-21 18:56:58 +01:00
|
|
|
|
2020-01-10 15:26:25 +01:00
|
|
|
// If we start with only one argument (path, appID, type),
|
2019-03-27 18:38:36 +01:00
|
|
|
// it means we want to test a single widget
|
2023-12-20 15:11:16 +01:00
|
|
|
if (app.arguments().length() == 1) {
|
2023-02-18 14:30:06 +01:00
|
|
|
QString exampleContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
|
2023-12-20 15:11:16 +01:00
|
|
|
using namespace ScreenPlay;
|
|
|
|
QList<QPair<QString, ContentTypes::InstalledType>> contentFolder = {
|
|
|
|
{ "/widget_weather", ContentTypes::InstalledType::QMLWidget }, // 0
|
|
|
|
{ "/widget_system_stats", ContentTypes::InstalledType::QMLWidget }, // 1 (Note: Windows only)
|
|
|
|
{ "/widget_hello_world", ContentTypes::InstalledType::QMLWidget }, // 2
|
|
|
|
{ "/widget_year_count_down", ContentTypes::InstalledType::QMLWidget }, // 3
|
|
|
|
{ "/widget_analog_clock", ContentTypes::InstalledType::QMLWidget }, // 4
|
|
|
|
{ "/widget_digital_clock", ContentTypes::InstalledType::QMLWidget }, // 5
|
|
|
|
{ "/widget_rss_hackernews", ContentTypes::InstalledType::QMLWidget }, // 6
|
|
|
|
{ "/widget_rss_guardian_news", ContentTypes::InstalledType::QMLWidget }, // 7
|
|
|
|
{ "/widget_xkcd", ContentTypes::InstalledType::QMLWidget }, // 8
|
2023-02-18 14:30:06 +01:00
|
|
|
};
|
2023-07-29 11:18:21 +02:00
|
|
|
const int index = 5;
|
2023-12-20 15:11:16 +01:00
|
|
|
QString projectPath = exampleContentPath + contentFolder.at(index).first;
|
2023-07-29 11:18:21 +02:00
|
|
|
|
|
|
|
// Lets center the widget
|
|
|
|
const auto* screen = QGuiApplication::screens().at(0);
|
2023-08-20 11:59:02 +02:00
|
|
|
const int offset = -200;
|
2023-12-20 15:11:16 +01:00
|
|
|
const QPoint center((screen->size().width() / 2) + offset, (screen->size().height() / 2) + offset);
|
|
|
|
const QString type = QVariant::fromValue<ContentTypes::InstalledType>(contentFolder.at(index).second).toString();
|
|
|
|
|
|
|
|
argumentList.append(
|
|
|
|
QStringList {
|
|
|
|
// Docs: Don't forget that arguments must start with the name of the executable (ignored, though).
|
|
|
|
QGuiApplication::applicationName(),
|
2023-12-21 13:18:23 +01:00
|
|
|
"--projectpath", projectPath,
|
2023-12-20 15:11:16 +01:00
|
|
|
"--appID", "qmz9lq4wglox5DdYaXumVgRSDeZYAUjC",
|
|
|
|
"--type", type,
|
|
|
|
"--posX", QString::number(center.x()),
|
|
|
|
"--posY", QString::number(center.y()),
|
2024-01-05 16:51:11 +01:00
|
|
|
"--mainapppid", "1" });
|
2023-12-20 15:11:16 +01:00
|
|
|
} else {
|
|
|
|
argumentList = app.arguments();
|
2019-03-24 16:52:07 +01:00
|
|
|
}
|
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription("ScreenPlay Widget");
|
|
|
|
parser.addHelpOption();
|
2023-12-21 13:18:23 +01:00
|
|
|
QCommandLineOption pathOption("projectpath", "Project path", "projectpath");
|
2023-12-20 15:11:16 +01:00
|
|
|
QCommandLineOption appIDOption("appID", "Application ID", "appid");
|
|
|
|
QCommandLineOption typeOption("type", "Content type", "type");
|
|
|
|
QCommandLineOption posXOption("posX", "X position", "positionX");
|
|
|
|
QCommandLineOption posYOption("posY", "Y position", "positionY");
|
2024-01-05 16:51:11 +01:00
|
|
|
QCommandLineOption mainAppPidOption("mainapppid", "pid of the main ScreenPlay app. User to check if we are still alive.", "mainapppid");
|
2023-12-20 15:11:16 +01:00
|
|
|
|
2024-01-05 16:51:11 +01:00
|
|
|
// Add the options to the parser
|
2023-12-20 15:11:16 +01:00
|
|
|
parser.addOption(pathOption);
|
|
|
|
parser.addOption(appIDOption);
|
|
|
|
parser.addOption(typeOption);
|
|
|
|
parser.addOption(posXOption);
|
|
|
|
parser.addOption(posYOption);
|
2024-01-05 16:51:11 +01:00
|
|
|
parser.addOption(mainAppPidOption);
|
2023-12-20 15:11:16 +01:00
|
|
|
|
2024-01-05 16:51:11 +01:00
|
|
|
// Process the actual command line arguments given by the user
|
2023-12-20 15:11:16 +01:00
|
|
|
parser.process(argumentList);
|
|
|
|
|
|
|
|
// Check if all required options are provided
|
|
|
|
if (!parser.isSet(pathOption)
|
|
|
|
|| !parser.isSet(appIDOption)
|
|
|
|
|| !parser.isSet(typeOption)
|
|
|
|
|| !parser.isSet(posXOption)
|
2024-01-05 16:51:11 +01:00
|
|
|
|| !parser.isSet(posYOption)
|
|
|
|
|| !parser.isSet(mainAppPidOption)) {
|
2023-12-20 15:11:16 +01:00
|
|
|
qCritical() << "Missing required arguments. Please provide all arguments."
|
|
|
|
<< argumentList
|
|
|
|
<< "pathOption" << parser.value(pathOption)
|
|
|
|
<< "appIDOption" << parser.value(appIDOption)
|
|
|
|
<< "typeOption" << parser.value(typeOption)
|
|
|
|
<< "posXOption" << parser.value(posXOption)
|
2024-01-05 16:51:11 +01:00
|
|
|
<< "posYOption" << parser.value(posYOption)
|
|
|
|
<< "mainAppPidOption" << parser.value(mainAppPidOption);
|
|
|
|
return static_cast<int>(WidgetExit::Code::Invalid_ArgumentSize);
|
2018-03-21 18:56:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-05 16:51:11 +01:00
|
|
|
QString pid = parser.value(mainAppPidOption);
|
|
|
|
QString appID = parser.value(appIDOption);
|
|
|
|
QString projectPath = parser.value(pathOption);
|
|
|
|
QString type = parser.value(typeOption);
|
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
bool okPosX = false, okPosY = false;
|
|
|
|
const int positionX = parser.value(posXOption).toInt(&okPosX);
|
2020-07-13 17:59:20 +02:00
|
|
|
if (!okPosX) {
|
2023-12-20 15:11:16 +01:00
|
|
|
qWarning() << "Could not parse PositionX value to int: " << parser.value(posXOption);
|
2024-01-05 16:51:11 +01:00
|
|
|
return static_cast<int>(WidgetExit::Code::Invalid_POSX);
|
2020-07-13 17:59:20 +02:00
|
|
|
}
|
2023-12-20 15:11:16 +01:00
|
|
|
|
|
|
|
const int positionY = parser.value(posYOption).toInt(&okPosY);
|
2020-07-13 17:59:20 +02:00
|
|
|
if (!okPosY) {
|
2023-12-20 15:11:16 +01:00
|
|
|
qWarning() << "Could not parse PositionY value to int: " << parser.value(posYOption);
|
2024-01-05 16:51:11 +01:00
|
|
|
return static_cast<int>(WidgetExit::Code::Invalid_POSY);
|
2020-07-13 17:59:20 +02:00
|
|
|
}
|
2023-12-20 15:11:16 +01:00
|
|
|
|
2024-01-05 16:51:11 +01:00
|
|
|
bool okPid = false;
|
|
|
|
const qint64 mainAppPidInt = pid.toInt(&okPid);
|
|
|
|
if (!okPid) {
|
|
|
|
qCritical("Could not parse mainAppPid");
|
|
|
|
return static_cast<int>(WidgetExit::Code::Invalid_PID);
|
2023-12-20 15:11:16 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 12:50:22 +02:00
|
|
|
WidgetWindow spwmw(
|
2023-12-20 15:11:16 +01:00
|
|
|
projectPath,
|
|
|
|
appID,
|
|
|
|
type,
|
|
|
|
QPoint { positionX, positionY },
|
2024-01-05 16:51:11 +01:00
|
|
|
mainAppPidInt,
|
|
|
|
false);
|
2023-02-18 14:30:06 +01:00
|
|
|
|
2023-11-09 18:06:52 +01:00
|
|
|
#if defined(Q_OS_MACOS)
|
2023-02-04 17:34:59 +01:00
|
|
|
MacUtils::showDockIcon(false);
|
|
|
|
#endif
|
2023-11-01 12:28:35 +01:00
|
|
|
logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlayWidget_" + appID);
|
2023-10-29 18:10:13 +01:00
|
|
|
const int status = app.exec();
|
|
|
|
logging.reset();
|
|
|
|
return status;
|
2018-03-08 22:03:05 +01:00
|
|
|
}
|