Remove a lot of the old MPRIS code from the Player class, and fix a couple of MPRIS2 bugs
This commit is contained in:
parent
f9959a4fba
commit
fc15d66321
|
@ -118,7 +118,7 @@ void Mpris1Player::Stop() {
|
|||
}
|
||||
|
||||
void Mpris1Player::Prev() {
|
||||
player_->Prev();
|
||||
player_->Previous();
|
||||
}
|
||||
|
||||
void Mpris1Player::Play() {
|
||||
|
@ -130,7 +130,8 @@ void Mpris1Player::Next() {
|
|||
}
|
||||
|
||||
void Mpris1Player::Repeat(bool repeat) {
|
||||
player_->Repeat(repeat);
|
||||
player_->playlists()->sequence()->SetRepeatMode(
|
||||
repeat ? PlaylistSequence::Repeat_Track : PlaylistSequence::Repeat_Off);
|
||||
}
|
||||
|
||||
DBusStatus Mpris1Player::GetStatus() const {
|
||||
|
@ -165,7 +166,7 @@ void Mpris1Player::VolumeSet(int volume) {
|
|||
}
|
||||
|
||||
int Mpris1Player::VolumeGet() const {
|
||||
return player_->VolumeGet();
|
||||
return player_->GetVolume();
|
||||
}
|
||||
|
||||
void Mpris1Player::PositionSet(int pos) {
|
||||
|
@ -173,7 +174,7 @@ void Mpris1Player::PositionSet(int pos) {
|
|||
}
|
||||
|
||||
int Mpris1Player::PositionGet() const {
|
||||
return player_->PositionGet();
|
||||
return player_->engine()->position();
|
||||
}
|
||||
|
||||
QVariantMap Mpris1Player::GetMetadata() const {
|
||||
|
@ -192,7 +193,7 @@ int Mpris1Player::GetCaps() const {
|
|||
|
||||
if (current_item) {
|
||||
caps |= CAN_PROVIDE_METADATA;
|
||||
if (state == Engine::Playing && (!current_item->options() & PlaylistItem::PauseDisabled)) {
|
||||
if (state == Engine::Playing && !(current_item->options() & PlaylistItem::PauseDisabled)) {
|
||||
caps |= CAN_PAUSE;
|
||||
}
|
||||
if (state != Engine::Empty && current_item->Metadata().filetype() != Song::Type_Stream) {
|
||||
|
@ -211,12 +212,12 @@ int Mpris1Player::GetCaps() const {
|
|||
return caps;
|
||||
}
|
||||
|
||||
void Mpris1Player::VolumeUp(int vol) {
|
||||
player_->VolumeUp(vol);
|
||||
void Mpris1Player::VolumeUp(int change) {
|
||||
VolumeSet(VolumeGet() + change);
|
||||
}
|
||||
|
||||
void Mpris1Player::VolumeDown(int vol) {
|
||||
player_->VolumeDown(vol);
|
||||
void Mpris1Player::VolumeDown(int change) {
|
||||
VolumeSet(VolumeGet() - change);
|
||||
}
|
||||
|
||||
void Mpris1Player::Mute() {
|
||||
|
@ -228,15 +229,17 @@ void Mpris1Player::ShowOSD() {
|
|||
}
|
||||
|
||||
int Mpris1TrackList::AddTrack(const QString& track, bool play) {
|
||||
return player_->AddTrack(track, play);
|
||||
player_->playlists()->active()->InsertUrls(
|
||||
QList<QUrl>() << QUrl(track), play);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Mpris1TrackList::DelTrack(int index) {
|
||||
player_->DelTrack(index);
|
||||
player_->playlists()->active()->removeRows(index, 1);
|
||||
}
|
||||
|
||||
int Mpris1TrackList::GetCurrentTrack() const {
|
||||
return player_->GetCurrentTrack();
|
||||
return player_->playlists()->active()->current_index();
|
||||
}
|
||||
|
||||
int Mpris1TrackList::GetLength() const {
|
||||
|
@ -248,11 +251,13 @@ QVariantMap Mpris1TrackList::GetMetadata(int pos) const {
|
|||
}
|
||||
|
||||
void Mpris1TrackList::SetLoop(bool enable) {
|
||||
player_->SetLoop(enable);
|
||||
player_->playlists()->active()->sequence()->SetRepeatMode(
|
||||
enable ? PlaylistSequence::Repeat_Playlist : PlaylistSequence::Repeat_Off);
|
||||
}
|
||||
|
||||
void Mpris1TrackList::SetRandom(bool enable) {
|
||||
player_->SetRandom(enable);
|
||||
player_->playlists()->active()->sequence()->SetShuffleMode(
|
||||
enable ? PlaylistSequence::Shuffle_All : PlaylistSequence::Shuffle_Off);
|
||||
}
|
||||
|
||||
void Mpris1TrackList::PlayTrack(int index) {
|
||||
|
|
|
@ -82,6 +82,10 @@ public:
|
|||
|
||||
static QVariantMap GetMetadata(const Song& song);
|
||||
|
||||
Mpris1Root* root() const { return root_; }
|
||||
Mpris1Player* player() const { return player_; }
|
||||
Mpris1TrackList* tracklist() const { return tracklist_; }
|
||||
|
||||
private:
|
||||
Mpris1Root* root_;
|
||||
Mpris1Player* player_;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "core/mpris2_tracklist.h"
|
||||
#include "core/player.h"
|
||||
#include "engines/enginebase.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "playlist/playlistmanager.h"
|
||||
#include "playlist/playlistsequence.h"
|
||||
#include "ui/mainwindow.h"
|
||||
|
@ -42,10 +43,11 @@ const char* Mpris2::kServiceName = "org.mpris.MediaPlayer2.clementine";
|
|||
const char* Mpris2::kFreedesktopPath = "org.freedesktop.DBus.Properties";
|
||||
|
||||
Mpris2::Mpris2(MainWindow* main_window, Player* player, ArtLoader* art_loader,
|
||||
QObject* parent)
|
||||
Mpris1* mpris1, QObject* parent)
|
||||
: QObject(parent),
|
||||
ui_(main_window),
|
||||
player_(player)
|
||||
player_(player),
|
||||
mpris1_(mpris1)
|
||||
{
|
||||
new Mpris2Root(this);
|
||||
new Mpris2TrackList(this);
|
||||
|
@ -202,13 +204,17 @@ QString Mpris2::LoopStatus() const {
|
|||
}
|
||||
|
||||
void Mpris2::SetLoopStatus(const QString& value) {
|
||||
PlaylistSequence::RepeatMode mode = PlaylistSequence::Repeat_Off;
|
||||
|
||||
if (value == "None") {
|
||||
player_->SetLoop(PlaylistSequence::Repeat_Off);
|
||||
mode = PlaylistSequence::Repeat_Off;
|
||||
} else if (value == "Track") {
|
||||
player_->SetLoop(PlaylistSequence::Repeat_Track);
|
||||
mode = PlaylistSequence::Repeat_Track;
|
||||
} else if (value == "Playlist") {
|
||||
player_->SetLoop(PlaylistSequence::Repeat_Playlist);
|
||||
mode = PlaylistSequence::Repeat_Playlist;
|
||||
}
|
||||
|
||||
player_->playlists()->active()->sequence()->SetRepeatMode(mode);
|
||||
EmitNotification("LoopStatus", value);
|
||||
}
|
||||
|
||||
|
@ -226,7 +232,7 @@ bool Mpris2::Shuffle() const {
|
|||
}
|
||||
|
||||
void Mpris2::SetShuffle(bool value) {
|
||||
player_->SetRandom(value);
|
||||
mpris1_->tracklist()->SetRandom(value);
|
||||
EmitNotification("Shuffle", value);
|
||||
}
|
||||
|
||||
|
@ -234,14 +240,16 @@ QVariantMap Mpris2::Metadata() const {
|
|||
return last_metadata_;
|
||||
}
|
||||
|
||||
QString Mpris2::current_track_id() const {
|
||||
return QString("/org/mpris/MediaPlayer2/Track/%1").arg(
|
||||
QString::number(mpris1_->tracklist()->GetCurrentTrack()));
|
||||
}
|
||||
|
||||
void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) {
|
||||
last_metadata_ = QVariantMap();
|
||||
|
||||
QString track_id = QString("/org/mpris/MediaPlayer2/Track/%1").
|
||||
arg(QString::number(player_->GetCurrentTrack()));
|
||||
|
||||
using mpris::AddMetadata;
|
||||
AddMetadata("mpris:trackid", track_id, &last_metadata_);
|
||||
AddMetadata("mpris:trackid", current_track_id(), &last_metadata_);
|
||||
AddMetadata("xesam:url", song.filename(), &last_metadata_);
|
||||
AddMetadata("xesam:title", song.PrettyTitle(), &last_metadata_);
|
||||
AddMetadata("xesam:artist", QStringList() << song.artist(), &last_metadata_);
|
||||
|
@ -264,7 +272,7 @@ void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) {
|
|||
}
|
||||
|
||||
double Mpris2::Volume() const {
|
||||
return player_->VolumeGet() / 100;
|
||||
return double(player_->GetVolume()) / 100;
|
||||
}
|
||||
|
||||
void Mpris2::SetVolume(double value) {
|
||||
|
@ -273,7 +281,7 @@ void Mpris2::SetVolume(double value) {
|
|||
}
|
||||
|
||||
qlonglong Mpris2::Position() const {
|
||||
return player_->PositionGet() * 1e6;
|
||||
return mpris1_->player()->PositionGet() * 1e3;
|
||||
}
|
||||
|
||||
double Mpris2::MaximumRate() const {
|
||||
|
@ -285,23 +293,23 @@ double Mpris2::MinimumRate() const {
|
|||
}
|
||||
|
||||
bool Mpris2::CanGoNext() const {
|
||||
return true;
|
||||
return mpris1_->player()->GetCaps() & CAN_GO_NEXT;
|
||||
}
|
||||
|
||||
bool Mpris2::CanGoPrevious() const {
|
||||
return true;
|
||||
return mpris1_->player()->GetCaps() & CAN_GO_PREV;
|
||||
}
|
||||
|
||||
bool Mpris2::CanPlay() const {
|
||||
return true;
|
||||
return mpris1_->player()->GetCaps() & CAN_PLAY;
|
||||
}
|
||||
|
||||
bool Mpris2::CanPause() const {
|
||||
return true;
|
||||
return mpris1_->player()->GetCaps() & CAN_PAUSE;
|
||||
}
|
||||
|
||||
bool Mpris2::CanSeek() const {
|
||||
return true;
|
||||
return mpris1_->player()->GetCaps() & CAN_SEEK;
|
||||
}
|
||||
|
||||
bool Mpris2::CanControl() const {
|
||||
|
@ -310,50 +318,41 @@ bool Mpris2::CanControl() const {
|
|||
|
||||
void Mpris2::Next() {
|
||||
player_->Next();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::Previous() {
|
||||
player_->Previous();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::Pause() {
|
||||
player_->Pause();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::PlayPause() {
|
||||
player_->PlayPause();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::Stop() {
|
||||
player_->Stop();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::Play() {
|
||||
player_->Play();
|
||||
EmitNotification("PlaybackStatus",PlaybackStatus());
|
||||
EmitNotification("Metadata",Metadata());
|
||||
}
|
||||
|
||||
void Mpris2::Seek(qlonglong offset) {
|
||||
player_->Seek(offset*1e6);
|
||||
player_->Seek((Position() + offset) / 1e6);
|
||||
}
|
||||
|
||||
void Mpris2::SetPosition(const QDBusObjectPath& trackId, qlonglong offset) {
|
||||
//TODO
|
||||
if (trackId.path() != current_track_id())
|
||||
return;
|
||||
|
||||
player_->Seek(offset / 1e6);
|
||||
}
|
||||
|
||||
void Mpris2::OpenUri(const QString &uri) {
|
||||
player_->AddTrack(uri,true);
|
||||
void Mpris2::OpenUri(const QString& uri) {
|
||||
mpris1_->tracklist()->AddTrack(uri, true);
|
||||
}
|
||||
|
||||
TrackIds Mpris2::Tracks() const {
|
||||
|
|
|
@ -36,6 +36,7 @@ Q_DECLARE_METATYPE(TrackMetadata)
|
|||
namespace mpris {
|
||||
|
||||
class ArtLoader;
|
||||
class Mpris1;
|
||||
|
||||
class Mpris2 : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -71,7 +72,8 @@ class Mpris2 : public QObject {
|
|||
Q_PROPERTY( bool CanEditTracks READ CanEditTracks )
|
||||
|
||||
public:
|
||||
Mpris2(MainWindow* main_window, Player* player, ArtLoader* art_loader, QObject* parent);
|
||||
Mpris2(MainWindow* main_window, Player* player, ArtLoader* art_loader,
|
||||
Mpris1* mpris1, QObject* parent);
|
||||
|
||||
// Root Properties
|
||||
bool CanQuit() const;
|
||||
|
@ -147,6 +149,8 @@ private:
|
|||
void EmitNotification(const QString& name);
|
||||
void EmitNotification(const QString& name, const QVariant& val);
|
||||
|
||||
QString current_track_id() const;
|
||||
|
||||
private:
|
||||
static const char* kMprisObjectPath;
|
||||
static const char* kServiceName;
|
||||
|
@ -156,6 +160,7 @@ private:
|
|||
|
||||
MainWindow* ui_;
|
||||
Player* player_;
|
||||
Mpris1* mpris1_;
|
||||
};
|
||||
|
||||
} // namespace mpris
|
||||
|
|
|
@ -78,7 +78,7 @@ Player::Player(MainWindow* main_window, PlaylistManager* playlists,
|
|||
mpris1_ = new mpris::Mpris1(this, art_loader, this);
|
||||
|
||||
//MPRIS 2.0 implementation
|
||||
mpris2_ = new mpris::Mpris2(main_window, this, art_loader, this);
|
||||
mpris2_ = new mpris::Mpris2(main_window, this, art_loader, mpris1_, this);
|
||||
#endif
|
||||
|
||||
settings_.beginGroup("Player");
|
||||
|
@ -412,59 +412,11 @@ void Player::Play() {
|
|||
}
|
||||
}
|
||||
|
||||
void Player::Prev() {
|
||||
Previous();
|
||||
}
|
||||
|
||||
int Player::PositionGet() const {
|
||||
return engine_->position();
|
||||
}
|
||||
|
||||
void Player::Repeat(bool enable) {
|
||||
playlists_->sequence()->SetRepeatMode(
|
||||
enable ? PlaylistSequence::Repeat_Track : PlaylistSequence::Repeat_Off);
|
||||
}
|
||||
|
||||
void Player::ShowOSD() {
|
||||
if (current_item_)
|
||||
emit ForceShowOSD(current_item_->Metadata());
|
||||
}
|
||||
|
||||
void Player::VolumeDown(int change) {
|
||||
SetVolume(GetVolume() - change);
|
||||
}
|
||||
|
||||
void Player::VolumeUp(int change) {
|
||||
SetVolume(GetVolume() + change);
|
||||
}
|
||||
|
||||
int Player::VolumeGet() const {
|
||||
return GetVolume();
|
||||
}
|
||||
|
||||
int Player::AddTrack(const QString& track, bool play_now) {
|
||||
playlists_->active()->InsertUrls(QList<QUrl>() << QUrl(track), play_now);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Player::DelTrack(int index) {
|
||||
playlists_->active()->removeRows(index, 1);
|
||||
}
|
||||
|
||||
int Player::GetCurrentTrack() const {
|
||||
return playlists_->active()->current_index();
|
||||
}
|
||||
|
||||
void Player::SetLoop(bool enable) {
|
||||
playlists_->active()->sequence()->SetRepeatMode(
|
||||
enable ? PlaylistSequence::Repeat_Playlist : PlaylistSequence::Repeat_Off);
|
||||
}
|
||||
|
||||
void Player::SetRandom(bool enable) {
|
||||
playlists_->active()->sequence()->SetShuffleMode(
|
||||
enable ? PlaylistSequence::Shuffle_All : PlaylistSequence::Shuffle_Off);
|
||||
}
|
||||
|
||||
void Player::TrackAboutToEnd() {
|
||||
if (engine_->is_autocrossfade_enabled()) {
|
||||
// Crossfade is on, so just start playing the next track. The current one
|
||||
|
|
|
@ -79,6 +79,8 @@ class Player : public QObject {
|
|||
|
||||
void Previous();
|
||||
void SetVolume(int value);
|
||||
void VolumeUp() { SetVolume(GetVolume() + 5); }
|
||||
void VolumeDown() { SetVolume(GetVolume() + 5); }
|
||||
void Seek(int seconds);
|
||||
void SeekForward() { Seek(+5); }
|
||||
void SeekBackward() { Seek(-5); }
|
||||
|
@ -86,27 +88,11 @@ class Player : public QObject {
|
|||
void HandleSpecialLoad(const PlaylistItem::SpecialLoadResult& result);
|
||||
void CurrentMetadataChanged(const Song& metadata);
|
||||
|
||||
// MPRIS /Player
|
||||
void Mute();
|
||||
void Pause();
|
||||
void Stop();
|
||||
void Play();
|
||||
void Prev();
|
||||
int PositionGet() const;
|
||||
void Repeat(bool);
|
||||
void ShowOSD();
|
||||
void VolumeDown(int);
|
||||
void VolumeUp(int);
|
||||
void VolumeDown() { VolumeDown(4); }
|
||||
void VolumeUp() { VolumeUp(4); }
|
||||
int VolumeGet() const;
|
||||
|
||||
// MPRIS /Tracklist
|
||||
int AddTrack(const QString&, bool);
|
||||
void DelTrack(int index);
|
||||
int GetCurrentTrack() const;
|
||||
void SetLoop(bool enable);
|
||||
void SetRandom(bool enable);
|
||||
|
||||
signals:
|
||||
void Playing();
|
||||
|
|
|
@ -1404,7 +1404,7 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
|
|||
if (options.seek_to() != -1)
|
||||
player_->Seek(options.seek_to());
|
||||
else if (options.seek_by() != 0)
|
||||
player_->Seek(player_->PositionGet() / 1000 + options.seek_by());
|
||||
player_->Seek(player_->engine()->position() / 1000 + options.seek_by());
|
||||
|
||||
if (options.play_track_at() != -1)
|
||||
player_->PlayAt(options.play_track_at(), Engine::Manual, true);
|
||||
|
|
Loading…
Reference in New Issue