1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 19:42:45 +01:00
ScreenPlay/main.cpp

108 lines
3.7 KiB
C++
Raw Normal View History

#include <QDebug>
#include <QDir>
#include <QGuiApplication>
2017-05-13 10:50:15 +02:00
#include <QIcon>
#include <QLibrary>
2017-04-05 13:04:13 +02:00
#include <QModelIndex>
#include <QObject>
2017-03-25 18:44:26 +01:00
#include <QQmlApplicationEngine>
2017-04-05 13:04:13 +02:00
#include <QQmlContext>
2017-04-23 12:53:00 +02:00
#include <QQmlEngine>
2017-05-13 10:50:15 +02:00
#include <QQuickStyle>
2017-03-25 18:44:26 +01:00
#include <QQuickView>
#include <QScreen>
2017-07-12 21:50:54 +02:00
#include <QTimer>
#include <QUrl>
2017-04-05 13:04:13 +02:00
#include <QVariant>
#include <QWindow>
2017-05-13 10:50:15 +02:00
#include <QtQuick/QQuickItem>
#include <qt_windows.h>
2017-03-25 18:44:26 +01:00
#include "installedlistmodel.h"
#include "monitorlistmodel.h"
2017-06-06 12:51:53 +02:00
#include "packagefilehandler.h"
#include "profilelistmodel.h"
2017-09-30 17:36:11 +02:00
#include "quazip5/quazip.h"
2017-05-02 21:26:43 +02:00
#include "settings.h"
2017-07-12 21:50:54 +02:00
#include "steam/steam_api.h"
#include "steamworkshop.h"
2017-09-30 17:36:11 +02:00
#include "steamworkshoplistmodel.h"
#include "widget.h"
2017-07-17 14:29:17 +02:00
int main(int argc, char* argv[])
2017-03-25 18:44:26 +01:00
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseOpenGLES);
2017-11-02 18:58:35 +01:00
2017-12-14 14:05:00 +01:00
QGuiApplication app(argc, argv);
2017-07-12 21:50:54 +02:00
2017-11-02 18:58:35 +01:00
AppId_t steamID = 672870;
2017-10-26 20:26:42 +02:00
QCoreApplication::setOrganizationName("Aimber");
QCoreApplication::setOrganizationDomain("aimber.net");
QCoreApplication::setApplicationName("ScreenPlay");
app.setWindowIcon(QIcon(":/assets/icons/favicon.ico"));
bool steamErrorRestart = false;
bool steamErrorAPIInit = false;
2017-11-02 18:54:24 +01:00
2017-07-12 21:50:54 +02:00
if (SteamAPI_RestartAppIfNecessary(steamID)) {
qWarning() << "SteamAPI_RestartAppIfNecessary";
2017-10-26 20:26:42 +02:00
steamErrorRestart = true;
2017-07-12 21:50:54 +02:00
}
if (!SteamAPI_Init()) {
qWarning() << "Could not init steam sdk!";
2017-10-26 20:26:42 +02:00
steamErrorAPIInit = true;
2017-07-12 21:50:54 +02:00
}
InstalledListModel installedListModel;
MonitorListModel monitorListModel;
2017-06-06 12:51:53 +02:00
PackageFileHandler packageFileHandler;
ProfileListModel profileListModel;
2017-11-02 18:58:35 +01:00
SteamWorkshopListModel steamWorkshopListModel;
2017-09-30 17:36:11 +02:00
// Create settings in the end because for now it depends on
2017-06-06 12:51:53 +02:00
// such things as the profile list model to complete
// It will also set the m_absoluteStoragePath in profileListModel and installedListModel
2017-07-17 14:29:17 +02:00
Settings settings(&profileListModel, &monitorListModel, &installedListModel, steamID);
2017-12-14 14:05:00 +01:00
SteamWorkshop steamWorkshop(steamID, &steamWorkshopListModel, &settings);
2017-11-02 18:58:35 +01:00
// All the list need the default path from the settings
// to know where to look for the files
profileListModel.loadProfiles();
settings.loadActiveProfiles();
2017-06-26 22:00:51 +02:00
QQmlApplicationEngine mainWindowEngine;
2017-11-02 18:58:35 +01:00
mainWindowEngine.rootContext()->setContextProperty("workshopListModel", &steamWorkshopListModel);
2017-06-26 22:00:51 +02:00
mainWindowEngine.rootContext()->setContextProperty("monitorListModel", &monitorListModel);
mainWindowEngine.rootContext()->setContextProperty("installedListModel", &installedListModel);
2017-11-02 18:58:35 +01:00
mainWindowEngine.rootContext()->setContextProperty("profileListModel", &profileListModel);
mainWindowEngine.rootContext()->setContextProperty("screenPlaySettings", &settings);
2017-06-26 22:00:51 +02:00
mainWindowEngine.rootContext()->setContextProperty("packageFileHandler", &packageFileHandler);
2017-07-12 21:50:54 +02:00
mainWindowEngine.rootContext()->setContextProperty("steamWorkshop", &steamWorkshop);
2017-10-26 20:26:42 +02:00
QQmlApplicationEngine errorWindowEngine;
if (steamErrorRestart || steamErrorAPIInit) {
errorWindowEngine.load(QUrl(QStringLiteral("qrc:/qml/Components/StartupErrorWindow.qml")));
} else {
mainWindowEngine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
}
2017-04-23 12:53:00 +02:00
installedListModel.loadScreens();
// FIXME: Needed workaround to close the app because
// apparently some thread still runs in the background
2017-07-15 10:46:50 +02:00
QObject::connect(&app, &QGuiApplication::lastWindowClosed, [&]() { exit(app.exec()); });
2017-04-06 23:12:58 +02:00
2017-07-12 21:50:54 +02:00
// Timer for steam polls. WTF?
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, [&]() { SteamAPI_RunCallbacks(); });
2017-11-02 18:54:24 +01:00
timer.setInterval(200);
2017-07-12 21:50:54 +02:00
timer.start();
int status = app.exec();
2017-09-30 17:36:11 +02:00
SteamAPI_Shutdown();
//Shutdown
2017-07-12 21:50:54 +02:00
return status;
2017-03-25 18:44:26 +01:00
}