2010-11-21 16:13:26 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2010-12-04 23:27:58 +01:00
|
|
|
#include "mpris_common.h"
|
2011-01-08 16:31:14 +01:00
|
|
|
#include "mpris1.h"
|
2010-11-21 16:13:26 +01:00
|
|
|
#include "mpris2.h"
|
|
|
|
#include "core/mpris2_player.h"
|
|
|
|
#include "core/mpris2_root.h"
|
|
|
|
#include "core/mpris2_tracklist.h"
|
|
|
|
#include "core/player.h"
|
2011-04-02 15:34:06 +02:00
|
|
|
#include "covers/artloader.h"
|
2010-12-04 23:27:58 +01:00
|
|
|
#include "engines/enginebase.h"
|
2010-12-05 12:39:06 +01:00
|
|
|
#include "playlist/playlist.h"
|
2010-11-21 16:13:26 +01:00
|
|
|
#include "playlist/playlistmanager.h"
|
|
|
|
#include "playlist/playlistsequence.h"
|
|
|
|
#include "ui/mainwindow.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDBusConnection>
|
2011-01-08 16:31:14 +01:00
|
|
|
#include <QtConcurrentRun>
|
2010-11-21 16:13:26 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBINDICATE
|
|
|
|
# include <qindicateserver.h>
|
|
|
|
#endif
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
namespace mpris {
|
2010-11-21 16:13:26 +01:00
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
const char* Mpris2::kMprisObjectPath = "/org/mpris/MediaPlayer2";
|
|
|
|
const char* Mpris2::kServiceName = "org.mpris.MediaPlayer2.clementine";
|
|
|
|
const char* Mpris2::kFreedesktopPath = "org.freedesktop.DBus.Properties";
|
|
|
|
|
2011-02-13 19:36:29 +01:00
|
|
|
Mpris2::Mpris2(PlayerInterface* player, ArtLoader* art_loader,
|
2010-12-05 12:39:06 +01:00
|
|
|
Mpris1* mpris1, QObject* parent)
|
2010-11-21 16:13:26 +01:00
|
|
|
: QObject(parent),
|
2010-12-05 12:39:06 +01:00
|
|
|
player_(player),
|
|
|
|
mpris1_(mpris1)
|
2010-11-21 16:13:26 +01:00
|
|
|
{
|
|
|
|
new Mpris2Root(this);
|
|
|
|
new Mpris2TrackList(this);
|
|
|
|
new Mpris2Player(this);
|
|
|
|
|
2011-02-23 20:31:12 +01:00
|
|
|
if (!QDBusConnection::sessionBus().registerService(kServiceName)) {
|
|
|
|
qWarning() << "Failed to register" << QString(kServiceName) << "on the session bus";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
QDBusConnection::sessionBus().registerObject(kMprisObjectPath, this);
|
|
|
|
|
2011-02-19 19:24:11 +01:00
|
|
|
connect(art_loader, SIGNAL(ArtLoaded(Song,QString,QImage)), SLOT(ArtLoaded(Song,QString)));
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
connect(player->engine(), SIGNAL(StateChanged(Engine::State)), SLOT(EngineStateChanged(Engine::State)));
|
2010-12-04 23:27:58 +01:00
|
|
|
connect(player, SIGNAL(VolumeChanged(int)), SLOT(VolumeChanged()));
|
2011-01-06 22:08:11 +01:00
|
|
|
connect(player, SIGNAL(Seeked(qlonglong)), SIGNAL(Seeked(qlonglong)));
|
2010-12-13 00:20:41 +01:00
|
|
|
|
2011-01-08 16:31:14 +01:00
|
|
|
connect(player->playlists(), SIGNAL(PlaylistManagerInitialized()), SLOT(PlaylistManagerInitialized()));
|
|
|
|
connect(player->playlists(), SIGNAL(CurrentSongChanged(Song)), SLOT(CurrentSongChanged(Song)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mpris2::InitLibIndicate() {
|
|
|
|
#ifdef HAVE_LIBINDICATE
|
|
|
|
QIndicate::Server* indicate_server = QIndicate::Server::defaultInstance();
|
|
|
|
indicate_server->setType("music.clementine");
|
|
|
|
indicate_server->setDesktopFile(DesktopEntryAbsolutePath());
|
|
|
|
indicate_server->show();
|
|
|
|
#endif
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
// when PlaylistManager gets it ready, we connect PlaylistSequence with this
|
|
|
|
void Mpris2::PlaylistManagerInitialized() {
|
|
|
|
connect(player_->playlists()->sequence(), SIGNAL(ShuffleModeChanged(PlaylistSequence::ShuffleMode)),
|
|
|
|
SLOT(ShuffleModeChanged()));
|
|
|
|
connect(player_->playlists()->sequence(), SIGNAL(RepeatModeChanged(PlaylistSequence::RepeatMode)),
|
|
|
|
SLOT(RepeatModeChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mpris2::EngineStateChanged(Engine::State newState) {
|
|
|
|
if(newState != Engine::Playing && newState != Engine::Paused) {
|
|
|
|
last_metadata_= QVariantMap();
|
|
|
|
EmitNotification("Metadata");
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitNotification("PlaybackStatus", PlaybackStatus(newState));
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mpris2::VolumeChanged() {
|
|
|
|
EmitNotification("Volume");
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
void Mpris2::ShuffleModeChanged() {
|
|
|
|
EmitNotification("Shuffle");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mpris2::RepeatModeChanged() {
|
|
|
|
EmitNotification("LoopStatus");
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::EmitNotification(const QString& name, const QVariant& val) {
|
2010-11-21 16:13:26 +01:00
|
|
|
QDBusMessage msg = QDBusMessage::createSignal(
|
|
|
|
kMprisObjectPath, kFreedesktopPath, "PropertiesChanged");
|
|
|
|
QVariantMap map;
|
|
|
|
map.insert(name, val);
|
|
|
|
QVariantList args = QVariantList()
|
|
|
|
<< "org.mpris.MediaPlayer2.Player"
|
|
|
|
<< map
|
|
|
|
<< QStringList();
|
|
|
|
msg.setArguments(args);
|
|
|
|
QDBusConnection::sessionBus().send(msg);
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::EmitNotification(const QString& name) {
|
2010-11-21 16:13:26 +01:00
|
|
|
QVariant value;
|
|
|
|
if (name == "PlaybackStatus") value = PlaybackStatus();
|
|
|
|
else if (name == "LoopStatus") value = LoopStatus();
|
|
|
|
else if (name == "Shuffle") value = Shuffle();
|
|
|
|
else if (name == "Metadata") value = Metadata();
|
|
|
|
else if (name == "Volume") value = Volume();
|
|
|
|
else if (name == "Position") value = Position();
|
|
|
|
|
|
|
|
if (value.isValid())
|
2010-12-04 23:27:58 +01:00
|
|
|
EmitNotification(name, value);
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------Root Interface--------------------------//
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanQuit() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanRaise() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::HasTrackList() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QString Mpris2::Identity() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return QString("%1 %2").arg(
|
|
|
|
QCoreApplication::applicationName(),
|
|
|
|
QCoreApplication::applicationVersion());
|
|
|
|
}
|
|
|
|
|
2011-01-06 20:29:54 +01:00
|
|
|
QString Mpris2::DesktopEntryAbsolutePath() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
QStringList xdg_data_dirs = QString(getenv("XDG_DATA_DIRS")).split(":");
|
|
|
|
xdg_data_dirs.append("/usr/local/share/");
|
|
|
|
xdg_data_dirs.append("/usr/share/");
|
|
|
|
|
|
|
|
foreach (const QString& directory, xdg_data_dirs) {
|
|
|
|
QString path = QString("%1/applications/%2.desktop").
|
|
|
|
arg(directory, QApplication::applicationName().toLower());
|
|
|
|
if (QFile::exists(path))
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2011-01-06 20:29:54 +01:00
|
|
|
QString Mpris2::DesktopEntry() const {
|
|
|
|
return QApplication::applicationName().toLower();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QStringList Mpris2::SupportedUriSchemes() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
static QStringList res = QStringList()
|
|
|
|
<< "file"
|
|
|
|
<< "http"
|
|
|
|
<< "cdda"
|
|
|
|
<< "smb"
|
|
|
|
<< "sftp";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QStringList Mpris2::SupportedMimeTypes() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
static QStringList res = QStringList()
|
|
|
|
<< "application/ogg"
|
|
|
|
<< "application/x-ogg"
|
|
|
|
<< "application/x-ogm-audio"
|
|
|
|
<< "audio/aac"
|
|
|
|
<< "audio/mp4"
|
|
|
|
<< "audio/mpeg"
|
|
|
|
<< "audio/mpegurl"
|
|
|
|
<< "audio/ogg"
|
|
|
|
<< "audio/vnd.rn-realaudio"
|
|
|
|
<< "audio/vorbis"
|
|
|
|
<< "audio/x-flac"
|
|
|
|
<< "audio/x-mp3"
|
|
|
|
<< "audio/x-mpeg"
|
|
|
|
<< "audio/x-mpegurl"
|
|
|
|
<< "audio/x-ms-wma"
|
|
|
|
<< "audio/x-musepack"
|
|
|
|
<< "audio/x-oggflac"
|
|
|
|
<< "audio/x-pn-realaudio"
|
|
|
|
<< "audio/x-scpls"
|
|
|
|
<< "audio/x-speex"
|
|
|
|
<< "audio/x-vorbis"
|
|
|
|
<< "audio/x-vorbis+ogg"
|
|
|
|
<< "audio/x-wav"
|
|
|
|
<< "video/x-ms-asf"
|
|
|
|
<< "x-content/audio-player";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Raise() {
|
2011-01-04 12:33:22 +01:00
|
|
|
emit RaiseMainWindow();
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Quit() {
|
2010-11-21 16:13:26 +01:00
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QString Mpris2::PlaybackStatus() const {
|
2010-12-13 00:20:41 +01:00
|
|
|
return PlaybackStatus(player_->GetState());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Mpris2::PlaybackStatus(Engine::State state) const {
|
|
|
|
switch (state) {
|
2010-11-21 16:13:26 +01:00
|
|
|
case Engine::Playing: return "Playing";
|
|
|
|
case Engine::Paused: return "Paused";
|
|
|
|
default: return "Stopped";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QString Mpris2::LoopStatus() const {
|
|
|
|
switch (player_->playlists()->sequence()->repeat_mode()) {
|
2010-11-21 16:13:26 +01:00
|
|
|
case PlaylistSequence::Repeat_Album:
|
|
|
|
case PlaylistSequence::Repeat_Playlist: return "Playlist";
|
|
|
|
case PlaylistSequence::Repeat_Track: return "Track";
|
|
|
|
default: return "None";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::SetLoopStatus(const QString& value) {
|
2010-12-05 12:39:06 +01:00
|
|
|
PlaylistSequence::RepeatMode mode = PlaylistSequence::Repeat_Off;
|
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
if (value == "None") {
|
2010-12-05 12:39:06 +01:00
|
|
|
mode = PlaylistSequence::Repeat_Off;
|
2010-11-21 16:13:26 +01:00
|
|
|
} else if (value == "Track") {
|
2010-12-05 12:39:06 +01:00
|
|
|
mode = PlaylistSequence::Repeat_Track;
|
2010-11-21 16:13:26 +01:00
|
|
|
} else if (value == "Playlist") {
|
2010-12-05 12:39:06 +01:00
|
|
|
mode = PlaylistSequence::Repeat_Playlist;
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
2010-12-05 12:39:06 +01:00
|
|
|
|
|
|
|
player_->playlists()->active()->sequence()->SetRepeatMode(mode);
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
double Mpris2::Rate() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
void Mpris2::SetRate(double rate) {
|
|
|
|
if(rate == 0) {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
mpris1_->player()->Pause();
|
|
|
|
}
|
2010-12-13 00:20:41 +01:00
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::Shuffle() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
return mpris1_->player()->GetStatus().random;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::SetShuffle(bool value) {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->tracklist()) {
|
|
|
|
mpris1_->tracklist()->SetRandom(value);
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
QVariantMap Mpris2::Metadata() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return last_metadata_;
|
|
|
|
}
|
|
|
|
|
2010-12-05 12:39:06 +01:00
|
|
|
QString Mpris2::current_track_id() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (!mpris1_->tracklist()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2010-12-05 12:39:06 +01:00
|
|
|
return QString("/org/mpris/MediaPlayer2/Track/%1").arg(
|
|
|
|
QString::number(mpris1_->tracklist()->GetCurrentTrack()));
|
|
|
|
}
|
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
// We send Metadata change notification as soon as the process of
|
|
|
|
// changing song starts...
|
|
|
|
void Mpris2::CurrentSongChanged(const Song& song) {
|
|
|
|
ArtLoaded(song, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ... and we add the cover information later, when it's available.
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) {
|
2010-11-21 16:13:26 +01:00
|
|
|
last_metadata_ = QVariantMap();
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
using mpris::AddMetadata;
|
2010-12-05 12:39:06 +01:00
|
|
|
AddMetadata("mpris:trackid", current_track_id(), &last_metadata_);
|
2010-12-04 23:27:58 +01:00
|
|
|
AddMetadata("xesam:url", song.filename(), &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
AddMetadata("xesam:title", song.PrettyTitle(), &last_metadata_);
|
2010-12-13 00:20:41 +01:00
|
|
|
AddMetadataAsList("xesam:artist", song.artist(), &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
AddMetadata("xesam:album", song.album(), &last_metadata_);
|
2010-12-13 00:20:41 +01:00
|
|
|
AddMetadataAsList("xesam:albumArtist", song.albumartist(), &last_metadata_);
|
2011-02-14 20:34:37 +01:00
|
|
|
AddMetadata("mpris:length", song.length_nanosec() / kNsecPerUsec, &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
AddMetadata("xesam:trackNumber", song.track(), &last_metadata_);
|
2010-12-13 00:20:41 +01:00
|
|
|
AddMetadataAsList("xesam:genre", song.genre(), &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
AddMetadata("xesam:discNumber", song.disc(), &last_metadata_);
|
2010-12-13 00:20:41 +01:00
|
|
|
AddMetadataAsList("xesam:comment", song.comment(), &last_metadata_);
|
|
|
|
AddMetadata("xesam:contentCreated", AsMPRISDateTimeType(song.ctime()), &last_metadata_);
|
|
|
|
AddMetadata("xesam:lastUsed", AsMPRISDateTimeType(song.lastplayed()), &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
AddMetadata("xesam:audioBPM", song.bpm(), &last_metadata_);
|
2010-12-13 00:20:41 +01:00
|
|
|
AddMetadataAsList("xesam:composer", song.composer(), &last_metadata_);
|
|
|
|
AddMetadata("xesam:useCount", song.playcount(), &last_metadata_);
|
|
|
|
AddMetadata("xesam:autoRating", song.score(), &last_metadata_);
|
|
|
|
if (song.rating() != -1.0) {
|
|
|
|
AddMetadata("rating", song.rating() * 5, &last_metadata_);
|
|
|
|
}
|
2010-12-04 23:27:58 +01:00
|
|
|
if (!art_uri.isEmpty()) {
|
|
|
|
AddMetadata("mpris:artUrl", art_uri, &last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
EmitNotification("Metadata", last_metadata_);
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
double Mpris2::Volume() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
return double(mpris1_->player()->VolumeGet()) / 100;
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::SetVolume(double value) {
|
2010-11-21 16:13:26 +01:00
|
|
|
player_->SetVolume(value * 100);
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
qlonglong Mpris2::Position() const {
|
2011-02-14 20:34:37 +01:00
|
|
|
return player_->engine()->position_nanosec() / kNsecPerUsec;
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
double Mpris2::MaximumRate() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
double Mpris2::MinimumRate() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanGoNext() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
return mpris1_->player()->GetCaps() & CAN_GO_NEXT;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanGoPrevious() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
return mpris1_->player()->GetCaps() & CAN_GO_PREV;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanPlay() const {
|
2010-12-05 12:39:06 +01:00
|
|
|
return mpris1_->player()->GetCaps() & CAN_PLAY;
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-13 00:20:41 +01:00
|
|
|
// This one's a bit different than MPRIS 1 - we want this to be true even when
|
2011-02-23 20:31:12 +01:00
|
|
|
// the song is already paused or stopped.
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanPause() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
2011-02-23 20:31:12 +01:00
|
|
|
return mpris1_->player()->GetCaps() & CAN_PAUSE
|
|
|
|
|| PlaybackStatus() == "Paused"
|
|
|
|
|| PlaybackStatus() == "Stopped";
|
2011-02-19 19:24:05 +01:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanSeek() const {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->player()) {
|
|
|
|
return mpris1_->player()->GetCaps() & CAN_SEEK;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanControl() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Next() {
|
2010-12-15 16:50:22 +01:00
|
|
|
if(CanGoNext()) {
|
|
|
|
player_->Next();
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Previous() {
|
2010-12-15 16:50:22 +01:00
|
|
|
if(CanGoPrevious()) {
|
|
|
|
player_->Previous();
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Pause() {
|
2010-12-15 16:50:22 +01:00
|
|
|
if(CanPause() && player_->GetState() != Engine::Paused) {
|
|
|
|
player_->Pause();
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::PlayPause() {
|
2011-02-23 20:31:12 +01:00
|
|
|
if (CanPause()) {
|
|
|
|
player_->PlayPause();
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Stop() {
|
2010-11-21 16:13:26 +01:00
|
|
|
player_->Stop();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Play() {
|
2010-12-15 16:50:22 +01:00
|
|
|
if(CanPlay()) {
|
|
|
|
player_->Play();
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::Seek(qlonglong offset) {
|
2010-12-15 16:50:22 +01:00
|
|
|
if(CanSeek()) {
|
2011-02-14 20:34:37 +01:00
|
|
|
player_->SeekTo(player_->engine()->position_nanosec() / kNsecPerSec +
|
|
|
|
offset / kUsecPerSec);
|
2010-12-15 16:50:22 +01:00
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::SetPosition(const QDBusObjectPath& trackId, qlonglong offset) {
|
2010-12-15 16:50:22 +01:00
|
|
|
if (CanSeek() && trackId.path() == current_track_id() && offset >= 0) {
|
2011-02-14 20:34:37 +01:00
|
|
|
offset *= kNsecPerUsec;
|
2010-12-05 12:39:06 +01:00
|
|
|
|
2011-02-13 19:34:30 +01:00
|
|
|
if(offset < player_->GetCurrentItem()->Metadata().length_nanosec()) {
|
2011-02-14 20:34:37 +01:00
|
|
|
player_->SeekTo(offset / kNsecPerSec);
|
2010-12-15 16:50:22 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-05 12:39:06 +01:00
|
|
|
void Mpris2::OpenUri(const QString& uri) {
|
2011-02-19 19:24:05 +01:00
|
|
|
if (mpris1_->tracklist()) {
|
|
|
|
mpris1_->tracklist()->AddTrack(uri, true);
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
TrackIds Mpris2::Tracks() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
//TODO
|
|
|
|
return TrackIds();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
bool Mpris2::CanEditTracks() const {
|
2010-11-21 16:13:26 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
TrackMetadata Mpris2::GetTracksMetadata(const TrackIds &tracks) const {
|
2010-11-21 16:13:26 +01:00
|
|
|
//TODO
|
|
|
|
return TrackMetadata();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::AddTrack(const QString &uri, const QDBusObjectPath &afterTrack, bool setAsCurrent) {
|
2010-11-21 16:13:26 +01:00
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::RemoveTrack(const QDBusObjectPath &trackId) {
|
2010-11-21 16:13:26 +01:00
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
void Mpris2::GoTo(const QDBusObjectPath &trackId) {
|
2010-11-21 16:13:26 +01:00
|
|
|
//TODO
|
|
|
|
}
|
2010-12-04 23:27:58 +01:00
|
|
|
|
|
|
|
} // namespace mpris
|