File psi-0.14-mpris.patch of Package psi

Index: src/tools/tunecontroller/plugins/mpris/mpriscontroller.cpp
===================================================================
--- /dev/null
+++ src/tools/tunecontroller/plugins/mpris/mpriscontroller.cpp
@@ -0,0 +1,99 @@
+/*
+ * mpristunecontroller.cpp
+ * Copyright (C) 2008  Matthieu Volat
+ *
+ * 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <QtDBus/QDBusMetaType>
+#include <QDBusReply>
+#include <QVariantMap>
+
+#include "mpriscontroller.h"
+
+/**
+ * \class MPRISTuneController
+ * \brief A common controller class for MPRIS compilant players.
+ */
+QDBusArgument &operator<<(QDBusArgument& arg, const PlayerStatus& ps)
+{
+	arg.beginStructure();
+	arg << ps.i1;
+	arg << ps.i2;
+	arg << ps.i3;
+	arg << ps.i4;
+	arg.endStructure();
+	return arg;
+}
+
+const QDBusArgument &operator>>(const QDBusArgument& arg, PlayerStatus& ps)
+{
+	arg.beginStructure();
+	arg >> ps.i1;
+	arg >> ps.i2;
+	arg >> ps.i3;
+	arg >> ps.i4;
+	arg.endStructure();
+	return arg;
+}
+
+MPRISController::MPRISController()
+{
+//	service_ = QString("org.mpris.") + player;
+	QDBusConnection bus = QDBusConnection::sessionBus();
+
+	qDBusRegisterMetaType<PlayerStatus>();
+	bus.connect(
+			QString(),
+			"/Player",
+			"org.freedesktop.MediaPlayer",
+			"StatusChange",
+			"(iiii)",
+			this,
+			SLOT(playerStatusChanged(PlayerStatus)));
+
+	bus.connect(
+			QString(),
+			"/Player",
+			"org.freedesktop.MediaPlayer",
+			"TrackChange",
+			"a{sv}",
+			this,
+			SLOT(playerTrackChanged(QVariantMap)));
+}
+
+Tune MPRISController::currentTune()
+{
+	return currentTune_;
+}
+
+void MPRISController::playerStatusChanged(const PlayerStatus& ps)
+{
+	// Many players do not send TrackChange when pausing/stopping, so
+	// we must use StatusChange instead of
+	if (ps.i1 != 0)
+		emit stopped();
+}
+
+void MPRISController::playerTrackChanged(QVariantMap map)
+{
+	currentTune_.setName(map.value("title").toString());
+	currentTune_.setArtist(map.value("artist").toString());
+	currentTune_.setAlbum(map.value("album").toString());
+	currentTune_.setTrack(map.value("track").toString());
+	currentTune_.setTime(map.value("time").toUInt());
+	emit playing(currentTune_);
+}
Index: src/tools/tunecontroller/plugins/mpris/mpriscontroller.h
===================================================================
--- /dev/null
+++ src/tools/tunecontroller/plugins/mpris/mpriscontroller.h
@@ -0,0 +1,57 @@
+/*
+ * mpristunecontroller.h
+ * Copyright (C) 2008 Matthieu Volat
+ *
+ * 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef MPRISCONTROLLER_H
+#define MPRISCONTROLLER_H
+
+#include <QDBusConnection>
+#include <QString>
+
+#include "tunecontrollerinterface.h"
+#include "tune.h"
+
+struct PlayerStatus
+{
+	int i1;
+	int i2;
+	int i3;
+	int i4;
+};
+
+Q_DECLARE_METATYPE(PlayerStatus)
+
+class MPRISController : public TuneController
+{
+	Q_OBJECT
+
+public:
+	MPRISController();
+
+	Tune currentTune();
+
+protected slots:
+	void playerStatusChanged(const PlayerStatus& ps);
+	void playerTrackChanged(QVariantMap map);
+
+private:
+	Tune currentTune_;
+};
+
+#endif
Index: src/tools/tunecontroller/plugins/mpris/mprisplugin.cpp
===================================================================
--- /dev/null
+++ src/tools/tunecontroller/plugins/mpris/mprisplugin.cpp
@@ -0,0 +1,54 @@
+/*
+ * mprisplugin.cpp
+ * Copyright (C) 2008  Matthieu Volat
+ *
+ * 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef QT_STATICPLUGIN
+#define QT_STATICPLUGIN
+#endif
+
+#include <QtCore>
+#include <QObject>
+#include <QString>
+
+#include "mpriscontroller.h"
+#include "tunecontrollerplugin.h"
+
+class MPRISPlugin : public QObject, public TuneControllerPlugin
+{
+	Q_OBJECT
+	Q_INTERFACES(TuneControllerPlugin)
+
+public:
+	virtual QString name();
+	virtual TuneController* createController();
+};
+
+Q_EXPORT_PLUGIN2(mprisplugin, MPRISPlugin);
+
+QString MPRISPlugin::name()
+{
+	return "MPRIS";
+}
+
+TuneController* MPRISPlugin::createController()
+{
+	return new MPRISController();
+}
+
+#include "mprisplugin.moc"
Index: src/tools/tunecontroller/tunecontrollermanager.cpp
===================================================================
--- src/tools/tunecontroller/tunecontrollermanager.cpp.orig
+++ src/tools/tunecontroller/tunecontrollermanager.cpp
@@ -119,3 +119,7 @@ Q_IMPORT_PLUGIN(winampplugin);
 #ifdef TC_PSIFILE
 Q_IMPORT_PLUGIN(psifileplugin);
 #endif
+
+#ifdef TC_MPRIS
+Q_IMPORT_PLUGIN(mprisplugin);
+#endif
Index: src/tools/tunecontroller/tunecontroller.pri
===================================================================
--- src/tools/tunecontroller/tunecontroller.pri.orig
+++ src/tools/tunecontroller/tunecontroller.pri
@@ -82,3 +82,13 @@ tc_psifile {
 		$$PSIFILE_PLUGIN_PATH/psifilecontroller.cpp \
 		$$PSIFILE_PLUGIN_PATH/psifileplugin.cpp
 }
+
+# MPRIS
+dbus {
+	DEFINES += TC_MPRIS
+	MPRIS_PLUGIN_PATH = $$PWD/plugins/mpris
+	SOURCES += $$MPRIS_PLUGIN_PATH/mprisplugin.cpp \
+	           $$MPRIS_PLUGIN_PATH/mpriscontroller.cpp
+	HEADERS += $$MPRIS_PLUGIN_PATH/mpriscontroller.h
+}
+