File indexing completed on 2024-04-21 04:56:51

0001 /**
0002  * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QDBusServiceWatcher>
0010 #include <QHash>
0011 #include <QSharedPointer>
0012 #include <QString>
0013 
0014 #include <core/kdeconnectplugin.h>
0015 
0016 class OrgFreedesktopDBusPropertiesInterface;
0017 class OrgMprisMediaPlayer2PlayerInterface;
0018 
0019 class MprisPlayer
0020 {
0021 public:
0022     MprisPlayer(const QString &serviceName, const QString &dbusObjectPath, const QDBusConnection &busConnection);
0023     MprisPlayer() = delete;
0024 
0025 public:
0026     const QString &serviceName() const
0027     {
0028         return m_serviceName;
0029     }
0030     OrgFreedesktopDBusPropertiesInterface *propertiesInterface() const
0031     {
0032         return m_propertiesInterface.data();
0033     }
0034     OrgMprisMediaPlayer2PlayerInterface *mediaPlayer2PlayerInterface() const
0035     {
0036         return m_mediaPlayer2PlayerInterface.data();
0037     }
0038 
0039 private:
0040     QString m_serviceName;
0041     QSharedPointer<OrgFreedesktopDBusPropertiesInterface> m_propertiesInterface;
0042     QSharedPointer<OrgMprisMediaPlayer2PlayerInterface> m_mediaPlayer2PlayerInterface;
0043 };
0044 
0045 #define PACKET_TYPE_MPRIS QStringLiteral("kdeconnect.mpris")
0046 
0047 class MprisControlPlugin : public KdeConnectPlugin
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052     explicit MprisControlPlugin(QObject *parent, const QVariantList &args);
0053 
0054     void receivePacket(const NetworkPacket &np) override;
0055 
0056 private Q_SLOTS:
0057     void propertiesChanged(const QString &propertyInterface, const QVariantMap &properties);
0058     void seeked(qlonglong);
0059 
0060 private:
0061     void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
0062     void addPlayer(const QString &serviceName);
0063     void removePlayer(const QString &serviceName);
0064     void sendPlayerList();
0065     void mprisPlayerMetadataToNetworkPacket(NetworkPacket &np, const QVariantMap &nowPlayingMap) const;
0066     bool sendAlbumArt(const NetworkPacket &np);
0067 
0068     QHash<QString, MprisPlayer> playerList;
0069     int prevVolume;
0070     QDBusServiceWatcher *m_watcher;
0071 };