Changeset View
Changeset View
Standalone View
Standalone View
lib/mpris2/mpris2service.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Gwenview: an image viewer | ||||
3 | Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
4 | | ||||
5 | This program is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public License | ||||
7 | as published by the Free Software Foundation; either version 2 | ||||
8 | of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This program is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | GNU General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU General Public License | ||||
16 | along with this program; if not, write to the Free Software | ||||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "mpris2service.h" | ||||
21 | | ||||
22 | // lib | ||||
23 | #include "mprismediaplayer2.h" | ||||
24 | #include "mprismediaplayer2player.h" | ||||
25 | #include <slideshow.h> | ||||
26 | // Qt | ||||
27 | #include <QDBusConnection> | ||||
28 | // std | ||||
29 | #include <unistd.h> | ||||
30 | | ||||
31 | namespace Gwenview | ||||
32 | { | ||||
33 | | ||||
34 | Mpris2Service::Mpris2Service(SlideShow* slideShow, SortedDirModel* dirModel, ContextManager* contextManager, | ||||
35 | QAction* toggleSlideShowAction, | ||||
36 | QAction* previousAction, QAction* nextAction, | ||||
37 | QObject* parent) | ||||
38 | : QObject(parent) | ||||
39 | { | ||||
40 | QString mpris2ServiceName = QStringLiteral("org.mpris.MediaPlayer2.Gwenview"); | ||||
41 | | ||||
42 | bool success = QDBusConnection::sessionBus().registerService(mpris2ServiceName); | ||||
43 | | ||||
44 | // Perhaps not the first instance? Try again with another name, as specified by MPRIS2 spec: | ||||
45 | if (!success) { | ||||
46 | mpris2ServiceName = mpris2ServiceName + QLatin1String(".instance") + QString::number(getpid()); | ||||
47 | success = QDBusConnection::sessionBus().registerService(mpris2ServiceName); | ||||
48 | } | ||||
49 | | ||||
50 | if (success) { | ||||
51 | const QString objectPath = QStringLiteral("/org/mpris/MediaPlayer2"); | ||||
52 | new MprisMediaPlayer2(objectPath, slideShow, this); | ||||
53 | new MprisMediaPlayer2Player(objectPath, slideShow, dirModel, contextManager, | ||||
54 | toggleSlideShowAction, previousAction, nextAction, this); | ||||
55 | | ||||
56 | QDBusConnection::sessionBus().registerObject(objectPath, this, QDBusConnection::ExportAdaptors); | ||||
57 | } | ||||
58 | } | ||||
59 | | ||||
60 | | ||||
61 | Mpris2Service::~Mpris2Service() | ||||
62 | { | ||||
63 | } | ||||
64 | | ||||
65 | } |