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

Remove QGuiApplication pointer to classes. This is not needed because we can call the static method QGuiApplication::instance() everywhere

Remove QSettings init because it is created after setting organization name url etc. See QSettings::QSettings(QObject *parent = nullptr) in the docs for more info
This commit is contained in:
Elias 2019-02-15 11:58:38 +01:00
parent 476d1b6a34
commit bb9db9117a
7 changed files with 36 additions and 43 deletions

View File

@ -1,4 +1,3 @@
#include <QDebug>
#include <QDir> #include <QDir>
#include <QFontDatabase> #include <QFontDatabase>
#include <QGuiApplication> #include <QGuiApplication>
@ -9,13 +8,8 @@
#include <QQmlEngine> #include <QQmlEngine>
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <QtGlobal>
#include <QtWebEngine> #include <QtWebEngine>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
#include "src/create.h" #include "src/create.h"
#include "src/installedlistfilter.h" #include "src/installedlistfilter.h"
#include "src/installedlistmodel.h" #include "src/installedlistmodel.h"
@ -36,6 +30,7 @@ int main(int argc, char* argv[])
QGuiApplication::setApplicationVersion("0.2.0"); QGuiApplication::setApplicationVersion("0.2.0");
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
app.setWindowIcon(QIcon(":/assets/icons/favicon.ico")); app.setWindowIcon(QIcon(":/assets/icons/favicon.ico"));
@ -55,15 +50,15 @@ int main(int argc, char* argv[])
QMLUtilities qmlUtil; QMLUtilities qmlUtil;
InstalledListModel installedListModel; InstalledListModel installedListModel;
InstalledListFilter installedListFilter(&installedListModel); InstalledListFilter installedListFilter(&installedListModel);
MonitorListModel monitorListModel(&app); MonitorListModel monitorListModel;
ProfileListModel profileListModel; ProfileListModel profileListModel;
SDKConnector sdkConnector; SDKConnector sdkConnector;
// Create settings in the end because for now it depends on // Create settings in the end because for now it depends on
// such things as the profile list model to complete // such things as the profile list model to complete
// It will also set the m_absoluteStoragePath in profileListModel and installedListModel // It will also set the m_absoluteStoragePath in profileListModel and installedListModel
Settings settings(&profileListModel, &monitorListModel, &installedListModel, &sdkConnector, &app); Settings settings(&profileListModel, &monitorListModel, &installedListModel, &sdkConnector);
ScreenPlay screenPlay(&installedListModel, &settings, &monitorListModel, &app, &sdkConnector); ScreenPlay screenPlay(&installedListModel, &settings, &monitorListModel, &sdkConnector);
Create create(&settings, &qmlUtil); Create create(&settings, &qmlUtil);
// All the list need the default path from the settings // All the list need the default path from the settings

View File

@ -1,17 +1,17 @@
#include "monitorlistmodel.h" #include "monitorlistmodel.h"
MonitorListModel::MonitorListModel(QGuiApplication* guiapp, QObject* parent) MonitorListModel::MonitorListModel(QObject* parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
loadMonitors(); loadMonitors();
m_qGuiApplication = guiapp; m_qGuiApplication = static_cast<QGuiApplication*>(QGuiApplication::instance());
connect(m_qGuiApplication, &QGuiApplication::screenAdded, this, &MonitorListModel::screenAdded); connect(m_qGuiApplication, &QGuiApplication::screenAdded, this, &MonitorListModel::screenAdded);
connect(m_qGuiApplication, &QGuiApplication::screenRemoved, this, &MonitorListModel::screenRemoved); connect(m_qGuiApplication, &QGuiApplication::screenRemoved, this, &MonitorListModel::screenRemoved);
} }
QHash<int, QByteArray> MonitorListModel::roleNames() const QHash<int, QByteArray> MonitorListModel::roleNames() const
{ {
static const QHash<int, QByteArray> roles{ static const QHash<int, QByteArray> roles {
{ IDRole, "monitorID" }, { IDRole, "monitorID" },
{ NameRole, "monitorName" }, { NameRole, "monitorName" },
{ SizeRole, "monitorSize" }, { SizeRole, "monitorSize" },
@ -126,7 +126,6 @@ int MonitorListModel::size()
void MonitorListModel::wallpaperRemoved() void MonitorListModel::wallpaperRemoved()
{ {
} }
bool MonitorListModel::getMonitorListItemAt(int position, Monitor* monitor) bool MonitorListModel::getMonitorListItemAt(int position, Monitor* monitor)
@ -163,17 +162,17 @@ void MonitorListModel::reset()
void MonitorListModel::setWallpaperActiveMonitor(QScreen* screen, QString fullPreviewImagePath) void MonitorListModel::setWallpaperActiveMonitor(QScreen* screen, QString fullPreviewImagePath)
{ {
// qDebug() << fullPreviewImagePath; // qDebug() << fullPreviewImagePath;
// for (int i = 0; i < m_monitorList.size(); ++i) { // for (int i = 0; i < m_monitorList.size(); ++i) {
// if (m_monitorList.at(i).m_screen == screen) { // if (m_monitorList.at(i).m_screen == screen) {
// m_monitorList[i].m_wallpaperPreviewPath = fullPreviewImagePath; // m_monitorList[i].m_wallpaperPreviewPath = fullPreviewImagePath;
// } // }
// } // }
// beginResetModel(); // beginResetModel();
// endResetModel(); // endResetModel();
for (int i = 0; i < m_qGuiApplication->screens().length(); ++i) { for (int i = 0; i < m_qGuiApplication->screens().length(); ++i) {
if(m_qGuiApplication->screens().at(i) == screen){ if (m_qGuiApplication->screens().at(i) == screen) {
emit setNewActiveMonitor(i,fullPreviewImagePath); emit setNewActiveMonitor(i, fullPreviewImagePath);
} }
} }
//emit monitorReloadCompleted(); //emit monitorReloadCompleted();

View File

@ -25,7 +25,7 @@ class MonitorListModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: public:
explicit MonitorListModel(QGuiApplication* guiapp, QObject* parent = nullptr); explicit MonitorListModel(QObject* parent = nullptr);
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;

View File

@ -1,12 +1,12 @@
#include "screenplay.h" #include "screenplay.h"
ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, QGuiApplication* qGuiApplication, SDKConnector* sdkc, QObject* parent) ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent)
: QObject(parent) : QObject(parent)
{ {
m_ilm = ilm; m_ilm = ilm;
m_settings = set; m_settings = set;
m_mlm = mlm; m_mlm = mlm;
m_qGuiApplication = qGuiApplication; m_qGuiApplication = static_cast<QGuiApplication*>(QGuiApplication::instance());
m_sdkc = sdkc; m_sdkc = sdkc;
} }
@ -19,7 +19,7 @@ void ScreenPlay::createWallpaper(int monitorIndex, QUrl absoluteStoragePath, QSt
} }
// Remove previous wallpaper // Remove previous wallpaper
//removeWallpaperAt(monitorIndex); removeWallpaperAt(monitorIndex);
m_settings->increaseActiveWallpaperCounter(); m_settings->increaseActiveWallpaperCounter();
QVector<int> tmpMonitorIndex; QVector<int> tmpMonitorIndex;
@ -96,9 +96,10 @@ void ScreenPlay::setAllWallpaperValue(QString key, QString value)
void ScreenPlay::removeWallpaperAt(int at) void ScreenPlay::removeWallpaperAt(int at)
{ {
Q_ASSERT(at < m_screenPlayWallpaperList.size()); //Q_ASSERT(m_screenPlayWallpaperList.size() < at);
// if(m_screenPlayWallpaperList.isEmpty())
// return; if (m_screenPlayWallpaperList.isEmpty())
return;
for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) { for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) {

View File

@ -27,7 +27,7 @@ class ScreenPlayWidget;
class ScreenPlay : public QObject { class ScreenPlay : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, QGuiApplication* qGuiApplication, SDKConnector* sdkc, QObject* parent = nullptr); explicit ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent = nullptr);
Settings* settings() const; Settings* settings() const;
@ -94,7 +94,7 @@ public:
m_appID = parent->generateID(); m_appID = parent->generateID();
proArgs.append("appID=" + m_appID); proArgs.append("appID=" + m_appID);
proArgs.append(parent->m_settings->decoder()); proArgs.append(parent->m_settings->decoder());
proArgs.append(QString::number(volume)); proArgs.append(QString::number(static_cast<double>(volume)));
proArgs.append(fillMode); proArgs.append(fillMode);
qDebug() << proArgs; qDebug() << proArgs;
@ -138,7 +138,6 @@ signals:
void previewImageChanged(QString previewImage); void previewImageChanged(QString previewImage);
void projectSettingsListModelAt(ProjectSettingsListModel* li); void projectSettingsListModelAt(ProjectSettingsListModel* li);
void appIDChanged(QString appID); void appIDChanged(QString appID);
void typeChanged(QString type); void typeChanged(QString type);
public slots: public slots:
@ -229,9 +228,8 @@ public:
m_process->setProgram(parent->m_settings->getScreenPlayWidgetPath().path()); m_process->setProgram(parent->m_settings->getScreenPlayWidgetPath().path());
} }
qDebug() << m_process->program(); qDebug() << m_process->program();
connect(m_process,&QProcess::errorOccurred, this, [](QProcess::ProcessError error){ connect(m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
qDebug() << "error: " << error; qDebug() << "error: " << error;
}); });
m_process->start(); m_process->start();
} }

