mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-22 02:32:29 +01:00
Move util functions and global enums into dedicated lib
This will make reusing easier like enum parsing between ScreenPlay and ScreenPlayWallpaper & project load/save
This commit is contained in:
parent
0435b0023d
commit
4dcea75242
@ -73,6 +73,7 @@ add_subdirectory(ScreenPlaySDK)
|
||||
add_subdirectory(ScreenPlayShader)
|
||||
add_subdirectory(ScreenPlayWallpaper)
|
||||
add_subdirectory(ScreenPlayWidget)
|
||||
add_subdirectory(ScreenPlayUtil)
|
||||
|
||||
if(WIN32)
|
||||
add_subdirectory(ScreenPlaySysInfo)
|
||||
|
@ -1,7 +1,6 @@
|
||||
project(ScreenPlay LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
@ -110,6 +109,7 @@ target_link_libraries(
|
||||
Qt5::WebEngine
|
||||
Qt5::WebSockets
|
||||
ScreenPlaySDK
|
||||
ScreenPlayUtil
|
||||
benchmark::benchmark
|
||||
benchmark::benchmark_main
|
||||
doctest::doctest)
|
||||
|
@ -48,8 +48,7 @@
|
||||
#include <QtQml>
|
||||
#include <QtWebEngine>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ganalytics.h"
|
||||
#include "src/create.h"
|
||||
#include "src/globalvariables.h"
|
||||
#include "src/installedlistfilter.h"
|
||||
@ -61,7 +60,8 @@
|
||||
#include "src/util.h"
|
||||
#include "src/wizards.h"
|
||||
|
||||
#include "ganalytics.h"
|
||||
#include <memory>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <sentry.h>
|
||||
#endif
|
||||
|
@ -76,6 +76,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
ScreenPlay::App app;
|
||||
|
||||
|
||||
if (app.m_isAnotherScreenPlayInstanceRunning) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -85,6 +86,7 @@ int main(int argc, char* argv[])
|
||||
#ifdef Q_OS_WIN
|
||||
sentry_shutdown();
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ Create::Create()
|
||||
void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec, const int quality)
|
||||
{
|
||||
clearFfmpegOutput();
|
||||
videoPath = Util::toLocal(videoPath);
|
||||
videoPath = ScreenPlayUtil::toLocal(videoPath);
|
||||
|
||||
const QDir dir(m_globalVariables->localStoragePath().toLocalFile());
|
||||
|
||||
@ -99,8 +99,8 @@ void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec, c
|
||||
*/
|
||||
void Create::saveWallpaper(QString title, QString description, QString filePath, QString previewImagePath, QString youtube, Create::VideoCodec codec, QVector<QString> tags)
|
||||
{
|
||||
filePath = Util::toLocal(filePath);
|
||||
previewImagePath = Util::toLocal(previewImagePath);
|
||||
filePath = ScreenPlayUtil::toLocal(filePath);
|
||||
previewImagePath = ScreenPlayUtil::toLocal(previewImagePath);
|
||||
|
||||
emit createWallpaperStateChanged(CreateImportVideo::ImportVideoState::CopyFiles);
|
||||
|
||||
@ -146,7 +146,7 @@ void Create::saveWallpaper(QString title, QString description, QString filePath,
|
||||
obj.insert("preview", previewImageFile.exists() ? previewImageFile.fileName() : "preview.jpg");
|
||||
obj.insert("previewThumbnail", "previewThumbnail.jpg");
|
||||
obj.insert("type", "videoWallpaper");
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
|
||||
QFile audioFile { m_workingDir + "/audio.mp3" };
|
||||
if (audioFile.exists() && audioFile.size() > 0) {
|
||||
|
@ -56,6 +56,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include "createimportvideo.h"
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "createimportvideo.h"
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
@ -38,8 +39,8 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex
|
||||
m_codec = codec;
|
||||
m_process = std::make_unique<QProcess>(this);
|
||||
|
||||
m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + Util::executableEnding();
|
||||
m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + Util::executableEnding();
|
||||
m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + ScreenPlayUtil::executableEnding();
|
||||
m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + ScreenPlayUtil::executableEnding();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -165,7 +166,7 @@ bool CreateImportVideo::createWallpaperInfo()
|
||||
|
||||
args.append(m_videoPath);
|
||||
|
||||
emit processOutput("ffprobe " + Util::toString(args));
|
||||
emit processOutput("ffprobe " + ScreenPlayUtil::toString(args));
|
||||
|
||||
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideo);
|
||||
|
||||
@ -174,7 +175,7 @@ bool CreateImportVideo::createWallpaperInfo()
|
||||
|
||||
emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoFinished);
|
||||
|
||||
auto obj = Util::parseQByteArrayToQJsonObject(QByteArray::fromStdString(ffmpegOut.toStdString()));
|
||||
auto obj = ScreenPlayUtil::parseQByteArrayToQJsonObject(QByteArray::fromStdString(ffmpegOut.toStdString()));
|
||||
|
||||
if (!obj) {
|
||||
QString error = ffmpegOut;
|
||||
@ -386,7 +387,7 @@ bool CreateImportVideo::createWallpaperVideoPreview()
|
||||
// Disable audio
|
||||
args.append("-an");
|
||||
args.append(m_exportPath + "/preview.webm");
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
emit processOutput("ffmpeg " + ScreenPlayUtil::toString(args));
|
||||
|
||||
const QString ffmpegOut = waitForFinished(args);
|
||||
const QFile previewVideo(m_exportPath + "/preview.webm");
|
||||
@ -429,7 +430,7 @@ bool CreateImportVideo::createWallpaperGifPreview()
|
||||
args.append("-filter_complex");
|
||||
args.append("[0:v] fps=12,scale=w=480:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1");
|
||||
args.append(m_exportPath + "/preview.gif");
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
emit processOutput("ffmpeg " + ScreenPlayUtil::toString(args));
|
||||
|
||||
const QString ffmpegOut = waitForFinished(args);
|
||||
|
||||
@ -488,7 +489,7 @@ bool CreateImportVideo::createWallpaperImageThumbnailPreview()
|
||||
}
|
||||
args.append(m_exportPath + "/previewThumbnail.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
emit processOutput("ffmpeg " + ScreenPlayUtil::toString(args));
|
||||
|
||||
const QString ffmpegOut = waitForFinished(args);
|
||||
if (!ffmpegOut.isEmpty()) {
|
||||
@ -533,7 +534,7 @@ bool CreateImportVideo::createWallpaperImagePreview()
|
||||
}
|
||||
args.append(m_exportPath + "/preview.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
emit processOutput("ffmpeg " + ScreenPlayUtil::toString(args));
|
||||
const QString ffmpegOut = waitForFinished(args);
|
||||
if (!ffmpegOut.isEmpty()) {
|
||||
const QFile previewImg(m_exportPath + "/preview.jpg");
|
||||
|
@ -41,84 +41,10 @@
|
||||
#include <QUrl>
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include "ScreenPlayUtil/contenttypes.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
/*!
|
||||
\class ScreenPlay::GlobalVariables
|
||||
\inmodule ScreenPlay
|
||||
\brief GlobalVariables.
|
||||
|
||||
A header only class used only for storing some global variables like localStoragePath.
|
||||
|
||||
*/
|
||||
|
||||
namespace SearchType {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class SearchType {
|
||||
All,
|
||||
Text,
|
||||
Scene, //QML, HTML, Godot, Gif, Website wallpaper
|
||||
Wallpaper,
|
||||
Widget,
|
||||
};
|
||||
Q_ENUM_NS(SearchType)
|
||||
|
||||
}
|
||||
|
||||
namespace FillMode {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class FillMode {
|
||||
Stretch,
|
||||
Fill,
|
||||
Contain,
|
||||
Cover,
|
||||
Scale_Down
|
||||
};
|
||||
Q_ENUM_NS(FillMode)
|
||||
|
||||
}
|
||||
|
||||
namespace InstalledType {
|
||||
Q_NAMESPACE
|
||||
|
||||
// When changing the enum, one also needs to change:
|
||||
// GlobalVariables::getAvailableWallpaper
|
||||
// GlobalVariables::getAvailableWidgets
|
||||
// Common/Util.js isWallpaper() and isWidget()
|
||||
// ScreenPlayWallpaper: BaseWindow::parseWallpaperType()
|
||||
enum class InstalledType {
|
||||
Unknown,
|
||||
//Wallpaper
|
||||
VideoWallpaper,
|
||||
QMLWallpaper,
|
||||
HTMLWallpaper,
|
||||
GodotWallpaper,
|
||||
GifWallpaper,
|
||||
WebsiteWallpaper,
|
||||
//Widgets
|
||||
QMLWidget,
|
||||
HTMLWidget,
|
||||
};
|
||||
Q_ENUM_NS(InstalledType)
|
||||
|
||||
static bool isWallpaper(const InstalledType type)
|
||||
{
|
||||
return (type == InstalledType::VideoWallpaper
|
||||
|| type == InstalledType::QMLWallpaper
|
||||
|| type == InstalledType::HTMLWallpaper
|
||||
|| type == InstalledType::GifWallpaper
|
||||
|| type == InstalledType::WebsiteWallpaper
|
||||
|| type == InstalledType::GodotWallpaper);
|
||||
}
|
||||
|
||||
static bool isWidget(const InstalledType type)
|
||||
{
|
||||
return (type == InstalledType::QMLWidget || type == InstalledType::HTMLWidget);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalVariables : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -131,30 +57,6 @@ class GlobalVariables : public QObject {
|
||||
public:
|
||||
explicit GlobalVariables(QObject* parent = nullptr);
|
||||
|
||||
static QStringList getAvailableWallpaper()
|
||||
{
|
||||
return {
|
||||
"qmlWallpaper",
|
||||
"htmlWallpaper",
|
||||
"videoWallpaper",
|
||||
"godotWallpaper",
|
||||
"gifWallpaper",
|
||||
"websiteWallpaper"
|
||||
};
|
||||
}
|
||||
static QStringList getAvailableWidgets()
|
||||
{
|
||||
return {
|
||||
"qmlWidget",
|
||||
"htmlWidget",
|
||||
};
|
||||
}
|
||||
|
||||
static QStringList getAvailableTypes()
|
||||
{
|
||||
return { getAvailableWallpaper() + getAvailableWidgets() };
|
||||
}
|
||||
|
||||
/*!
|
||||
\property GlobalVariables::localStoragePath
|
||||
\brief Returns the localStoragePath.
|
||||
|
@ -166,7 +166,7 @@ void InstalledListModel::loadInstalledContent()
|
||||
for (auto&& item : list) {
|
||||
projectItemPath = m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json";
|
||||
|
||||
if (auto obj = Util::openJsonFileToObject(projectItemPath)) {
|
||||
if (auto obj = ScreenPlayUtil::openJsonFileToObject(projectItemPath)) {
|
||||
|
||||
if (obj->isEmpty())
|
||||
continue;
|
||||
@ -174,8 +174,8 @@ void InstalledListModel::loadInstalledContent()
|
||||
if (!obj->contains("type"))
|
||||
continue;
|
||||
|
||||
if (GlobalVariables::getAvailableTypes().contains(obj->value("type").toString())) {
|
||||
if (GlobalVariables::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) {
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) {
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) {
|
||||
emit addInstalledItem(*obj, item.baseName());
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
@ -34,7 +34,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "profile.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@ -45,6 +44,7 @@
|
||||
#include <QVector>
|
||||
|
||||
#include "globalvariables.h"
|
||||
#include "profile.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -103,7 +104,7 @@ struct ProjectFile {
|
||||
if (!obj.contains("type"))
|
||||
return;
|
||||
|
||||
auto type = Util::getInstalledTypeFromString(obj.value("type").toString());
|
||||
auto type = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString());
|
||||
if (!type) {
|
||||
qWarning() << "Type could not parsed from: " << *type << folderName;
|
||||
return;
|
||||
@ -113,7 +114,7 @@ struct ProjectFile {
|
||||
if (m_type == InstalledType::InstalledType::GifWallpaper) {
|
||||
m_preview = m_previewGIF;
|
||||
}
|
||||
m_searchType = Util::getSearchTypeFromInstalledType(m_type);
|
||||
m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type);
|
||||
}
|
||||
|
||||
ProjectFile() { }
|
||||
|
@ -130,7 +130,7 @@ void ScreenPlayManager::createWallpaper(
|
||||
}
|
||||
|
||||
const QString path = QUrl::fromUserInput(absoluteStoragePath).toLocalFile();
|
||||
const QString appID = Util::generateRandomString();
|
||||
const QString appID = ScreenPlayUtil::generateRandomString();
|
||||
|
||||
// Only support remove wallpaper that spans over 1 monitor
|
||||
if (monitorIndex.length() == 1) {
|
||||
@ -195,7 +195,7 @@ void ScreenPlayManager::createWidget(
|
||||
}
|
||||
});
|
||||
|
||||
const QString appID = Util::generateRandomString();
|
||||
const QString appID = ScreenPlayUtil::generateRandomString();
|
||||
const QString path = QUrl::fromUserInput(absoluteStoragePath).toLocalFile();
|
||||
|
||||
if (path.isEmpty()) {
|
||||
@ -421,7 +421,7 @@ void ScreenPlayManager::closeAllWallpapers()
|
||||
if (m_screenPlayWallpapers.empty() && m_activeWallpaperCounter == 0)
|
||||
return;
|
||||
|
||||
closeConntectionByType(GlobalVariables::getAvailableWallpaper());
|
||||
closeConntectionByType(ScreenPlayUtil::getAvailableWallpaper());
|
||||
setActiveWallpaperCounter(0);
|
||||
}
|
||||
|
||||
@ -438,7 +438,7 @@ void ScreenPlayManager::closeAllWidgets()
|
||||
if (m_screenPlayWidgets.empty() && m_activeWidgetsCounter == 0)
|
||||
return;
|
||||
|
||||
closeConntectionByType(GlobalVariables::getAvailableWidgets());
|
||||
closeConntectionByType(ScreenPlayUtil::getAvailableWidgets());
|
||||
setActiveWidgetsCounter(0);
|
||||
}
|
||||
|
||||
@ -552,14 +552,14 @@ bool ScreenPlayManager::removeWallpaperByAppID(const QString& appID)
|
||||
*/
|
||||
void ScreenPlayManager::loadProfiles()
|
||||
{
|
||||
auto configObj = Util::openJsonFileToObject(m_globalVariables->localSettingsPath().toString() + "/profiles.json");
|
||||
auto configObj = ScreenPlayUtil::openJsonFileToObject(m_globalVariables->localSettingsPath().toString() + "/profiles.json");
|
||||
|
||||
if (!configObj) {
|
||||
qWarning() << "Could not load active profiles at path: " << m_globalVariables->localSettingsPath().toString() + "/profiles.json";
|
||||
return;
|
||||
}
|
||||
|
||||
std::optional<QVersionNumber> version = Util::getVersionNumberFromString(configObj->value("version").toString());
|
||||
std::optional<QVersionNumber> version = ScreenPlayUtil::getVersionNumberFromString(configObj->value("version").toString());
|
||||
|
||||
if (version && *version != m_globalVariables->version()) {
|
||||
qWarning() << "Version missmatch fileVersion: " << version->toString() << "m_version: " << m_globalVariables->version().toString();
|
||||
|
@ -47,7 +47,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
projectSettingsListModelProperties.insert("playbackRate", m_playbackRate);
|
||||
} else {
|
||||
if (properties.isEmpty()) {
|
||||
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
|
||||
auto obj = ScreenPlayUtil::openJsonFileToObject(absolutePath + "/project.json");
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
|
@ -34,7 +34,7 @@ ScreenPlayWidget::ScreenPlayWidget(
|
||||
QJsonObject projectSettingsListModelProperties;
|
||||
|
||||
if (properties.isEmpty()) {
|
||||
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
|
||||
auto obj = ScreenPlayUtil::openJsonFileToObject(absolutePath + "/project.json");
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
|
@ -42,12 +42,13 @@
|
||||
#include <QPoint>
|
||||
#include <QProcess>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include "globalvariables.h"
|
||||
#include "projectsettingslistmodel.h"
|
||||
#include "sdkconnection.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
class ScreenPlayWidget : public QObject {
|
||||
|
@ -48,7 +48,7 @@ void ScreenPlay::SDKConnection::readyRead()
|
||||
m_appID = appID.remove("appID=");
|
||||
|
||||
bool typeFound = false;
|
||||
for (const QString& type : GlobalVariables::getAvailableTypes()) {
|
||||
for (const QString& type : ScreenPlayUtil::getAvailableTypes()) {
|
||||
if (msg.contains(type, Qt::CaseInsensitive)) {
|
||||
m_type = type;
|
||||
typeFound = true;
|
||||
@ -57,7 +57,7 @@ void ScreenPlay::SDKConnection::readyRead()
|
||||
}
|
||||
|
||||
if (!typeFound) {
|
||||
qCritical() << "Wallpaper type not found. Expected: " << GlobalVariables::getAvailableTypes() << " got: " << msg;
|
||||
qCritical() << "Wallpaper type not found. Expected: " << ScreenPlayUtil::getAvailableTypes() << " got: " << msg;
|
||||
}
|
||||
|
||||
qInfo() << "New connection" << m_appID << msg;
|
||||
|
@ -46,11 +46,12 @@
|
||||
#include <QVector>
|
||||
#include <QWebSocketServer>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
/*!
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
/*!
|
||||
@ -173,8 +175,8 @@ void Settings::setupWidgetAndWindowPaths()
|
||||
QDir workingDir(QGuiApplication::applicationDirPath());
|
||||
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
|
||||
m_globalVariables->setWidgetExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWidget" + Util::executableEnding()));
|
||||
m_globalVariables->setWallpaperExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWallpaper" + Util::executableEnding()));
|
||||
m_globalVariables->setWidgetExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWidget" + ScreenPlayUtil::executableEnding()));
|
||||
m_globalVariables->setWallpaperExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWallpaper" + ScreenPlayUtil::executableEnding()));
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_OSX)
|
||||
|
@ -60,12 +60,12 @@
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <qt_windows.h>
|
||||
#endif
|
||||
|
@ -42,107 +42,6 @@ void Util::copyToClipboard(const QString& text) const
|
||||
clipboard->setText(text);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Opens a json file (absolute path) and tries to convert it to a QJsonObject.
|
||||
Returns std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QJsonObject> Util::openJsonFileToObject(const QString& path)
|
||||
{
|
||||
auto jsonString = openJsonFileToString(path);
|
||||
|
||||
if (!jsonString.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDocument;
|
||||
QJsonParseError parseError {};
|
||||
jsonDocument = QJsonDocument::fromJson(jsonString->toUtf8(), &parseError);
|
||||
|
||||
if (!(parseError.error == QJsonParseError::NoError)) {
|
||||
qWarning() << "Settings Json Parse Error: " << parseError.errorString();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return jsonDocument.object();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Opens a json file (absolute path) and tries to convert it to a QString.
|
||||
Returns std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QString> Util::openJsonFileToString(const QString& path)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
QString fileContent = file.readAll();
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
return { fileContent };
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Generates a (non secure) random string with the default length of 32. Can contain:
|
||||
\list
|
||||
\li A-Z
|
||||
\li a-z
|
||||
\li 0-9
|
||||
\endlist
|
||||
*/
|
||||
QString Util::generateRandomString(quint32 length)
|
||||
{
|
||||
const QString possibleCharacters {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
};
|
||||
const auto radomGen = QRandomGenerator::system();
|
||||
|
||||
QString randomString;
|
||||
for (quint32 i = 0; i < length; ++i) {
|
||||
const int index = radomGen->bounded(possibleCharacters.length());
|
||||
const QChar nextChar = possibleCharacters.at(index);
|
||||
randomString.append(nextChar);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Return .exe in windows otherwise empty string.
|
||||
*/
|
||||
QString Util::executableEnding()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return ".exe";
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Parses a version from a given QString. The QString must be looke like this:
|
||||
1.0.0 - Major.Minor.Patch. A fixed position is used for parsing (at 0,2,4).
|
||||
Return std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QVersionNumber> Util::getVersionNumberFromString(const QString& str)
|
||||
{
|
||||
// Must be: Major.Minor.Patch
|
||||
bool okMajor { false };
|
||||
bool okMinor { false };
|
||||
bool okPatch { false };
|
||||
|
||||
int major = QString(str.at(0)).toInt(&okMajor);
|
||||
int minor = QString(str.at(2)).toInt(&okMinor);
|
||||
int patch = QString(str.at(4)).toInt(&okPatch);
|
||||
|
||||
if (okMajor && okMinor && okPatch) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return QVersionNumber(major, minor, patch);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Writes a given QJsonObject to a file. The path must be absolute. When truncate is set to
|
||||
true the exsisting json file will be overriten.
|
||||
@ -170,18 +69,6 @@ bool Util::writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObj
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Helper function to append a QStringList into a QString with a space between the items.
|
||||
*/
|
||||
QString Util::toString(const QStringList& list)
|
||||
{
|
||||
QString out;
|
||||
for (const auto& string : list) {
|
||||
out += " " + string;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void Util::appendToMetricsFile(const QString& key, const QVariant& value)
|
||||
{
|
||||
if (!QGuiApplication::arguments().contains("--benchmark"))
|
||||
@ -203,23 +90,6 @@ void Util::appendToMetricsFile(const QString& key, const QVariant& value)
|
||||
metricsFile.close();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Parses a QByteArray to a QJsonObject. If returns and std::nullopt on failure.
|
||||
*/
|
||||
std::optional<QJsonObject> Util::parseQByteArrayToQJsonObject(const QByteArray& byteArray)
|
||||
{
|
||||
QJsonObject obj;
|
||||
QJsonParseError err {};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(byteArray, &err);
|
||||
|
||||
if (err.error == QJsonParseError::NoError) {
|
||||
obj = doc.object();
|
||||
return { obj };
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Opens a native folder window on the given path. Windows and Mac only for now!
|
||||
*/
|
||||
@ -311,85 +181,6 @@ void Util::Util::requestDataProtection()
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Util function that converts a QVector of Strings into a QJsonArray.
|
||||
|
||||
*/
|
||||
QJsonArray Util::fillArray(const QVector<QString>& items)
|
||||
{
|
||||
QJsonArray array;
|
||||
for (const QString& item : items) {
|
||||
array.append(item);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Maps the Search type to an installed type. Used for filtering the installed
|
||||
content.
|
||||
|
||||
*/
|
||||
SearchType::SearchType Util::getSearchTypeFromInstalledType(const InstalledType::InstalledType type)
|
||||
{
|
||||
using InstalledType::InstalledType;
|
||||
using SearchType::SearchType;
|
||||
|
||||
switch (type) {
|
||||
case InstalledType::GodotWallpaper:
|
||||
case InstalledType::HTMLWallpaper:
|
||||
case InstalledType::QMLWallpaper:
|
||||
case InstalledType::GifWallpaper:
|
||||
case InstalledType::WebsiteWallpaper:
|
||||
return SearchType::Scene;
|
||||
case InstalledType::VideoWallpaper:
|
||||
return SearchType::Wallpaper;
|
||||
case InstalledType::HTMLWidget:
|
||||
case InstalledType::QMLWidget:
|
||||
return SearchType::Widget;
|
||||
case InstalledType::Unknown:
|
||||
default:
|
||||
return SearchType::All;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Maps the installed type from a QString to an enum. Used for parsing the project.json.
|
||||
*/
|
||||
std::optional<InstalledType::InstalledType> Util::getInstalledTypeFromString(const QString& type)
|
||||
{
|
||||
if (type.endsWith("Wallpaper")) {
|
||||
if (type.startsWith("video", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::VideoWallpaper;
|
||||
}
|
||||
if (type.startsWith("qml", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::QMLWallpaper;
|
||||
}
|
||||
if (type.startsWith("html", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::HTMLWallpaper;
|
||||
}
|
||||
if (type.startsWith("godot", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::GodotWallpaper;
|
||||
}
|
||||
if (type.startsWith("website", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::WebsiteWallpaper;
|
||||
}
|
||||
if (type.startsWith("gif", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::GifWallpaper;
|
||||
}
|
||||
}
|
||||
|
||||
if (type.endsWith("Widget")) {
|
||||
if (type.startsWith("qml", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::QMLWidget;
|
||||
}
|
||||
if (type.startsWith("html", Qt::CaseInsensitive)) {
|
||||
return InstalledType::InstalledType::HTMLWidget;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static const char*
|
||||
logLevelForMessageType(QtMsgType msgType)
|
||||
{
|
||||
@ -553,12 +344,4 @@ bool Util::copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnai
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Converts the given \a url string to a local file path.
|
||||
*/
|
||||
QString Util::toLocal(const QString& url)
|
||||
{
|
||||
return QUrl(url).toLocalFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,12 +53,12 @@
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <qqml.h>
|
||||
|
||||
#include "globalvariables.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
#include "globalvariables.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
template <typename T>
|
||||
@ -93,7 +93,7 @@ signals:
|
||||
void requestNavigation(QString nav);
|
||||
void requestNavigationActive(bool isActive);
|
||||
void requestToggleWallpaperConfiguration();
|
||||
void setSidebarItem(QString folderName, ScreenPlay::InstalledType::InstalledType type);
|
||||
void setSidebarItem(QString folderName, InstalledType::InstalledType type);
|
||||
void allLicenseLoaded(QString licensesText);
|
||||
void allDataProtectionLoaded(QString dataProtectionText);
|
||||
void debugMessagesChanged(QString debugMessages);
|
||||
@ -105,13 +105,6 @@ public slots:
|
||||
void requestAllLicenses();
|
||||
void requestDataProtection();
|
||||
|
||||
static QJsonArray fillArray(const QVector<QString>& items);
|
||||
static SearchType::SearchType getSearchTypeFromInstalledType(const InstalledType::InstalledType type);
|
||||
static std::optional<InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);
|
||||
static std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray);
|
||||
static std::optional<QJsonObject> openJsonFileToObject(const QString& path);
|
||||
static std::optional<QString> openJsonFileToString(const QString& path);
|
||||
static std::optional<QVersionNumber> getVersionNumberFromString(const QString& str);
|
||||
static void appendToMetricsFile(const QString& key, const QVariant& value);
|
||||
static void logToGui(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
||||
static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true);
|
||||
@ -119,10 +112,6 @@ public slots:
|
||||
static bool writeFile(const QString& text, const QString& absolutePath);
|
||||
static bool writeFileFromQrc(const QString& qrcPath, const QString& absolutePath);
|
||||
static bool copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, const QString& destination);
|
||||
static QString toString(const QStringList& list);
|
||||
static QString toLocal(const QString& url);
|
||||
static QString generateRandomString(quint32 length = 32);
|
||||
static QString executableEnding();
|
||||
|
||||
void setNavigation(QString nav)
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "wizards.h"
|
||||
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
/*!
|
||||
\class ScreenPlay::Wizards
|
||||
@ -37,12 +39,12 @@ void Wizards::createQMLWidget(const QString& title,
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", licenseName);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("type", "qmlWidget");
|
||||
obj.insert("file", "main.qml");
|
||||
@ -98,13 +100,13 @@ void Wizards::createHTMLWidget(const QString& title,
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", licenseName);
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("type", "htmlWidget");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
@ -161,13 +163,13 @@ void Wizards::createHTMLWallpaper(
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", licenseName);
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("type", "htmlWallpaper");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
@ -223,13 +225,13 @@ void Wizards::createQMLWallpaper(
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", licenseName);
|
||||
obj.insert("title", title);
|
||||
obj.insert("createdBy", createdBy);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("type", "qmlWallpaper");
|
||||
obj.insert("file", "main.qml");
|
||||
|
||||
@ -276,8 +278,8 @@ void Wizards::createGifWallpaper(
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString gifFileName = QFileInfo(Util::toLocal(file)).fileName();
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString gifFileName = QFileInfo(ScreenPlayUtil::toLocal(file)).fileName();
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("license", licenseName);
|
||||
@ -285,7 +287,7 @@ void Wizards::createGifWallpaper(
|
||||
obj.insert("title", title);
|
||||
obj.insert("file", gifFileName);
|
||||
obj.insert("previewGIF", gifFileName);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("type", "gifWallpaper");
|
||||
|
||||
if (!Util::writeFileFromQrc(":/assets/wizards/" + licenseFile, workingPath + "/" + licenseFile)) {
|
||||
@ -299,7 +301,7 @@ void Wizards::createGifWallpaper(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QFile::copy(Util::toLocal(file), workingPath + "/" + gifFileName)) {
|
||||
if (!QFile::copy(ScreenPlayUtil::toLocal(file), workingPath + "/" + gifFileName)) {
|
||||
qWarning() << "Could not copy gif " << file << " to: " << workingPath + "/" + gifFileName;
|
||||
emit widgetCreationFinished(WizardResult::CopyFileError);
|
||||
return;
|
||||
@ -326,11 +328,11 @@ void Wizards::createWebsiteWallpaper(
|
||||
return;
|
||||
}
|
||||
|
||||
const QString workingPath = Util::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
const QString workingPath = ScreenPlayUtil::toLocal(m_globalVariables->localStoragePath().toString() + "/" + folderName.value());
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("title", title);
|
||||
obj.insert("tags", Util::fillArray(tags));
|
||||
obj.insert("tags", ScreenPlayUtil::fillArray(tags));
|
||||
obj.insert("type", "websiteWallpaper");
|
||||
obj.insert("url", url.toString());
|
||||
|
||||
|
@ -54,14 +54,12 @@
|
||||
#include <QUrl>
|
||||
#include <QtMath>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "createimportvideo.h"
|
||||
#include "globalvariables.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
project(ScreenPlaySDK LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
project(ScreenPlayShader LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
project(ScreenPlaySysInfo LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
26
ScreenPlayUtil/CMakeLists.txt
Normal file
26
ScreenPlayUtil/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
project(ScreenPlayUtil LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
find_package(
|
||||
Qt5
|
||||
COMPONENTS Core
|
||||
REQUIRED)
|
||||
|
||||
set(SOURCES
|
||||
src/util.cpp
|
||||
src/contenttypes.cpp
|
||||
)
|
||||
|
||||
set(HEADER
|
||||
inc/public/ScreenPlayUtil/util.h
|
||||
inc/public/ScreenPlayUtil/contenttypes.h
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADER})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core )
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC inc/public/ PRIVATE src/)
|
100
ScreenPlayUtil/inc/public/ScreenPlayUtil/contenttypes.h
Normal file
100
ScreenPlayUtil/inc/public/ScreenPlayUtil/contenttypes.h
Normal file
@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 Elias Steurer (Kelteseth)
|
||||
** Contact: https://screen-play.app
|
||||
**
|
||||
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
|
||||
** order to ensure its sustainability. When you contribute to ScreenPlay
|
||||
** you accept that your work will be available under the two following licenses:
|
||||
**
|
||||
** $SCREENPLAY_BEGIN_LICENSE$
|
||||
**
|
||||
** #### Affero General Public License Usage (AGPLv3)
|
||||
** Alternatively, this file may be used under the terms of the GNU Affero
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file "ScreenPlay License.md" included in the
|
||||
** packaging of this App. Please review the following information to
|
||||
** ensure the GNU Affero Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
|
||||
**
|
||||
** #### Commercial License
|
||||
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
|
||||
** terms written in:
|
||||
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
|
||||
** * Legal/individual_contributor_license_agreement.md - For individual contributors
|
||||
**
|
||||
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
|
||||
** This License does not grant any rights in the trademarks,
|
||||
** service marks, or logos.
|
||||
**
|
||||
**
|
||||
** $SCREENPLAY_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <qobjectdefs.h>
|
||||
|
||||
namespace ScreenPlay {
|
||||
/*!
|
||||
\class ScreenPlay::GlobalVariables
|
||||
\inmodule ScreenPlay
|
||||
\brief GlobalVariables.
|
||||
|
||||
A header only class used only for storing some global variables like localStoragePath.
|
||||
|
||||
*/
|
||||
|
||||
namespace SearchType {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class SearchType {
|
||||
All,
|
||||
Text,
|
||||
Scene, //QML, HTML, Godot, Gif, Website wallpaper
|
||||
Wallpaper,
|
||||
Widget,
|
||||
};
|
||||
Q_ENUM_NS(SearchType)
|
||||
|
||||
}
|
||||
|
||||
namespace FillMode {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class FillMode {
|
||||
Stretch,
|
||||
Fill,
|
||||
Contain,
|
||||
Cover,
|
||||
Scale_Down
|
||||
};
|
||||
Q_ENUM_NS(FillMode)
|
||||
|
||||
}
|
||||
|
||||
namespace InstalledType {
|
||||
Q_NAMESPACE
|
||||
|
||||
// When changing the enum, one also needs to change:
|
||||
// GlobalVariables::getAvailableWallpaper
|
||||
// GlobalVariables::getAvailableWidgets
|
||||
// Common/Util.js isWallpaper() and isWidget()
|
||||
// ScreenPlayWallpaper: BaseWindow::parseWallpaperType()
|
||||
enum class InstalledType {
|
||||
Unknown,
|
||||
//Wallpaper
|
||||
VideoWallpaper,
|
||||
QMLWallpaper,
|
||||
HTMLWallpaper,
|
||||
GodotWallpaper,
|
||||
GifWallpaper,
|
||||
WebsiteWallpaper,
|
||||
//Widgets
|
||||
QMLWidget,
|
||||
HTMLWidget,
|
||||
};
|
||||
Q_ENUM_NS(InstalledType)
|
||||
|
||||
}
|
||||
}
|
65
ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h
Normal file
65
ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h
Normal file
@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 Elias Steurer (Kelteseth)
|
||||
** Contact: https://screen-play.app
|
||||
**
|
||||
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
|
||||
** order to ensure its sustainability. When you contribute to ScreenPlay
|
||||
** you accept that your work will be available under the two following licenses:
|
||||
**
|
||||
** $SCREENPLAY_BEGIN_LICENSE$
|
||||
**
|
||||
** #### Affero General Public License Usage (AGPLv3)
|
||||
** Alternatively, this file may be used under the terms of the GNU Affero
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file "ScreenPlay License.md" included in the
|
||||
** packaging of this App. Please review the following information to
|
||||
** ensure the GNU Affero Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
|
||||
**
|
||||
** #### Commercial License
|
||||
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
|
||||
** terms written in:
|
||||
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
|
||||
** * Legal/individual_contributor_license_agreement.md - For individual contributors
|
||||
**
|
||||
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
|
||||
** This License does not grant any rights in the trademarks,
|
||||
** service marks, or logos.
|
||||
**
|
||||
**
|
||||
** $SCREENPLAY_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "ScreenPlayUtil/contenttypes.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
#include <QVersionNumber>
|
||||
#include <optional>
|
||||
|
||||
namespace ScreenPlayUtil {
|
||||
QJsonArray fillArray(const QVector<QString>& items);
|
||||
ScreenPlay::SearchType::SearchType getSearchTypeFromInstalledType(const ScreenPlay::InstalledType::InstalledType type);
|
||||
std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);
|
||||
std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray);
|
||||
std::optional<QJsonObject> openJsonFileToObject(const QString& path);
|
||||
std::optional<QString> openJsonFileToString(const QString& path);
|
||||
std::optional<QVersionNumber> getVersionNumberFromString(const QString& str);
|
||||
bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true);
|
||||
bool writeSettings(const QJsonObject& obj, const QString& absolutePath);
|
||||
bool writeFile(const QString& text, const QString& absolutePath);
|
||||
bool writeFileFromQrc(const QString& qrcPath, const QString& absolutePath);
|
||||
bool copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, const QString& destination);
|
||||
QString toString(const QStringList& list);
|
||||
QString toLocal(const QString& url);
|
||||
QString generateRandomString(quint32 length = 32);
|
||||
QString executableEnding();
|
||||
QStringList getAvailableWallpaper();
|
||||
QStringList getAvailableWidgets();
|
||||
QStringList getAvailableTypes();
|
||||
bool isWallpaper(const ScreenPlay::InstalledType::InstalledType type);
|
||||
bool isWidget(const ScreenPlay::InstalledType::InstalledType type);
|
||||
}
|
5
ScreenPlayUtil/src/contenttypes.cpp
Normal file
5
ScreenPlayUtil/src/contenttypes.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "ScreenPlayUtil/contenttypes.h"
|
||||
|
||||
namespace ScreenPlayUtil {
|
||||
|
||||
}
|
273
ScreenPlayUtil/src/util.cpp
Normal file
273
ScreenPlayUtil/src/util.cpp
Normal file
@ -0,0 +1,273 @@
|
||||
#include "ScreenPlayUtil/util.h"
|
||||
#include <QFile>
|
||||
#include <QJsonParseError>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
namespace ScreenPlayUtil {
|
||||
|
||||
/*!
|
||||
\brief Opens a json file (absolute path) and tries to convert it to a QJsonObject.
|
||||
Returns std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QJsonObject> openJsonFileToObject(const QString& path)
|
||||
{
|
||||
auto jsonString = openJsonFileToString(path);
|
||||
|
||||
if (!jsonString.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDocument;
|
||||
QJsonParseError parseError {};
|
||||
jsonDocument = QJsonDocument::fromJson(jsonString->toUtf8(), &parseError);
|
||||
|
||||
if (!(parseError.error == QJsonParseError::NoError)) {
|
||||
qWarning() << "Settings Json Parse Error: " << parseError.errorString();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return jsonDocument.object();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Opens a json file (absolute path) and tries to convert it to a QString.
|
||||
Returns std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QString> openJsonFileToString(const QString& path)
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
QString fileContent = file.readAll();
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
return { fileContent };
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Generates a (non secure) random string with the default length of 32. Can contain:
|
||||
\list
|
||||
\li A-Z
|
||||
\li a-z
|
||||
\li 0-9
|
||||
\endlist
|
||||
*/
|
||||
QString generateRandomString(quint32 length)
|
||||
{
|
||||
const QString possibleCharacters {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
};
|
||||
const auto radomGen = QRandomGenerator::system();
|
||||
|
||||
QString randomString;
|
||||
for (quint32 i = 0; i < length; ++i) {
|
||||
const int index = radomGen->bounded(possibleCharacters.length());
|
||||
const QChar nextChar = possibleCharacters.at(index);
|
||||
randomString.append(nextChar);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Return .exe in windows otherwise empty string.
|
||||
*/
|
||||
QString executableEnding()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return ".exe";
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Parses a version from a given QString. The QString must be looke like this:
|
||||
1.0.0 - Major.Minor.Patch. A fixed position is used for parsing (at 0,2,4).
|
||||
Return std::nullopt when not successful.
|
||||
*/
|
||||
std::optional<QVersionNumber> getVersionNumberFromString(const QString& str)
|
||||
{
|
||||
// Must be: Major.Minor.Patch
|
||||
bool okMajor { false };
|
||||
bool okMinor { false };
|
||||
bool okPatch { false };
|
||||
|
||||
int major = QString(str.at(0)).toInt(&okMajor);
|
||||
int minor = QString(str.at(2)).toInt(&okMinor);
|
||||
int patch = QString(str.at(4)).toInt(&okPatch);
|
||||
|
||||
if (okMajor && okMinor && okPatch) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return QVersionNumber(major, minor, patch);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Parses a QByteArray to a QJsonObject. If returns and std::nullopt on failure.
|
||||
*/
|
||||
std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray)
|
||||
{
|
||||
QJsonObject obj;
|
||||
QJsonParseError err {};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(byteArray, &err);
|
||||
|
||||
if (err.error == QJsonParseError::NoError) {
|
||||
obj = doc.object();
|
||||
return { obj };
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Helper function to append a QStringList into a QString with a space between the items.
|
||||
*/
|
||||
QString toString(const QStringList& list)
|
||||
{
|
||||
QString out;
|
||||
for (const auto& string : list) {
|
||||
out += " " + string;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Util function that converts a QVector of Strings into a QJsonArray.
|
||||
|
||||
*/
|
||||
QJsonArray fillArray(const QVector<QString>& items)
|
||||
{
|
||||
QJsonArray array;
|
||||
for (const QString& item : items) {
|
||||
array.append(item);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Maps the Search type to an installed type. Used for filtering the installed
|
||||
content.
|
||||
|
||||
*/
|
||||
ScreenPlay::SearchType::SearchType getSearchTypeFromInstalledType(const ScreenPlay::InstalledType::InstalledType type)
|
||||
{
|
||||
using ScreenPlay::InstalledType::InstalledType;
|
||||
using ScreenPlay::SearchType::SearchType;
|
||||
|
||||
switch (type) {
|
||||
case InstalledType::GodotWallpaper:
|
||||
case InstalledType::HTMLWallpaper:
|
||||
case InstalledType::QMLWallpaper:
|
||||
case InstalledType::GifWallpaper:
|
||||
case InstalledType::WebsiteWallpaper:
|
||||
return SearchType::Scene;
|
||||
case InstalledType::VideoWallpaper:
|
||||
return SearchType::Wallpaper;
|
||||
case InstalledType::HTMLWidget:
|
||||
case InstalledType::QMLWidget:
|
||||
return SearchType::Widget;
|
||||
case InstalledType::Unknown:
|
||||
default:
|
||||
return SearchType::All;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Maps the installed type from a QString to an enum. Used for parsing the project.json.
|
||||
*/
|
||||
std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromString(const QString& type)
|
||||
{
|
||||
using ScreenPlay::InstalledType::InstalledType;
|
||||
|
||||
if (type.endsWith("Wallpaper")) {
|
||||
if (type.startsWith("video", Qt::CaseInsensitive)) {
|
||||
return InstalledType::VideoWallpaper;
|
||||
}
|
||||
if (type.startsWith("qml", Qt::CaseInsensitive)) {
|
||||
return InstalledType::QMLWallpaper;
|
||||
}
|
||||
if (type.startsWith("html", Qt::CaseInsensitive)) {
|
||||
return InstalledType::HTMLWallpaper;
|
||||
}
|
||||
if (type.startsWith("godot", Qt::CaseInsensitive)) {
|
||||
return InstalledType::GodotWallpaper;
|
||||
}
|
||||
if (type.startsWith("website", Qt::CaseInsensitive)) {
|
||||
return InstalledType::WebsiteWallpaper;
|
||||
}
|
||||
if (type.startsWith("gif", Qt::CaseInsensitive)) {
|
||||
return InstalledType::GifWallpaper;
|
||||
}
|
||||
}
|
||||
|
||||
if (type.endsWith("Widget")) {
|
||||
if (type.startsWith("qml", Qt::CaseInsensitive)) {
|
||||
return InstalledType::QMLWidget;
|
||||
}
|
||||
if (type.startsWith("html", Qt::CaseInsensitive)) {
|
||||
return InstalledType::HTMLWidget;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Converts the given \a url string to a local file path.
|
||||
*/
|
||||
QString toLocal(const QString& url)
|
||||
{
|
||||
return QUrl(url).toLocalFile();
|
||||
}
|
||||
|
||||
QStringList getAvailableWallpaper()
|
||||
{
|
||||
return {
|
||||
"qmlWallpaper",
|
||||
"htmlWallpaper",
|
||||
"videoWallpaper",
|
||||
"godotWallpaper",
|
||||
"gifWallpaper",
|
||||
"websiteWallpaper"
|
||||
};
|
||||
}
|
||||
|
||||
QStringList getAvailableWidgets()
|
||||
{
|
||||
return {
|
||||
"qmlWidget",
|
||||
"htmlWidget",
|
||||
};
|
||||
}
|
||||
|
||||
QStringList getAvailableTypes()
|
||||
{
|
||||
return { getAvailableWallpaper() + getAvailableWidgets() };
|
||||
}
|
||||
|
||||
bool isWallpaper(const ScreenPlay::InstalledType::InstalledType type)
|
||||
{
|
||||
|
||||
using ScreenPlay::InstalledType::InstalledType;
|
||||
|
||||
return (type == InstalledType::VideoWallpaper
|
||||
|| type == InstalledType::QMLWallpaper
|
||||
|| type == InstalledType::HTMLWallpaper
|
||||
|| type == InstalledType::GifWallpaper
|
||||
|| type == InstalledType::WebsiteWallpaper
|
||||
|| type == InstalledType::GodotWallpaper);
|
||||
}
|
||||
|
||||
bool isWidget(const ScreenPlay::InstalledType::InstalledType type)
|
||||
{
|
||||
|
||||
using ScreenPlay::InstalledType::InstalledType;
|
||||
|
||||
return (type == InstalledType::QMLWidget || type == InstalledType::HTMLWidget);
|
||||
}
|
||||
|
||||
}
|
6
ScreenPlayUtil/util.cpp
Normal file
6
ScreenPlayUtil/util.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "util.h"
|
||||
|
||||
Util::Util()
|
||||
{
|
||||
|
||||
}
|
11
ScreenPlayUtil/util.h
Normal file
11
ScreenPlayUtil/util.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
|
||||
class Util
|
||||
{
|
||||
public:
|
||||
Util();
|
||||
};
|
||||
|
||||
#endif // UTIL_H
|
@ -1,5 +1,6 @@
|
||||
project(ScreenPlayWallpaper LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
project(ScreenPlayWidget LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user