2023-02-03 16:17:47 +01:00
|
|
|
|
2023-02-03 17:03:10 +01:00
|
|
|
#include <QGuiApplication>
|
2019-03-27 18:38:36 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QStringList>
|
2020-02-15 17:49:48 +01:00
|
|
|
#include <QVector>
|
2019-03-27 18:38:36 +01:00
|
|
|
#include <QtGlobal>
|
2023-07-29 11:21:05 +02:00
|
|
|
#include <QtWebEngineQuick>
|
|
|
|
|
|
|
|
#include "ScreenPlayWallpaper/CMakeVariables.h"
|
2019-03-10 21:20:55 +01:00
|
|
|
|
2023-01-22 16:28:15 +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 "ScreenPlayUtil/util.h"
|
2021-04-18 17:23:21 +02:00
|
|
|
|
2019-03-10 21:20:55 +01:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include "src/winwindow.h"
|
2022-04-23 20:15:32 +02:00
|
|
|
Q_IMPORT_QML_PLUGIN(ScreenPlaySysInfoPlugin)
|
2021-05-12 17:42:38 +02:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2023-10-29 11:26:42 +01:00
|
|
|
#include "src/linuxwaylandwindow.h"
|
2023-11-01 12:28:35 +01:00
|
|
|
#include "src/linuxx11window.h"
|
2023-11-09 18:06:52 +01:00
|
|
|
#elif defined(Q_OS_MACOS)
|
2019-04-04 17:20:13 +02:00
|
|
|
#include "src/macwindow.h"
|
2019-03-27 18:38:36 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-20 17:55:26 +01: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-02-18 16:46:47 +01:00
|
|
|
int main(int argc, char* argv[])
|
2023-01-28 11:02:10 +01:00
|
|
|
{
|
2023-12-03 11:43:17 +01:00
|
|
|
using namespace ScreenPlay;
|
2023-07-29 11:21:05 +02:00
|
|
|
QtWebEngineQuick::initialize();
|
|
|
|
|
2023-02-03 16:17:47 +01:00
|
|
|
QGuiApplication app(argc, argv);
|
2023-12-20 15:11:16 +01:00
|
|
|
|
|
|
|
QCoreApplication::setApplicationName("ScreenPlayWallpaper");
|
|
|
|
QCoreApplication::setApplicationVersion("1.0");
|
2023-10-29 18:10:13 +01:00
|
|
|
std::unique_ptr<const ScreenPlayUtil::LoggingHandler> logging;
|
2023-10-29 11:26:42 +01:00
|
|
|
std::unique_ptr<BaseWindow> window;
|
2019-11-23 11:40:52 +01:00
|
|
|
|
2023-01-20 14:42:48 +01:00
|
|
|
#if defined(Q_OS_WIN)
|
2023-10-29 11:26:42 +01:00
|
|
|
window = std::make_unique<WinWindow>();
|
2023-01-20 14:42:48 +01:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2024-02-02 16:28:19 +01:00
|
|
|
const auto platformName = QGuiApplication::platformName();
|
2023-11-01 12:28:35 +01:00
|
|
|
if (platformName == "xcb") {
|
|
|
|
window = std::make_unique<LinuxX11Window>();
|
|
|
|
} else if (platformName == "wayland") {
|
2023-10-29 11:26:42 +01:00
|
|
|
window = std::make_unique<LinuxWaylandWindow>();
|
|
|
|
}
|
2023-11-09 18:06:52 +01:00
|
|
|
#elif defined(Q_OS_MACOS)
|
2023-10-29 11:26:42 +01:00
|
|
|
window = std::make_unique<MacWindow>();
|
2023-01-20 14:42:48 +01:00
|
|
|
#endif
|
2019-03-27 18:38:36 +01:00
|
|
|
|
2019-03-24 16:52:07 +01:00
|
|
|
// If we start with only one argument (app path)
|
|
|
|
// It means we want to test a single wallpaper
|
2019-07-27 11:36:33 +02:00
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
QStringList argumentList;
|
|
|
|
if (app.arguments().length() == 1) {
|
2023-02-18 14:30:06 +01:00
|
|
|
QString exampleContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
|
|
|
|
QStringList contentFolder = {
|
2023-07-29 11:18:21 +02:00
|
|
|
"/wallpaper_html", // 0
|
|
|
|
"/wallpaper_qml", // 1
|
|
|
|
"/wallpaper_qml_landscape", // 2
|
|
|
|
"/wallpaper_qml_particles", // 3
|
|
|
|
"/wallpaper_video_astronaut_vp9", // 4
|
|
|
|
"/wallpaper_video_nebula_h264" // 5
|
2023-02-18 14:30:06 +01:00
|
|
|
};
|
2023-10-29 18:10:13 +01:00
|
|
|
const int index = 5;
|
2023-07-29 11:18:21 +02:00
|
|
|
QString projectPath = exampleContentPath + contentFolder.at(index);
|
2023-02-18 14:30:06 +01:00
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
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",
|
|
|
|
"--screens", "{0}",
|
|
|
|
"--volume", "1",
|
|
|
|
"--fillmode", "Contain",
|
|
|
|
"--type", "VideoWallpaper",
|
2024-01-05 16:51:11 +01:00
|
|
|
"--check", "0",
|
|
|
|
"--mainapppid", "1" });
|
2023-01-20 14:42:48 +01:00
|
|
|
} else {
|
2023-12-20 15:11:16 +01:00
|
|
|
argumentList = app.arguments();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription("ScreenPlay Wallpaper");
|
|
|
|
parser.addHelpOption();
|
|
|
|
|
|
|
|
// Define the command line options
|
2023-12-21 13:18:23 +01:00
|
|
|
QCommandLineOption pathOption("projectpath", "Set the project path.", "projectpath");
|
2023-12-20 15:11:16 +01:00
|
|
|
QCommandLineOption appIDOption("appID", "Set the application ID.", "appID");
|
|
|
|
QCommandLineOption screensOption("screens", "Set screens parameter.", "screens");
|
|
|
|
QCommandLineOption volumeOption("volume", "Set volume level.", "volume");
|
|
|
|
QCommandLineOption fillmodeOption("fillmode", "Set fill mode.", "fillmode");
|
|
|
|
QCommandLineOption typeOption("type", "Set the type.", "type");
|
|
|
|
QCommandLineOption checkOption("check", "Set check value.", "check");
|
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
|
|
|
|
|
|
|
// Add the options to the parser
|
|
|
|
parser.addOption(pathOption);
|
|
|
|
parser.addOption(appIDOption);
|
|
|
|
parser.addOption(screensOption);
|
|
|
|
parser.addOption(volumeOption);
|
|
|
|
parser.addOption(fillmodeOption);
|
|
|
|
parser.addOption(typeOption);
|
|
|
|
parser.addOption(checkOption);
|
2024-01-05 16:51:11 +01:00
|
|
|
parser.addOption(mainAppPidOption);
|
2023-12-20 15:11:16 +01:00
|
|
|
|
|
|
|
// Process the actual command line arguments given by the user
|
|
|
|
parser.process(argumentList);
|
|
|
|
|
|
|
|
// Check if all required options are provided
|
|
|
|
if (!parser.isSet(pathOption)
|
|
|
|
|| !parser.isSet(appIDOption)
|
|
|
|
|| !parser.isSet(screensOption)
|
|
|
|
|| !parser.isSet(volumeOption)
|
|
|
|
|| !parser.isSet(fillmodeOption)
|
|
|
|
|| !parser.isSet(typeOption)
|
2024-01-05 16:51:11 +01:00
|
|
|
|| !parser.isSet(checkOption)
|
|
|
|
|| !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)
|
|
|
|
<< "volumeOption" << parser.value(volumeOption)
|
|
|
|
<< "fillmodeOption" << parser.value(fillmodeOption)
|
|
|
|
<< "typeOption" << parser.value(typeOption)
|
2024-01-05 16:51:11 +01:00
|
|
|
<< "checkOption" << parser.value(checkOption)
|
|
|
|
<< "mainAppPidOption" << parser.value(mainAppPidOption);
|
2023-12-20 15:11:16 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString path = parser.value(pathOption);
|
|
|
|
QString appID = parser.value(appIDOption);
|
|
|
|
QString screens = parser.value(screensOption);
|
|
|
|
QString volume = parser.value(volumeOption);
|
|
|
|
QString fillmode = parser.value(fillmodeOption);
|
|
|
|
QString type = parser.value(typeOption);
|
|
|
|
QString check = parser.value(checkOption);
|
2024-01-05 16:51:11 +01:00
|
|
|
QString pid = parser.value(mainAppPidOption);
|
2023-12-20 15:11:16 +01:00
|
|
|
|
|
|
|
ScreenPlay::Util util;
|
|
|
|
|
|
|
|
auto activeScreensList = util.parseStringToIntegerList(screens);
|
|
|
|
if (!activeScreensList.has_value()) {
|
|
|
|
qCritical() << "Could not parse activeScreensList" << screens;
|
|
|
|
return static_cast<int>(WallpaperExit::Code::Invalid_ActiveScreensList);
|
2019-03-14 18:56:19 +01:00
|
|
|
}
|
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
auto installedType = util.getInstalledTypeFromString(type);
|
|
|
|
if (!installedType.has_value()) {
|
|
|
|
qCritical() << "Cannot parse Wallpaper type from value" << type;
|
|
|
|
return static_cast<int>(WallpaperExit::Code::Invalid_InstalledType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool okParseCheckWallpaperVisible = false;
|
|
|
|
const bool checkWallpaperVisible = check.toInt(&okParseCheckWallpaperVisible);
|
|
|
|
if (!okParseCheckWallpaperVisible) {
|
|
|
|
qCritical("Could not parse checkWallpaperVisible");
|
|
|
|
return static_cast<int>(WallpaperExit::Code::Invalid_CheckWallpaperVisible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool okParseVolume = false;
|
|
|
|
const float volumeFloat = volume.toFloat(&okParseVolume);
|
|
|
|
if (!okParseVolume) {
|
|
|
|
qCritical("Could not parse Volume");
|
|
|
|
return static_cast<int>(WallpaperExit::Code::Invalid_Volume);
|
|
|
|
}
|
|
|
|
|
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>(WallpaperExit::Code::Invalid_PID);
|
|
|
|
}
|
|
|
|
|
2023-12-20 15:11:16 +01:00
|
|
|
// Set the properties of the window object
|
|
|
|
window->setActiveScreensList(activeScreensList.value());
|
|
|
|
window->setProjectPath(path);
|
|
|
|
window->setAppID(appID);
|
|
|
|
window->setVolume(volumeFloat);
|
|
|
|
window->setFillMode(fillmode);
|
|
|
|
window->setType(installedType.value());
|
|
|
|
window->setCheckWallpaperVisible(checkWallpaperVisible);
|
|
|
|
window->setDebugMode(false);
|
2024-01-05 16:51:11 +01:00
|
|
|
window->setMainAppPID(mainAppPidInt);
|
2023-12-20 15:11:16 +01:00
|
|
|
|
2023-10-29 11:26:42 +01:00
|
|
|
const auto setupStatus = window->setup();
|
2023-12-03 11:43:17 +01:00
|
|
|
if (setupStatus != WallpaperExit::Code::Ok) {
|
2023-01-20 14:42:48 +01:00
|
|
|
return static_cast<int>(setupStatus);
|
2018-02-18 16:46:47 +01:00
|
|
|
}
|
2023-10-29 11:26:42 +01:00
|
|
|
const auto startStatus = window->start();
|
2023-12-03 11:43:17 +01:00
|
|
|
if (startStatus != WallpaperExit::Code::Ok) {
|
2023-01-20 14:42:48 +01:00
|
|
|
return static_cast<int>(startStatus);
|
2020-02-15 17:49:48 +01:00
|
|
|
}
|
2023-10-29 11:26:42 +01:00
|
|
|
emit window->qmlStart();
|
2023-12-20 15:11:16 +01:00
|
|
|
logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlayWallpaper_" + parser.value(appIDOption));
|
2023-10-29 18:10:13 +01:00
|
|
|
const int status = app.exec();
|
|
|
|
logging.reset();
|
|
|
|
return status;
|
2018-01-31 21:54:25 +01:00
|
|
|
}
|