summaryrefslogtreecommitdiff
path: root/src/mpris2
diff options
context:
space:
mode:
authorMateusz Łukasik <mati75@linuxmint.pl>2015-04-26 20:41:29 +0200
committerMateusz Łukasik <mati75@linuxmint.pl>2015-04-26 20:41:29 +0200
commit6027a8ff2d6ae4eba912427c30c58208009c1ebc (patch)
tree756eddd2fc9e7a9943b43e6ff3f9e92cbd4c3352 /src/mpris2
parent45ee5ac6dc2159352596ce8e8ec744e0c864d492 (diff)
Imported Upstream version 14.9.0.6887~ds0
Diffstat (limited to 'src/mpris2')
-rw-r--r--src/mpris2/mediaplayer2.cpp126
-rw-r--r--src/mpris2/mediaplayer2.h96
-rw-r--r--src/mpris2/mediaplayer2player.cpp292
-rw-r--r--src/mpris2/mediaplayer2player.h123
-rw-r--r--src/mpris2/mpris2.cpp95
-rw-r--r--src/mpris2/mpris2.h60
6 files changed, 792 insertions, 0 deletions
diff --git a/src/mpris2/mediaplayer2.cpp b/src/mpris2/mediaplayer2.cpp
new file mode 100644
index 0000000..dd6c02d
--- /dev/null
+++ b/src/mpris2/mediaplayer2.cpp
@@ -0,0 +1,126 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ * Copyright 2012 Bernd Buschinski <b.buschinski@googlemail.com>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#include "mediaplayer2.h"
+#include "mpris2.h"
+#include "basegui.h"
+#include <QApplication>
+
+
+MediaPlayer2::MediaPlayer2(BaseGui* gui, QObject* parent)
+ : QDBusAbstractAdaptor(parent),
+ m_gui(gui)
+{
+// connect(m_gui, SIGNAL(fullScreen(bool)), this, SLOT(emitFullscreenChange(bool)));
+}
+
+MediaPlayer2::~MediaPlayer2()
+{
+}
+
+bool MediaPlayer2::CanQuit() const
+{
+ return true;
+}
+
+void MediaPlayer2::Quit() const
+{
+ m_gui->runActions("close");
+}
+
+bool MediaPlayer2::CanRaise() const
+{
+ return true;
+}
+
+void MediaPlayer2::Raise() const
+{
+ m_gui->raise();
+}
+
+bool MediaPlayer2::Fullscreen() const
+{
+ return m_gui->isFullScreen();
+}
+
+void MediaPlayer2::setFullscreen(bool fullscreen) const
+{
+ m_gui->toggleFullscreen(fullscreen);
+}
+
+void MediaPlayer2::emitFullscreenChange(bool fullscreen) const
+{
+ QVariantMap properties;
+ properties["Fullscreen"] = fullscreen;
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+bool MediaPlayer2::CanSetFullscreen() const
+{
+ return true;
+}
+
+bool MediaPlayer2::HasTrackList() const
+{
+ return false;
+}
+
+QString MediaPlayer2::Identity() const
+{
+ return QString("SMPlayer");
+}
+
+QString MediaPlayer2::DesktopEntry() const
+{
+ return QString("smplayer");
+}
+
+QStringList MediaPlayer2::SupportedUriSchemes() const
+{
+ //TODO: Implement me
+ return QStringList();
+}
+
+QStringList MediaPlayer2::SupportedMimeTypes() const
+{
+ //TODO: Implement me
+ return QStringList();
+}
+
+#include "moc_mediaplayer2.cpp"
diff --git a/src/mpris2/mediaplayer2.h b/src/mpris2/mediaplayer2.h
new file mode 100644
index 0000000..4f784bf
--- /dev/null
+++ b/src/mpris2/mediaplayer2.h
@@ -0,0 +1,96 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#ifndef MEDIAPLAYER2_H
+#define MEDIAPLAYER2_H
+
+#include <QDBusAbstractAdaptor>
+#include <QStringList>
+
+class BaseGui;
+
+class MediaPlayer2 : public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2") // Docs: http://www.mpris.org/2.1/spec/Root_Node.html
+
+ Q_PROPERTY(bool CanQuit READ CanQuit)
+ Q_PROPERTY(bool CanRaise READ CanRaise)
+
+ Q_PROPERTY(bool Fullscreen READ Fullscreen WRITE setFullscreen)
+ Q_PROPERTY(bool CanSetFullscreen READ CanSetFullscreen)
+
+ Q_PROPERTY(bool HasTrackList READ HasTrackList)
+
+ Q_PROPERTY(QString Identity READ Identity)
+ Q_PROPERTY(QString DesktopEntry READ DesktopEntry)
+
+ Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes)
+ Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes)
+
+ public:
+ explicit MediaPlayer2(BaseGui* gui, QObject* parent);
+ ~MediaPlayer2();
+
+ bool CanQuit() const;
+ bool CanRaise() const;
+
+ bool Fullscreen() const;
+ void setFullscreen(bool fullscreen) const;
+ bool CanSetFullscreen() const;
+
+ bool HasTrackList() const;
+
+ QString Identity() const;
+ QString DesktopEntry() const;
+
+ QStringList SupportedUriSchemes() const;
+ QStringList SupportedMimeTypes() const;
+
+ public slots:
+ void Raise() const;
+ void Quit() const;
+
+ private slots:
+ void emitFullscreenChange(bool fullscreen) const;
+ private:
+ BaseGui* m_gui;
+};
+
+#endif
diff --git a/src/mpris2/mediaplayer2player.cpp b/src/mpris2/mediaplayer2player.cpp
new file mode 100644
index 0000000..b38b18d
--- /dev/null
+++ b/src/mpris2/mediaplayer2player.cpp
@@ -0,0 +1,292 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ * Copyright 2012 Bernd Buschinski <b.buschinski@googlemail.com>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#include "mediaplayer2player.h"
+#include "mpris2.h"
+#include "basegui.h"
+#include "core.h"
+#include "playlist.h"
+
+#include <QCryptographicHash>
+
+static QByteArray makeTrackId(const QString& source)
+{
+ return QByteArray("/org/smplayer/") + "smplayer" + "/tid_" +
+ QCryptographicHash::hash(source.toLocal8Bit(), QCryptographicHash::Sha1)
+ .toHex();
+}
+
+MediaPlayer2Player::MediaPlayer2Player(BaseGui * gui, QObject* parent)
+ : QDBusAbstractAdaptor(parent),
+ m_core(gui->getCore()),
+ m_playlist(gui->getPlaylist())
+{
+// connect(m_core, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
+// connect(m_core, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
+ connect(m_core, SIGNAL(mediaPlaying(QString,QString)), this, SLOT(currentSourceChanged()));
+ connect(m_core, SIGNAL(stateChanged(Core::State)), this, SLOT(stateUpdated()));
+ connect(m_core, SIGNAL(mediaInfoChanged()), this, SLOT(emitMetadataChange()));
+ connect(m_core, SIGNAL(volumeChanged(int)), this, SLOT(volumeChanged()));
+}
+
+MediaPlayer2Player::~MediaPlayer2Player()
+{
+}
+
+bool MediaPlayer2Player::CanGoNext() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::Next() const
+{
+ m_playlist->playNext();
+}
+
+bool MediaPlayer2Player::CanGoPrevious() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::Previous() const
+{
+ m_playlist->playPrev();
+}
+
+bool MediaPlayer2Player::CanPause() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::Pause() const
+{
+ m_core->pause();
+}
+
+void MediaPlayer2Player::PlayPause() const
+{
+ m_core->play_or_pause();
+}
+
+void MediaPlayer2Player::Stop() const
+{
+ m_core->stop();
+}
+
+bool MediaPlayer2Player::CanPlay() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::Play() const
+{
+ m_core->play();
+}
+
+void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const
+{
+ if (TrackId.path().toLocal8Bit() == makeTrackId(m_core->mdat.filename))
+ m_core->seek(static_cast<int>(Position / 1000000));
+}
+
+void MediaPlayer2Player::OpenUri(QString uri) const
+{
+ m_core->open(uri);
+}
+
+QString MediaPlayer2Player::PlaybackStatus() const
+{
+ return m_core->stateToString();
+}
+
+QString MediaPlayer2Player::LoopStatus() const
+{
+ return "None";
+}
+
+void MediaPlayer2Player::setLoopStatus(const QString& loopStatus) const
+{
+ Q_UNUSED(loopStatus)
+}
+
+double MediaPlayer2Player::Rate() const
+{
+ return m_core->mset.speed;
+}
+
+void MediaPlayer2Player::setRate(double rate) const
+{
+ m_core->setSpeed(rate);
+}
+
+bool MediaPlayer2Player::Shuffle() const
+{
+ return false;
+}
+
+void MediaPlayer2Player::setShuffle(bool shuffle) const
+{
+ Q_UNUSED(shuffle)
+}
+
+QVariantMap MediaPlayer2Player::Metadata() const
+{
+ QVariantMap metaData;
+
+ if (!m_core->mdat.initialized)
+ return metaData;
+
+ metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(makeTrackId(m_core->mdat.filename).constData()));
+ metaData["mpris:length"] = m_core->mdat.duration * 1000000;
+
+ if (m_core->mdat.type == TYPE_STREAM)
+ metaData["xesam:url"] = m_core->mdat.stream_url;
+ else
+ metaData["xesam:url"] = m_core->mdat.filename;
+
+ if (!m_core->mdat.clip_album.isEmpty())
+ metaData["xesam:album"] = m_core->mdat.clip_album;
+ if (!m_core->mdat.clip_name.isEmpty())
+ metaData["xesam:title"] = m_core->mdat.clip_name;
+ else if (!m_core->mdat.filename.isEmpty()) {
+ QFileInfo fileInfo(m_core->mdat.filename);
+ metaData["xesam:title"] = fileInfo.fileName();
+ }
+ if (!m_core->mdat.clip_artist.isEmpty())
+ metaData["xesam:artist"] = m_core->mdat.clip_artist;
+ if (!m_core->mdat.clip_genre.isEmpty())
+ metaData["xesam:genre"] = m_core->mdat.clip_genre;
+
+ return metaData;
+}
+
+double MediaPlayer2Player::Volume() const
+{
+ return static_cast<double>(m_core->mset.volume / 100.0);
+}
+
+void MediaPlayer2Player::setVolume(double volume) const
+{
+ m_core->setVolume(static_cast<int>(volume*100));
+}
+
+qlonglong MediaPlayer2Player::Position() const
+{
+ return static_cast<qlonglong>(m_core->mset.current_sec * 1000000);
+}
+
+double MediaPlayer2Player::MinimumRate() const
+{
+ return 0.01;
+}
+
+double MediaPlayer2Player::MaximumRate() const
+{
+ return 100.0;
+}
+
+bool MediaPlayer2Player::CanSeek() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::Seek(qlonglong Offset) const
+{
+ m_core->seek(static_cast<int>(Offset/1000000));
+}
+
+bool MediaPlayer2Player::CanControl() const
+{
+ return true;
+}
+
+void MediaPlayer2Player::tick(qint64 newPos)
+{
+// if (newPos - oldPos > tickInterval + 250 || newPos < oldPos)
+// emit Seeked(newPos * 1000);
+
+ oldPos = newPos;
+}
+
+void MediaPlayer2Player::emitMetadataChange() const
+{
+ QVariantMap properties;
+ properties["Metadata"] = Metadata();
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+void MediaPlayer2Player::currentSourceChanged() const
+{
+ QVariantMap properties;
+ properties["Metadata"] = Metadata();
+ properties["CanSeek"] = CanSeek();
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+void MediaPlayer2Player::stateUpdated() const
+{
+ QVariantMap properties;
+ properties["PlaybackStatus"] = PlaybackStatus();
+ properties["CanPause"] = CanPause();
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+void MediaPlayer2Player::totalTimeChanged() const
+{
+ QVariantMap properties;
+ properties["Metadata"] = Metadata();
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+void MediaPlayer2Player::seekableChanged(bool seekable) const
+{
+ QVariantMap properties;
+ properties["CanSeek"] = seekable;
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+void MediaPlayer2Player::volumeChanged() const
+{
+ QVariantMap properties;
+ properties["Volume"] = Volume();
+ Mpris2::signalPropertiesChange(this, properties);
+}
+
+#include "moc_mediaplayer2player.cpp"
diff --git a/src/mpris2/mediaplayer2player.h b/src/mpris2/mediaplayer2player.h
new file mode 100644
index 0000000..1b205b1
--- /dev/null
+++ b/src/mpris2/mediaplayer2player.h
@@ -0,0 +1,123 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#ifndef MEDIAPLAYER2PLAYER_H
+#define MEDIAPLAYER2PLAYER_H
+
+#include <QDBusAbstractAdaptor>
+#include <QDBusObjectPath>
+
+class BaseGui;
+class Core;
+class Playlist;
+
+class MediaPlayer2Player : public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") // Docs: http://www.mpris.org/2.1/spec/Player_Node.html
+
+ Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
+ Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE setLoopStatus)
+ Q_PROPERTY(double Rate READ Rate WRITE setRate)
+ Q_PROPERTY(bool Shuffle READ Shuffle WRITE setShuffle)
+ Q_PROPERTY(QVariantMap Metadata READ Metadata)
+ Q_PROPERTY(double Volume READ Volume WRITE setVolume)
+ Q_PROPERTY(qlonglong Position READ Position)
+ Q_PROPERTY(double MinimumRate READ MinimumRate)
+ Q_PROPERTY(double MaximumRate READ MaximumRate)
+ Q_PROPERTY(bool CanGoNext READ CanGoNext)
+ Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
+ Q_PROPERTY(bool CanPlay READ CanPlay)
+ Q_PROPERTY(bool CanPause READ CanPause)
+ Q_PROPERTY(bool CanSeek READ CanSeek)
+ Q_PROPERTY(bool CanControl READ CanControl)
+
+ public:
+ explicit MediaPlayer2Player(BaseGui * gui, QObject* parent);
+ ~MediaPlayer2Player();
+
+ QString PlaybackStatus() const;
+ QString LoopStatus() const;
+ void setLoopStatus(const QString& loopStatus) const;
+ double Rate() const;
+ void setRate(double rate) const;
+ bool Shuffle() const;
+ void setShuffle(bool shuffle) const;
+ QVariantMap Metadata() const;
+ double Volume() const;
+ void setVolume(double volume) const;
+ qlonglong Position() const;
+ double MinimumRate() const;
+ double MaximumRate() const;
+ bool CanGoNext() const;
+ bool CanGoPrevious() const;
+ bool CanPlay() const;
+ bool CanPause() const;
+ bool CanSeek() const;
+ bool CanControl() const;
+
+ signals:
+ void Seeked(qlonglong Position) const;
+
+ public slots:
+ void Next() const;
+ void Previous() const;
+ void Pause() const;
+ void PlayPause() const;
+ void Stop() const;
+ void Play() const;
+ void Seek(qlonglong Offset) const;
+ void SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const;
+ void OpenUri(QString uri) const;
+
+ private slots:
+ void tick(qint64 newPos);
+ void emitMetadataChange() const;
+ void currentSourceChanged() const;
+ void stateUpdated() const;
+ void totalTimeChanged() const;
+ void seekableChanged(bool seekable) const;
+ void volumeChanged() const;
+
+ private:
+ qint64 oldPos;
+ Core* m_core;
+ Playlist* m_playlist;
+};
+
+#endif
diff --git a/src/mpris2/mpris2.cpp b/src/mpris2/mpris2.cpp
new file mode 100644
index 0000000..779c2b6
--- /dev/null
+++ b/src/mpris2/mpris2.cpp
@@ -0,0 +1,95 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ * Copyright 2012 Bernd Buschinski <b.buschinski@googlemail.com>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#include "mpris2.h"
+#include "mediaplayer2.h"
+#include "mediaplayer2player.h"
+
+#include <QDBusConnection>
+#include <QDBusMessage>
+#include <QMetaClassInfo>
+#include <QStringList>
+
+#include <unistd.h>
+
+// basegui.h includes windows.h which creates a conflict with QDBusConnection
+// so moved here to avoid it
+#include "basegui.h"
+
+Mpris2::Mpris2(BaseGui* gui, QObject* parent)
+ : QObject(parent)
+{
+ QString mpris2Name("org.mpris.MediaPlayer2." + QLatin1String("smplayer"));
+
+ bool success = QDBusConnection::sessionBus().registerService(mpris2Name);
+
+ // If the above failed, it's likely because we're not the first instance
+ // and the name is already taken. In that event the MPRIS2 spec wants the
+ // following:
+ if (!success)
+ success = QDBusConnection::sessionBus().registerService(mpris2Name + ".instance" + QString::number(getpid()));
+
+ if (success)
+ {
+ new MediaPlayer2(gui, this);
+ new MediaPlayer2Player(gui, this);
+ QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2", this, QDBusConnection::ExportAdaptors);
+ }
+}
+
+Mpris2::~Mpris2()
+{
+}
+
+void Mpris2::signalPropertiesChange(const QObject* adaptor, const QVariantMap& properties)
+{
+ QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
+ "org.freedesktop.DBus.Properties", "PropertiesChanged" );
+
+ QVariantList args;
+ args << adaptor->metaObject()->classInfo(0).value();
+ args << properties;
+ args << QStringList();
+
+ msg.setArguments(args);
+
+ QDBusConnection::sessionBus().send(msg);
+}
+
+#include "moc_mpris2.cpp"
diff --git a/src/mpris2/mpris2.h b/src/mpris2/mpris2.h
new file mode 100644
index 0000000..fc1d311
--- /dev/null
+++ b/src/mpris2/mpris2.h
@@ -0,0 +1,60 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program 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 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+/***********************************************************************
+ * Copyright 2012 Eike Hein <hein@kde.org>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************/
+
+#ifndef MPRIS2_H
+#define MPRIS2_H
+
+#include <QObject>
+#include <QVariantMap>
+
+class Core;
+class BaseGui;
+
+class Mpris2 : public QObject
+{
+ Q_OBJECT
+
+ public:
+ explicit Mpris2(BaseGui* gui, QObject* parent);
+ ~Mpris2();
+
+ static void signalPropertiesChange(const QObject* adaptor, const QVariantMap& properties);
+};
+
+#endif