mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-02 08:39:49 +02:00
class ScreenPlay - minor changes and improvements
This commit is contained in:
parent
273a4cbaca
commit
14bddbe991
@ -1,97 +1,93 @@
|
||||
#include "screenplay.h"
|
||||
|
||||
ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_ilm = ilm;
|
||||
m_settings = set;
|
||||
m_mlm = mlm;
|
||||
m_qGuiApplication = static_cast<QGuiApplication*>(QGuiApplication::instance());
|
||||
m_sdkc = sdkc;
|
||||
}
|
||||
: QObject{parent},
|
||||
m_ilm{ilm},
|
||||
m_settings{set},
|
||||
m_mlm{mlm},
|
||||
m_qGuiApplication{static_cast<QGuiApplication*>(QGuiApplication::instance())},
|
||||
m_sdkc{sdkc}
|
||||
{}
|
||||
|
||||
void ScreenPlay::createWallpaper(int monitorIndex, QUrl absoluteStoragePath, QString previewImage, float volume, QString fillMode, QString type)
|
||||
void ScreenPlay::createWallpaper(
|
||||
const int monitorIndex, QUrl absoluteStoragePath,
|
||||
const QString &previewImage, const float volume,
|
||||
const QString &fillMode, const QString &type)
|
||||
{
|
||||
ProjectFile project;
|
||||
|
||||
ProjectFile project{};
|
||||
if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove previous wallpaper
|
||||
removeWallpaperAt(monitorIndex);
|
||||
|
||||
// Remove previous wallpaper, if any
|
||||
//this->removeAllWallpaper();
|
||||
this->removeWallpaperAt(0);
|
||||
m_settings->increaseActiveWallpaperCounter();
|
||||
QVector<int> tmpMonitorIndex;
|
||||
tmpMonitorIndex.append(monitorIndex);
|
||||
m_screenPlayWallpaperList.append(QSharedPointer<ScreenPlayWallpaper>(new ScreenPlayWallpaper(tmpMonitorIndex, absoluteStoragePath.toLocalFile(), previewImage, volume, fillMode, type, this)));
|
||||
|
||||
m_mlm->setWallpaperActiveMonitor(m_qGuiApplication->screens().at(monitorIndex), absoluteStoragePath.toLocalFile() + "/" + previewImage);
|
||||
m_screenPlayWallpaperList.emplace_back(
|
||||
RefSPWall::create(
|
||||
QVector<int>{monitorIndex}, absoluteStoragePath.toLocalFile(),
|
||||
previewImage, volume, fillMode, type, this)
|
||||
);
|
||||
m_mlm->setWallpaperActiveMonitor(m_qGuiApplication->screens().at(monitorIndex),
|
||||
QString{absoluteStoragePath.toLocalFile() + "/" + previewImage});
|
||||
}
|
||||
|
||||
void ScreenPlay::createWidget(QUrl absoluteStoragePath, QString previewImage)
|
||||
void ScreenPlay::createWidget(QUrl absoluteStoragePath, const QString &previewImage)
|
||||
{
|
||||
ProjectFile project;
|
||||
ProjectFile project{};
|
||||
if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString fullPath = absoluteStoragePath.toLocalFile() + "/" + project.m_file.toString();
|
||||
|
||||
m_screenPlayWidgetList.append(QSharedPointer<ScreenPlayWidget>(new ScreenPlayWidget(absoluteStoragePath.toLocalFile(), previewImage, fullPath, this)));
|
||||
m_screenPlayWidgetList.emplace_back(
|
||||
RefSPWidget::create(
|
||||
absoluteStoragePath.toLocalFile(), previewImage,
|
||||
QString{absoluteStoragePath.toLocalFile() + "/" + project.m_file.toString()},
|
||||
this)
|
||||
);
|
||||
}
|
||||
|
||||
void ScreenPlay::removeAllWallpaper()
|
||||
void ScreenPlay::removeAllWallpaper() noexcept
|
||||
{
|
||||
m_sdkc->closeAllWallpapers();
|
||||
m_settings->setActiveWallpaperCounter(0);
|
||||
m_screenPlayWallpaperList.clear();
|
||||
emit allWallpaperRemoved();
|
||||
if(m_sdkc && m_settings && !m_screenPlayWallpaperList.empty()){
|
||||
m_sdkc->closeAllWallpapers();
|
||||
m_settings->setActiveWallpaperCounter(0);
|
||||
m_screenPlayWallpaperList.clear();
|
||||
emit allWallpaperRemoved();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void ScreenPlay::requestProjectSettingsListModelAt(int index)
|
||||
void ScreenPlay::requestProjectSettingsListModelAt(const int index) const noexcept
|
||||
{
|
||||
|
||||
//Q_ASSERT(index > m_mlm->size());
|
||||
for (int i = 0; i < m_screenPlayWallpaperList.count(); ++i) {
|
||||
if (m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0) == index) {
|
||||
emit projectSettingsListModelFound(m_screenPlayWallpaperList.at(i).data()->projectSettingsListModel().data(), m_screenPlayWallpaperList.at(i).data()->type());
|
||||
for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) {
|
||||
if (!refSPWallpaper.data()->screenNumber().empty() &&
|
||||
refSPWallpaper.data()->screenNumber()[0] == index) { // ??? only at index == 0
|
||||
emit projectSettingsListModelFound(
|
||||
refSPWallpaper.data()->projectSettingsListModel().data(),
|
||||
refSPWallpaper.data()->type());
|
||||
return;
|
||||
}
|
||||
}
|
||||
emit projectSettingsListModelNotFound();
|
||||
}
|
||||
|
||||
QString ScreenPlay::generateID()
|
||||
void ScreenPlay::setWallpaperValue(const int at, const QString &key, const QString &value) noexcept
|
||||
{
|
||||
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
const int randomStringLength = 32;
|
||||
auto* radomGen = QRandomGenerator::system();
|
||||
|
||||
QString randomString;
|
||||
for (int i = 0; i < randomStringLength; ++i) {
|
||||
int index = radomGen->bounded(possibleCharacters.length());
|
||||
QChar nextChar = possibleCharacters.at(index);
|
||||
randomString.append(nextChar);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
void ScreenPlay::setWallpaperValue(int at, QString key, QString value)
|
||||
{
|
||||
Q_ASSERT(at < m_screenPlayWallpaperList.size());
|
||||
for (int i = 0; i < m_screenPlayWallpaperList.count(); ++i) {
|
||||
if (m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0) == at) {
|
||||
m_sdkc->setWallpaperValue(m_screenPlayWallpaperList.at(i).data()->appID(), key, value);
|
||||
Q_ASSERT(static_cast<std::size_t>(at) < m_screenPlayWallpaperList.size() && m_sdkc);
|
||||
for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) {
|
||||
if (!refSPWallpaper.data()->screenNumber().empty() && m_sdkc &&
|
||||
refSPWallpaper.data()->screenNumber()[0] == at) { // ??? only at index == 0
|
||||
m_sdkc->setWallpaperValue(refSPWallpaper.data()->appID(), key, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenPlay::setAllWallpaperValue(QString key, QString value)
|
||||
void ScreenPlay::setAllWallpaperValue(const QString &key, const QString &value) noexcept
|
||||
{
|
||||
for (int i = 0; i < m_screenPlayWallpaperList.count(); ++i) {
|
||||
m_sdkc->setWallpaperValue(m_screenPlayWallpaperList.at(i).data()->appID(), key, value);
|
||||
Q_ASSERT(m_sdkc);
|
||||
for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) {
|
||||
if(m_sdkc) m_sdkc->setWallpaperValue(refSPWallpaper.data()->appID(), key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,20 +108,30 @@ void ScreenPlay::removeWallpaperAt(int at)
|
||||
}
|
||||
}
|
||||
|
||||
QVector<int> ScreenPlay::getMonitorByAppID(QString appID)
|
||||
QVector<int> ScreenPlay::getMonitorByAppID(const QString &appID) const
|
||||
{
|
||||
for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) {
|
||||
if (m_screenPlayWallpaperList.at(i).data()->appID() == appID) {
|
||||
return m_screenPlayWallpaperList.at(i).data()->screenNumber();
|
||||
for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) {
|
||||
if (refSPWallpaper.data()->appID() == appID) {
|
||||
return refSPWallpaper.data()->screenNumber();
|
||||
}
|
||||
}
|
||||
|
||||
return QVector<int>();
|
||||
return QVector<int>{};
|
||||
}
|
||||
|
||||
Settings* ScreenPlay::settings() const
|
||||
QString ScreenPlay::generateID() const
|
||||
{
|
||||
return m_settings;
|
||||
const QString possibleCharacters{
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"};
|
||||
const int randomStringLength = 32;
|
||||
const auto radomGen = QRandomGenerator::system();
|
||||
|
||||
QString randomString;
|
||||
for (int i = 0; i < randomStringLength; ++i) {
|
||||
const int index = radomGen->bounded(possibleCharacters.length());
|
||||
const QChar nextChar = possibleCharacters.at(index);
|
||||
randomString.append(nextChar);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
QSharedPointer<ProjectSettingsListModel> ScreenPlayWallpaper::projectSettingsListModel() const
|
||||
|
@ -24,40 +24,60 @@
|
||||
class ScreenPlayWallpaper;
|
||||
class ScreenPlayWidget;
|
||||
|
||||
// conveniences types
|
||||
using RefSPWall = QSharedPointer<ScreenPlayWallpaper>;
|
||||
using RefSPWidget = QSharedPointer<ScreenPlayWidget>;
|
||||
|
||||
class ScreenPlay : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
InstalledListModel *const m_ilm{nullptr};
|
||||
Settings *const m_settings{nullptr};
|
||||
MonitorListModel *const m_mlm{nullptr};
|
||||
QGuiApplication *const m_qGuiApplication{nullptr};
|
||||
SDKConnector *const m_sdkc{nullptr};
|
||||
std::vector<RefSPWall> m_screenPlayWallpaperList;
|
||||
std::vector<RefSPWidget> m_screenPlayWidgetList;
|
||||
|
||||
public:
|
||||
explicit ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent = nullptr);
|
||||
// constructor(s)
|
||||
explicit ScreenPlay(
|
||||
InstalledListModel* ilm, Settings* set,
|
||||
MonitorListModel* mlm, SDKConnector* sdkc,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
// copy and move disable(for now) : remember rule of 1/3/5
|
||||
Q_DISABLE_COPY_MOVE(ScreenPlay)
|
||||
|
||||
Settings* settings() const;
|
||||
|
||||
InstalledListModel* m_ilm;
|
||||
Settings* m_settings;
|
||||
MonitorListModel* m_mlm;
|
||||
QGuiApplication* m_qGuiApplication;
|
||||
SDKConnector* m_sdkc;
|
||||
|
||||
signals:
|
||||
void allWallpaperRemoved();
|
||||
void projectSettingsListModelFound(ProjectSettingsListModel* li, QString type);
|
||||
void projectSettingsListModelNotFound();
|
||||
void allWallpaperRemoved() const;
|
||||
void projectSettingsListModelFound(ProjectSettingsListModel* li, const QString &type) const;
|
||||
void projectSettingsListModelNotFound() const;
|
||||
|
||||
public slots:
|
||||
void createWallpaper(int monitorIndex, QUrl absoluteStoragePath, QString previewImage, float volume, QString fillMode, QString type);
|
||||
void createWidget(QUrl absoluteStoragePath, QString previewImage);
|
||||
void removeAllWallpaper();
|
||||
void requestProjectSettingsListModelAt(int index);
|
||||
void setWallpaperValue(int at, QString key, QString value);
|
||||
void setAllWallpaperValue(QString key, QString value);
|
||||
void removeWallpaperAt(int at);
|
||||
QVector<int> getMonitorByAppID(QString appID);
|
||||
QString generateID();
|
||||
|
||||
private:
|
||||
QVector<QSharedPointer<ScreenPlayWallpaper>> m_screenPlayWallpaperList;
|
||||
QVector<QSharedPointer<ScreenPlayWidget>> m_screenPlayWidgetList;
|
||||
void createWallpaper(
|
||||
const int monitorIndex, QUrl absoluteStoragePath,
|
||||
const QString &previewImage, const float volume,
|
||||
const QString &fillMode, const QString &type);
|
||||
void createWidget(QUrl absoluteStoragePath, const QString &previewImage);
|
||||
void removeAllWallpaper() noexcept;
|
||||
void requestProjectSettingsListModelAt(const int index) const noexcept;
|
||||
void setWallpaperValue(const int at, const QString &key, const QString &value) noexcept;
|
||||
void setAllWallpaperValue(const QString &key, const QString &value) noexcept;
|
||||
void removeWallpaperAt(const int at);
|
||||
QVector<int> getMonitorByAppID(const QString &appID) const;
|
||||
QString generateID() const;
|
||||
};
|
||||
|
||||
/*!
|
||||
\class ScreenPlayWallpaper
|
||||
\brief Used for Creation of Wallpaper, Scenes and Widgets
|
||||
*/
|
||||
|
||||
class ScreenPlayWallpaper : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -72,6 +92,7 @@ public:
|
||||
{
|
||||
m_screenNumber = screenNumber;
|
||||
m_projectPath = projectPath;
|
||||
|
||||
m_previewImage = previewImage;
|
||||
m_type = type;
|
||||
|
||||
@ -93,7 +114,7 @@ public:
|
||||
proArgs.append(m_projectPath);
|
||||
m_appID = parent->generateID();
|
||||
proArgs.append("appID=" + m_appID);
|
||||
proArgs.append(parent->m_settings->decoder());
|
||||
proArgs.append(parent->settings()->decoder());
|
||||
proArgs.append(QString::number(static_cast<double>(volume)));
|
||||
proArgs.append(fillMode);
|
||||
|
||||
@ -225,7 +246,7 @@ public:
|
||||
if (fullPath.endsWith(".exe")) {
|
||||
m_process->setProgram(fullPath);
|
||||
} else if (fullPath.endsWith(".qml")) {
|
||||
m_process->setProgram(parent->m_settings->getScreenPlayWidgetPath().path());
|
||||
m_process->setProgram(parent->settings()->getScreenPlayWidgetPath().path());
|
||||
}
|
||||
qDebug() << m_process->program();
|
||||
connect(m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
|
||||
|
Loading…
Reference in New Issue
Block a user