| 1 |
/* This file is part of the KDE project |
| 2 |
Copyright (C) 2007 Matthias Kretz <kretz@kde.org> |
| 3 |
Copyright (C) 2008 Ian Monroe <ian@monroe.nu> |
| 4 |
|
| 5 |
This library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Lesser General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2.1 of the License, or (at your option) version 3, or any |
| 9 |
later version accepted by the membership of KDE e.V. (or its |
| 10 |
successor approved by the membership of KDE e.V.), Nokia Corporation |
| 11 |
(or its successors, if any) and the KDE Free Qt Foundation, which shall |
| 12 |
act as a proxy defined in Section 6 of version 3 of the license. |
| 13 |
|
| 14 |
This library is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
Lesser General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU Lesser General Public |
| 20 |
License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
*/ |
| 23 |
|
| 24 |
#include "mediacontroller.h" |
| 25 |
#include "mediaobject.h" |
| 26 |
#include "addoninterface.h" |
| 27 |
#include <QtCore/QList> |
| 28 |
#include <QtCore/QVariant> |
| 29 |
#include "frontendinterface_p.h" |
| 30 |
|
| 31 |
QT_BEGIN_NAMESPACE |
| 32 |
|
| 33 |
#ifndef QT_NO_PHONON_MEDIACONTROLLER |
| 34 |
|
| 35 |
namespace Phonon |
| 36 |
{ |
| 37 |
|
| 38 |
class MediaControllerPrivate : public FrontendInterfacePrivate |
| 39 |
{ |
| 40 |
public: |
| 41 |
MediaControllerPrivate(MediaObject *mp) : FrontendInterfacePrivate(mp) {} |
| 42 |
|
| 43 |
virtual void backendObjectChanged(QObject *); |
| 44 |
MediaController *q; |
| 45 |
}; |
| 46 |
|
| 47 |
MediaController::MediaController(MediaObject *mp) |
| 48 |
: QObject(mp) |
| 49 |
, d(new MediaControllerPrivate(mp)) |
| 50 |
{ |
| 51 |
d->q = this; |
| 52 |
d->_backendObjectChanged(); |
| 53 |
} |
| 54 |
|
| 55 |
void MediaControllerPrivate::backendObjectChanged(QObject *m_backendObject) |
| 56 |
{ |
| 57 |
QObject::connect(m_backendObject, SIGNAL(availableSubtitlesChanged()), q, SIGNAL(availableSubtitlesChanged())); |
| 58 |
QObject::connect(m_backendObject, SIGNAL(availableAudioChannelsChanged()), q, SIGNAL(availableAudioChannelsChanged())); |
| 59 |
QObject::connect(m_backendObject, SIGNAL(titleChanged(int)), q, SIGNAL(titleChanged(int))); |
| 60 |
QObject::connect(m_backendObject, SIGNAL(availableTitlesChanged(int)), q, SIGNAL(availableTitlesChanged(int))); |
| 61 |
QObject::connect(m_backendObject, SIGNAL(chapterChanged(int)), q, SIGNAL(chapterChanged(int))); |
| 62 |
QObject::connect(m_backendObject, SIGNAL(availableChaptersChanged(int)), q, SIGNAL(availableChaptersChanged(int))); |
| 63 |
QObject::connect(m_backendObject, SIGNAL(angleChanged(int)), q, SIGNAL(angleChanged(int))); |
| 64 |
QObject::connect(m_backendObject, SIGNAL(availableAnglesChanged(int)), q, SIGNAL(availableAnglesChanged(int))); |
| 65 |
} |
| 66 |
|
| 67 |
MediaController::~MediaController() |
| 68 |
{ |
| 69 |
delete d; |
| 70 |
} |
| 71 |
|
| 72 |
#define IFACE \ |
| 73 |
AddonInterface *iface = d->iface(); \ |
| 74 |
if (!iface) return |
| 75 |
|
| 76 |
MediaController::Features MediaController::supportedFeatures() const |
| 77 |
{ |
| 78 |
if (!d || !d->media) { |
| 79 |
return Features(); |
| 80 |
} |
| 81 |
IFACE Features(); |
| 82 |
Features ret; |
| 83 |
if (iface->hasInterface(AddonInterface::AngleInterface)) { |
| 84 |
ret |= Angles; |
| 85 |
} |
| 86 |
if (iface->hasInterface(AddonInterface::ChapterInterface)) { |
| 87 |
ret |= Chapters; |
| 88 |
} |
| 89 |
if (iface->hasInterface(AddonInterface::TitleInterface)) { |
| 90 |
ret |= Titles; |
| 91 |
} |
| 92 |
return ret; |
| 93 |
} |
| 94 |
|
| 95 |
int MediaController::availableTitles() const |
| 96 |
{ |
| 97 |
IFACE 0; |
| 98 |
return iface->interfaceCall(AddonInterface::TitleInterface, |
| 99 |
AddonInterface::availableTitles).toInt(); |
| 100 |
} |
| 101 |
|
| 102 |
int MediaController::currentTitle() const |
| 103 |
{ |
| 104 |
IFACE 0; |
| 105 |
return iface->interfaceCall(AddonInterface::TitleInterface, |
| 106 |
AddonInterface::title).toInt(); |
| 107 |
} |
| 108 |
|
| 109 |
void MediaController::setCurrentTitle(int titleNumber) |
| 110 |
{ |
| 111 |
IFACE; |
| 112 |
iface->interfaceCall(AddonInterface::TitleInterface, |
| 113 |
AddonInterface::setTitle, QList<QVariant>() << QVariant(titleNumber)); |
| 114 |
} |
| 115 |
|
| 116 |
bool MediaController::autoplayTitles() const |
| 117 |
{ |
| 118 |
IFACE true; |
| 119 |
return iface->interfaceCall(AddonInterface::TitleInterface, |
| 120 |
AddonInterface::autoplayTitles).toBool(); |
| 121 |
} |
| 122 |
|
| 123 |
void MediaController::setAutoplayTitles(bool b) |
| 124 |
{ |
| 125 |
IFACE; |
| 126 |
iface->interfaceCall(AddonInterface::TitleInterface, |
| 127 |
AddonInterface::setAutoplayTitles, QList<QVariant>() << QVariant(b)); |
| 128 |
} |
| 129 |
|
| 130 |
void MediaController::nextTitle() |
| 131 |
{ |
| 132 |
setCurrentTitle(currentTitle() + 1); |
| 133 |
} |
| 134 |
|
| 135 |
void MediaController::previousTitle() |
| 136 |
{ |
| 137 |
setCurrentTitle(currentTitle() - 1); |
| 138 |
} |
| 139 |
|
| 140 |
int MediaController::availableChapters() const |
| 141 |
{ |
| 142 |
IFACE 0; |
| 143 |
return iface->interfaceCall(AddonInterface::ChapterInterface, |
| 144 |
AddonInterface::availableChapters).toInt(); |
| 145 |
} |
| 146 |
|
| 147 |
int MediaController::currentChapter() const |
| 148 |
{ |
| 149 |
IFACE 0; |
| 150 |
return iface->interfaceCall(AddonInterface::ChapterInterface, |
| 151 |
AddonInterface::chapter).toInt(); |
| 152 |
} |
| 153 |
|
| 154 |
void MediaController::setCurrentChapter(int titleNumber) |
| 155 |
{ |
| 156 |
IFACE; |
| 157 |
iface->interfaceCall(AddonInterface::ChapterInterface, |
| 158 |
AddonInterface::setChapter, QList<QVariant>() << QVariant(titleNumber)); |
| 159 |
} |
| 160 |
|
| 161 |
int MediaController::availableAngles() const |
| 162 |
{ |
| 163 |
IFACE 0; |
| 164 |
return iface->interfaceCall(AddonInterface::AngleInterface, |
| 165 |
AddonInterface::availableAngles).toInt(); |
| 166 |
} |
| 167 |
|
| 168 |
int MediaController::currentAngle() const |
| 169 |
{ |
| 170 |
IFACE 0; |
| 171 |
return iface->interfaceCall(AddonInterface::AngleInterface, |
| 172 |
AddonInterface::angle).toInt(); |
| 173 |
} |
| 174 |
|
| 175 |
void MediaController::setCurrentAngle(int titleNumber) |
| 176 |
{ |
| 177 |
IFACE; |
| 178 |
iface->interfaceCall(AddonInterface::AngleInterface, |
| 179 |
AddonInterface::setAngle, QList<QVariant>() << QVariant(titleNumber)); |
| 180 |
} |
| 181 |
|
| 182 |
AudioChannelDescription MediaController::currentAudioChannel() const |
| 183 |
{ |
| 184 |
IFACE AudioChannelDescription(); |
| 185 |
return iface->interfaceCall(AddonInterface::AudioChannelInterface, |
| 186 |
AddonInterface::currentAudioChannel).value<AudioChannelDescription>(); |
| 187 |
} |
| 188 |
|
| 189 |
SubtitleDescription MediaController::currentSubtitle() const |
| 190 |
{ |
| 191 |
IFACE SubtitleDescription(); |
| 192 |
return iface->interfaceCall(AddonInterface::SubtitleInterface, |
| 193 |
AddonInterface::currentSubtitle).value<SubtitleDescription>(); |
| 194 |
} |
| 195 |
|
| 196 |
QList<AudioChannelDescription> MediaController::availableAudioChannels() const |
| 197 |
{ |
| 198 |
QList<AudioChannelDescription> retList; |
| 199 |
IFACE retList; |
| 200 |
retList = iface->interfaceCall(AddonInterface::AudioChannelInterface, |
| 201 |
AddonInterface::availableAudioChannels).value< QList<AudioChannelDescription> >(); |
| 202 |
return retList; |
| 203 |
} |
| 204 |
|
| 205 |
QList<SubtitleDescription> MediaController::availableSubtitles() const |
| 206 |
{ |
| 207 |
QList<SubtitleDescription> retList; |
| 208 |
IFACE retList; |
| 209 |
retList = iface->interfaceCall(AddonInterface::SubtitleInterface, |
| 210 |
AddonInterface::availableSubtitles) |
| 211 |
.value< QList<SubtitleDescription> >(); |
| 212 |
return retList; |
| 213 |
} |
| 214 |
|
| 215 |
void MediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream) |
| 216 |
{ |
| 217 |
IFACE; |
| 218 |
iface->interfaceCall(AddonInterface::AudioChannelInterface, |
| 219 |
AddonInterface::setCurrentAudioChannel, QList<QVariant>() << QVariant::fromValue(stream)); |
| 220 |
} |
| 221 |
|
| 222 |
void MediaController::setCurrentSubtitle(const Phonon::SubtitleDescription &stream) |
| 223 |
{ |
| 224 |
IFACE; |
| 225 |
iface->interfaceCall(AddonInterface::SubtitleInterface, |
| 226 |
AddonInterface::setCurrentSubtitle, QList<QVariant>() << QVariant::fromValue(stream)); |
| 227 |
} |
| 228 |
|
| 229 |
#undef IFACE |
| 230 |
|
| 231 |
} // namespace Phonon |
| 232 |
|
| 233 |
#endif //QT_NO_PHONON_MEDIACONTROLLER |
| 234 |
|
| 235 |
QT_END_NAMESPACE |
| 236 |
|
| 237 |
#include "moc_mediacontroller.cpp" |
| 238 |
|
| 239 |
// vim: sw=4 sts=4 et tw=100 |