Commit 7b0bbebc authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

First implementation of the mpris control packageinterface

parent 3eb6ecaa
......@@ -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
......
......@@ -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<QVariant>&)
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
......
......@@ -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
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "mpriscontrolpackageinterface.h"
#include <QDebug>
#include <QDBusConnection>
#include <QDBusInterface>
#include <qdbusconnectioninterface.h>
#include <QDBusReply>
#include <QDBusMessage>
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<QString>("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;
}
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MPRISCONTROLPACKAGEINTERFACE_H
#define MPRISCONTROLPACKAGEINTERFACE_H
#include "packageinterface.h"
#include <QSet>
#include <QString>
class MprisControlPackageInterface
: public PackageInterface
{
public:
MprisControlPackageInterface();
virtual bool receivePackage(const Device& device, const NetworkPackage& np);
};
#endif
......@@ -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();
......
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PAUSEMUSICPACKAGERECEIVER_H
#define PAUSEMUSICPACKAGERECEIVER_H
#ifndef PAUSEMUSICPACKAGEINTERFACE_H
#define PAUSEMUSICPACKAGEINTERFACE_H
#include "packageinterface.h"
......@@ -40,4 +40,4 @@ private:
};
#endif // PAUSEMUSICPACKAGERECEIVER_H
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment