File: mixer_mpris2.h

package info (click to toggle)
kmix 4%3A20.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,504 kB
  • sloc: cpp: 14,313; xml: 408; sh: 97; makefile: 7
file content (174 lines) | stat: -rw-r--r-- 4,416 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
 * KMix -- MPRIS2 backend
 *
 * Copyright (C) 2011 Christian Esken <esken@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#ifndef Mixer_MPRIS2_H
#define Mixer_MPRIS2_H

#include <QString>
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
#include <QMap>
#include <QMutex>
#include <QWaitCondition>
#include <QQueue>

#include "mixer_backend.h"

class MPrisControl : public QObject
{
  Q_OBJECT 

public:
  MPrisControl(QString id, QString busDestination);
  ~MPrisControl();

	enum DATA_ELEM
	{
		NONE = 0, NAME = 1, VOLUME = 2, ALL = 3
	};

  QDBusInterface* propertyIfc;
  QDBusInterface* playerIfc;

  
private:
	QString id;
	QString busDestination;
	QString name;
	int volume;

	int retrievedElems;

public:
	const QString& getId() const
	{
		return id;
	}

	const QString& getBusDestination() const
	{
		return busDestination;
	}

	const QString& getName() const
	{
		return name;
	}

	void setName(const QString& name)
	{
		retrievedElems |= MPrisControl::NAME;
		this->name = name;
	}

	int getVolume() const
	{
		return volume;
	}

	void setVolume(int volume)
	{
		retrievedElems |= MPrisControl::VOLUME;
		this->volume = volume;
	}

	bool isComplete()
	{
		return retrievedElems == MPrisControl::ALL;
	}



public slots:
  void trackChangedIncoming(QVariantMap msg);
  void onPropertyChange(QString,QVariantMap,QStringList);

signals:
  void volumeChanged(MPrisControl* mad, double);
  void playbackStateChanged(MPrisControl* mad, MediaController::PlayState);
};

class Mixer_MPRIS2 : public Mixer_Backend
{
  Q_OBJECT

//  friend class Mixer_MPRIS2_Thread;

public:
   Mixer_MPRIS2(Mixer *mixer, int device);
    virtual ~Mixer_MPRIS2();
    QString getDriverName() override;
    QString getId() const override { return _id; }

  int open() override;
  int close() override;
  int readVolumeFromHW( const QString& id, shared_ptr<MixDevice> ) override;
  int writeVolumeToHW( const QString& id, shared_ptr<MixDevice> ) override;
  void setEnumIdHW(const QString& id, unsigned int) override;
  unsigned int enumIdHW(const QString& id) override;
  bool needsPolling() override { return false; }

  int mediaPlay(QString id) override;
  int mediaPrev(QString id) override;
  int mediaNext(QString id) override;
  virtual int mediaControl(QString id, QString command);

  static MediaController::PlayState mprisPlayStateString2PlayState(const QString& playbackStatus);

public slots:
    void volumeChanged(MPrisControl *mad, double);
    void playbackStateChanged(MPrisControl* mad, MediaController::PlayState);

    void newMediaPlayer(QString name, QString oldOwner, QString newOwner);
    void addMprisControlAsync(QString arg1);
    void announceControlListAsync(QString streamId);

private slots:
    // asynchronous announce call slots
    void announceControlList();
    void announceGUI();
    void announceVolume();

    // Async QDBusPendingCallWatcher's
    void watcherMediaControl(QDBusPendingCallWatcher* watcher);
    void watcherPlugControlId(QDBusPendingCallWatcher* watcher);
    void watcherInitialVolume(QDBusPendingCallWatcher* watcher);
    void watcherInitialPlayState(QDBusPendingCallWatcher* watcher);
    void watcherDesktopFile(QDBusPendingCallWatcher* watcher);

private:
    // Helpers for the watchers
    MPrisControl* watcherHelperGetMPrisControl(QDBusPendingCallWatcher* watcher);


private:
//    void asyncAddMprisControl(QString busDestination);
//    void messageQueueThreadLoop();
    int addAllRunningPlayersAndInitHotplug();
    void volumeChangedInternal(shared_ptr<MixDevice> md, int volumePercentage);
	QString busDestinationToControlId(const QString& busDestination);

  QMap<QString,MPrisControl*> controls;
  QString _id;
};

#endif