mpriscontrolplugin-win.h 2.3 KB
Newer Older
Yuri Chornoivan's avatar
Yuri Chornoivan committed
1
/**
2
 * SPDX-FileCopyrightText: 2018 Jun Bo Bi <jambonmcyeah@gmail.com>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
3
 *
4
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
Yuri Chornoivan's avatar
Yuri Chornoivan committed
5
6
 */

7
8
9
10
11
#ifndef MPRISCONTROLPLUGINWIN_H
#define MPRISCONTROLPLUGINWIN_H

#include <core/kdeconnectplugin.h>

12
#include <variant>
13

14
15
16
17
18
#include <QHash>
#include <vector>

#include <winrt/Windows.Media.Control.h>
#include <winrt/Windows.Storage.Streams.h>
19
#include <winrt/Windows.Foundation.Collections.h>
20
#include <winrt/Windows.ApplicationModel.h>
21
22
23
24

using namespace winrt;
using namespace Windows::Media::Control;
using namespace Windows::Storage::Streams;
25
using namespace Windows::ApplicationModel;
26
27
28

#define PACKET_TYPE_MPRIS QStringLiteral("kdeconnect.mpris")

29
class Q_DECL_EXPORT MprisControlPlugin
30
31
32
33
34
35
36
37
38
39
40
    : public KdeConnectPlugin
{
    Q_OBJECT

  public:
    explicit MprisControlPlugin(QObject *parent, const QVariantList &args);

    bool receivePacket(const NetworkPacket &np) override;
    void connected() override {}

  private:
41
42
    std::optional<GlobalSystemMediaTransportControlsSessionManager> sessionManager;
    QHash<QString, GlobalSystemMediaTransportControlsSession> playerList;
43

44
45
46
47
48
49
50
51
52
53
54
55
56
    std::vector<GlobalSystemMediaTransportControlsSession::PlaybackInfoChanged_revoker> playbackInfoChangedHandlers;
    std::vector<GlobalSystemMediaTransportControlsSession::MediaPropertiesChanged_revoker> mediaPropertiesChangedHandlers;
    std::vector<GlobalSystemMediaTransportControlsSession::TimelinePropertiesChanged_revoker> timelinePropertiesChangedHandlers;

    std::optional<QString> getPlayerName(GlobalSystemMediaTransportControlsSession const& player);
    void sendMediaProperties(std::variant<NetworkPacket, QString> const& packetOrName, GlobalSystemMediaTransportControlsSession const& player);
    void sendPlaybackInfo(std::variant<NetworkPacket, QString> const& packetOrName, GlobalSystemMediaTransportControlsSession const& player);
    void sendTimelineProperties(std::variant<NetworkPacket, QString> const& packetOrName, GlobalSystemMediaTransportControlsSession const& player, bool lengthOnly = false);
    void updatePlayerList();
    void sendPlayerList();
    bool sendAlbumArt(std::variant<NetworkPacket, QString> const& packetOrName, GlobalSystemMediaTransportControlsSession const& player, QString artUrl);

    QString randomUrl();
57
};
Yuri Chornoivan's avatar
Yuri Chornoivan committed
58
#endif //MPRISCONTROLPLUGINWIN_H