Warning, file /multimedia/dragon/src/mpris2/mpris2.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2012 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "mpris2.h"
0008 #include "codeine.h"
0009 #include "mediaplayer2.h"
0010 #include "mediaplayer2player.h"
0011 
0012 #include <QDBusConnection>
0013 #include <QDBusMessage>
0014 #include <QMetaClassInfo>
0015 #include <QStringList>
0016 
0017 #include <unistd.h>
0018 
0019 Mpris2::Mpris2(QObject *parent)
0020     : QObject(parent)
0021 {
0022     const QString mpris2Name = QStringLiteral("org.mpris.MediaPlayer2." APP_NAME);
0023 
0024     bool success = QDBusConnection::sessionBus().registerService(mpris2Name);
0025 
0026     // If the above failed, it's likely because we're not the first instance
0027     // and the name is already taken. In that event the MPRIS2 spec wants the
0028     // following:
0029     if (!success)
0030         success = QDBusConnection::sessionBus().registerService(mpris2Name + QLatin1String(".instance") + QString::number(getpid()));
0031 
0032     if (success) {
0033         new MediaPlayer2(this);
0034         new MediaPlayer2Player(this);
0035         QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/mpris/MediaPlayer2"), this, QDBusConnection::ExportAdaptors);
0036     }
0037 }
0038 
0039 Mpris2::~Mpris2()
0040 {
0041 }
0042 
0043 void Mpris2::signalPropertiesChange(const QObject *adaptor, const QVariantMap &properties)
0044 {
0045     QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/mpris/MediaPlayer2"),
0046                                                   QStringLiteral("org.freedesktop.DBus.Properties"),
0047                                                   QStringLiteral("PropertiesChanged"));
0048 
0049     msg << QString::fromUtf8(adaptor->metaObject()->classInfo(0).value());
0050     msg << properties;
0051     msg << QStringList();
0052 
0053     QDBusConnection::sessionBus().send(msg);
0054 }
0055 
0056 #include "moc_mpris2.cpp"