From 2dcb49366bd0fbe52d7fa1d00caa2e6f6164b294 Mon Sep 17 00:00:00 2001 From: Elias Date: Thu, 14 Mar 2019 18:56:55 +0100 Subject: [PATCH] Workaround for working wallpaper two times --- ScreenPlay/src/installedlistmodel.cpp | 11 +++++++++-- ScreenPlay/src/installedlistmodel.h | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ScreenPlay/src/installedlistmodel.cpp b/ScreenPlay/src/installedlistmodel.cpp index 39886a6d..488fa5e3 100644 --- a/ScreenPlay/src/installedlistmodel.cpp +++ b/ScreenPlay/src/installedlistmodel.cpp @@ -10,7 +10,6 @@ InstalledListModel::InstalledListModel(QObject* parent) QObject::connect(&m_loadScreenWatcher, &QFutureWatcher::progressValueChanged, [](int progressValue) { qDebug() << progressValue; }); - } int InstalledListModel::rowCount(const QModelIndex& parent) const @@ -95,9 +94,17 @@ void InstalledListModel::loadInstalledContent() { if (m_loadScreenWatcher.isRunning()) qDebug() << "allready running"; + qDebug() << QThread::currentThreadId(); + if (m_isLoadingContent) { + qDebug() << "Called loading installed files twice! Aborting"; + return; + } + m_loadScreenFuture = QtConcurrent::run([this]() { + auto cleanup = qScopeGuard([this] { setIsLoadingContent(false); }); + setIsLoadingContent(true); qDebug() << QThread::currentThreadId(); QJsonDocument jsonProject; QJsonParseError parseError; @@ -138,7 +145,7 @@ void InstalledListModel::loadInstalledContent() obj.insert("type", "video"); } - if (fileEnding.endsWith(".webm") || (obj.value("type").toString() == "qmlScene" || fileEnding.endsWith(".html"))) + if (fileEnding.endsWith(".webm") || (obj.value("type").toString() == "qmlScene" || fileEnding.endsWith(".html"))) emit addInstalledItem(obj, item.baseName()); if (obj.value("type") == "qmlWidget" || obj.value("type") == "standalonewidget") diff --git a/ScreenPlay/src/installedlistmodel.h b/ScreenPlay/src/installedlistmodel.h index 9c7bf087..a743d079 100644 --- a/ScreenPlay/src/installedlistmodel.h +++ b/ScreenPlay/src/installedlistmodel.h @@ -40,6 +40,7 @@ public: bool getProjectByAbsoluteStoragePath(QUrl* path, ProjectFile* spf); Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged) + Q_PROPERTY(bool isLoadingContent READ isLoadingContent WRITE setIsLoadingContent NOTIFY isLoadingContentChanged) enum InstalledRole { TitleRole, @@ -58,6 +59,11 @@ public: return m_absoluteStoragePath; } + bool isLoadingContent() const + { + return m_isLoadingContent; + } + public slots: void loadInstalledContent(); QVariantMap get(QString folderId); @@ -73,6 +79,15 @@ public slots: int getAmountItemLoaded(); void reset(); + void setIsLoadingContent(bool isLoadingContent) + { + if (m_isLoadingContent == isLoadingContent) + return; + + m_isLoadingContent = isLoadingContent; + emit isLoadingContentChanged(m_isLoadingContent); + } + signals: void setScreenVisible(bool visible); void setScreenToVideo(QString absolutePath); @@ -80,9 +95,14 @@ signals: void addInstalledItem(const QJsonObject, const QString); void installedLoadingFinished(); + void isLoadingContentChanged(bool isLoadingContent); + private: QVector m_screenPlayFiles; QUrl m_absoluteStoragePath; QFuture m_loadScreenFuture; QFutureWatcher m_loadScreenWatcher; + + + bool m_isLoadingContent = false; };