From 7b0bbebc02df93124e21365876a9db0798b12cad Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Mon, 29 Jul 2013 18:43:13 +0200 Subject: [PATCH] First implementation of the mpris control packageinterface --- daemon/CMakeLists.txt | 1 + daemon/daemon.cpp | 2 + daemon/networkpackagetypes.h | 2 +- .../mpriscontrolpackageinterface.cpp | 53 +++++++++++++++++++ .../mpriscontrolpackageinterface.h | 38 +++++++++++++ .../pausemusicpackageinterface.cpp | 4 +- .../pausemusicpackageinterface.h | 6 +-- 7 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 daemon/packageinterfaces/mpriscontrolpackageinterface.cpp create mode 100644 daemon/packageinterfaces/mpriscontrolpackageinterface.h diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 4e1d64a2e..28ccc91bb 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -14,6 +14,7 @@ set(kded_kdeconnect_SRCS packageinterfaces/pausemusicpackageinterface.cpp packageinterfaces/clipboardpackageinterface.cpp packageinterfaces/batterypackageinterface.cpp + packageinterfaces/mpriscontrolpackageinterface.cpp packageinterfaces/devicebatteryinformation_p.cpp networkpackage.cpp diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp index 244866e31..d8fa935c7 100644 --- a/daemon/daemon.cpp +++ b/daemon/daemon.cpp @@ -27,6 +27,7 @@ #include "packageinterfaces/pausemusicpackageinterface.h" #include "packageinterfaces/clipboardpackageinterface.h" #include "packageinterfaces/batterypackageinterface.h" +#include "packageinterfaces/mpriscontrolpackageinterface.h" #include "linkproviders/avahitcplinkprovider.h" #include "linkproviders/loopbacklinkprovider.h" @@ -65,6 +66,7 @@ Daemon::Daemon(QObject *parent, const QList&) mPackageInterfaces.push_back(new PauseMusicPackageInterface()); mPackageInterfaces.push_back(new ClipboardPackageInterface()); mPackageInterfaces.push_back(new BatteryPackageInterface(this)); + mPackageInterfaces.push_back(new MprisControlPackageInterface()); //TODO: Do not hardcode the load of the device locators //use: https://techbase.kde.org/Development/Tutorials/Services/Plugins diff --git a/daemon/networkpackagetypes.h b/daemon/networkpackagetypes.h index 981139f1c..aff696c5d 100644 --- a/daemon/networkpackagetypes.h +++ b/daemon/networkpackagetypes.h @@ -27,7 +27,7 @@ #define PACKAGE_TYPE_BATTERY QString("kdeconnect.battery") #define PACKAGE_TYPE_CALL QString("kdeconnect.call") #define PACKAGE_TYPE_CLIPBOARD QString("kdeconnect.clipboard") - +#define PACKAGE_TYPE_MPRIS QString("kdeconnect.mpris") #endif // NETWORKPACKAGETYPES_H diff --git a/daemon/packageinterfaces/mpriscontrolpackageinterface.cpp b/daemon/packageinterfaces/mpriscontrolpackageinterface.cpp new file mode 100644 index 000000000..71b20ecaa --- /dev/null +++ b/daemon/packageinterfaces/mpriscontrolpackageinterface.cpp @@ -0,0 +1,53 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "mpriscontrolpackageinterface.h" + +#include +#include +#include +#include +#include +#include + +MprisControlPackageInterface::MprisControlPackageInterface() +{ + //TODO: Emit info read form mpris to the phone +} + +bool MprisControlPackageInterface::receivePackage (const Device& device, const NetworkPackage& np) +{ + Q_UNUSED(device); + + if (np.type() != PACKAGE_TYPE_MPRIS) return false; + + QString action = np.get("action"); + + QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + Q_FOREACH (const QString& iface, interfaces) { + if (iface.startsWith("org.mpris.MediaPlayer2")) { + QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player"); + mprisInterface.asyncCall(action); + } + } + + return true; + +} diff --git a/daemon/packageinterfaces/mpriscontrolpackageinterface.h b/daemon/packageinterfaces/mpriscontrolpackageinterface.h new file mode 100644 index 000000000..02d8eecb3 --- /dev/null +++ b/daemon/packageinterfaces/mpriscontrolpackageinterface.h @@ -0,0 +1,38 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MPRISCONTROLPACKAGEINTERFACE_H +#define MPRISCONTROLPACKAGEINTERFACE_H + +#include "packageinterface.h" + +#include +#include + +class MprisControlPackageInterface + : public PackageInterface +{ +public: + MprisControlPackageInterface(); + virtual bool receivePackage(const Device& device, const NetworkPackage& np); + +}; + +#endif diff --git a/daemon/packageinterfaces/pausemusicpackageinterface.cpp b/daemon/packageinterfaces/pausemusicpackageinterface.cpp index e38ba2be0..43e3b8b41 100644 --- a/daemon/packageinterfaces/pausemusicpackageinterface.cpp +++ b/daemon/packageinterfaces/pausemusicpackageinterface.cpp @@ -69,7 +69,7 @@ bool PauseMusicPackageInterface::receivePackage (const Device& device, const Net if (status == "Playing") { if (!pausedSources.contains(iface)) { pausedSources.insert(iface); - mprisInterface.call(QDBus::Block,"Pause"); + mprisInterface.asyncCall("Pause"); } } } @@ -81,7 +81,7 @@ bool PauseMusicPackageInterface::receivePackage (const Device& device, const Net //mprisInterface->call(QDBus::Block,"Play"); //Workaround: Using playpause instead (checking first if it is already playing) QString status = mprisInterface.property("PlaybackStatus").toString(); - if (status == "Paused") mprisInterface.call(QDBus::Block,"PlayPause"); + if (status == "Paused") mprisInterface.asyncCall("PlayPause"); //End of workaround } pausedSources.clear(); diff --git a/daemon/packageinterfaces/pausemusicpackageinterface.h b/daemon/packageinterfaces/pausemusicpackageinterface.h index 17935381e..3d5a8de4a 100644 --- a/daemon/packageinterfaces/pausemusicpackageinterface.h +++ b/daemon/packageinterfaces/pausemusicpackageinterface.h @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -#ifndef PAUSEMUSICPACKAGERECEIVER_H -#define PAUSEMUSICPACKAGERECEIVER_H +#ifndef PAUSEMUSICPACKAGEINTERFACE_H +#define PAUSEMUSICPACKAGEINTERFACE_H #include "packageinterface.h" @@ -40,4 +40,4 @@ private: }; -#endif // PAUSEMUSICPACKAGERECEIVER_H +#endif