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

Fix start of wallpaper

This commit is contained in:
Elias Steurer 2024-05-21 14:06:28 +02:00
parent 7dcaa3b016
commit 00d77d815e
9 changed files with 317 additions and 285 deletions

View File

@ -51,223 +51,25 @@ public:
Q_INVOKABLE bool removeAllWidgets(bool saveToProfile = false);
Q_INVOKABLE bool removeWallpaperAt(const int index);
// Timeline wallpaper updates:
// 1. Disable timeline updates
// Optional: 1.1 Insert new timeline
// 2. Call setWallpaperAtTimelineIndex
Q_INVOKABLE ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID);
// We always handle the endTimeString, because it is the handle for the
// timeline. The last, default, timeline does not have a handle.
Q_INVOKABLE bool moveTimelineAt(
const int index,
const QString identifier,
const float relativePosition,
QString positionTimeString)
{
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
QString positionTimeString);
auto& wallpapterTimelineSection = m_wallpaperTimelineSectionsList.at(index);
QTime newPositionTime = QTime::fromString(positionTimeString, "hh:mm");
if (!newPositionTime.isValid()) {
qWarning() << "Unable to move with invalid time:" << positionTimeString;
return false;
}
wallpapterTimelineSection->endTime = newPositionTime;
wallpapterTimelineSection->relativePosition = relativePosition;
// We set the identifier here, because we generate it in qml
// The identiefier is only used for debugging
wallpapterTimelineSection->identifier = identifier;
Q_INVOKABLE QString getTimeString(double relativeLinePosition);
const auto timelineCount = m_wallpaperTimelineSectionsList.size();
// Only update the next timeline startTime
// if we are not end last wallpaper, that always
// must end at 24:00
if (index <= timelineCount) {
auto& wallpapterTimelineSectionNext = m_wallpaperTimelineSectionsList.at(index + 1);
wallpapterTimelineSectionNext->startTime = newPositionTime;
}
printTimelines();
return true;
}
Q_INVOKABLE QString getTimeString(double relativeLinePosition)
{
const double totalHours = relativeLinePosition * 24;
int hours = static_cast<int>(std::floor(totalHours)); // Gets the whole hour part
double fractionalHours = totalHours - hours;
int minutes = static_cast<int>(std::floor(fractionalHours * 60)); // Calculates the minutes
double fractionalMinutes = fractionalHours * 60 - minutes;
int seconds = static_cast<int>(std::round(fractionalMinutes * 60)); // Calculates the seconds
// Adjust minutes and seconds if seconds rolled over to 60
if (seconds == 60) {
seconds = 0;
minutes += 1;
}
// Adjust hours and minutes if minutes rolled over to 60
if (minutes == 60) {
minutes = 0;
hours += 1;
}
// Ensure hours wrap correctly at 24
if (hours == 24) {
hours = 0;
}
// Format the output to "HH:MM:SS"
return QString("%1:%2:%3").arg(hours, 2, 10, QChar('0')).arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0'));
}
void updateIndices()
{
// Sort the vector based on relativePosition
std::sort(m_wallpaperTimelineSectionsList.begin(), m_wallpaperTimelineSectionsList.end(),
[](const auto& a, const auto& b) {
return a->startTime < b->startTime;
});
// Update the indices based on new order
for (int i = 0; i < m_wallpaperTimelineSectionsList.size(); ++i) {
m_wallpaperTimelineSectionsList[i]->index = i;
}
}
Q_INVOKABLE bool addTimelineAt(
const int index,
const float reltiaveLinePosition,
QString identifier)
{
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
// We always get the new endTime
const QString newStopPosition = getTimeString(reltiaveLinePosition);
QTime newStopPositionTime = QTime::fromString(newStopPosition, m_timelineTimeFormat);
if (!newStopPositionTime.isValid()) {
return false;
}
// IMPORTANT: The new element is always on the left. The first
// handle always persists because the
// user can never delete it. It only gets "pushed" further
// to the right, by increasing the size.
// | Insert here
// ˇ
// |-----------------------------------------------|
// 0 ID: AAA
//
//
// |-----------------------|-----------------------|
// 0 ID: BBB 1 - ID: AAA
// We directly get the new index of 0 in this example from qml
auto newTimelineSection = std::make_shared<WallpaperTimelineSection>();
newTimelineSection->index = index;
newTimelineSection->identifier = identifier;
newTimelineSection->endTime = newStopPositionTime;
// We can use the given index here, because it points
// the the current item at that index, and we have not yet
// added our new timelineSection to our list.
newTimelineSection->startTime = m_wallpaperTimelineSectionsList.at(index)->startTime;
const bool isLast = (m_wallpaperTimelineSectionsList.length() - 1) == index;
if(isLast){
m_wallpaperTimelineSectionsList.last()->startTime = newTimelineSection->endTime;
}
m_wallpaperTimelineSectionsList.append(newTimelineSection);
updateIndices();
printTimelines();
return true;
}
Q_INVOKABLE bool removeTimelineAt(const int index)
{
printTimelines();
const auto timelineCount = m_wallpaperTimelineSectionsList.size();
if (timelineCount == 0) {
qCritical() << "Timeline empty";
return false;
}
if (timelineCount == 1) {
qCritical() << "Timeline must always have at least one element, that span across the whole timeline from 00:00:00 to 23:59:59.";
return false;
}
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
auto& wallpapterTimelineSection = m_wallpaperTimelineSectionsList.at(index);
// When we have two timelines, we know that only the first
// timeline can be removed and the second one will then span
// across the whole timeline
// remove <- expand
// |-----------|-----------|
// 0 1
if (timelineCount == 2) {
if (index != 0) {
qCritical() << "Removing the last timeline is not allowed. This must always span the whole timeline";
return false;
}
m_wallpaperTimelineSectionsList.removeAt(index);
m_wallpaperTimelineSectionsList.first()->startTime = QTime::fromString("00:00:00", m_timelineTimeFormat);
updateIndices();
printTimelines();
return true;
}
// Now handle all states where we have more than two wallpaper
// There is no timeline before if we want to remove
// the timeline at index 0. We do not need to make the same
// check for the timelineAfter, because the last timeline
// cannot be deleted
QTime endTime;
if(index == 0){
endTime = QTime::fromString("00:00:00", m_timelineTimeFormat);
}else {
endTime = m_wallpaperTimelineSectionsList.at(index - 1)->endTime;
}
auto timelineAfter = m_wallpaperTimelineSectionsList.at(index + 1);
// before remove <- expand
// |-----------|-----------|-----------|
// 0 1 2
// Now when removing timeline at index 1, the next (after)
// wallpaper gets the remaining space
timelineAfter->startTime = endTime;
m_wallpaperTimelineSectionsList.removeAt(index);
updateIndices();
printTimelines();
return true;
printTimelines();
return true;
}
void printTimelines()
{
std::cout << "#############################\n";
for (auto& timeline : m_wallpaperTimelineSectionsList) {
std::cout <<timeline->index << ": " << timeline->identifier.toStdString() << "\t" << timeline->relativePosition << " start: " << timeline->startTime.toString().toStdString() << " end: " << timeline->endTime.toString().toStdString() << std::endl;
}
}
Q_INVOKABLE QVariantMap initialStopPositions()
{
QVariantMap sectionPositions;
for (const auto& timelineSection : m_wallpaperTimelineSectionsList) {
sectionPositions.insert({timelineSection->identifier},{timelineSection->relativePosition});
}
return sectionPositions;
}
QString identifier);
Q_INVOKABLE bool removeTimelineAt(const int index);
Q_INVOKABLE QVariantMap initialStopPositions();
Q_INVOKABLE bool setWallpaperAtTimelineIndex(
const ScreenPlay::ContentTypes::InstalledType type,
const ScreenPlay::Video::FillMode fillMode,
@ -279,8 +81,7 @@ public:
const float playbackRate,
const QJsonObject& properties,
const int timelineIndex,
const QString& startTimeString,
const QString& endTimeString,
const QString& identifier,
const bool saveToProfilesConfigFile);
Q_INVOKABLE bool createWidget(
@ -297,8 +98,8 @@ public:
Q_INVOKABLE bool setWallpaperFillModeAtMonitorIndex(const int index, const int fillmode);
Q_INVOKABLE bool setAllWallpaperValue(const QString& key, const QString& value);
Q_INVOKABLE bool setWallpaperValue(const QString& appID, const QString& key, const QString& value);
QVersionNumber getProfilesVersion() const;
bool removeWallpaperAtTimelineIndex(const int timelineIndex, const int monitorIndex);
signals:
void activeWallpaperCounterChanged(int activeWallpaperCounter);
void activeWidgetsCounterChanged(int activeWidgetsCounter);
@ -366,7 +167,10 @@ public slots:
}
private:
void printTimelines();
bool loadProfiles();
void updateIndices();
bool loadWidgetConfig(const QJsonObject& widget);
std::optional<WallpaperData> loadWallpaperConfig(const QJsonObject& wallpaper);
bool checkIsAnotherScreenPlayInstanceRunning();
@ -397,5 +201,6 @@ private:
// We use a 24 hour system
const QString m_timelineTimeFormat = "hh:mm:ss";
const quint16 m_webSocketPort = 16395;
};
}

