[175] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[175] | 3 |
|
---|
| 4 | This program is free software; you can redistribute it and/or modify
|
---|
| 5 | it under the terms of the GNU General Public License as published by
|
---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 7 | (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This program is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 12 | GNU General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | /***********************************************************************
|
---|
| 20 | * Copyright 2012 Eike Hein <hein@kde.org>
|
---|
| 21 | * Copyright 2012 Bernd Buschinski <b.buschinski@googlemail.com>
|
---|
| 22 | *
|
---|
| 23 | * This program is free software; you can redistribute it and/or
|
---|
| 24 | * modify it under the terms of the GNU General Public License as
|
---|
| 25 | * published by the Free Software Foundation; either version 2 of
|
---|
| 26 | * the License or (at your option) version 3 or any later version
|
---|
| 27 | * accepted by the membership of KDE e.V. (or its successor approved
|
---|
| 28 | * by the membership of KDE e.V.), which shall act as a proxy
|
---|
| 29 | * defined in Section 14 of version 3 of the license.
|
---|
| 30 | *
|
---|
| 31 | * This program is distributed in the hope that it will be useful,
|
---|
| 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 34 | * GNU General Public License for more details.
|
---|
| 35 | *
|
---|
| 36 | * You should have received a copy of the GNU General Public License
|
---|
| 37 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 38 | ***********************************************************************/
|
---|
| 39 |
|
---|
| 40 | #include "mpris2.h"
|
---|
| 41 | #include "mediaplayer2.h"
|
---|
| 42 | #include "mediaplayer2player.h"
|
---|
| 43 |
|
---|
| 44 | #include <QDBusConnection>
|
---|
| 45 | #include <QDBusMessage>
|
---|
| 46 | #include <QMetaClassInfo>
|
---|
| 47 | #include <QStringList>
|
---|
| 48 |
|
---|
| 49 | #include <unistd.h>
|
---|
| 50 |
|
---|
| 51 | // basegui.h includes windows.h which creates a conflict with QDBusConnection
|
---|
| 52 | // so moved here to avoid it
|
---|
| 53 | #include "basegui.h"
|
---|
| 54 |
|
---|
| 55 | Mpris2::Mpris2(BaseGui* gui, QObject* parent)
|
---|
| 56 | : QObject(parent)
|
---|
| 57 | {
|
---|
| 58 | QString mpris2Name("org.mpris.MediaPlayer2." + QLatin1String("smplayer"));
|
---|
| 59 |
|
---|
| 60 | bool success = QDBusConnection::sessionBus().registerService(mpris2Name);
|
---|
| 61 |
|
---|
| 62 | // If the above failed, it's likely because we're not the first instance
|
---|
| 63 | // and the name is already taken. In that event the MPRIS2 spec wants the
|
---|
| 64 | // following:
|
---|
| 65 | if (!success)
|
---|
| 66 | success = QDBusConnection::sessionBus().registerService(mpris2Name + ".instance" + QString::number(getpid()));
|
---|
| 67 |
|
---|
| 68 | if (success)
|
---|
| 69 | {
|
---|
| 70 | new MediaPlayer2(gui, this);
|
---|
| 71 | new MediaPlayer2Player(gui, this);
|
---|
| 72 | QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2", this, QDBusConnection::ExportAdaptors);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Mpris2::~Mpris2()
|
---|
| 77 | {
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void Mpris2::signalPropertiesChange(const QObject* adaptor, const QVariantMap& properties)
|
---|
| 81 | {
|
---|
| 82 | QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
|
---|
| 83 | "org.freedesktop.DBus.Properties", "PropertiesChanged" );
|
---|
| 84 |
|
---|
| 85 | QVariantList args;
|
---|
| 86 | args << adaptor->metaObject()->classInfo(0).value();
|
---|
| 87 | args << properties;
|
---|
| 88 | args << QStringList();
|
---|
| 89 |
|
---|
| 90 | msg.setArguments(args);
|
---|
| 91 |
|
---|
| 92 | QDBusConnection::sessionBus().send(msg);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | #include "moc_mpris2.cpp"
|
---|