1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 12:13:00 +01:00

Add widget type to the ScreenPlayWidget executable as an argument. This can be ether qmlWidget or htmlWidget for now.

This commit is contained in:
Elias Steurer 2020-01-09 16:08:32 +01:00
parent 57001e500a
commit 04705a5ec3
9 changed files with 128 additions and 83 deletions

View File

@ -337,14 +337,14 @@ Item {
+ "/" + activeScreen,
ScreenPlay.installedListModel.get(activeScreen).screenPreview,
(Math.round(sliderVolume.value * 100) / 100),
settingsComboBox.model.get(settingsComboBox.currentIndex).text.toString(
), type)
settingsComboBox.model.get(settingsComboBox.currentIndex).text.toString(),
type)
} else {
ScreenPlay.screenPlayManager.createWidget(
ScreenPlay.globalVariables.localStoragePath + "/" + activeScreen,
ScreenPlay.installedListModel.get(
activeScreen).screenPreview)
ScreenPlay.installedListModel.get(activeScreen).screenPreview,
type)
}
sidebar.state = "inactive"
monitorSelection.deselectAll()

View File

@ -36,73 +36,87 @@ Create::Create()
void Create::createWidget(const QString& localStoragePath, const QString& title, const QString& previewThumbnail, const QString& createdBy, const QString& license, const QString& type, const QVector<QString>& tags)
{
QUrl localStoragePathUrl { localStoragePath };
QDir dir;
dir.cd(localStoragePathUrl.toLocalFile());
// Create a temp dir so we can later alter it to the workshop id
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
QtConcurrent::run([=]() {
QUrl localStoragePathUrl { localStoragePath };
QDir dir;
dir.cd(localStoragePathUrl.toLocalFile());
// Create a temp dir so we can later alter it to the workshop id
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
QString workingPath = dir.path() + "/" + folderName;
if (!dir.mkdir(folderName)) {
qDebug() << "Could create folder: " << folderName;
return;
}
QJsonObject obj;
obj.insert("license", license);
obj.insert("title", title);
obj.insert("createdBy", createdBy);
if (type == "QML") {
obj.insert("type", "qmlWidget");
obj.insert("file", "main.qml");
} else {
obj.insert("type", "htmlWidget");
obj.insert("file", "index.html");
}
QJsonArray tagsJsonArray;
for (QString tmp : tags) {
tagsJsonArray.append(tmp);
}
obj.insert("tags", tagsJsonArray);
QString workingPath = dir.path() + "/" + folderName;
QFile file(workingPath + "/project.json");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Could not open /project.json";
return;
}
QUrl previewThumbnailUrl { previewThumbnail };
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
if (!previewThumbnail.isEmpty()) {
obj.insert("previewThumbnail", previewImageFile.fileName());
obj.insert("preview", previewImageFile.fileName());
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
if (!dir.mkdir(folderName)) {
qDebug() << "Could create folder: " << folderName;
return;
}
}
QTextStream out(&file);
out.setCodec("UTF-8");
QJsonDocument doc(obj);
out << doc.toJson();
file.close();
QJsonObject obj;
obj.insert("license", license);
obj.insert("title", title);
obj.insert("createdBy", createdBy);
QFile fileMainQML(workingPath + "/main.qml");
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Could not open /main.qml";
return;
}
if (type == "QML") {
obj.insert("type", "qmlWidget");
obj.insert("file", "main.qml");
QTextStream outMainQML(&fileMainQML);
outMainQML.setCodec("UTF-8");
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
fileMainQML.close();
QFile fileMainQML(workingPath + "/main.qml");
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Could not open /main.qml";
return;
}
emit widgetCreatedSuccessful(workingPath);
QTextStream outMainQML(&fileMainQML);
outMainQML.setCodec("UTF-8");
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
fileMainQML.close();
} else {
obj.insert("type", "htmlWidget");
obj.insert("file", "index.html");
QFile fileMainHTML(workingPath + "/index.html");
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Could not open /index.html";
return;
}
QTextStream outMainHTML(&fileMainHTML);
outMainHTML.setCodec("UTF-8");
outMainHTML << "<html>\n<head></head>\n<body></body>\n</html>";
fileMainHTML.close();
}
QJsonArray tagsJsonArray;
for (QString tmp : tags) {
tagsJsonArray.append(tmp);
}
obj.insert("tags", tagsJsonArray);
QFile file(workingPath + "/project.json");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Could not open /project.json";
return;
}
QUrl previewThumbnailUrl { previewThumbnail };
QFileInfo previewImageFile(previewThumbnailUrl.toLocalFile());
if (!previewThumbnail.isEmpty()) {
obj.insert("previewThumbnail", previewImageFile.fileName());
obj.insert("preview", previewImageFile.fileName());
if (!QFile::copy(previewThumbnailUrl.toLocalFile(), workingPath + "/" + previewImageFile.fileName())) {
qDebug() << "Could not copy" << previewThumbnailUrl.toLocalFile() << " to " << workingPath + "/" + previewImageFile.fileName();
return;
}
}
QTextStream out(&file);
out.setCodec("UTF-8");
QJsonDocument doc(obj);
out << doc.toJson();
file.close();
emit widgetCreatedSuccessful(workingPath);
});
}
/*!

View File

@ -41,7 +41,7 @@ void ScreenPlayManager::createWallpaper(
const bool saveToProfilesConfigFile)
{
m_tracker->sendEvent("wallpaper","start");
m_tracker->sendEvent("wallpaper", "start");
QString path = absoluteStoragePath;
if (absoluteStoragePath.contains("file:///"))
@ -105,9 +105,9 @@ void ScreenPlayManager::createWallpaper(
/*!
Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path).
*/
void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QString& previewImage)
void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QString& previewImage, const QString& type)
{
m_tracker->sendEvent("widget","start");
m_tracker->sendEvent("widget", "start");
increaseActiveWidgetsCounter();
m_screenPlayWidgets.append(
@ -117,7 +117,7 @@ void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QStr
absoluteStoragePath.toLocalFile(),
previewImage,
absoluteStoragePath.toString(),
this));
type));
}
/*!
@ -127,7 +127,7 @@ void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QStr
void ScreenPlayManager::removeAllWallpapers()
{
if (!m_screenPlayWallpapers.empty()) {
m_tracker->sendEvent("wallpaper","stopAll");
m_tracker->sendEvent("wallpaper", "stopAll");
m_sdkconnector->closeAllWallpapers();
m_screenPlayWallpapers.clear();
m_monitorListModel->clearActiveWallpaper();
@ -168,7 +168,7 @@ void ScreenPlayManager::removeAllWallpapers()
*/
bool ScreenPlayManager::removeWallpaperAt(int at)
{
m_tracker->sendEvent("wallpaper","removeSingleWallpaper");
m_tracker->sendEvent("wallpaper", "removeSingleWallpaper");
if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(at)) {
m_sdkconnector->closeWallpaper(appID.value());

View File

@ -95,7 +95,7 @@ public slots:
const QString& fillMode,
const QString& type, const bool saveToProfilesConfigFile = true);
void createWidget(const QUrl& absoluteStoragePath, const QString& previewImage);
void createWidget(const QUrl& absoluteStoragePath, const QString& previewImage, const QString &type);
void removeAllWallpapers();
bool removeWallpaperAt(const int at = 0);