View File

@ -122,6 +122,9 @@ public:
ScreenPlay::Settings::DesktopEnvironment desktopEnvironment() const { return m_desktopEnvironment; }
const QString& buildInfos() const { return m_buildInfos; }
bool showDefaultContent() const { return m_showDefaultContent; }
void writeDefaultProfiles();
QVersionNumber getProfilesVersion() const;
signals:
void requestRetranslation();
@ -146,7 +149,7 @@ signals:
public slots:
void setupLanguage();
void writeJsonFileFromResource(const QString& filename);
void initProfilesSettings();
void setupWidgetAndWindowPaths();
bool retranslateUI();
@ -167,7 +170,6 @@ public slots:
void setBuildInfos(const QString& buildInfos);
private:
void restoreDefault(const QString& appConfigLocation, const QString& settingsFileType);
void initInstalledPath();
void initSteamInstalledPath();
QString fixLanguageCode(const QString& languageCode);
@ -192,5 +194,7 @@ private:
QString m_font { "Roboto" };
QString m_decoder;
QString m_buildInfos;
QVersionNumber m_profilesVersion { 2, 0, 0 };
};
}

View File

@ -1,16 +1,19 @@
{
"version":"1.0.0",
"profilesWallpaper":[
],
"profilesWidgets":[
"profiles": [
{
}
],
"profilesAppDrawer":[
"appdrawer": [],
"name": "default",
"timelineWallpaper": [
{
}
"name": "default",
"startTime": "00:00:00",
"endTime": "23:59:59",
"wallpaper": [
]
}
],
"widgets": []
}
],
"version": "2.0.0"
}

