2011-01-08 16:31:14 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPRIS1_H
|
|
|
|
#define MPRIS1_H
|
|
|
|
|
|
|
|
#include "core/player.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDBusArgument>
|
|
|
|
#include <QObject>
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2011-01-08 16:31:14 +01:00
|
|
|
class Playlist;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
struct DBusStatus { // From Amarok.
|
2012-08-20 11:28:29 +02:00
|
|
|
DBusStatus()
|
2014-02-07 16:34:20 +01:00
|
|
|
: play(Mpris_Stopped), random(0), repeat(0), repeat_playlist(0) {}
|
|
|
|
|
|
|
|
int play; // Playing = 0, Paused = 1, Stopped = 2
|
|
|
|
int random; // Linearly = 0, Randomly = 1
|
|
|
|
int repeat; // Go_To_Next = 0, Repeat_Current = 1
|
|
|
|
int repeat_playlist; // Stop_When_Finished = 0, Never_Give_Up_Playing = 1,
|
|
|
|
// Never_Let_You_Down = 42
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
enum MprisPlayState {
|
|
|
|
Mpris_Playing = 0,
|
|
|
|
Mpris_Paused = 1,
|
|
|
|
Mpris_Stopped = 2,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(DBusStatus);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QDBusArgument& operator<<(QDBusArgument& arg, const DBusStatus& status);
|
|
|
|
const QDBusArgument& operator>>(const QDBusArgument& arg, DBusStatus& status);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
struct Version {
|
|
|
|
quint16 minor;
|
|
|
|
quint16 major;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(Version);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QDBusArgument& operator<<(QDBusArgument& arg, const Version& version);
|
|
|
|
const QDBusArgument& operator>>(const QDBusArgument& arg, Version& version);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
namespace mpris {
|
|
|
|
|
|
|
|
enum DBusCaps {
|
2014-02-07 16:34:20 +01:00
|
|
|
NONE = 0,
|
|
|
|
CAN_GO_NEXT = 1 << 0,
|
|
|
|
CAN_GO_PREV = 1 << 1,
|
|
|
|
CAN_PAUSE = 1 << 2,
|
|
|
|
CAN_PLAY = 1 << 3,
|
|
|
|
CAN_SEEK = 1 << 4,
|
2011-01-08 16:31:14 +01:00
|
|
|
CAN_PROVIDE_METADATA = 1 << 5,
|
2014-02-07 16:34:20 +01:00
|
|
|
CAN_HAS_TRACKLIST = 1 << 6,
|
2011-01-08 16:31:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Mpris1Root;
|
|
|
|
class Mpris1Player;
|
|
|
|
class Mpris1TrackList;
|
|
|
|
|
|
|
|
class Mpris1 : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
Mpris1(Application* app, QObject* parent = nullptr,
|
2011-02-13 19:37:21 +01:00
|
|
|
const QString& dbus_service_name = QString());
|
|
|
|
~Mpris1();
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
static QVariantMap GetMetadata(const Song& song);
|
|
|
|
|
|
|
|
Mpris1Root* root() const { return root_; }
|
|
|
|
Mpris1Player* player() const { return player_; }
|
|
|
|
Mpris1TrackList* tracklist() const { return tracklist_; }
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-02-13 19:37:21 +01:00
|
|
|
static const char* kDefaultDbusServiceName;
|
|
|
|
|
|
|
|
QString dbus_service_name_;
|
|
|
|
|
2011-01-08 16:31:14 +01:00
|
|
|
Mpris1Root* root_;
|
|
|
|
Mpris1Player* player_;
|
|
|
|
Mpris1TrackList* tracklist_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Mpris1Root : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
Mpris1Root(Application* app, QObject* parent = nullptr);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
QString Identity();
|
|
|
|
void Quit();
|
|
|
|
Version MprisVersion();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2011-01-08 16:31:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Mpris1Player : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
Mpris1Player(Application* app, QObject* parent = nullptr);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
void Pause();
|
|
|
|
void Stop();
|
|
|
|
void Prev();
|
|
|
|
void Play();
|
|
|
|
void Next();
|
|
|
|
void Repeat(bool);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// those methods will use engine's state obtained with player->GetState()
|
|
|
|
// method
|
2011-01-08 16:31:14 +01:00
|
|
|
DBusStatus GetStatus() const;
|
|
|
|
int GetCaps() const;
|
|
|
|
// those methods will use engine's state provided as an argument
|
|
|
|
DBusStatus GetStatus(Engine::State state) const;
|
|
|
|
int GetCaps(Engine::State state) const;
|
|
|
|
|
|
|
|
void VolumeSet(int volume);
|
|
|
|
int VolumeGet() const;
|
2011-02-13 19:34:30 +01:00
|
|
|
void PositionSet(int pos_msec);
|
2011-01-08 16:31:14 +01:00
|
|
|
int PositionGet() const;
|
|
|
|
QVariantMap GetMetadata() const;
|
|
|
|
|
|
|
|
// Amarok extensions
|
|
|
|
void VolumeUp(int vol);
|
|
|
|
void VolumeDown(int vol);
|
|
|
|
void Mute();
|
|
|
|
void ShowOSD();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
|
|
|
void CurrentSongChanged(const Song& song, const QString& art_uri,
|
|
|
|
const QImage&);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void CapsChange(int);
|
|
|
|
void TrackChange(const QVariantMap&);
|
|
|
|
void StatusChange(DBusStatus);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2011-01-08 16:31:14 +01:00
|
|
|
void PlaylistManagerInitialized();
|
|
|
|
|
|
|
|
void EngineStateChanged(Engine::State state);
|
|
|
|
void ShuffleModeChanged();
|
|
|
|
void RepeatModeChanged();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
QVariantMap last_metadata_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Mpris1TrackList : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
Mpris1TrackList(Application* app, QObject* parent = nullptr);
|
2011-01-08 16:31:14 +01:00
|
|
|
|
|
|
|
int AddTrack(const QString&, bool);
|
|
|
|
void DelTrack(int index);
|
|
|
|
int GetCurrentTrack() const;
|
|
|
|
int GetLength() const;
|
|
|
|
QVariantMap GetMetadata(int) const;
|
|
|
|
void SetLoop(bool enable);
|
|
|
|
void SetRandom(bool enable);
|
|
|
|
|
|
|
|
// Amarok extension
|
|
|
|
void PlayTrack(int index);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void TrackListChange(int i);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2011-01-08 16:31:14 +01:00
|
|
|
void PlaylistChanged(Playlist* playlist);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2011-01-08 16:31:14 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
} // namespace mpris
|
2011-01-08 16:31:14 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // MPRIS1_H
|