mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-07 03:22:33 +01:00
Add profile Loading
This commit is contained in:
parent
f78f0b889d
commit
1c39a2a595
@ -4,3 +4,13 @@ Profile::Profile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Profile::Profile(QString id, QString version, QString wallpaperId, QRect rect, bool isLooping)
|
||||
{
|
||||
m_id = id;
|
||||
m_version = version;
|
||||
m_wallpaperId = wallpaperId;
|
||||
m_rect = rect;
|
||||
m_isLooping = isLooping;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,19 @@
|
||||
#ifndef PROFILE_H
|
||||
#define PROFILE_H
|
||||
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
|
||||
class Profile
|
||||
{
|
||||
class Profile {
|
||||
public:
|
||||
Profile();
|
||||
Profile(QString id, QString version, QString wallpaperId, QRect rect, bool isLooping);
|
||||
|
||||
QString m_id;
|
||||
QString m_version = "";
|
||||
QString m_wallpaperId = "";
|
||||
QRect m_rect;
|
||||
bool m_isLooping = true;
|
||||
};
|
||||
|
||||
#endif // PROFILE_H
|
||||
#endif // PROFILE_H
|
||||
|
@ -1,8 +1,15 @@
|
||||
#include "profilelistmodel.h"
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfoList>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QPair>
|
||||
|
||||
ProfileListModel::ProfileListModel(QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
loadProfiles();
|
||||
}
|
||||
|
||||
int ProfileListModel::rowCount(const QModelIndex& parent) const
|
||||
@ -40,17 +47,71 @@ QHash<int, QByteArray> ProfileListModel::roleNames() const
|
||||
void ProfileListModel::loadProfiles()
|
||||
{
|
||||
|
||||
QString writablePath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) ;
|
||||
QString writablePath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/Profiles";
|
||||
if (!QDir(writablePath).exists()) {
|
||||
if (!QDir().mkdir(writablePath)) {
|
||||
qWarning("ERROR: Cloud not create install dir");
|
||||
|
||||
qWarning("Error could not create Profiles folder");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
QFileInfoList list = QDir(writablePath).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
|
||||
QString tmpPath;
|
||||
QJsonDocument profileDoc;
|
||||
QJsonParseError parseError;
|
||||
QJsonObject profileObj;
|
||||
|
||||
for (auto&& item : list) {
|
||||
tmpPath = writablePath + "/" + item.baseName() + "/profile.json";
|
||||
|
||||
QFile settings;
|
||||
settings.setFileName(tmpPath);
|
||||
settings.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QString projectConfigData = settings.readAll();
|
||||
profileDoc = QJsonDocument::fromJson(projectConfigData.toUtf8(), &parseError);
|
||||
|
||||
if (!(parseError.error == QJsonParseError::NoError))
|
||||
continue;
|
||||
|
||||
profileObj = profileDoc.object();
|
||||
|
||||
Profile tmpProfile;
|
||||
tmpProfile.m_id = item.baseName();
|
||||
|
||||
if (profileObj.contains("version"))
|
||||
tmpProfile.m_version = profileObj.value("version").toString();
|
||||
|
||||
if (profileObj.contains("wallpaperId"))
|
||||
tmpProfile.m_wallpaperId = profileObj.value("wallpaperId").toString();
|
||||
|
||||
if (profileObj.contains("width") && profileObj.contains("height") && profileObj.contains("xPos") && profileObj.contains("yPos")) {
|
||||
//Check for inpossible values
|
||||
if (profileObj.value("width").toInt() == 0 || profileObj.value("height").toInt() == 0) {
|
||||
continue;
|
||||
}
|
||||
tmpProfile.m_rect.setWidth(profileObj.value("width").toInt());
|
||||
tmpProfile.m_rect.setHeight(profileObj.value("height").toInt());
|
||||
tmpProfile.m_rect.setX(profileObj.value("xPos").toInt());
|
||||
tmpProfile.m_rect.setY(profileObj.value("yPos").toInt());
|
||||
|
||||
} else {
|
||||
qWarning("Parsing error");
|
||||
}
|
||||
|
||||
if (profileObj.contains("isLooping"))
|
||||
tmpProfile.m_isLooping = profileObj.value("isLooping").toBool();
|
||||
|
||||
m_profileList.append(tmpProfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ProfileListModel::getProfileByName(QString id, Profile* profile)
|
||||
{
|
||||
for (int i = 0; i < m_profileList.size(); i++) {
|
||||
if (m_profileList.at(i).m_id == id) {
|
||||
*profile = m_profileList.at(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
|
||||
#include "profile.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QVector>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class Profile;
|
||||
|
||||
class ProfileListModel : public QAbstractListModel {
|
||||
@ -26,10 +28,11 @@ public:
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
virtual QHash<int, QByteArray> roleNames() const override;
|
||||
void loadProfiles();
|
||||
bool getProfileByName(QString id, Profile* profile);
|
||||
|
||||
private:
|
||||
QHash<int, QByteArray> m_roleNames;
|
||||
QVector<Profile*> m_profileList;
|
||||
QVector<Profile> m_profileList;
|
||||
};
|
||||
|
||||
#endif // PROFILELISTMODEL_H
|
||||
|
@ -1,15 +1,20 @@
|
||||
#include "settings.h"
|
||||
|
||||
Settings::Settings(QObject* parent)
|
||||
Settings::Settings(ProfileListModel* plm, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
m_plm = plm;
|
||||
|
||||
QFile configTmp;
|
||||
QString appConfigLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
configTmp.setFileName(appConfigLocation + "/settings.json");
|
||||
|
||||
// App Settings
|
||||
if (!configTmp.exists())
|
||||
if (!configTmp.exists()) {
|
||||
qWarning("No Settings found, creating default settings");
|
||||
createDefaultConfig();
|
||||
}
|
||||
|
||||
QJsonDocument configJsonDocument;
|
||||
QJsonParseError parseError;
|
||||
@ -20,6 +25,7 @@ Settings::Settings(QObject* parent)
|
||||
configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError);
|
||||
|
||||
if (!(parseError.error == QJsonParseError::NoError)) {
|
||||
qWarning("Settings Json Parse Error ");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -33,6 +39,7 @@ Settings::Settings(QObject* parent)
|
||||
//Checks if the settings file has the same version as ScreeenPlay
|
||||
if (!(major == m_version.major && minor == m_version.minor && patch == m_version.patch)) {
|
||||
//TODO Display error message
|
||||
qWarning("Version missmatch");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,21 +59,24 @@ Settings::Settings(QObject* parent)
|
||||
// Only load profiles if we have any
|
||||
if (size > 0) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
QString profile = activeProfilesTmp.at(i).toObject().value("profile").toString();
|
||||
QString profileName = activeProfilesTmp.at(i).toObject().value("profile").toString();
|
||||
QString monitorID = activeProfilesTmp.at(i).toObject().value("monitorID").toString();
|
||||
m_activeProfiles.append(ActiveProfiles(profile, monitorID));
|
||||
Profile profile;
|
||||
if (!m_plm->getProfileByName(profileName, &profile))
|
||||
continue;
|
||||
m_activeProfiles.append(ActiveProfiles(monitorID, profile));
|
||||
constructWallpaper(profile, monitorID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Settings::createNewProfile(int screenNumber)
|
||||
{
|
||||
}
|
||||
|
||||
void Settings::constructWallpaper(QString profile, QString monitorID)
|
||||
void Settings::constructWallpaper(Profile profile, QString monitorID)
|
||||
{
|
||||
qDebug() << monitorID;
|
||||
//m_wallpapers.append(Wallpaper( ));
|
||||
}
|
||||
|
||||
@ -92,8 +102,8 @@ ActiveProfiles::ActiveProfiles()
|
||||
{
|
||||
}
|
||||
|
||||
ActiveProfiles::ActiveProfiles(QString name, QString id)
|
||||
ActiveProfiles::ActiveProfiles(QString wallpaperId, Profile profile)
|
||||
{
|
||||
m_name = name;
|
||||
m_id = id;
|
||||
m_monitorId = wallpaperId;
|
||||
m_profile = profile;
|
||||
}
|
||||
|
@ -8,17 +8,18 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QObject >
|
||||
#include <QPair>
|
||||
#include <QQmlPropertyMap>
|
||||
#include <QStandardPaths>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
#include <QUrl>
|
||||
|
||||
#include "wallpaper.h"
|
||||
#include "profile.h"
|
||||
|
||||
#include "profilelistmodel.h"
|
||||
#include "wallpaper.h"
|
||||
|
||||
class ActiveProfiles;
|
||||
class Profile;
|
||||
@ -26,7 +27,7 @@ class Profile;
|
||||
class Settings : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Settings(QObject* parent = nullptr);
|
||||
explicit Settings(ProfileListModel* plm, QObject* parent = nullptr);
|
||||
|
||||
Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
|
||||
Q_PROPERTY(bool highPriorityStart READ highPriorityStart WRITE setHighPriorityStart NOTIFY highPriorityStartChanged)
|
||||
@ -35,7 +36,7 @@ public:
|
||||
Q_PROPERTY(Version version READ version)
|
||||
|
||||
Q_INVOKABLE void createNewProfile(int screenNumber);
|
||||
Q_INVOKABLE void constructWallpaper(QString profile, QString monitorID);
|
||||
Q_INVOKABLE void constructWallpaper(Profile profile, QString monitorID);
|
||||
|
||||
enum Renderer {
|
||||
OpenGL,
|
||||
@ -46,7 +47,7 @@ public:
|
||||
struct Version {
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
int patch = 1;
|
||||
};
|
||||
|
||||
bool autostart() const
|
||||
@ -88,7 +89,6 @@ public slots:
|
||||
|
||||
void setAutostart(bool autostart)
|
||||
{
|
||||
qDebug() << autostart;
|
||||
if (m_autostart == autostart)
|
||||
return;
|
||||
|
||||
@ -141,22 +141,19 @@ private:
|
||||
Renderer m_renderer = Renderer::OpenGL;
|
||||
bool m_sendStatistics;
|
||||
Version m_version;
|
||||
ProfileListModel* m_plm;
|
||||
|
||||
QVector<Wallpaper> m_wallpapers;
|
||||
QVector<ActiveProfiles> m_activeProfiles;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ActiveProfiles {
|
||||
public:
|
||||
ActiveProfiles();
|
||||
ActiveProfiles(QString name, QString id);
|
||||
ActiveProfiles(QString monitorId, Profile profile);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_id;
|
||||
QString m_monitorId;
|
||||
Profile m_profile;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user