1
0
Fork 0
VideoPlayer/src/main.cpp

126 lines
3.4 KiB
C++
Raw Normal View History

2020-04-26 01:05:09 +01:00
#include <QApplication>
#include <QProcess>
#include <QQmlApplicationEngine>
2020-05-06 12:43:01 +01:00
#include <QtGlobal>
#include <QtQml>
#include <locale.h>
2020-04-24 17:06:14 +01:00
#ifdef QT_QML_DEBUG
#warning "QML Debugging Enabled!!!"
2020-04-26 01:05:09 +01:00
#include <QQmlDebug>
2020-04-24 17:06:14 +01:00
#endif
2020-05-06 12:43:01 +01:00
#include "logger.h"
#include "spdlog/logger.h"
2020-04-26 01:05:09 +01:00
#include <QSettings>
#include <QString>
#include <QUrl>
#include <QVariant>
2020-04-22 10:56:45 +01:00
#include <cstdlib>
#include <exception>
#include <iosfwd>
#include <memory>
2020-05-06 12:43:01 +01:00
#include <spdlog/fmt/fmt.h>
extern void registerTypes();
2018-10-31 07:53:38 +00:00
#ifdef WIN32
#include "setenv_mingw.hpp"
#endif
2018-11-11 13:43:18 +00:00
auto qmlLogger = initLogger("qml");
auto miscLogger = initLogger("misc");
2020-05-06 12:43:01 +01:00
void spdLogger(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
2020-05-06 12:43:01 +01:00
std::string localMsg = msg.toUtf8().constData();
std::shared_ptr<spdlog::logger> logger;
if (QString(context.category).startsWith(QString("qml"))) {
logger = qmlLogger;
} else {
logger = miscLogger;
}
switch (type) {
case QtDebugMsg:
2020-05-06 12:43:01 +01:00
logger->debug("{}", localMsg);
break;
case QtInfoMsg:
2020-05-06 12:43:01 +01:00
logger->info("{}", localMsg);
break;
case QtWarningMsg:
2020-05-06 12:43:01 +01:00
logger->warn("{}", localMsg);
break;
case QtCriticalMsg:
2020-05-06 12:43:01 +01:00
logger->critical("{}", localMsg);
break;
case QtFatalMsg:
2020-05-06 12:43:01 +01:00
logger->critical("{}", localMsg);
abort();
}
}
2020-05-06 12:43:01 +01:00
int main(int argc, char* argv[])
2018-10-13 15:38:31 +01:00
{
2020-05-06 12:43:01 +01:00
qInstallMessageHandler(spdLogger);
2020-05-06 12:43:01 +01:00
auto launcherLogger = initLogger("launcher");
launcherLogger->info("Starting up!");
2018-12-18 16:22:17 +00:00
2020-05-06 12:43:01 +01:00
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
QApplication app(argc, argv);
2018-11-16 09:10:26 +00:00
2020-05-06 12:43:01 +01:00
app.setOrganizationName("KittehPlayer");
app.setOrganizationDomain("kitteh.pw");
app.setApplicationName("KittehPlayer");
2018-12-18 16:22:17 +00:00
2020-04-24 17:06:14 +01:00
#ifdef QT_QML_DEBUG
2020-05-06 12:43:01 +01:00
// Allows debug.
QQmlDebuggingEnabler enabler;
2020-04-24 17:06:14 +01:00
#endif
2020-05-06 12:43:01 +01:00
QSettings settings;
2020-05-06 12:43:01 +01:00
bool ranFirstTimeSetup = settings.value("Setup/ranSetup", false).toBool();
#ifdef __linux__
2020-05-07 22:53:15 +01:00
bool pinephone;
#ifdef PINEPHONE
pinephone = true;
#else
pinephone = false;
#endif
2020-05-06 12:43:01 +01:00
// WARNING, THIS IS A BIG HACK
// this is only to make it so KittehPlayer works first try on pinephone.
// TODO: launch a opengl window or use offscreen to see if GL_ARB_framebuffer_object
// can be found
2020-05-08 21:31:51 +01:00
if (!(settings.value("Backend/disableSunxiCheck", false).toBool() || ranFirstTimeSetup) || pinephone ) {
2020-05-06 12:43:01 +01:00
FILE* fd = popen("grep sun[x8]i /proc/modules", "r");
char buf[16];
2020-05-08 10:29:01 +01:00
if (fread(buf, 1, sizeof(buf), fd) > 0 || pinephone) {
2020-05-06 12:43:01 +01:00
launcherLogger->info("Running on sunxi, switching to NoFBO.");
settings.setValue("Appearance/clickToPause", false);
settings.setValue("Appearance/doubleTapToSeek", true);
settings.setValue("Appearance/scaleFactor", 2.2);
settings.setValue("Appearance/subtitlesFontSize", 38);
settings.setValue("Appearance/uiFadeTimer", 0);
2020-05-08 21:40:38 +01:00
settings.setValue("Backend/fbo", false);
2020-05-06 12:43:01 +01:00
}
2020-04-24 11:15:49 +01:00
}
#endif
2020-05-06 12:43:01 +01:00
settings.setValue("Setup/ranSetup", true);
2020-05-06 12:43:01 +01:00
QString newpath = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + "/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
setenv("PATH", newpath.toUtf8().constData(), 1);
2018-10-23 23:56:24 +01:00
2020-05-06 12:43:01 +01:00
registerTypes();
2020-05-06 12:43:01 +01:00
setlocale(LC_NUMERIC, "C");
launcherLogger->info("Loading player...");
2018-10-13 15:38:31 +01:00
2020-05-06 12:43:01 +01:00
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
2018-10-27 16:11:29 +01:00
2020-05-06 12:43:01 +01:00
return app.exec();
2018-10-13 15:38:31 +01:00
}