| 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 | |
| 40 | namespace Phonon |
| 41 | { |
| 42 | |
| 43 | class MediaControllerPrivate : public FrontendInterfacePrivate |
| 44 | { |
| 45 | public: |
| 46 | MediaControllerPrivate(MediaObject *mp) : FrontendInterfacePrivate(mp) {} |
| 47 | |
| 48 | void backendObjectChanged(QObject *) override; |
| 49 | MediaController *q; |
| 50 | }; |
| 51 | |
| 52 | MediaController::MediaController(MediaObject *mp) |
| 53 | : QObject(mp) |
| 54 | , d(new MediaControllerPrivate(mp)) |
| 55 | { |
| 56 | d->q = this; |
| 57 | d->_backendObjectChanged(); |
| 58 | setSubtitleAutodetect(true); |
| 59 | } |
| 60 | |
| 61 | void MediaControllerPrivate::backendObjectChanged(QObject *m_backendObject) |
| 62 | { |
| 63 | QObject::connect(sender: m_backendObject, SIGNAL(availableSubtitlesChanged()), receiver: q, SIGNAL(availableSubtitlesChanged())); |
| 64 | QObject::connect(sender: m_backendObject, SIGNAL(availableAudioChannelsChanged()), receiver: q, SIGNAL(availableAudioChannelsChanged())); |
| 65 | QObject::connect(sender: m_backendObject, SIGNAL(titleChanged(int)), receiver: q, SIGNAL(titleChanged(int))); |
| 66 | QObject::connect(sender: m_backendObject, SIGNAL(availableTitlesChanged(int)), receiver: q, SIGNAL(availableTitlesChanged(int))); |
| 67 | QObject::connect(sender: m_backendObject, SIGNAL(chapterChanged(int)), receiver: q, SIGNAL(chapterChanged(int))); |
| 68 | QObject::connect(sender: m_backendObject, SIGNAL(availableChaptersChanged(int)), receiver: q, SIGNAL(availableChaptersChanged(int))); |
| 69 | QObject::connect(sender: m_backendObject, SIGNAL(angleChanged(int)), receiver: q, SIGNAL(angleChanged(int))); |
| 70 | QObject::connect(sender: m_backendObject, SIGNAL(availableAnglesChanged(int)), receiver: q, SIGNAL(availableAnglesChanged(int))); |
| 71 | } |
| 72 | |
| 73 | MediaController::~MediaController() |
| 74 | { |
| 75 | delete d; |
| 76 | } |
| 77 | |
| 78 | #define IFACE \ |
| 79 | AddonInterface *iface = d->iface(); \ |
| 80 | if (!iface) return |
| 81 | |
| 82 | MediaController::Features MediaController::supportedFeatures() const |
| 83 | { |
| 84 | if (!d || !d->media) { |
| 85 | return Features(); |
| 86 | } |
| 87 | IFACE Features(); |
| 88 | Features ret; |
| 89 | if (iface->hasInterface(iface: AddonInterface::AngleInterface)) { |
| 90 | ret |= Angles; |
| 91 | } |
| 92 | if (iface->hasInterface(iface: AddonInterface::ChapterInterface)) { |
| 93 | ret |= Chapters; |
| 94 | } |
| 95 | if (iface->hasInterface(iface: AddonInterface::NavigationInterface)) { |
| 96 | ret |= Navigations; |
| 97 | } |
| 98 | if (iface->hasInterface(iface: AddonInterface::TitleInterface)) { |
| 99 | ret |= Titles; |
| 100 | } |
| 101 | if (iface->hasInterface(iface: AddonInterface::SubtitleInterface)) { |
| 102 | ret |= Subtitles; |
| 103 | } |
| 104 | if(iface->hasInterface(iface: AddonInterface::AudioChannelInterface)) { |
| 105 | ret |= AudioChannels; |
| 106 | } |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | // -- Angle Control -- // |
| 111 | |
| 112 | int MediaController::availableAngles() const |
| 113 | { |
| 114 | IFACE 0; |
| 115 | return iface->interfaceCall(iface: AddonInterface::AngleInterface, |
| 116 | command: AddonInterface::availableAngles).toInt(); |
| 117 | } |
| 118 | |
| 119 | int MediaController::currentAngle() const |
| 120 | { |
| 121 | IFACE 0; |
| 122 | return iface->interfaceCall(iface: AddonInterface::AngleInterface, |
| 123 | command: AddonInterface::angle).toInt(); |
| 124 | } |
| 125 | |
| 126 | void MediaController::setCurrentAngle(int titleNumber) |
| 127 | { |
| 128 | IFACE; |
| 129 | iface->interfaceCall(iface: AddonInterface::AngleInterface, |
| 130 | command: AddonInterface::setAngle, arguments: QList<QVariant>() << QVariant(titleNumber)); |
| 131 | } |
| 132 | |
| 133 | // -- Chapter Control -- // |
| 134 | |
| 135 | int MediaController::availableChapters() const |
| 136 | { |
| 137 | IFACE 0; |
| 138 | return iface->interfaceCall(iface: AddonInterface::ChapterInterface, |
| 139 | command: AddonInterface::availableChapters).toInt(); |
| 140 | } |
| 141 | |
| 142 | int MediaController::currentChapter() const |
| 143 | { |
| 144 | IFACE 0; |
| 145 | return iface->interfaceCall(iface: AddonInterface::ChapterInterface, |
| 146 | command: AddonInterface::chapter).toInt(); |
| 147 | } |
| 148 | |
| 149 | void MediaController::setCurrentChapter(int titleNumber) |
| 150 | { |
| 151 | IFACE; |
| 152 | iface->interfaceCall(iface: AddonInterface::ChapterInterface, |
| 153 | command: AddonInterface::setChapter, arguments: QList<QVariant>() << QVariant(titleNumber)); |
| 154 | } |
| 155 | |
| 156 | // -- Navigation Menu Control -- // |
| 157 | |
| 158 | QString MediaController::(NavigationMenu ) |
| 159 | { |
| 160 | switch (menu) { |
| 161 | case RootMenu: |
| 162 | return tr(s: "Main Menu" ); |
| 163 | case TitleMenu : |
| 164 | return tr(s: "Title Menu" ); |
| 165 | case AudioMenu: |
| 166 | return tr(s: "Audio Menu" ); |
| 167 | case SubtitleMenu: |
| 168 | return tr(s: "Subtitle Menu" ); |
| 169 | case ChapterMenu: |
| 170 | return tr(s: "Chapter Menu" ); |
| 171 | case AngleMenu: |
| 172 | return tr(s: "Angle Menu" ); |
| 173 | } |
| 174 | return QString(); |
| 175 | } |
| 176 | |
| 177 | QList<MediaController::NavigationMenu> MediaController::() const |
| 178 | { |
| 179 | QList<NavigationMenu> ; |
| 180 | IFACE menus; |
| 181 | menus = |
| 182 | iface->interfaceCall(iface: AddonInterface::NavigationInterface, |
| 183 | command: AddonInterface::availableMenus).value< QList<NavigationMenu> >(); |
| 184 | |
| 185 | return menus; |
| 186 | } |
| 187 | |
| 188 | void MediaController::(NavigationMenu ) |
| 189 | { |
| 190 | IFACE; |
| 191 | iface->interfaceCall(iface: AddonInterface::NavigationInterface, |
| 192 | command: AddonInterface::setMenu, arguments: QList<QVariant>() << QVariant::fromValue(value: menu)); |
| 193 | } |
| 194 | // -- Title Control -- // |
| 195 | |
| 196 | int MediaController::availableTitles() const |
| 197 | { |
| 198 | IFACE 0; |
| 199 | return iface->interfaceCall(iface: AddonInterface::TitleInterface, |
| 200 | command: AddonInterface::availableTitles).toInt(); |
| 201 | } |
| 202 | |
| 203 | int MediaController::currentTitle() const |
| 204 | { |
| 205 | IFACE 0; |
| 206 | return iface->interfaceCall(iface: AddonInterface::TitleInterface, |
| 207 | command: AddonInterface::title).toInt(); |
| 208 | } |
| 209 | |
| 210 | void MediaController::setCurrentTitle(int titleNumber) |
| 211 | { |
| 212 | IFACE; |
| 213 | iface->interfaceCall(iface: AddonInterface::TitleInterface, |
| 214 | command: AddonInterface::setTitle, arguments: QList<QVariant>() << QVariant(titleNumber)); |
| 215 | } |
| 216 | |
| 217 | bool MediaController::autoplayTitles() const |
| 218 | { |
| 219 | IFACE true; |
| 220 | return iface->interfaceCall(iface: AddonInterface::TitleInterface, |
| 221 | command: AddonInterface::autoplayTitles).toBool(); |
| 222 | } |
| 223 | |
| 224 | void MediaController::setAutoplayTitles(bool b) |
| 225 | { |
| 226 | IFACE; |
| 227 | iface->interfaceCall(iface: AddonInterface::TitleInterface, |
| 228 | command: AddonInterface::setAutoplayTitles, arguments: QList<QVariant>() << QVariant(b)); |
| 229 | } |
| 230 | |
| 231 | void MediaController::nextTitle() |
| 232 | { |
| 233 | setCurrentTitle(currentTitle() + 1); |
| 234 | } |
| 235 | |
| 236 | void MediaController::previousTitle() |
| 237 | { |
| 238 | setCurrentTitle(currentTitle() - 1); |
| 239 | } |
| 240 | |
| 241 | // -- Audio Channel & Subtitle Control -- // |
| 242 | |
| 243 | AudioChannelDescription MediaController::currentAudioChannel() const |
| 244 | { |
| 245 | IFACE AudioChannelDescription(); |
| 246 | return iface->interfaceCall(iface: AddonInterface::AudioChannelInterface, |
| 247 | command: AddonInterface::currentAudioChannel).value<AudioChannelDescription>(); |
| 248 | } |
| 249 | |
| 250 | bool MediaController::subtitleAutodetect() const |
| 251 | { |
| 252 | IFACE true; |
| 253 | return iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 254 | command: AddonInterface::subtitleAutodetect).toBool(); |
| 255 | } |
| 256 | |
| 257 | void MediaController::setSubtitleAutodetect(bool enable) |
| 258 | { |
| 259 | IFACE; |
| 260 | iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 261 | command: AddonInterface::setSubtitleAutodetect, arguments: QList<QVariant>() << QVariant(enable)); |
| 262 | } |
| 263 | |
| 264 | QString MediaController::subtitleEncoding() const |
| 265 | { |
| 266 | IFACE QString(); |
| 267 | return iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 268 | command: AddonInterface::subtitleEncoding).toString(); |
| 269 | } |
| 270 | |
| 271 | void 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(iface: AddonInterface::SubtitleInterface, |
| 282 | command: AddonInterface::setSubtitleEncoding, arguments: QList<QVariant>() << QVariant(encoding)); |
| 283 | } |
| 284 | |
| 285 | void MediaController::setSubtitleFont(const QFont &font) |
| 286 | { |
| 287 | IFACE; |
| 288 | iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 289 | command: AddonInterface::setSubtitleFont, arguments: QList<QVariant>() << QVariant(font)); |
| 290 | } |
| 291 | |
| 292 | QFont MediaController::subtitleFont() const |
| 293 | { |
| 294 | IFACE QFont(); |
| 295 | return iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 296 | command: AddonInterface::subtitleFont).value<QFont>(); |
| 297 | } |
| 298 | |
| 299 | SubtitleDescription MediaController::currentSubtitle() const |
| 300 | { |
| 301 | IFACE SubtitleDescription(); |
| 302 | return iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 303 | command: AddonInterface::currentSubtitle).value<SubtitleDescription>(); |
| 304 | } |
| 305 | |
| 306 | QList<AudioChannelDescription> MediaController::availableAudioChannels() const |
| 307 | { |
| 308 | QList<AudioChannelDescription> retList; |
| 309 | IFACE retList; |
| 310 | retList = iface->interfaceCall(iface: AddonInterface::AudioChannelInterface, |
| 311 | command: AddonInterface::availableAudioChannels).value< QList<AudioChannelDescription> >(); |
| 312 | return retList; |
| 313 | } |
| 314 | |
| 315 | QList<SubtitleDescription> MediaController::availableSubtitles() const |
| 316 | { |
| 317 | QList<SubtitleDescription> retList; |
| 318 | IFACE retList; |
| 319 | retList = iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 320 | command: AddonInterface::availableSubtitles) |
| 321 | .value< QList<SubtitleDescription> >(); |
| 322 | return retList; |
| 323 | } |
| 324 | |
| 325 | void MediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream) |
| 326 | { |
| 327 | IFACE; |
| 328 | iface->interfaceCall(iface: AddonInterface::AudioChannelInterface, |
| 329 | command: AddonInterface::setCurrentAudioChannel, arguments: QList<QVariant>() << QVariant::fromValue(value: stream)); |
| 330 | } |
| 331 | |
| 332 | void MediaController::setCurrentSubtitle(const Phonon::SubtitleDescription &stream) |
| 333 | { |
| 334 | IFACE; |
| 335 | iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 336 | command: AddonInterface::setCurrentSubtitle, arguments: QList<QVariant>() << QVariant::fromValue(value: stream)); |
| 337 | } |
| 338 | |
| 339 | void MediaController::setCurrentSubtitle(const QUrl &url) |
| 340 | { |
| 341 | IFACE; |
| 342 | iface->interfaceCall(iface: AddonInterface::SubtitleInterface, |
| 343 | command: AddonInterface::setCurrentSubtitleFile, arguments: 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 |
| 355 | |