View File

@ -16,20 +16,21 @@ ScreenPlayWidget::ScreenPlayWidget(
const QString& projectPath,
const QString& previewImage,
const QString& fullPath,
QObject* parent)
: QObject { parent }
const QString& type)
: QObject { nullptr }
, m_globalVariables { globalVariables }
, m_projectPath { projectPath }
, m_previewImage { previewImage }
, m_appID { appID }
, m_position { 0, 0 }
, m_type { type }
{
const QStringList proArgs { m_projectPath, m_appID };
const QStringList proArgs { m_projectPath, m_appID, m_type };
m_process.setArguments(proArgs);
if (fullPath.endsWith(".exe")) {
m_process.setProgram(fullPath);
} else if (fullPath.endsWith(".qml")) {
} else {
m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
}

View File

@ -22,6 +22,7 @@ class ScreenPlayWidget : public QObject {
Q_PROPERTY(QString previewImage READ previewImage WRITE setPreviewImage NOTIFY previewImageChanged)
Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
public:
explicit ScreenPlayWidget(
@ -30,7 +31,7 @@ public:
const QString& projectPath,
const QString& previewImage,
const QString& fullPath,
QObject* parent = nullptr);
const QString& type);
~ScreenPlayWidget() {}
@ -54,6 +55,11 @@ public:
return m_appID;
}
QString type() const
{
return m_type;
}
public slots:
void setProjectPath(QString projectPath)
{
@ -91,12 +97,23 @@ public slots:
emit appIDChanged(m_appID);
}
void setType(QString type)
{
if (m_type == type)
return;
m_type = type;
emit typeChanged(m_type);
}
signals:
void projectPathChanged(QString projectPath);
void previewImageChanged(QString previewImage);
void positionChanged(QPoint position);
void appIDChanged(QString appID);
void typeChanged(QString type);
private:
QProcess m_process;
const shared_ptr<GlobalVariables>& m_globalVariables;
@ -105,5 +122,6 @@ private:
QString m_previewImage;
QString m_appID;
QPoint m_position;
QString m_type;
};
}

View File

@ -14,18 +14,18 @@ int main(int argc, char* argv[])
QStringList argumentList = app.arguments();
// If we start with only one argument (app path),
// If we start with only one argument (app, path, type),
// it means we want to test a single widget
if (argumentList.length() == 1) {
WidgetWindow spwmw("test","appid" );
WidgetWindow spwmw("test","appid", "qmlWidget");
return app.exec();
}
if (argumentList.length() != 3) {
if (argumentList.length() != 4) {
return -3;
}
WidgetWindow spwmw(argumentList.at(1), argumentList.at(2));
WidgetWindow spwmw(argumentList.at(1), argumentList.at(2), argumentList.at(3));
QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &spwmw, &WidgetWindow::destroyThis);
QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &spwmw, &WidgetWindow::messageReceived);

View File

@ -2,10 +2,20 @@
#include <QCoreApplication>
WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
: QObject(parent)
WidgetWindow::WidgetWindow(const QString projectPath, const QString appid, const QString type)
: QObject(nullptr)
, m_appID { appid }
, m_type { type }
{
QStringList availableTypes {
"qmlWidget",
"htmlWidget",
"standaloneWidget"
};
if (!availableTypes.contains(m_type)) {
QGuiApplication::exit(-4);
}
Qt::WindowFlags flags = m_window.flags();
m_window.setWidth(300);
@ -41,6 +51,7 @@ WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
}
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
// m_window.setResizeMode(QQuickView::ResizeMode::SizeViewToRootObject);
m_window.setSource(QUrl("qrc:/mainWidget.qml"));

View File

@ -15,6 +15,7 @@
#include <QWindow>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickWindow>
#include <QGuiApplication>
#ifdef Q_OS_WIN
#include <qt_windows.h>
@ -24,7 +25,7 @@ class WidgetWindow : public QObject {
Q_OBJECT
public:
explicit WidgetWindow(QString projectPath, QString appid, QObject* parent = nullptr);
explicit WidgetWindow(const QString projectPath, const QString appid, const QString type);
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)