2013-07-29 17:43:13 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2019-03-23 16:29:26 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2013-07-29 17:43:13 +01:00
|
|
|
*/
|
|
|
|
|
2013-08-13 14:48:02 +01:00
|
|
|
#ifndef MPRISCONTROLPLUGIN_H
|
|
|
|
#define MPRISCONTROLPLUGIN_H
|
2013-07-29 17:43:13 +01:00
|
|
|
|
|
|
|
#include <QString>
|
2013-07-30 19:21:06 +01:00
|
|
|
#include <QHash>
|
2014-09-21 23:44:47 +01:00
|
|
|
#include <QLoggingCategory>
|
2015-05-05 00:40:04 +01:00
|
|
|
#include <QDBusServiceWatcher>
|
2018-03-16 12:44:16 +00:00
|
|
|
#include <QSharedPointer>
|
2013-07-29 17:43:13 +01:00
|
|
|
|
2014-06-14 15:34:00 +01:00
|
|
|
#include <core/kdeconnectplugin.h>
|
2013-08-13 05:35:58 +01:00
|
|
|
|
2018-03-16 12:44:16 +00:00
|
|
|
|
|
|
|
class OrgFreedesktopDBusPropertiesInterface;
|
|
|
|
class OrgMprisMediaPlayer2PlayerInterface;
|
|
|
|
|
|
|
|
class MprisPlayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MprisPlayer(const QString& serviceName, const QString& dbusObjectPath, const QDBusConnection& busConnection);
|
|
|
|
MprisPlayer() = delete;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const QString& serviceName() const { return m_serviceName; }
|
|
|
|
OrgFreedesktopDBusPropertiesInterface* propertiesInterface() const { return m_propertiesInterface.data(); }
|
|
|
|
OrgMprisMediaPlayer2PlayerInterface* mediaPlayer2PlayerInterface() const { return m_mediaPlayer2PlayerInterface.data(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_serviceName;
|
|
|
|
QSharedPointer<OrgFreedesktopDBusPropertiesInterface> m_propertiesInterface;
|
|
|
|
QSharedPointer<OrgMprisMediaPlayer2PlayerInterface> m_mediaPlayer2PlayerInterface;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
#define PACKET_TYPE_MPRIS QStringLiteral("kdeconnect.mpris")
|
2013-10-11 14:19:23 +01:00
|
|
|
|
2014-09-21 23:44:47 +01:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_MPRIS)
|
|
|
|
|
2013-08-13 05:35:58 +01:00
|
|
|
class MprisControlPlugin
|
|
|
|
: public KdeConnectPlugin
|
2013-07-29 17:43:13 +01:00
|
|
|
{
|
2013-07-30 19:21:06 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-07-29 17:43:13 +01:00
|
|
|
public:
|
2017-09-03 20:39:44 +01:00
|
|
|
explicit MprisControlPlugin(QObject* parent, const QVariantList& args);
|
2013-08-13 05:35:58 +01:00
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
bool receivePacket(const NetworkPacket& np) override;
|
2016-06-20 08:05:02 +01:00
|
|
|
void connected() override { }
|
2013-07-29 17:43:13 +01:00
|
|
|
|
2013-08-10 04:21:55 +01:00
|
|
|
private Q_SLOTS:
|
2013-11-18 01:34:34 +00:00
|
|
|
void propertiesChanged(const QString& propertyInterface, const QVariantMap& properties);
|
2014-12-13 22:41:53 +00:00
|
|
|
void seeked(qlonglong);
|
2013-07-30 19:21:06 +01:00
|
|
|
|
|
|
|
private:
|
2016-04-08 00:12:10 +01:00
|
|
|
void serviceOwnerChanged(const QString& serviceName, const QString& oldOwner, const QString& newOwner);
|
2018-03-16 12:44:16 +00:00
|
|
|
void addPlayer(const QString& serviceName);
|
|
|
|
void removePlayer(const QString& serviceName);
|
2013-08-13 05:35:58 +01:00
|
|
|
void sendPlayerList();
|
2018-03-04 19:48:51 +00:00
|
|
|
void mprisPlayerMetadataToNetworkPacket(NetworkPacket& np, const QVariantMap& nowPlayingMap) const;
|
2018-03-04 12:47:29 +00:00
|
|
|
bool sendAlbumArt(const NetworkPacket& np);
|
2013-08-13 14:48:02 +01:00
|
|
|
|
2018-03-16 12:44:16 +00:00
|
|
|
QHash<QString, MprisPlayer> playerList;
|
2013-08-10 04:21:55 +01:00
|
|
|
int prevVolume;
|
2015-05-05 00:40:04 +01:00
|
|
|
QDBusServiceWatcher* m_watcher;
|
2013-07-30 19:21:06 +01:00
|
|
|
|
2013-07-29 17:43:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|