View File

@ -2,17 +2,16 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QStandardPaths> #include <QStandardPaths>
Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QGuiApplication* app, QObject* parent) Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QObject* parent)
: QObject(parent) : QObject(parent)
, m_version(QVersionNumber(0, 0, 1)) , m_version(QVersionNumber(0, 0, 1))
, m_qSettings(QSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, app->organizationName(), app->applicationName()))
{ {
m_plm = plm; m_plm = plm;
m_mlm = mlm; m_mlm = mlm;
m_ilm = ilm; m_ilm = ilm;
m_sdkc = sdkc; m_sdkc = sdkc;
m_app = app; m_app = static_cast<QGuiApplication*>(QGuiApplication::instance());
if (m_qSettings.value("language").isNull()) { if (m_qSettings.value("language").isNull()) {
auto locale = QLocale::system().uiLanguages(); auto locale = QLocale::system().uiLanguages();
@ -25,13 +24,13 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
m_translator.load(":/translations/ScreenPlay_" + localeSplits.at(0) + ".qm"); m_translator.load(":/translations/ScreenPlay_" + localeSplits.at(0) + ".qm");
m_qSettings.setValue("language", QVariant(localeSplits.at(0))); m_qSettings.setValue("language", QVariant(localeSplits.at(0)));
m_qSettings.sync(); m_qSettings.sync();
app->installTranslator(&m_translator); m_app->installTranslator(&m_translator);
} }
} else { } else {
QFile tsFile; QFile tsFile;
if (tsFile.exists(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm")) { if (tsFile.exists(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm")) {
m_translator.load(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm"); m_translator.load(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm");
app->installTranslator(&m_translator); m_app->installTranslator(&m_translator);
} }
} }

View File

@ -3,6 +3,7 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QGuiApplication>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
@ -11,7 +12,6 @@
#include <QProcess> #include <QProcess>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QQmlPropertyMap> #include <QQmlPropertyMap>
#include <QtConcurrent/QtConcurrent>
#include <QSettings> #include <QSettings>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStandardPaths> #include <QStandardPaths>
@ -21,8 +21,9 @@
#include <QUrl> #include <QUrl>
#include <QVariant> #include <QVariant>
#include <QVector> #include <QVector>
#include <QtGlobal>
#include <QVersionNumber> #include <QVersionNumber>
#include <QtConcurrent/QtConcurrent>
#include <QtGlobal>
#include "installedlistmodel.h" #include "installedlistmodel.h"
#include "monitorlistmodel.h" #include "monitorlistmodel.h"
@ -50,7 +51,7 @@ class Settings : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QGuiApplication* app, QObject* parent = nullptr); explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QObject* parent = nullptr);
~Settings(); ~Settings();
Q_PROPERTY(QVersionNumber version READ version) Q_PROPERTY(QVersionNumber version READ version)