From e0d5927bcae855c033263c1477d388942b88ce1b Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 21 Jan 2020 02:55:46 +0000 Subject: [PATCH] Generat --- plugins/pausemusic/CMakeLists.txt | 4 +- .../org.mpris.MediaPlayer2.Player.xml | 108 ++++++++++++++++++ plugins/pausemusic/pausemusicplugin.cpp | 20 ++-- 3 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 plugins/pausemusic/org.mpris.MediaPlayer2.Player.xml diff --git a/plugins/pausemusic/CMakeLists.txt b/plugins/pausemusic/CMakeLists.txt index 26aa7a874..d2b99d025 100644 --- a/plugins/pausemusic/CMakeLists.txt +++ b/plugins/pausemusic/CMakeLists.txt @@ -1,6 +1,6 @@ if(WIN32) set(kdeconnect_pausemusic_SRCS - pausemusicplugin-win.cpp + pausemusicplugin-win.cpp ) else() set(kdeconnect_pausemusic_SRCS @@ -8,6 +8,8 @@ else() ) endif() +qt5_add_dbus_interface(kdeconnect_pausemusic_SRCS org.mpris.MediaPlayer2.Player.xml mprisplayer) + kdeconnect_add_plugin(kdeconnect_pausemusic JSON kdeconnect_pausemusic.json SOURCES ${kdeconnect_pausemusic_SRCS}) target_link_libraries(kdeconnect_pausemusic diff --git a/plugins/pausemusic/org.mpris.MediaPlayer2.Player.xml b/plugins/pausemusic/org.mpris.MediaPlayer2.Player.xml new file mode 100644 index 000000000..5f9d0d1d1 --- /dev/null +++ b/plugins/pausemusic/org.mpris.MediaPlayer2.Player.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/pausemusic/pausemusicplugin.cpp b/plugins/pausemusic/pausemusicplugin.cpp index cf2ce0d1c..e71e38bee 100644 --- a/plugins/pausemusic/pausemusicplugin.cpp +++ b/plugins/pausemusic/pausemusicplugin.cpp @@ -20,16 +20,12 @@ #include "pausemusicplugin.h" -#include -#include -#include -#include - #include #include #include #include +#include "mprisplayer.h" //In older Qt released, qAsConst isnt available #include "qtcompat_p.h" @@ -80,15 +76,15 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) const QStringList interfaces = DBusHelper::sessionBus().interface()->registeredServiceNames().value(); for (const QString& iface : interfaces) { if (iface.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) { - QDBusInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.mpris.MediaPlayer2.Player")); - QString status = mprisInterface.property("PlaybackStatus").toString(); + OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus()); + QString status = mprisInterface.playbackStatus(); if (status == QLatin1String("Playing")) { if (!pausedSources.contains(iface)) { pausedSources.insert(iface); - if (mprisInterface.property("CanPause").toBool()) { - mprisInterface.asyncCall(QStringLiteral("Pause")); + if (mprisInterface.canPause()) { + mprisInterface.Pause(); } else { - mprisInterface.asyncCall(QStringLiteral("Stop")); + mprisInterface.Stop(); } } } @@ -113,8 +109,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) if (pause && !pausedSources.empty()) { for (const QString& iface : qAsConst(pausedSources)) { - QDBusInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.mpris.MediaPlayer2.Player")); - mprisInterface.asyncCall(QStringLiteral("Play")); + OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus()); + mprisInterface.Play(); } pausedSources.clear(); }