View File

@ -14,6 +14,11 @@ Control {
leftPadding: 20
rightPadding: 20
property int activeTimelineIndex: 0
function getActiveTimeline(){
return timeLine.sectionsList[root.activeTimelineIndex]
}
function removeAll(){
timeLine.removeAll()
@ -162,14 +167,15 @@ Control {
App.screenPlayManager.moveTimelineAt(section.index, section.identifier, lineHandle.linePosition, lineHandle.timeString)
}
function lineIndicatorSelected(selectedIndicatorindex) {
function lineIndicatorSelected(activeTimelineIndex) {
for (let i = 0; i < timeLine.sectionsList.length; i++) {
if (i === selectedIndicatorindex) {
if (i === activeTimelineIndex) {
timeLine.sectionsList[i].lineIndicator.selected = true
continue
}
timeLine.sectionsList[i].lineIndicator.selected = false
}
root.activeTimelineIndex = activeTimelineIndex
}
// We must update all indexes when removing/adding an element

View File

@ -6,7 +6,6 @@ import QtQuick.Dialogs
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
import ScreenPlayApp
import ScreenPlayUtil
import "../Monitors"
import "../Components"
@ -381,19 +380,16 @@ Drawer {
return
}
const activeTimeline = timeline.getActiveTimeline()
const screenFile = item.m_file
const playbackRate = 1
const jsonProperties = {}
const timelineIndex = 0
const startTimeString = 0
const endTimeString = 0
let success = App.screenPlayManager.addWallpaperAtTimelineIndex(
let success = App.screenPlayManager.setWallpaperAtTimelineIndex(
root.type, cbVideoFillMode.currentValue,
absoluteStoragePath, previewImage, screenFile,
activeMonitors, volume, playbackRate, jsonProperties,
timelineIndex,
startTimeString,
endTimeString,
activeTimeline.activeTimelineIndex,
activeTimeline.identifier,
true)
}
if (App.util.isWidget(root.type))

View File

@ -37,7 +37,7 @@ namespace ScreenPlay {
*/
/*!
\brief Constructor when loading properties from settings.json
\brief Constructor when loading properties from profiles.json
We need to _flatten_ the json to make it work with a flat list model!
See \sa getActiveSettingsJson to make the flat list to a hierarchical json object
*/

View File

@ -56,6 +56,7 @@ std::shared_ptr<WallpaperTimelineSection> ScreenPlayManager::findActiveSection()
}
return nullptr; // No active section contains the current time
}
/*!
\brief Checks if we need to display a different wallpaper at the current time.
*/
@ -92,10 +93,6 @@ void ScreenPlayManager::checkActiveWallpaperTimeline()
// TODO: Check if we can reuse some active wallpaper
}
bool ScreenPlayManager::removeWallpaperAtTimelineIndex(const int timelineIndex, const int monitorIndex)
{
return {};
}
/*!
\brief Qml function, because we cannot create the WallpaperData in qml.
@ -111,8 +108,7 @@ bool ScreenPlayManager::setWallpaperAtTimelineIndex(
const float playbackRate,
const QJsonObject& properties,
const int timelineIndex,
const QString& startTimeString,
const QString& endTimeString,
const QString& identifier,
const bool saveToProfilesConfigFile)
{
WallpaperData wallpaperData;
@ -126,12 +122,16 @@ bool ScreenPlayManager::setWallpaperAtTimelineIndex(
wallpaperData.playbackRate = playbackRate;
wallpaperData.properties = properties;
const QTime startTime = QTime::fromString(startTimeString, m_timelineTimeFormat);
const QTime endTime = QTime::fromString(startTimeString, m_timelineTimeFormat);
if (!startTime.isValid() || !endTime.isValid()) {
qWarning() << "Invalid time, startTime: " << startTime << " endTime " << endTime;
return false;
for (auto& timelineSection : m_wallpaperTimelineSectionsList) {
const bool sameIndex = timelineSection->index == timelineIndex;
const bool sameIdentifier = timelineSection->identifier == identifier;
if(sameIndex && sameIdentifier){
// TODO vec
timelineSection->wallpaperData = {wallpaperData};
break;
} else if(sameIdentifier || sameIdentifier){
qCritical()<< "Invalid";
}
}
auto wallpaper = startWallpaper(
@ -158,7 +158,7 @@ void ScreenPlayManager::init(
// the existing one
if (!loadProfiles()) {
qInfo() << "Reset default profiles.json at:" << m_globalVariables->localSettingsPath();
m_settings->writeJsonFileFromResource("profiles");
m_settings->writeDefaultProfiles();
}
}
@ -438,6 +438,209 @@ ScreenPlayWallpaper* ScreenPlayManager::getWallpaperByAppID(const QString& appID
return nullptr;
}
// We always handle the endTimeString, because it is the handle for the
// timeline. The last, default, timeline does not have a handle.
bool ScreenPlayManager::moveTimelineAt(const int index, const QString identifier, const float relativePosition, QString positionTimeString)
{
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
auto& wallpapterTimelineSection = m_wallpaperTimelineSectionsList.at(index);
QTime newPositionTime = QTime::fromString(positionTimeString, "hh:mm");
if (!newPositionTime.isValid()) {
qWarning() << "Unable to move with invalid time:" << positionTimeString;
return false;
}
wallpapterTimelineSection->endTime = newPositionTime;
wallpapterTimelineSection->relativePosition = relativePosition;
// We set the identifier here, because we generate it in qml
// The identiefier is only used for debugging
wallpapterTimelineSection->identifier = identifier;
const auto timelineCount = m_wallpaperTimelineSectionsList.size();
// Only update the next timeline startTime
// if we are not end last wallpaper, that always
// must end at 24:00
if (index <= timelineCount) {
auto& wallpapterTimelineSectionNext = m_wallpaperTimelineSectionsList.at(index + 1);
wallpapterTimelineSectionNext->startTime = newPositionTime;
}
printTimelines();
return true;
}
QString ScreenPlayManager::getTimeString(double relativeLinePosition)
{
const double totalHours = relativeLinePosition * 24;
int hours = static_cast<int>(std::floor(totalHours)); // Gets the whole hour part
double fractionalHours = totalHours - hours;
int minutes = static_cast<int>(std::floor(fractionalHours * 60)); // Calculates the minutes
double fractionalMinutes = fractionalHours * 60 - minutes;
int seconds = static_cast<int>(std::round(fractionalMinutes * 60)); // Calculates the seconds
// Adjust minutes and seconds if seconds rolled over to 60
if (seconds == 60) {
seconds = 0;
minutes += 1;
}
// Adjust hours and minutes if minutes rolled over to 60
if (minutes == 60) {
minutes = 0;
hours += 1;
}
// Ensure hours wrap correctly at 24
if (hours == 24) {
hours = 0;
}
// Format the output to "HH:MM:SS"
return QString("%1:%2:%3").arg(hours, 2, 10, QChar('0')).arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0'));
}
void ScreenPlayManager::updateIndices()
{
// Sort the vector based on startTime
std::sort(m_wallpaperTimelineSectionsList.begin(), m_wallpaperTimelineSectionsList.end(),
[](const auto& a, const auto& b) {
return a->startTime < b->startTime;
});
// Update the indices based on new order
for (int i = 0; i < m_wallpaperTimelineSectionsList.size(); ++i) {
m_wallpaperTimelineSectionsList[i]->index = i;
}
}
bool ScreenPlayManager::addTimelineAt(const int index, const float reltiaveLinePosition, QString identifier)
{
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
// We always get the new endTime
const QString newStopPosition = getTimeString(reltiaveLinePosition);
QTime newStopPositionTime = QTime::fromString(newStopPosition, m_timelineTimeFormat);
if (!newStopPositionTime.isValid()) {
return false;
}
// IMPORTANT: The new element is always on the left. The first
// handle always persists because the
// user can never delete it. It only gets "pushed" further
// to the right, by increasing the size.
// | Insert here
// ˇ
// |-----------------------------------------------|
// 0 ID: AAA
//
//
// |-----------------------|-----------------------|
// 0 ID: BBB 1 - ID: AAA
// We directly get the new index of 0 in this example from qml
auto newTimelineSection = std::make_shared<WallpaperTimelineSection>();
newTimelineSection->index = index;
newTimelineSection->identifier = identifier;
newTimelineSection->endTime = newStopPositionTime;
// We can use the given index here, because it points
// the the current item at that index, and we have not yet
// added our new timelineSection to our list.
newTimelineSection->startTime = m_wallpaperTimelineSectionsList.at(index)->startTime;
const bool isLast = (m_wallpaperTimelineSectionsList.length() - 1) == index;
if(isLast){
m_wallpaperTimelineSectionsList.last()->startTime = newTimelineSection->endTime;
}
m_wallpaperTimelineSectionsList.append(newTimelineSection);
updateIndices();
printTimelines();
return true;
}
bool ScreenPlayManager::removeTimelineAt(const int index)
{
printTimelines();
const auto timelineCount = m_wallpaperTimelineSectionsList.size();
if (timelineCount == 0) {
qCritical() << "Timeline empty";
return false;
}
if (timelineCount == 1) {
qCritical() << "Timeline must always have at least one element, that span across the whole timeline from 00:00:00 to 23:59:59.";
return false;
}
m_contentTimer.stop();
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
auto& wallpapterTimelineSection = m_wallpaperTimelineSectionsList.at(index);
// When we have two timelines, we know that only the first
// timeline can be removed and the second one will then span
// across the whole timeline
// remove <- expand
// |-----------|-----------|
// 0 1
if (timelineCount == 2) {
if (index != 0) {
qCritical() << "Removing the last timeline is not allowed. This must always span the whole timeline";
return false;
}
m_wallpaperTimelineSectionsList.removeAt(index);
m_wallpaperTimelineSectionsList.first()->startTime = QTime::fromString("00:00:00", m_timelineTimeFormat);
updateIndices();
printTimelines();
return true;
}
// Now handle all states where we have more than two wallpaper
// There is no timeline before if we want to remove
// the timeline at index 0. We do not need to make the same
// check for the timelineAfter, because the last timeline
// cannot be deleted
QTime endTime;
if(index == 0){
endTime = QTime::fromString("00:00:00", m_timelineTimeFormat);
}else {
endTime = m_wallpaperTimelineSectionsList.at(index - 1)->endTime;
}
auto timelineAfter = m_wallpaperTimelineSectionsList.at(index + 1);
// before remove <- expand
// |-----------|-----------|-----------|
// 0 1 2
// Now when removing timeline at index 1, the next (after)
// wallpaper gets the remaining space
timelineAfter->startTime = endTime;
m_wallpaperTimelineSectionsList.removeAt(index);
updateIndices();
printTimelines();
return true;
printTimelines();
return true;
}
void ScreenPlayManager::printTimelines()
{
std::cout << "#############################\n";
for (auto& timeline : m_wallpaperTimelineSectionsList) {
std::cout <<timeline->index << ": " << timeline->identifier.toStdString() << "\t" << timeline->relativePosition << " start: " << timeline->startTime.toString().toStdString() << " end: " << timeline->endTime.toString().toStdString() << std::endl;
}
}
QVariantMap ScreenPlayManager::initialStopPositions()
{
QVariantMap sectionPositions;
for (const auto& timelineSection : m_wallpaperTimelineSectionsList) {
sectionPositions.insert({timelineSection->identifier},{timelineSection->relativePosition});
}
return sectionPositions;
}
/*!
\brief Appends a new SDKConnection object shared_ptr to the m_clients list.
*/
@ -637,7 +840,7 @@ bool ScreenPlayManager::loadProfiles()
}
std::optional<QVersionNumber> version = util.getVersionNumberFromString(configObj->value("version").toString());
QVersionNumber requiredVersion { 1, 0, 0 };
QVersionNumber requiredVersion = m_settings->getProfilesVersion();
if (version && *version != requiredVersion) {
qWarning() << "Version missmatch fileVersion: " << version->toString() << "m_version: " << requiredVersion.toString();
return false;
@ -697,7 +900,7 @@ bool ScreenPlayManager::loadProfiles()
}
// The can happen if the user unpluggs a wallpaper but it still exists
// in the settings.json. For this we save all profiles with now active
// in the profiles.json. For this we save all profiles with now active
// content.
if (containsInvalidData)
saveProfiles();

View File

@ -98,43 +98,73 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
setAnonymousTelemetry(m_qSettings.value("AnonymousTelemetry", true).toBool());
// Wallpaper and Widgets config
QFile profilesFile(m_globalVariables->localSettingsPath().toString() + "/profiles.json");
if (!profilesFile.exists()) {
qInfo("No profiles.json found, creating default profiles.json");
writeJsonFileFromResource("profiles");
}
initProfilesSettings();
initInstalledPath();
setupWidgetAndWindowPaths();
}
/*!
\brief Writes the default JsonFile from the resources and the given \a filename. Currently we have two default json files:
\list
\li profiles.json
\li settings.json
\endlist
\brief Writes the default profiles json if we do not have any or we do have a major
version bump. We delete the old config for now.
*/
void Settings::writeJsonFileFromResource(const QString& filename)
void Settings::initProfilesSettings()
{
QFile file(m_globalVariables->localSettingsPath().toString() + "/" + filename + ".json");
const QString defaultProfilesFilePath = m_globalVariables->localSettingsPath().toString() + "/profiles.json";
// Wallpaper and Widgets config
QFile profilesFile(defaultProfilesFilePath);
if (!profilesFile.exists()) {
qInfo("No profiles.json found, creating default profiles.json");
return writeDefaultProfiles();
}
profilesFile.close();
// TODO version check
const auto jsonObjOpt = Util().openJsonFileToObject(defaultProfilesFilePath);
if (jsonObjOpt.has_value()) {
const QJsonObject profilesSettings = jsonObjOpt.value();
if(!profilesSettings.contains("version"))
return writeDefaultProfiles();
const auto profilesSettingsVersion = QVersionNumber::fromString(profilesSettings.value("version").toString());
if(profilesSettingsVersion.isNull())
return writeDefaultProfiles();
if(profilesSettingsVersion < m_profilesVersion)
return writeDefaultProfiles();
}
}
void Settings::writeDefaultProfiles(){
QFileInfo fileInfo(m_globalVariables->localSettingsPath().toString() + "/profiles.json");
QFile profilesFile(fileInfo.absoluteFilePath());
qInfo() << "Writing default profiles config to: " << fileInfo.absoluteFilePath();
QDir directory(m_globalVariables->localSettingsPath().toString());
if (!directory.exists()) {
directory.mkpath(directory.path());
}
QFile defaultSettings(":/qml/ScreenPlayApp/" + filename + ".json");
QFile defaultProfileFile(":/qml/ScreenPlayApp/profiles.json");
file.open(QIODevice::WriteOnly | QIODevice::Text);
defaultSettings.open(QIODevice::ReadOnly | QIODevice::Text);
profilesFile.open(QIODevice::WriteOnly | QIODevice::Text);
defaultProfileFile.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream out(&file);
QTextStream defaultOut(&defaultSettings);
QTextStream out(&profilesFile);
QTextStream defaultOut(&defaultProfileFile);
out << defaultOut.readAll();
file.close();
defaultSettings.close();
profilesFile.close();
defaultProfileFile.close();
}
QVersionNumber Settings::getProfilesVersion() const
{
return m_profilesVersion;
}
/*!
@ -190,21 +220,6 @@ void Settings::setupWidgetAndWindowPaths()
}
}
/*!
\brief When no default language is set in the registry we check the system set language. If there is no
matching translation is available we set it to english. This function gets called from the UI when
the user manually changes the language.
*/
void Settings::restoreDefault(const QString& appConfigLocation, const QString& settingsFileType)
{
QString fullSettingsPath { appConfigLocation + "/" + settingsFileType + ".json" };
qWarning() << "Unable to load config from " << fullSettingsPath
<< ". Restoring default!";
QFile file { fullSettingsPath };
file.remove();
writeJsonFileFromResource(settingsFileType);
}
void Settings::initInstalledPath()
{
const QString contentPath = m_qSettings.value("ScreenPlayContentPath", "").toString();

View File

@ -48,5 +48,5 @@
"widgets": []
}
],
"version": "1.0.0"
"version": "2.0.0"
}