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
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
178{
180 IFACE menus;
181 menus =
182 iface->interfaceCall(AddonInterface::NavigationInterface,
184
185 return menus;
186}
187
194// -- Title Control -- //
195
196int MediaController::availableTitles() const
197{
198 IFACE 0;
199 return iface->interfaceCall(AddonInterface::TitleInterface,
201}
202
203int MediaController::currentTitle() const
204{
205 IFACE 0;
206 return iface->interfaceCall(AddonInterface::TitleInterface,
207 AddonInterface::title).toInt();
208}
209
211{
212 IFACE;
213 iface->interfaceCall(AddonInterface::TitleInterface,
215}
216
217bool MediaController::autoplayTitles() const
218{
219 IFACE true;
220 return iface->interfaceCall(AddonInterface::TitleInterface,
222}
223
224void MediaController::setAutoplayTitles(bool b)
225{
226 IFACE;
227 iface->interfaceCall(AddonInterface::TitleInterface,
228 AddonInterface::setAutoplayTitles, QList<QVariant>() << QVariant(b));
229}
230
232{
233 setCurrentTitle(currentTitle() + 1);
234}
235
237{
238 setCurrentTitle(currentTitle() - 1);
239}
240
241// -- Audio Channel & Subtitle Control -- //
242
243AudioChannelDescription MediaController::currentAudioChannel() const
244{
245 IFACE AudioChannelDescription();
246 return iface->interfaceCall(AddonInterface::AudioChannelInterface,
247 AddonInterface::currentAudioChannel).value<AudioChannelDescription>();
248}
249
251{
252 IFACE true;
253 return iface->interfaceCall(AddonInterface::SubtitleInterface,
255}
256
258{
259 IFACE;
260 iface->interfaceCall(AddonInterface::SubtitleInterface,
262}
263
265{
266 IFACE QString();
267 return iface->interfaceCall(AddonInterface::SubtitleInterface,
269}
270
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
286{
287 IFACE;
288 iface->interfaceCall(AddonInterface::SubtitleInterface,
290}
291
293{
294 IFACE QFont();
295 return iface->interfaceCall(AddonInterface::SubtitleInterface,
297}
298
299SubtitleDescription MediaController::currentSubtitle() const
300{
301 IFACE SubtitleDescription();
302 return iface->interfaceCall(AddonInterface::SubtitleInterface,
303 AddonInterface::currentSubtitle).value<SubtitleDescription>();
304}
305
314
316{
318 IFACE retList;
319 retList = iface->interfaceCall(AddonInterface::SubtitleInterface,
322 return retList;
323}
324
325void MediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream)
326{
327 IFACE;
328 iface->interfaceCall(AddonInterface::AudioChannelInterface,
330}
331
332void MediaController::setCurrentSubtitle(const Phonon::SubtitleDescription &stream)
333{
334 IFACE;
335 iface->interfaceCall(AddonInterface::SubtitleInterface,
337}
338
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
@ setMenu
Sets the current menu to the first MediaController::NavigationMenu in a QList.
@ SubtitleInterface
Interface for subtitle control.
@ TitleInterface
Interface for title control.
@ NavigationInterface
Interface for (menu) navigation.
@ AudioChannelInterface
Interface for audio channel control.
@ setCurrentAudioChannel
Sets the current audio channel to the first int in the QList.
@ setCurrentSubtitle
Sets the current subtitle to the first int in the QList.
@ subtitleFont
Sets the current encoding used to render subtitles.
@ setSubtitleAutodetect
Sets/Unsets subtitles autodetection.
@ setSubtitleFont
Sets the current font used to render subtitles.
@ setCurrentSubtitleFile
Sets the current subtitle to the first QUrl.
@ setTitle
Sets the current title to the first int in the QList.
void previousTitle()
Skips to the previous title.
@ SubtitleMenu
< Audio menu for language (and sometimes also subtitle) settings etc.
@ AngleMenu
< Chapter menu for chapter selection.
@ ChapterMenu
< Subtitle menu.
@ TitleMenu
< Root/main menu.
@ AudioMenu
< Title Menu to access different titles on the media source.
QList< SubtitleDescription > availableSubtitles() const
Returns the subtitle streams that can be selected by the user.
void setSubtitleFont(const QFont &font)
Selects the current font used to render subtitles.
void setCurrentMenu(NavigationMenu menu)
Switches to a menu (e.g.
SubtitleDescription currentSubtitle() const
Returns the selected subtitle stream.
bool subtitleAutodetect() const
Subtitle auto-detection transparently tries to find a subtitle file for the current MediaSource and w...
static QString navigationMenuToString(NavigationMenu menu)
Translates a NavigationMenu enum to a string you can use in your GUI.
void setCurrentSubtitle(const Phonon::SubtitleDescription &stream)
Selects a subtitle stream from the media.
QList< NavigationMenu > availableMenus() const
Get the list of currently available menus for the present media source.
void setSubtitleAutodetect(bool enable)
Sets/Unsets subtitles autodetection.
AudioChannelDescription currentAudioChannel() const
Returns the selected audio stream.
void nextTitle()
Skips to the next title.
QList< Phonon::AudioChannelDescription > availableAudioChannels() const
Returns the audio streams that can be selected by the user.
void setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream)
Selects an audio stream from the media.
void setSubtitleEncoding(const QString &encoding)
Selects the current encoding used to render subtitles.
QFont subtitleFont() const
Returns the font used to render subtitles.
void setCurrentTitle(int titleNumber)
Skips to the given title titleNumber.
QString subtitleEncoding() const
Returns the encoding used to render subtitles.
Interface for media playback of a given URL.
Definition mediaobject.h:94
const char * constData() const const
T value(qsizetype i) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
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-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:05 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.