2018-11-18 19:23:31 +00:00
|
|
|
#include "DirectMpvPlayerBackend.h"
|
2018-11-26 19:03:37 +00:00
|
|
|
#ifndef DISABLE_MpvPlayerBackend
|
2018-11-06 07:39:42 +00:00
|
|
|
#include "MpvPlayerBackend.h"
|
2018-11-26 19:03:37 +00:00
|
|
|
#endif
|
2018-11-18 19:23:31 +00:00
|
|
|
|
|
|
|
#include "enums.hpp"
|
2018-12-09 02:35:08 +00:00
|
|
|
#include "logger.h"
|
2018-11-07 11:10:38 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2018-12-08 22:21:12 +00:00
|
|
|
#include "Process.h"
|
2018-11-17 15:45:21 +00:00
|
|
|
#include "enums.hpp"
|
2018-10-13 15:38:31 +01:00
|
|
|
#include <QApplication>
|
2018-10-23 11:37:51 +01:00
|
|
|
#include <QProcessEnvironment>
|
2018-11-06 07:39:42 +00:00
|
|
|
#include <QQmlApplicationEngine>
|
2018-12-09 02:35:08 +00:00
|
|
|
#include <QtConcurrent>
|
2018-11-07 11:10:38 +00:00
|
|
|
#include <QtCore>
|
2018-12-08 22:21:12 +00:00
|
|
|
#include <QtQml>
|
2018-11-07 07:42:47 +00:00
|
|
|
#include <stdbool.h>
|
2018-10-31 07:53:38 +00:00
|
|
|
#ifdef WIN32
|
2018-10-30 16:16:53 +00:00
|
|
|
#include "setenv_mingw.hpp"
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 22:21:12 +00:00
|
|
|
#include "ThumbnailCache.h"
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-11-11 13:43:18 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2018-11-16 09:16:04 +00:00
|
|
|
void
|
|
|
|
catchUnixSignals(std::initializer_list<int> quitSignals)
|
|
|
|
{
|
|
|
|
auto handler = [](int sig) -> void { QCoreApplication::quit(); };
|
|
|
|
|
|
|
|
sigset_t blocking_mask;
|
|
|
|
sigemptyset(&blocking_mask);
|
|
|
|
for (auto sig : quitSignals)
|
|
|
|
sigaddset(&blocking_mask, sig);
|
|
|
|
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = handler;
|
|
|
|
sa.sa_mask = blocking_mask;
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
|
|
|
for (auto sig : quitSignals)
|
|
|
|
sigaction(sig, &sa, nullptr);
|
2018-11-11 13:43:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-09 02:35:08 +00:00
|
|
|
auto qmlLogger = initLogger("qml");
|
|
|
|
auto miscLogger = initLogger("misc");
|
|
|
|
|
|
|
|
void
|
|
|
|
spdLogger(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
logger->debug("{}", localMsg);
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
logger->info("{}", localMsg);
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
logger->warn("{}", localMsg);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
logger->critical("{}", localMsg);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
logger->critical("{}", localMsg);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2018-10-13 15:38:31 +01:00
|
|
|
{
|
2018-12-06 10:36:13 +00:00
|
|
|
|
2018-12-09 02:35:08 +00:00
|
|
|
qInstallMessageHandler(spdLogger);
|
|
|
|
|
|
|
|
auto launcherLogger = initLogger("launcher");
|
|
|
|
launcherLogger->info("Starting up!");
|
2018-12-12 08:28:53 +00:00
|
|
|
|
2018-12-09 02:35:08 +00:00
|
|
|
QString backendString;
|
2018-11-26 16:50:25 +00:00
|
|
|
#ifdef DISABLE_MpvPlayerBackend
|
|
|
|
Enums::Backends backend = Enums::Backends::DirectMpvBackend;
|
|
|
|
#else
|
2018-11-18 19:23:31 +00:00
|
|
|
Enums::Backends backend = Enums::Backends::MpvBackend;
|
2018-11-26 16:50:25 +00:00
|
|
|
#endif
|
2018-11-06 07:39:42 +00:00
|
|
|
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
|
|
|
|
QApplication app(argc, argv);
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-12-06 10:36:13 +00:00
|
|
|
app.setOrganizationName("KittehPlayer");
|
|
|
|
app.setOrganizationDomain("namedkitten.pw");
|
|
|
|
app.setApplicationName("KittehPlayer");
|
2018-12-12 08:28:53 +00:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-12-06 10:36:13 +00:00
|
|
|
QSettings settings;
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-12-06 10:36:13 +00:00
|
|
|
bool checkForUpdates =
|
|
|
|
settings.value("Backend/checkForUpdatesOnLaunch", false).toBool();
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!qstrcmp(argv[i], "--no-update-check")) {
|
|
|
|
checkForUpdates = false;
|
|
|
|
}
|
2018-11-16 09:16:04 +00:00
|
|
|
}
|
2018-12-06 10:36:13 +00:00
|
|
|
|
|
|
|
if (checkForUpdates) {
|
2018-12-09 02:35:08 +00:00
|
|
|
QtConcurrent::run(Utils::checkForUpdates);
|
2018-11-16 09:16:04 +00:00
|
|
|
}
|
2018-11-16 09:10:26 +00:00
|
|
|
|
2018-11-26 16:50:25 +00:00
|
|
|
QString backendSetting = settings.value("Backend/backend", "").toString();
|
|
|
|
if (backendSetting.length() == 0) {
|
2018-11-28 18:41:54 +00:00
|
|
|
#ifndef DISABLE_MpvPlayerBackend
|
|
|
|
settings.setValue("Backend/backend", "mpv");
|
|
|
|
#else
|
|
|
|
settings.setValue("Backend/backend", "direct-mpv");
|
|
|
|
#endif
|
2018-11-24 21:00:04 +00:00
|
|
|
}
|
2018-12-09 02:35:08 +00:00
|
|
|
backendString = backendSetting;
|
2018-11-26 16:50:25 +00:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!qstrcmp(argv[i], "--update")) {
|
2018-11-18 13:33:45 +00:00
|
|
|
Utils::updateAppImage();
|
2018-11-28 18:41:54 +00:00
|
|
|
} else if (!qstrcmp(argv[i], "--backend=mpv") || backendSetting == "mpv") {
|
2018-11-18 19:23:31 +00:00
|
|
|
backend = Enums::Backends::MpvBackend;
|
2018-12-09 02:35:08 +00:00
|
|
|
backendString = QString("mpv");
|
2018-11-28 18:41:54 +00:00
|
|
|
} else if (!qstrcmp(argv[i], "--backend=direct-mpv") ||
|
|
|
|
backendSetting == "direct-mpv") {
|
2018-12-09 02:35:08 +00:00
|
|
|
backendString = QString("direct-mpv");
|
2018-11-18 19:23:31 +00:00
|
|
|
backend = Enums::Backends::DirectMpvBackend;
|
2018-10-23 11:37:51 +01:00
|
|
|
}
|
2018-11-06 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 02:35:08 +00:00
|
|
|
launcherLogger->info("Using backend={}", backendString.toUtf8().constData());
|
|
|
|
|
2018-11-18 13:33:45 +00:00
|
|
|
Utils::SetDPMS(false);
|
2018-11-06 07:39:42 +00:00
|
|
|
|
2018-11-16 09:16:04 +00:00
|
|
|
QString newpath =
|
|
|
|
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
|
|
|
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
|
2018-11-06 07:39:42 +00:00
|
|
|
setenv("PATH", newpath.toUtf8().constData(), 1);
|
2018-10-23 23:56:24 +01:00
|
|
|
|
2018-11-17 15:45:21 +00:00
|
|
|
qmlRegisterUncreatableMetaObject(
|
2018-11-26 16:50:25 +00:00
|
|
|
Enums::staticMetaObject, "player", 1, 0, "Enums", "Error: only enums");
|
2018-11-17 15:45:21 +00:00
|
|
|
qRegisterMetaType<Enums::PlayStatus>("Enums.PlayStatus");
|
|
|
|
qRegisterMetaType<Enums::VolumeStatus>("Enums.VolumeStatus");
|
2018-11-18 19:23:31 +00:00
|
|
|
qRegisterMetaType<Enums::Backends>("Enums.Backends");
|
2018-11-17 19:33:32 +00:00
|
|
|
qRegisterMetaType<Enums::Commands>("Enums.Commands");
|
2018-12-08 22:21:12 +00:00
|
|
|
qmlRegisterType<Process>("player", 1, 0, "Process");
|
2018-12-09 02:35:08 +00:00
|
|
|
|
2018-12-08 22:21:12 +00:00
|
|
|
qmlRegisterType<ThumbnailCache>("player", 1, 0, "ThumbnailCache");
|
2018-11-28 18:41:54 +00:00
|
|
|
|
2018-11-26 16:50:25 +00:00
|
|
|
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
|
|
|
|
|
2018-11-18 19:23:31 +00:00
|
|
|
switch (backend) {
|
|
|
|
case Enums::Backends::MpvBackend: {
|
2018-11-28 18:41:54 +00:00
|
|
|
#ifndef DISABLE_MpvPlayerBackend
|
|
|
|
qmlRegisterType<MpvPlayerBackend>("player", 1, 0, "PlayerBackend");
|
|
|
|
#else
|
|
|
|
qDebug() << "Normal MPV backend not available, resetting backend option "
|
|
|
|
"to blank.";
|
|
|
|
settings.setValue("Backend/backend", "direct-mpv");
|
|
|
|
app.exit();
|
|
|
|
#endif
|
|
|
|
break;
|
2018-11-18 19:23:31 +00:00
|
|
|
}
|
|
|
|
case Enums::Backends::DirectMpvBackend: {
|
|
|
|
qmlRegisterType<DirectMpvPlayerBackend>("player", 1, 0, "PlayerBackend");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
std::setlocale(LC_NUMERIC, "C");
|
2018-12-09 02:35:08 +00:00
|
|
|
launcherLogger->info("Loading player...");
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2018-11-28 18:41:54 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
2018-10-27 16:11:29 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
return app.exec();
|
2018-10-13 15:38:31 +01:00
|
|
|
}
|