Changeset View
Changeset View
Standalone View
Standalone View
mpris2/mpris2service.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> * | ||||
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 | | ||||
10 | #include "mpris2service.h" | ||||
11 | | ||||
12 | // lib | ||||
13 | #include "mprismediaplayer2.h" | ||||
14 | #include "mprismediaplayer2player.h" | ||||
15 | // KF | ||||
16 | #include <KActionCollection> | ||||
17 | #include <KStandardAction> | ||||
18 | // Qt | ||||
19 | #include <QDBusConnection> | ||||
20 | // std | ||||
21 | #include <unistd.h> | ||||
22 | | ||||
23 | namespace Okular | ||||
24 | { | ||||
25 | | ||||
26 | Mpris2Service::Mpris2Service(Document *document, | ||||
27 | KActionCollection *actionCollection, | ||||
28 | PresentationWidget *presentationWidget, | ||||
29 | QObject *parent) | ||||
30 | : QObject(parent) | ||||
31 | { | ||||
32 | QString mpris2ServiceName = QStringLiteral("org.mpris.MediaPlayer2.Okular"); | ||||
33 | | ||||
34 | bool success = QDBusConnection::sessionBus().registerService(mpris2ServiceName); | ||||
35 | | ||||
36 | // Perhaps not the first instance? Try again with another name, as specified by MPRIS2 spec: | ||||
37 | if (!success) { | ||||
38 | mpris2ServiceName = mpris2ServiceName + QLatin1String(".instance") + QString::number(getpid()); | ||||
39 | success = QDBusConnection::sessionBus().registerService(mpris2ServiceName); | ||||
40 | } | ||||
41 | | ||||
42 | if (success) { | ||||
43 | const QString objectPath = QStringLiteral("/org/mpris/MediaPlayer2"); | ||||
44 | QAction *priorAction = actionCollection->action( QString::fromLatin1(KStandardAction::name(KStandardAction::Prior))); | ||||
45 | QAction *nextAction = actionCollection->action( QString::fromLatin1(KStandardAction::name(KStandardAction::Next))); | ||||
46 | // addAction( m_ac->action( QString::fromLatin1(KStandardAction::name(KStandardAction::DocumentBack)))); | ||||
47 | // addAction( m_ac->action( QString::fromLatin1(KStandardAction::name(KStandardAction::DocumentForward)))); | ||||
48 | | ||||
49 | QAction *playPauseAction = actionCollection->action(QStringLiteral("presentation_play_pause")); | ||||
50 | | ||||
51 | new MprisMediaPlayer2(objectPath, this); | ||||
52 | new MprisMediaPlayer2Player(objectPath, document, playPauseAction, priorAction, nextAction, presentationWidget, this); | ||||
53 | | ||||
54 | QDBusConnection::sessionBus().registerObject(objectPath, this, QDBusConnection::ExportAdaptors); | ||||
55 | } | ||||
56 | } | ||||
57 | | ||||
58 | | ||||
59 | Mpris2Service::~Mpris2Service() | ||||
60 | { | ||||
61 | } | ||||
62 | | ||||
63 | } |