1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Add default content to list model

Add option to disable default content
This commit is contained in:
Elias Steurer 2023-08-03 14:14:24 +02:00
parent 5ebe56d067
commit aebda377fc
8 changed files with 58 additions and 12 deletions

View File

@ -10,6 +10,7 @@ function(generate_cmake_variable_header TARGET)
# Specify the configuration file from which the header file will be generated
configure_file(${CMAKE_SOURCE_DIR}/CMake/CMakeVariables.h.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/CMakeVariables.h @ONLY)
message(STATUS "GENERATE: ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/CMakeVariables.h and add ${TARGET} to ${CMAKE_CURRENT_BINARY_DIR}")
# Add the directory containing the generated header
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endfunction()

View File

@ -448,4 +448,5 @@ endif()
# ##### USE CMAKE VARIABLES IN CODE #####
include(GenerateCMakeVariableHeader)
generate_cmake_variable_header(${PROJECT_NAME})
# Note: Must not be ${PROJECT_NAME}, but ScreenPlayApp to work!
generate_cmake_variable_header(ScreenPlayApp)

View File

@ -24,6 +24,7 @@
#include "ScreenPlay/globalvariables.h"
#include "ScreenPlay/profilelistmodel.h"
#include "ScreenPlay/settings.h"
#include "ScreenPlay/util.h"
#include "ScreenPlayUtil/projectfile.h"
@ -40,6 +41,7 @@ class InstalledListModel : public QAbstractListModel {
public:
explicit InstalledListModel(
const std::shared_ptr<GlobalVariables>& globalVariables,
std::shared_ptr<Settings> settings,
QObject* parent = nullptr);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
@ -97,5 +99,6 @@ private:
std::atomic_bool m_isLoading { false };
const std::shared_ptr<GlobalVariables>& m_globalVariables;
std::shared_ptr<Settings> m_settings;
};
}

View File

@ -45,6 +45,7 @@ class Settings : public QObject {
Q_OBJECT
QML_UNCREATABLE("")
Q_PROPERTY(bool showDefaultContent READ showDefaultContent WRITE setShowDefaultContent NOTIFY showDefaultContentChanged)
Q_PROPERTY(bool anonymousTelemetry READ anonymousTelemetry WRITE setAnonymousTelemetry NOTIFY anonymousTelemetryChanged)
Q_PROPERTY(bool silentStart READ silentStart WRITE setSilentStart NOTIFY silentStartChanged)
Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
@ -121,6 +122,7 @@ public:
bool steamVersion() const { return m_steamVersion; }
DesktopEnvironment desktopEnvironment() const { return m_desktopEnvironment; }
const QString& buildInfos() const { return m_buildInfos; }
bool showDefaultContent() const { return m_showDefaultContent; }
signals:
void requestRetranslation();
@ -141,6 +143,7 @@ signals:
void steamVersionChanged(bool steamVersion);
void desktopEnvironmentChanged(DesktopEnvironment desktopEnvironment);
void buildInfosChanged(const QString& buildInfos);
void showDefaultContentChanged(bool showDefaultContent);
public slots:
void setupLanguage();
@ -148,6 +151,14 @@ public slots:
void setupWidgetAndWindowPaths();
bool retranslateUI();
void setShowDefaultContent(bool showDefaultContent)
{
if (m_showDefaultContent == showDefaultContent)
return;
m_showDefaultContent = showDefaultContent;
emit showDefaultContentChanged(showDefaultContent);
}
void setqSetting(const QString& key, const QVariant& value)
{
m_qSettings.setValue(key, value);
@ -459,6 +470,7 @@ private:
bool m_checkWallpaperVisible { false };
bool m_silentStart { false };
bool m_anonymousTelemetry { true };
bool m_showDefaultContent { true };
QString m_decoder;
ScreenPlay::FillMode::FillMode m_videoFillMode { ScreenPlay::FillMode::FillMode::Cover };

View File

@ -76,6 +76,19 @@ Item {
SettingsHorizontalSeperator {
}
SettingBool {
headline: qsTr("Show default installed content")
description: qsTr("ScreenPlay will show build in content.")
isChecked: App.settings.showDefaultContent
onCheckboxChanged: function (checked) {
App.settings.setShowDefaultContent(checked);
App.installedListModel.reset()
}
}
SettingsHorizontalSeperator {
}
SettingBool {
height: 70
headline: qsTr("Send anonymous crash reports and statistics")

View File

@ -142,11 +142,11 @@ void App::init()
// Util should be created as first so we redirect qDebugs etc. into the log
m_util = make_unique<Util>();
m_globalVariables = make_shared<GlobalVariables>();
m_installedListModel = make_shared<InstalledListModel>(m_globalVariables);
m_installedListFilter = make_shared<InstalledListFilter>(m_installedListModel);
m_monitorListModel = make_shared<MonitorListModel>();
m_profileListModel = make_shared<ProfileListModel>(m_globalVariables);
m_settings = make_shared<Settings>(m_globalVariables);
m_installedListModel = make_shared<InstalledListModel>(m_globalVariables, m_settings);
m_installedListFilter = make_shared<InstalledListFilter>(m_installedListModel);
m_mainWindowEngine = make_unique<QQmlApplicationEngine>();
// Only create anonymousTelemetry if user did not disallow!

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "ScreenPlay/installedlistmodel.h"
#include "ScreenPlay/CMakeVariables.h"
#include <QDebug>
#include <QGuiApplication>
namespace ScreenPlay {
@ -20,9 +22,11 @@ namespace ScreenPlay {
*/
InstalledListModel::InstalledListModel(
const std::shared_ptr<GlobalVariables>& globalVariables,
std::shared_ptr<Settings> settings,
QObject* parent)
: QAbstractListModel(parent)
, m_globalVariables { globalVariables }
, m_settings { settings }
{
}
@ -205,7 +209,7 @@ void InstalledListModel::append(const QString& projectJsonFilePath)
}
/*!
\brief Loads all installed content.
\brief Loads all installed and default content.
- Skips if the loadContentFuture is already running.
- Skips projects.json without a "type" field.
*/
@ -217,18 +221,31 @@ void InstalledListModel::loadInstalledContent()
}
m_isLoading = true;
auto unused = QtConcurrent::run([this]() {
QFileInfoList list = QDir(m_globalVariables->localStoragePath().toLocalFile()).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
int counter = 0;
auto loadFiles = [this, &counter](const QString path) { // capture counter by reference
const QFileInfoList list = QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
for (const QFileInfo& item : list) {
const QString absoluteFilePath = m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json";
for (const QFileInfo& item : list) {
const QString absoluteFilePath = path + "/" + item.baseName() + "/project.json";
if (!QFile::exists(absoluteFilePath))
continue;
if (!QFile::exists(absoluteFilePath))
continue;
append(absoluteFilePath);
counter += 1;
append(absoluteFilePath);
counter += 1;
}
};
#ifdef DEPLOY_VERSION
const QString defaultContentPath = QGuiApplication::instance()->applicationDirPath() + "/Content";
#else
const QString defaultContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
#endif
if (m_settings->showDefaultContent()) {
loadFiles(defaultContentPath);
}
const QString installedPath = m_globalVariables->localStoragePath().toLocalFile();
loadFiles(installedPath);
setCount(counter);
emit installedLoadingFinished();
m_isLoading = false;

View File

@ -1,6 +1,5 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "ScreenPlay/settings.h"
#include "ScreenPlayUtil/util.h"
#include <QFileInfo>