Phonon

mediacontroller.cpp
1/*
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3 Copyright (C) 2008 Ian Monroe <ian@monroe.nu>
4 Copyright (C) 2011 Harald Sitter <sitter@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) version 3, or any
10 later version accepted by the membership of KDE e.V. (or its
11 successor approved by the membership of KDE e.V.), Nokia Corporation
12 (or its successors, if any) and the KDE Free Qt Foundation, which shall
13 act as a proxy defined in Section 6 of version 3 of the license.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library. If not, see <http://www.gnu.org/licenses/>.
22
23*/
24
25#include "mediacontroller.h"
26#include "mediaobject.h"
27#include "addoninterface.h"
28#include <QList>
29#include <QVariant>
30#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31#include <QTextCodec>
32#else
33#include <QStringDecoder>
34#endif
35#include <QFont>
36#include "frontendinterface_p.h"
37
38#ifndef QT_NO_PHONON_MEDIACONTROLLER
39
40namespace Phonon
41{
42
43class MediaControllerPrivate : public FrontendInterfacePrivate
44{
45 public:
46 MediaControllerPrivate(MediaObject *mp) : FrontendInterfacePrivate(mp) {}
47
48 void backendObjectChanged(QObject *) override;
49 MediaController *q;
50};
51
52MediaController::MediaController(MediaObject *mp)
53 : QObject(mp)
54 , d(new MediaControllerPrivate(mp))
55{
56 d->q = this;
57 d->_backendObjectChanged();
58 setSubtitleAutodetect(true);
59}
60
61void MediaControllerPrivate::backendObjectChanged(QObject *m_backendObject)
62{
63 QObject::connect(m_backendObject, SIGNAL(availableSubtitlesChanged()), q, SIGNAL(availableSubtitlesChanged()));
64 QObject::connect(m_backendObject, SIGNAL(availableAudioChannelsChanged()), q, SIGNAL(availableAudioChannelsChanged()));
65 QObject::connect(m_backendObject, SIGNAL(titleChanged(int)), q, SIGNAL(titleChanged(int)));
66 QObject::connect(m_backendObject, SIGNAL(availableTitlesChanged(int)), q, SIGNAL(availableTitlesChanged(int)));
67 QObject::connect(m_backendObject, SIGNAL(chapterChanged(int)), q, SIGNAL(chapterChanged(int)));
68 QObject::connect(m_backendObject, SIGNAL(availableChaptersChanged(int)), q, SIGNAL(availableChaptersChanged(int)));
69 QObject::connect(m_backendObject, SIGNAL(angleChanged(int)), q, SIGNAL(angleChanged(int)));
70 QObject::connect(m_backendObject, SIGNAL(availableAnglesChanged(int)), q, SIGNAL(availableAnglesChanged(int)));
71}
72
73MediaController::~MediaController()
74{
75 delete d;
76}
77
78#define IFACE \
79 AddonInterface *iface = d->iface(); \
80 if (!iface) return
81
82MediaController::Features MediaController::supportedFeatures() const
83{
84 if (!d || !d->media) {
85 return Features();
86 }
87 IFACE Features();
88 Features ret;
89 if (iface->hasInterface(AddonInterface::AngleInterface)) {
90 ret |= Angles;
91 }
92 if (iface->hasInterface(AddonInterface::ChapterInterface)) {
93 ret |= Chapters;
94 }
95 if (iface->hasInterface(AddonInterface::NavigationInterface)) {
96 ret |= Navigations;
97 }
98 if (iface->hasInterface(AddonInterface::TitleInterface)) {
99 ret |= Titles;
100 }
101 if (iface->hasInterface(AddonInterface::SubtitleInterface)) {
102 ret |= Subtitles;
103 }
104 if(iface->hasInterface(AddonInterface::AudioChannelInterface)) {
105 ret |= AudioChannels;
106 }
107 return ret;
108}
109
110// -- Angle Control -- //
111
112int MediaController::availableAngles() const
113{
114 IFACE 0;
115 return iface->interfaceCall(AddonInterface::AngleInterface,
116 AddonInterface::availableAngles).toInt();
117}
118
119int MediaController::currentAngle() const
120{
121 IFACE 0;
122 return iface->interfaceCall(AddonInterface::AngleInterface,
123 AddonInterface::angle).toInt();
124}
125
126void MediaController::setCurrentAngle(int titleNumber)
127{
128 IFACE;
129 iface->interfaceCall(AddonInterface::AngleInterface,
130 AddonInterface::setAngle, QList<QVariant>() << QVariant(titleNumber));
131}
132
133// -- Chapter Control -- //
134
135int MediaController::availableChapters() const
136{
137 IFACE 0;
138 return iface->interfaceCall(AddonInterface::ChapterInterface,
139 AddonInterface::availableChapters).toInt();
140}
141
142int MediaController::currentChapter() const
143{
144 IFACE 0;
145 return iface->interfaceCall(AddonInterface::ChapterInterface,
146 AddonInterface::chapter).toInt();
147}
148
149void MediaController::setCurrentChapter(int titleNumber)
150{
151 IFACE;
152 iface->interfaceCall(AddonInterface::ChapterInterface,
153 AddonInterface::setChapter, QList<QVariant>() << QVariant(titleNumber));
154}
155
156// -- Navigation Menu Control -- //
157
158QString MediaController::navigationMenuToString(NavigationMenu menu)
159{
160 switch (menu) {
161 case RootMenu:
162 return tr("Main Menu");
163 case TitleMenu :
164 return tr("Title Menu");
165 case AudioMenu:
166 return tr("Audio Menu");
167 case SubtitleMenu:
168 return tr("Subtitle Menu");
169 case ChapterMenu:
170 return tr("Chapter Menu");
171 case AngleMenu:
172 return tr("Angle Menu");
173 }
174 return QString();
175}
176
177QList<MediaController::NavigationMenu> MediaController::availableMenus() const
178{
180 IFACE menus;
181 menus =
182 iface->interfaceCall(AddonInterface::NavigationInterface,
183 AddonInterface::availableMenus).value< QList<NavigationMenu> >();
184
185 return menus;
186}
187
188void MediaController::setCurrentMenu(NavigationMenu menu)
189{
190 IFACE;
191 iface->interfaceCall(AddonInterface::NavigationInterface,
192 AddonInterface::setMenu, QList<QVariant>() << QVariant::fromValue(menu));
193}
194// -- Title Control -- //
195
196int MediaController::availableTitles() const
197{
198 IFACE 0;
199 return iface->interfaceCall(AddonInterface::TitleInterface,
200 AddonInterface::availableTitles).toInt();
201}
202
203int MediaController::currentTitle() const
204{
205 IFACE 0;
206 return iface->interfaceCall(AddonInterface::TitleInterface,
207 AddonInterface::title).toInt();
208}
209
210void MediaController::setCurrentTitle(int titleNumber)
211{
212 IFACE;
213 iface->interfaceCall(AddonInterface::TitleInterface,
214 AddonInterface::setTitle, QList<QVariant>() << QVariant(titleNumber));
215}
216
217bool MediaController::autoplayTitles() const
218{
219 IFACE true;
220 return iface->interfaceCall(AddonInterface::TitleInterface,
221 AddonInterface::autoplayTitles).toBool();
222}
223
224void MediaController::setAutoplayTitles(bool b)
225{
226 IFACE;
227 iface->interfaceCall(AddonInterface::TitleInterface,
228 AddonInterface::setAutoplayTitles, QList<QVariant>() << QVariant(b));
229}
230
231void MediaController::nextTitle()
232{
233 setCurrentTitle(currentTitle() + 1);
234}
235
236void MediaController::previousTitle()
237{
238 setCurrentTitle(currentTitle() - 1);
239}
240
241// -- Audio Channel & Subtitle Control -- //
242
243AudioChannelDescription MediaController::currentAudioChannel() const
244{
246 return iface->interfaceCall(AddonInterface::AudioChannelInterface,
247 AddonInterface::currentAudioChannel).value<AudioChannelDescription>();
248}
249
250bool MediaController::subtitleAutodetect() const
251{
252 IFACE true;
253 return iface->interfaceCall(AddonInterface::SubtitleInterface,
254 AddonInterface::subtitleAutodetect).toBool();
255}
256
257void MediaController::setSubtitleAutodetect(bool enable)
258{
259 IFACE;
260 iface->interfaceCall(AddonInterface::SubtitleInterface,
261 AddonInterface::setSubtitleAutodetect, QList<QVariant>() << QVariant(enable));
262}
263
264QString MediaController::subtitleEncoding() const
265{
266 IFACE QString();
267 return iface->interfaceCall(AddonInterface::SubtitleInterface,
268 AddonInterface::subtitleEncoding).toString();
269}
270
271void MediaController::setSubtitleEncoding(const QString &encoding)
272{
273 IFACE;
274#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
275 if (!QTextCodec::availableCodecs().contains(encoding.toLocal8Bit()))
276 return;
277#else
278 if (!QStringDecoder(encoding.toUtf8().constData()).isValid())
279 return;
280#endif
281 iface->interfaceCall(AddonInterface::SubtitleInterface,
282 AddonInterface::setSubtitleEncoding, QList<QVariant>() << QVariant(encoding));
283}
284
285void MediaController::setSubtitleFont(const QFont &font)
286{
287 IFACE;
288 iface->interfaceCall(AddonInterface::SubtitleInterface,
289 AddonInterface::setSubtitleFont, QList<QVariant>() << QVariant(font));
290}
291
292QFont MediaController::subtitleFont() const
293{
294 IFACE QFont();
295 return iface->interfaceCall(AddonInterface::SubtitleInterface,
296 AddonInterface::subtitleFont).value<QFont>();
297}
298
299SubtitleDescription MediaController::currentSubtitle() const
300{
301 IFACE SubtitleDescription();
302 return iface->interfaceCall(AddonInterface::SubtitleInterface,
303 AddonInterface::currentSubtitle).value<SubtitleDescription>();
304}
305
306QList<AudioChannelDescription> MediaController::availableAudioChannels() const
307{
309 IFACE retList;
310 retList = iface->interfaceCall(AddonInterface::AudioChannelInterface,
311 AddonInterface::availableAudioChannels).value< QList<AudioChannelDescription> >();
312 return retList;
313}
314
315QList<SubtitleDescription> MediaController::availableSubtitles() const
316{
318 IFACE retList;
319 retList = iface->interfaceCall(AddonInterface::SubtitleInterface,
320 AddonInterface::availableSubtitles)
322 return retList;
323}
324
325void MediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream)
326{
327 IFACE;
328 iface->interfaceCall(AddonInterface::AudioChannelInterface,
329 AddonInterface::setCurrentAudioChannel, QList<QVariant>() << QVariant::fromValue(stream));
330}
331
332void MediaController::setCurrentSubtitle(const Phonon::SubtitleDescription &stream)
333{
334 IFACE;
335 iface->interfaceCall(AddonInterface::SubtitleInterface,
336 AddonInterface::setCurrentSubtitle, QList<QVariant>() << QVariant::fromValue(stream));
337}
338
339void MediaController::setCurrentSubtitle(const QUrl &url)
340{
341 IFACE;
342 iface->interfaceCall(AddonInterface::SubtitleInterface,
343 AddonInterface::setCurrentSubtitleFile, QList<QVariant>() << url);
344}
345
346#undef IFACE
347
348} // namespace Phonon
349
350#endif //QT_NO_PHONON_MEDIACONTROLLER
351
352#include "moc_mediacontroller.cpp"
353
354// vim: sw=4 sts=4 et tw=100
Provides a tuple of enduser visible name and description.
const char * constData() const const
T value(qsizetype i) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QByteArray toLocal8Bit() const const
QByteArray toUtf8() const const
bool isValid() const const
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:10:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.