From 60989e52b3f3bc0a95d3e61bd8e59fa4d9b7ab83 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 26 Nov 2023 01:10:36 -0500 Subject: The 2 year constipation. (mpris plugin) Probably buggy as hell. --- mpris-plugin/qmpriswrapper.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 mpris-plugin/qmpriswrapper.cpp (limited to 'mpris-plugin/qmpriswrapper.cpp') diff --git a/mpris-plugin/qmpriswrapper.cpp b/mpris-plugin/qmpriswrapper.cpp new file mode 100644 index 0000000..8a3f273 --- /dev/null +++ b/mpris-plugin/qmpriswrapper.cpp @@ -0,0 +1,77 @@ +#include "qmpriswrapper.hpp" +#include "qmprisdbusinterface.hpp" +#include +#include +#include + +#include "../include/qmpcorepublic.hpp" + +QMPrisWrapper::QMPrisWrapper(QString serviceSuffix, qmpPluginAPI *_api, QObject *parent) : + api(_api), + QObject(parent), + svcsuffix(serviceSuffix) +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); + qDBusRegisterMetaType>(); +} + +void QMPrisWrapper::post_creation() +{ + QDBusConnection sessbus = QDBusConnection::sessionBus(); + sessbus.registerService("org.mpris.MediaPlayer2." + svcsuffix); + sessbus.registerObject("/org/mpris/MediaPlayer2", this); + api->registerUIHook("main.stop", [this](const void* a, void* _) { + tracklist->TrackListReplaced({}, QDBusObjectPath("/")); + this->notifyPropertyChange(PLAYER_INTERFACE, "Metadata", player->getMetadata()); + this->notifyPropertyChange(PLAYER_INTERFACE, "PlaybackStatus", player->getPlaybackStatus()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPause", player->getCanPause()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPlay", player->getCanPlay()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanSeek", player->getCanSeek()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoNext", player->getCanGoNext()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoPrevious", player->getCanGoPrevious()); + }, nullptr); + api->registerUIHook("main.start", [this](const void* a, void* _) { + tracklist->TrackListReplaced(tracklist->getTracks(), QDBusObjectPath("/org/chrisoft/qmidiplayer/dummylist/0")); + this->notifyPropertyChange(PLAYER_INTERFACE, "Metadata", player->getMetadata()); + this->notifyPropertyChange(PLAYER_INTERFACE, "PlaybackStatus", player->getPlaybackStatus()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPause", player->getCanPause()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPlay", player->getCanPlay()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanSeek", player->getCanSeek()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoNext", player->getCanGoNext()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoPrevious", player->getCanGoPrevious()); + this->notifyPropertyChange(PLAYER_INTERFACE, "Rate", player->getRate()); + }, nullptr); + api->registerUIHook("main.pause", [this](const void* a, void* _) { + this->notifyPropertyChange(PLAYER_INTERFACE, "PlaybackStatus", player->getPlaybackStatus()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPause", player->getCanPause()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanPlay", player->getCanPlay()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanSeek", player->getCanSeek()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoNext", player->getCanGoNext()); + this->notifyPropertyChange(PLAYER_INTERFACE, "CanGoPrevious", player->getCanGoPrevious()); + }, nullptr); + api->registerUIHook("main.seek", [this](const void* a, void *_) { + auto ps = static_cast(a); + player->Seeked(ps->curtime_ms * 1000); + }, nullptr); +} + +QMPrisWrapper::~QMPrisWrapper() +{ + QDBusConnection sessbus = QDBusConnection::sessionBus(); + sessbus.unregisterObject("/org/mpris/MediaPlayer2"); + sessbus.unregisterService("org.mpris.MediaPlayer2." + svcsuffix); +} + +void QMPrisWrapper::notifyPropertyChange(QString intf, QString prop, QVariant val) +{ + QDBusConnection sessbus = QDBusConnection::sessionBus(); + auto signal = QDBusMessage::createSignal("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "PropertiesChanged"); + signal.setArguments({ + intf, + QVariantMap{{prop, val}}, + QStringList{} + }); + sessbus.send(signal); +} -- cgit v1.2.3