1
0
Fork 0

[Backend] Moved backends into their own folder.

This commit is contained in:
NamedKitten 2018-12-20 14:37:29 +00:00
parent 287a51ba0b
commit 4f7da53bb4
10 changed files with 153 additions and 96 deletions

View file

@ -37,16 +37,17 @@ endif(X11_FOUND AND Xext_FOUND)
set(SOURCES set(SOURCES
src/main.cpp src/main.cpp
src/DirectMpvPlayerBackend.cpp src/Backends/DirectMPV/DirectMPVBackend.cpp
src/utils.cpp src/utils.cpp
src/enums.hpp src/enums.hpp
src/Process.cpp src/Process.cpp
src/ThumbnailCache.cpp src/ThumbnailCache.cpp
src/logger.cpp src/logger.cpp
src/qmldebugger.cpp
) )
if(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0") if(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0")
set(SOURCES ${SOURCES} src/MpvPlayerBackend.cpp) set(SOURCES ${SOURCES} src/Backends/MPV/MPVBackend.cpp)
else() else()
add_definitions(-DDISABLE_MpvPlayerBackend) add_definitions(-DDISABLE_MpvPlayerBackend)
endif(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0") endif(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0")

View file

@ -2,9 +2,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdexcept> #include <stdexcept>
#include "DirectMpvPlayerBackend.h" #include "src/Backends/DirectMPV/DirectMPVBackend.hpp"
#include "utils.hpp" #include "src/utils.hpp"
#include <QApplication> #include <QApplication>
#include <QMainWindow> #include <QMainWindow>
#include <QOpenGLContext> #include <QOpenGLContext>
@ -17,7 +17,7 @@
void void
wakeup(void* ctx) wakeup(void* ctx)
{ {
QCoreApplication::postEvent((DirectMpvPlayerBackend*)ctx, QCoreApplication::postEvent((DirectMPVBackend*)ctx,
new QEvent(QEvent::User)); new QEvent(QEvent::User));
} }
@ -66,7 +66,7 @@ MpvRenderer::paint()
window->resetOpenGLState(); window->resetOpenGLState();
} }
DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent) DirectMPVBackend::DirectMPVBackend(QQuickItem* parent)
: QQuickItem(parent) : QQuickItem(parent)
, mpv_gl(0) , mpv_gl(0)
, renderer(0) , renderer(0)
@ -117,27 +117,27 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
if (!mpv_gl) if (!mpv_gl)
throw std::runtime_error("OpenGL not compiled in"); throw std::runtime_error("OpenGL not compiled in");
mpv_opengl_cb_set_update_callback( mpv_opengl_cb_set_update_callback(
mpv_gl, DirectMpvPlayerBackend::on_update, (void*)this); mpv_gl, DirectMPVBackend::on_update, (void*)this);
connect(this, connect(this,
&DirectMpvPlayerBackend::onUpdate, &DirectMPVBackend::onUpdate,
this, this,
&DirectMpvPlayerBackend::doUpdate, &DirectMPVBackend::doUpdate,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, connect(this,
&DirectMpvPlayerBackend::positionChanged, &DirectMPVBackend::positionChanged,
&DirectMpvPlayerBackend::updateDurationString); &DirectMPVBackend::updateDurationString);
connect(this, connect(this,
&DirectMpvPlayerBackend::durationChanged, &DirectMPVBackend::durationChanged,
&DirectMpvPlayerBackend::updateDurationString); &DirectMPVBackend::updateDurationString);
connect(this, connect(this,
&QQuickItem::windowChanged, &QQuickItem::windowChanged,
this, this,
&DirectMpvPlayerBackend::handleWindowChanged); &DirectMPVBackend::handleWindowChanged);
} }
DirectMpvPlayerBackend::~DirectMpvPlayerBackend() DirectMPVBackend::~DirectMPVBackend()
{ {
printf("Shutting down...\n"); printf("Shutting down...\n");
qApp->quit(); qApp->quit();
@ -145,7 +145,7 @@ DirectMpvPlayerBackend::~DirectMpvPlayerBackend()
} }
void void
DirectMpvPlayerBackend::sync() DirectMPVBackend::sync()
{ {
if (!renderer) { if (!renderer) {
@ -163,13 +163,13 @@ DirectMpvPlayerBackend::sync()
} }
void void
DirectMpvPlayerBackend::swapped() DirectMPVBackend::swapped()
{ {
mpv_opengl_cb_report_flip(mpv_gl, 0); mpv_opengl_cb_report_flip(mpv_gl, 0);
} }
void void
DirectMpvPlayerBackend::cleanup() DirectMPVBackend::cleanup()
{ {
if (renderer) { if (renderer) {
delete renderer; delete renderer;
@ -178,45 +178,45 @@ DirectMpvPlayerBackend::cleanup()
} }
void void
DirectMpvPlayerBackend::on_update(void* ctx) DirectMPVBackend::on_update(void* ctx)
{ {
DirectMpvPlayerBackend* self = (DirectMpvPlayerBackend*)ctx; DirectMPVBackend* self = (DirectMPVBackend*)ctx;
emit self->onUpdate(); emit self->onUpdate();
} }
void void
DirectMpvPlayerBackend::doUpdate() DirectMPVBackend::doUpdate()
{ {
window()->update(); window()->update();
update(); update();
} }
QVariant QVariant
DirectMpvPlayerBackend::getProperty(const QString& name) const DirectMPVBackend::getProperty(const QString& name) const
{ {
return mpv::qt::get_property_variant(mpv, name); return mpv::qt::get_property_variant(mpv, name);
} }
void void
DirectMpvPlayerBackend::command(const QVariant& params) DirectMPVBackend::command(const QVariant& params)
{ {
mpv::qt::command_variant(mpv, params); mpv::qt::command_variant(mpv, params);
} }
void void
DirectMpvPlayerBackend::setProperty(const QString& name, const QVariant& value) DirectMPVBackend::setProperty(const QString& name, const QVariant& value)
{ {
mpv::qt::set_property_variant(mpv, name, value); mpv::qt::set_property_variant(mpv, name, value);
} }
void void
DirectMpvPlayerBackend::setOption(const QString& name, const QVariant& value) DirectMPVBackend::setOption(const QString& name, const QVariant& value)
{ {
mpv::qt::set_option_variant(mpv, name, value); mpv::qt::set_option_variant(mpv, name, value);
} }
void void
DirectMpvPlayerBackend::launchAboutQt() DirectMPVBackend::launchAboutQt()
{ {
QApplication* qapp = QApplication* qapp =
qobject_cast<QApplication*>(QCoreApplication::instance()); qobject_cast<QApplication*>(QCoreApplication::instance());
@ -224,13 +224,13 @@ DirectMpvPlayerBackend::launchAboutQt()
} }
QVariant QVariant
DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd) DirectMPVBackend::playerCommand(const Enums::Commands& cmd)
{ {
return playerCommand(cmd, QVariant("NoArgProvided")); return playerCommand(cmd, QVariant("NoArgProvided"));
} }
QVariant QVariant
DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd, DirectMPVBackend::playerCommand(const Enums::Commands& cmd,
const QVariant& args) const QVariant& args)
{ {
switch (cmd) { switch (cmd) {
@ -392,37 +392,37 @@ DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
} }
void void
DirectMpvPlayerBackend::handleWindowChanged(QQuickWindow* win) DirectMPVBackend::handleWindowChanged(QQuickWindow* win)
{ {
if (!win) if (!win)
return; return;
connect(win, connect(win,
&QQuickWindow::beforeSynchronizing, &QQuickWindow::beforeSynchronizing,
this, this,
&DirectMpvPlayerBackend::sync, &DirectMPVBackend::sync,
Qt::DirectConnection); Qt::DirectConnection);
connect(win, connect(win,
&QQuickWindow::sceneGraphInvalidated, &QQuickWindow::sceneGraphInvalidated,
this, this,
&DirectMpvPlayerBackend::cleanup, &DirectMPVBackend::cleanup,
Qt::DirectConnection); Qt::DirectConnection);
connect(win, connect(win,
&QQuickWindow::frameSwapped, &QQuickWindow::frameSwapped,
this, this,
&DirectMpvPlayerBackend::swapped, &DirectMPVBackend::swapped,
Qt::DirectConnection); Qt::DirectConnection);
win->setClearBeforeRendering(false); win->setClearBeforeRendering(false);
} }
void void
DirectMpvPlayerBackend::toggleOnTop() DirectMPVBackend::toggleOnTop()
{ {
onTop = !onTop; onTop = !onTop;
Utils::AlwaysOnTop(window()->winId(), onTop); Utils::AlwaysOnTop(window()->winId(), onTop);
} }
bool bool
DirectMpvPlayerBackend::event(QEvent* event) DirectMPVBackend::event(QEvent* event)
{ {
if (event->type() == QEvent::User) { if (event->type() == QEvent::User) {
on_mpv_events(); on_mpv_events();
@ -431,7 +431,7 @@ DirectMpvPlayerBackend::event(QEvent* event)
} }
void void
DirectMpvPlayerBackend::on_mpv_events() DirectMPVBackend::on_mpv_events()
{ {
while (mpv) { while (mpv) {
mpv_event* event = mpv_wait_event(mpv, 0); mpv_event* event = mpv_wait_event(mpv, 0);
@ -443,7 +443,7 @@ DirectMpvPlayerBackend::on_mpv_events()
} }
void void
DirectMpvPlayerBackend::updateDurationString(int numTime) DirectMPVBackend::updateDurationString(int numTime)
{ {
QVariant speed = getProperty("speed"); QVariant speed = getProperty("speed");
QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex()); QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
@ -474,13 +474,13 @@ DirectMpvPlayerBackend::updateDurationString(int numTime)
} }
void void
DirectMpvPlayerBackend::updateAppImage() DirectMPVBackend::updateAppImage()
{ {
Utils::updateAppImage(); Utils::updateAppImage();
} }
QVariantMap QVariantMap
DirectMpvPlayerBackend::getAudioDevices() const DirectMPVBackend::getAudioDevices() const
{ {
QVariant drivers = getProperty("audio-device-list"); QVariant drivers = getProperty("audio-device-list");
QVariant currentDevice = getProperty("audio-device"); QVariant currentDevice = getProperty("audio-device");
@ -502,7 +502,7 @@ DirectMpvPlayerBackend::getAudioDevices() const
} }
void void
DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event) DirectMPVBackend::handle_mpv_event(mpv_event* event)
{ {
switch (event->event_id) { switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: { case MPV_EVENT_PROPERTY_CHANGE: {

View file

@ -1,5 +1,5 @@
#ifndef DirectMpvPlayerBackend_H #ifndef DirectMPVBackend_H
#define DirectMpvPlayerBackend_H #define DirectMPVBackend_H
#include <mpv/client.h> #include <mpv/client.h>
#include <mpv/opengl_cb.h> #include <mpv/opengl_cb.h>
@ -11,8 +11,8 @@
#include <QSettings> #include <QSettings>
#include <QWidget> #include <QWidget>
#include "backendinterface.hpp" #include "src/backendinterface.hpp"
#include "enums.hpp" #include "src/enums.hpp"
class MpvRenderer : public QObject class MpvRenderer : public QObject
{ {
@ -31,7 +31,7 @@ public slots:
void paint(); void paint();
}; };
class DirectMpvPlayerBackend class DirectMPVBackend
: public QQuickItem : public QQuickItem
, public BackendInterface , public BackendInterface
{ {
@ -62,8 +62,8 @@ public:
} }
bool logging() const { return m_logging; } bool logging() const { return m_logging; }
DirectMpvPlayerBackend(QQuickItem* parent = 0); DirectMPVBackend(QQuickItem* parent = 0);
virtual ~DirectMpvPlayerBackend(); virtual ~DirectMPVBackend();
public slots: public slots:
QVariant playerCommand(const Enums::Commands& command, const QVariant& args); QVariant playerCommand(const Enums::Commands& command, const QVariant& args);

View file

@ -1,6 +1,6 @@
#include "MpvPlayerBackend.h" #include "src/Backends/MPV/MPVBackend.hpp"
#include "logger.h" #include "src/logger.h"
#include "utils.hpp" #include "src/utils.hpp"
#include <QApplication> #include <QApplication>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QOpenGLContext> #include <QOpenGLContext>
@ -27,14 +27,14 @@ namespace {
void void
wakeup(void* ctx) wakeup(void* ctx)
{ {
QCoreApplication::postEvent((MpvPlayerBackend*)ctx, new QEvent(QEvent::User)); QCoreApplication::postEvent((MPVBackend*)ctx, new QEvent(QEvent::User));
} }
void void
on_mpv_redraw(void* ctx) on_mpv_redraw(void* ctx)
{ {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
reinterpret_cast<MpvPlayerBackend*>(ctx), "update", Qt::QueuedConnection); reinterpret_cast<MPVBackend*>(ctx), "update", Qt::QueuedConnection);
} }
static void* static void*
@ -53,10 +53,10 @@ get_proc_address_mpv(void* ctx, const char* name)
class MpvRenderer : public QQuickFramebufferObject::Renderer class MpvRenderer : public QQuickFramebufferObject::Renderer
{ {
MpvPlayerBackend* obj; MPVBackend* obj;
public: public:
MpvRenderer(MpvPlayerBackend* new_obj) MpvRenderer(MPVBackend* new_obj)
: obj{ new_obj } : obj{ new_obj }
{} {}
@ -124,7 +124,7 @@ public:
} }
}; };
MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent) MPVBackend::MPVBackend(QQuickItem* parent)
: QQuickFramebufferObject(parent) : QQuickFramebufferObject(parent)
, mpv{ mpv_create() } , mpv{ mpv_create() }
, mpv_gl(nullptr) , mpv_gl(nullptr)
@ -171,23 +171,23 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
throw std::runtime_error("could not initialize mpv context"); throw std::runtime_error("could not initialize mpv context");
connect(this, connect(this,
&MpvPlayerBackend::onUpdate, &MPVBackend::onUpdate,
this, this,
&MpvPlayerBackend::doUpdate, &MPVBackend::doUpdate,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, connect(this,
&MpvPlayerBackend::positionChanged, &MPVBackend::positionChanged,
this, this,
&MpvPlayerBackend::updateDurationString, &MPVBackend::updateDurationString,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, connect(this,
&MpvPlayerBackend::durationChanged, &MPVBackend::durationChanged,
this, this,
&MpvPlayerBackend::updateDurationString, &MPVBackend::updateDurationString,
Qt::QueuedConnection); Qt::QueuedConnection);
} }
MpvPlayerBackend::~MpvPlayerBackend() MPVBackend::~MPVBackend()
{ {
printf("Shutting down...\n"); printf("Shutting down...\n");
Utils::SetDPMS(true); Utils::SetDPMS(true);
@ -198,33 +198,33 @@ MpvPlayerBackend::~MpvPlayerBackend()
} }
void void
MpvPlayerBackend::on_update(void* ctx) MPVBackend::on_update(void* ctx)
{ {
MpvPlayerBackend* self = (MpvPlayerBackend*)ctx; MPVBackend* self = (MPVBackend*)ctx;
emit self->onUpdate(); emit self->onUpdate();
} }
void void
MpvPlayerBackend::doUpdate() MPVBackend::doUpdate()
{ {
update(); update();
} }
QVariant QVariant
MpvPlayerBackend::getProperty(const QString& name) const MPVBackend::getProperty(const QString& name) const
{ {
return mpv::qt::get_property_variant(mpv, name); return mpv::qt::get_property_variant(mpv, name);
} }
void void
MpvPlayerBackend::command(const QVariant& params) MPVBackend::command(const QVariant& params)
{ {
mpv::qt::node_builder node(params); mpv::qt::node_builder node(params);
mpv_command_node(mpv, node.node(), nullptr); mpv_command_node(mpv, node.node(), nullptr);
} }
void void
MpvPlayerBackend::setProperty(const QString& name, const QVariant& value) MPVBackend::setProperty(const QString& name, const QVariant& value)
{ {
mpv::qt::node_builder node(value); mpv::qt::node_builder node(value);
qDebug() << "Setting property" << name << "to" << value; qDebug() << "Setting property" << name << "to" << value;
@ -232,19 +232,19 @@ MpvPlayerBackend::setProperty(const QString& name, const QVariant& value)
} }
void void
MpvPlayerBackend::setOption(const QString& name, const QVariant& value) MPVBackend::setOption(const QString& name, const QVariant& value)
{ {
mpv::qt::set_option_variant(mpv, name, value); mpv::qt::set_option_variant(mpv, name, value);
} }
QVariant QVariant
MpvPlayerBackend::playerCommand(const Enums::Commands& cmd) MPVBackend::playerCommand(const Enums::Commands& cmd)
{ {
return playerCommand(cmd, QVariant("NoArgProvided")); return playerCommand(cmd, QVariant("NoArgProvided"));
} }
QVariant QVariant
MpvPlayerBackend::playerCommand(const Enums::Commands& cmd, MPVBackend::playerCommand(const Enums::Commands& cmd,
const QVariant& args) const QVariant& args)
{ {
switch (cmd) { switch (cmd) {
@ -414,14 +414,14 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
} }
void void
MpvPlayerBackend::toggleOnTop() MPVBackend::toggleOnTop()
{ {
onTop = !onTop; onTop = !onTop;
Utils::AlwaysOnTop(window()->winId(), onTop); Utils::AlwaysOnTop(window()->winId(), onTop);
} }
bool bool
MpvPlayerBackend::event(QEvent* event) MPVBackend::event(QEvent* event)
{ {
if (event->type() == QEvent::User) { if (event->type() == QEvent::User) {
on_mpv_events(); on_mpv_events();
@ -430,7 +430,7 @@ MpvPlayerBackend::event(QEvent* event)
} }
void void
MpvPlayerBackend::on_mpv_events() MPVBackend::on_mpv_events()
{ {
while (mpv) { while (mpv) {
mpv_event* event = mpv_wait_event(mpv, 0); mpv_event* event = mpv_wait_event(mpv, 0);
@ -442,7 +442,7 @@ MpvPlayerBackend::on_mpv_events()
} }
void void
MpvPlayerBackend::updateDurationString(int numTime) MPVBackend::updateDurationString(int numTime)
{ {
QVariant speed = getProperty("speed"); QVariant speed = getProperty("speed");
QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex()); QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
@ -473,7 +473,7 @@ MpvPlayerBackend::updateDurationString(int numTime)
} }
QVariantMap QVariantMap
MpvPlayerBackend::getAudioDevices(const QVariant& drivers) const MPVBackend::getAudioDevices(const QVariant& drivers) const
{ {
QVariantMap newDrivers; QVariantMap newDrivers;
@ -486,7 +486,7 @@ MpvPlayerBackend::getAudioDevices(const QVariant& drivers) const
} }
void void
MpvPlayerBackend::handle_mpv_event(mpv_event* event) MPVBackend::handle_mpv_event(mpv_event* event)
{ {
switch (event->event_id) { switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: { case MPV_EVENT_PROPERTY_CHANGE: {
@ -590,10 +590,10 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} }
QQuickFramebufferObject::Renderer* QQuickFramebufferObject::Renderer*
MpvPlayerBackend::createRenderer() const MPVBackend::createRenderer() const
{ {
window()->setIcon(QIcon(":/icon.png")); window()->setIcon(QIcon(":/icon.png"));
window()->setPersistentOpenGLContext(true); window()->setPersistentOpenGLContext(true);
window()->setPersistentSceneGraph(true); window()->setPersistentSceneGraph(true);
return new MpvRenderer(const_cast<MpvPlayerBackend*>(this)); return new MpvRenderer(const_cast<MPVBackend*>(this));
} }

View file

@ -1,5 +1,5 @@
#ifndef MpvPlayerBackend_H #ifndef MPVBackend_H
#define MpvPlayerBackend_H #define MPVBackend_H
#include <mpv/client.h> #include <mpv/client.h>
#include <mpv/qthelper.hpp> #include <mpv/qthelper.hpp>
@ -11,13 +11,13 @@
#include <QQuickFramebufferObject> #include <QQuickFramebufferObject>
#include <QSettings> #include <QSettings>
#include "backendinterface.hpp" #include "src/backendinterface.hpp"
#include "enums.hpp" #include "src/enums.hpp"
#include "utils.hpp" #include "src/utils.hpp"
class MpvRenderer; class MpvRenderer;
class MpvPlayerBackend class MPVBackend
: public QQuickFramebufferObject : public QQuickFramebufferObject
, public BackendInterface , public BackendInterface
{ {
@ -42,8 +42,8 @@ class MpvPlayerBackend
public: public:
static void on_update(void* ctx); static void on_update(void* ctx);
MpvPlayerBackend(QQuickItem* parent = 0); MPVBackend(QQuickItem* parent = 0);
virtual ~MpvPlayerBackend(); virtual ~MPVBackend();
virtual Renderer* createRenderer() const; virtual Renderer* createRenderer() const;
void setLogging(bool a) void setLogging(bool a)

View file

@ -50,8 +50,8 @@ Q_ENUM_NS(Commands)
enum class Backends : int enum class Backends : int
{ {
MpvBackend = 0, MPVBackend = 0,
DirectMpvBackend = 1 DirectMPVBackend = 1
}; };
Q_ENUM_NS(Backends) Q_ENUM_NS(Backends)

View file

@ -1,8 +1,9 @@
#include "DirectMpvPlayerBackend.h" #include "Backends/DirectMPV/DirectMPVBackend.hpp"
#ifndef DISABLE_MpvPlayerBackend #ifndef DISABLE_MpvPlayerBackend
#include "MpvPlayerBackend.h" #include "Backends/MPV/MPVBackend.hpp"
#endif #endif
#include "qmldebugger.h"
#include "enums.hpp" #include "enums.hpp"
#include "logger.h" #include "logger.h"
#include "utils.hpp" #include "utils.hpp"
@ -159,14 +160,15 @@ main(int argc, char* argv[])
qRegisterMetaType<Enums::Commands>("Enums.Commands"); qRegisterMetaType<Enums::Commands>("Enums.Commands");
qmlRegisterType<Process>("player", 1, 0, "Process"); qmlRegisterType<Process>("player", 1, 0, "Process");
qmlRegisterType<QMLDebugger>("player", 1, 0, "QMLDebugger");
qmlRegisterType<ThumbnailCache>("player", 1, 0, "ThumbnailCache"); qmlRegisterType<ThumbnailCache>("player", 1, 0, "ThumbnailCache");
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils"); qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
if (backendString == "mpv") { if (backendString == "mpv") {
backend = Enums::Backends::MpvBackend; backend = Enums::Backends::MPVBackend;
} else if (backendString == "direct-mpv") { } else if (backendString == "direct-mpv") {
backend = Enums::Backends::DirectMpvBackend; backend = Enums::Backends::DirectMPVBackend;
} else { } else {
launcherLogger->error("Invalid backend {}.", launcherLogger->error("Invalid backend {}.",
backendString.toUtf8().constData()); backendString.toUtf8().constData());
@ -176,9 +178,9 @@ main(int argc, char* argv[])
launcherLogger->info("Using backend={}", backendString.toUtf8().constData()); launcherLogger->info("Using backend={}", backendString.toUtf8().constData());
switch (backend) { switch (backend) {
case Enums::Backends::MpvBackend: { case Enums::Backends::MPVBackend: {
#ifndef DISABLE_MpvPlayerBackend #ifndef DISABLE_MpvPlayerBackend
qmlRegisterType<MpvPlayerBackend>("player", 1, 0, "PlayerBackend"); qmlRegisterType<MPVBackend>("player", 1, 0, "PlayerBackend");
#else #else
qDebug() << "Normal MPV backend not available, resetting backend option " qDebug() << "Normal MPV backend not available, resetting backend option "
"to blank."; "to blank.";
@ -187,8 +189,8 @@ main(int argc, char* argv[])
#endif #endif
break; break;
} }
case Enums::Backends::DirectMpvBackend: { case Enums::Backends::DirectMPVBackend: {
qmlRegisterType<DirectMpvPlayerBackend>("player", 1, 0, "PlayerBackend"); qmlRegisterType<DirectMPVBackend>("player", 1, 0, "PlayerBackend");
break; break;
} }
} }

View file

@ -20,6 +20,10 @@ Window {
property bool onTop: false property bool onTop: false
QMLDebugger {
id: qmlDebugger
}
function getAppearanceValueForTheme(themeName, name) { function getAppearanceValueForTheme(themeName, name) {
if (themeName == "YouTube") { if (themeName == "YouTube") {
return youTubeAppearance[name] return youTubeAppearance[name]
@ -223,6 +227,7 @@ Window {
} }
function startPlayer() { function startPlayer() {
console.info(qmlDebugger.properties(player))
console.info("OwO!") console.info("OwO!")
var args = Qt.application.arguments var args = Qt.application.arguments

33
src/qmldebugger.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "qmldebugger.h"
#include <QMetaObject>
#include <QMetaProperty>
QString QMLDebugger::properties(QQuickItem *item, bool linebreak)
{
const QMetaObject *meta = item->metaObject();
QHash<QString, QVariant> list;
for (int i = 0; i < meta->propertyCount(); i++)
{
QMetaProperty property = meta->property(i);
const char* name = property.name();
QVariant value = item->property(name);
list[name] = value;
}
QString out;
QHashIterator<QString, QVariant> i(list);
while (i.hasNext()) {
i.next();
if (!out.isEmpty())
{
out += ", ";
if (linebreak) out += "\n";
}
out.append(i.key());
out.append(": ");
out.append(i.value().toString());
}
return out;
}

16
src/qmldebugger.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef QMLDEBUGGER_H
#define QMLDEBUGGER_H
#include <QObject>
#include <QQuickItem>
class QMLDebugger : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE static QString properties(QQuickItem *item, bool linebreak
= true);
};
#endif // QMLDEBUGGER_H