File indexing completed on 2024-04-28 16:01:47
0001 /* 0002 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 0003 Copyright (C) 2008 Ian Monroe <ian@monroe.nu> 0004 Copyright (C) 2011 Harald Sitter <sitter@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Lesser General Public 0008 License as published by the Free Software Foundation; either 0009 version 2.1 of the License, or (at your option) version 3, or any 0010 later version accepted by the membership of KDE e.V. (or its 0011 successor approved by the membership of KDE e.V.), Nokia Corporation 0012 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0013 act as a proxy defined in Section 6 of version 3 of the license. 0014 0015 This library is distributed in the hope that it will be useful, 0016 but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0018 Lesser General Public License for more details. 0019 0020 You should have received a copy of the GNU Lesser General Public 0021 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0022 0023 */ 0024 0025 #include "mediacontroller.h" 0026 #include "mediaobject.h" 0027 #include "addoninterface.h" 0028 #include <QList> 0029 #include <QVariant> 0030 #include <QTextCodec> 0031 #include <QFont> 0032 #include "frontendinterface_p.h" 0033 0034 #ifndef QT_NO_PHONON_MEDIACONTROLLER 0035 0036 namespace Phonon 0037 { 0038 0039 class MediaControllerPrivate : public FrontendInterfacePrivate 0040 { 0041 public: 0042 MediaControllerPrivate(MediaObject *mp) : FrontendInterfacePrivate(mp) {} 0043 0044 void backendObjectChanged(QObject *) override; 0045 MediaController *q; 0046 }; 0047 0048 MediaController::MediaController(MediaObject *mp) 0049 : QObject(mp) 0050 , d(new MediaControllerPrivate(mp)) 0051 { 0052 d->q = this; 0053 d->_backendObjectChanged(); 0054 setSubtitleAutodetect(true); 0055 } 0056 0057 void MediaControllerPrivate::backendObjectChanged(QObject *m_backendObject) 0058 { 0059 QObject::connect(m_backendObject, SIGNAL(availableSubtitlesChanged()), q, SIGNAL(availableSubtitlesChanged())); 0060 QObject::connect(m_backendObject, SIGNAL(availableAudioChannelsChanged()), q, SIGNAL(availableAudioChannelsChanged())); 0061 QObject::connect(m_backendObject, SIGNAL(titleChanged(int)), q, SIGNAL(titleChanged(int))); 0062 QObject::connect(m_backendObject, SIGNAL(availableTitlesChanged(int)), q, SIGNAL(availableTitlesChanged(int))); 0063 QObject::connect(m_backendObject, SIGNAL(chapterChanged(int)), q, SIGNAL(chapterChanged(int))); 0064 QObject::connect(m_backendObject, SIGNAL(availableChaptersChanged(int)), q, SIGNAL(availableChaptersChanged(int))); 0065 QObject::connect(m_backendObject, SIGNAL(angleChanged(int)), q, SIGNAL(angleChanged(int))); 0066 QObject::connect(m_backendObject, SIGNAL(availableAnglesChanged(int)), q, SIGNAL(availableAnglesChanged(int))); 0067 } 0068 0069 MediaController::~MediaController() 0070 { 0071 delete d; 0072 } 0073 0074 #define IFACE \ 0075 AddonInterface *iface = d->iface(); \ 0076 if (!iface) return 0077 0078 MediaController::Features MediaController::supportedFeatures() const 0079 { 0080 if (!d || !d->media) { 0081 return Features(); 0082 } 0083 IFACE Features(); 0084 Features ret; 0085 if (iface->hasInterface(AddonInterface::AngleInterface)) { 0086 ret |= Angles; 0087 } 0088 if (iface->hasInterface(AddonInterface::ChapterInterface)) { 0089 ret |= Chapters; 0090 } 0091 if (iface->hasInterface(AddonInterface::NavigationInterface)) { 0092 ret |= Navigations; 0093 } 0094 if (iface->hasInterface(AddonInterface::TitleInterface)) { 0095 ret |= Titles; 0096 } 0097 if (iface->hasInterface(AddonInterface::SubtitleInterface)) { 0098 ret |= Subtitles; 0099 } 0100 if(iface->hasInterface(AddonInterface::AudioChannelInterface)) { 0101 ret |= AudioChannels; 0102 } 0103 return ret; 0104 } 0105 0106 // -- Angle Control -- // 0107 0108 int MediaController::availableAngles() const 0109 { 0110 IFACE 0; 0111 return iface->interfaceCall(AddonInterface::AngleInterface, 0112 AddonInterface::availableAngles).toInt(); 0113 } 0114 0115 int MediaController::currentAngle() const 0116 { 0117 IFACE 0; 0118 return iface->interfaceCall(AddonInterface::AngleInterface, 0119 AddonInterface::angle).toInt(); 0120 } 0121 0122 void MediaController::setCurrentAngle(int titleNumber) 0123 { 0124 IFACE; 0125 iface->interfaceCall(AddonInterface::AngleInterface, 0126 AddonInterface::setAngle, QList<QVariant>() << QVariant(titleNumber)); 0127 } 0128 0129 // -- Chapter Control -- // 0130 0131 int MediaController::availableChapters() const 0132 { 0133 IFACE 0; 0134 return iface->interfaceCall(AddonInterface::ChapterInterface, 0135 AddonInterface::availableChapters).toInt(); 0136 } 0137 0138 int MediaController::currentChapter() const 0139 { 0140 IFACE 0; 0141 return iface->interfaceCall(AddonInterface::ChapterInterface, 0142 AddonInterface::chapter).toInt(); 0143 } 0144 0145 void MediaController::setCurrentChapter(int titleNumber) 0146 { 0147 IFACE; 0148 iface->interfaceCall(AddonInterface::ChapterInterface, 0149 AddonInterface::setChapter, QList<QVariant>() << QVariant(titleNumber)); 0150 } 0151 0152 // -- Navigation Menu Control -- // 0153 0154 QString MediaController::navigationMenuToString(NavigationMenu menu) 0155 { 0156 switch (menu) { 0157 case RootMenu: 0158 return tr("Main Menu"); 0159 case TitleMenu : 0160 return tr("Title Menu"); 0161 case AudioMenu: 0162 return tr("Audio Menu"); 0163 case SubtitleMenu: 0164 return tr("Subtitle Menu"); 0165 case ChapterMenu: 0166 return tr("Chapter Menu"); 0167 case AngleMenu: 0168 return tr("Angle Menu"); 0169 } 0170 return QString(); 0171 } 0172 0173 QList<MediaController::NavigationMenu> MediaController::availableMenus() const 0174 { 0175 QList<NavigationMenu> menus; 0176 IFACE menus; 0177 menus = 0178 iface->interfaceCall(AddonInterface::NavigationInterface, 0179 AddonInterface::availableMenus).value< QList<NavigationMenu> >(); 0180 0181 return menus; 0182 } 0183 0184 void MediaController::setCurrentMenu(NavigationMenu menu) 0185 { 0186 IFACE; 0187 iface->interfaceCall(AddonInterface::NavigationInterface, 0188 AddonInterface::setMenu, QList<QVariant>() << QVariant::fromValue(menu)); 0189 } 0190 // -- Title Control -- // 0191 0192 int MediaController::availableTitles() const 0193 { 0194 IFACE 0; 0195 return iface->interfaceCall(AddonInterface::TitleInterface, 0196 AddonInterface::availableTitles).toInt(); 0197 } 0198 0199 int MediaController::currentTitle() const 0200 { 0201 IFACE 0; 0202 return iface->interfaceCall(AddonInterface::TitleInterface, 0203 AddonInterface::title).toInt(); 0204 } 0205 0206 void MediaController::setCurrentTitle(int titleNumber) 0207 { 0208 IFACE; 0209 iface->interfaceCall(AddonInterface::TitleInterface, 0210 AddonInterface::setTitle, QList<QVariant>() << QVariant(titleNumber)); 0211 } 0212 0213 bool MediaController::autoplayTitles() const 0214 { 0215 IFACE true; 0216 return iface->interfaceCall(AddonInterface::TitleInterface, 0217 AddonInterface::autoplayTitles).toBool(); 0218 } 0219 0220 void MediaController::setAutoplayTitles(bool b) 0221 { 0222 IFACE; 0223 iface->interfaceCall(AddonInterface::TitleInterface, 0224 AddonInterface::setAutoplayTitles, QList<QVariant>() << QVariant(b)); 0225 } 0226 0227 void MediaController::nextTitle() 0228 { 0229 setCurrentTitle(currentTitle() + 1); 0230 } 0231 0232 void MediaController::previousTitle() 0233 { 0234 setCurrentTitle(currentTitle() - 1); 0235 } 0236 0237 // -- Audio Channel & Subtitle Control -- // 0238 0239 AudioChannelDescription MediaController::currentAudioChannel() const 0240 { 0241 IFACE AudioChannelDescription(); 0242 return iface->interfaceCall(AddonInterface::AudioChannelInterface, 0243 AddonInterface::currentAudioChannel).value<AudioChannelDescription>(); 0244 } 0245 0246 bool MediaController::subtitleAutodetect() const 0247 { 0248 IFACE true; 0249 return iface->interfaceCall(AddonInterface::SubtitleInterface, 0250 AddonInterface::subtitleAutodetect).toBool(); 0251 } 0252 0253 void MediaController::setSubtitleAutodetect(bool enable) 0254 { 0255 IFACE; 0256 iface->interfaceCall(AddonInterface::SubtitleInterface, 0257 AddonInterface::setSubtitleAutodetect, QList<QVariant>() << QVariant(enable)); 0258 } 0259 0260 QString MediaController::subtitleEncoding() const 0261 { 0262 IFACE QString(); 0263 return iface->interfaceCall(AddonInterface::SubtitleInterface, 0264 AddonInterface::subtitleEncoding).toString(); 0265 } 0266 0267 void MediaController::setSubtitleEncoding(const QString &encoding) 0268 { 0269 IFACE; 0270 if (!QTextCodec::availableCodecs().contains(encoding.toLocal8Bit())) 0271 return; 0272 iface->interfaceCall(AddonInterface::SubtitleInterface, 0273 AddonInterface::setSubtitleEncoding, QList<QVariant>() << QVariant(encoding)); 0274 } 0275 0276 void MediaController::setSubtitleFont(const QFont &font) 0277 { 0278 IFACE; 0279 iface->interfaceCall(AddonInterface::SubtitleInterface, 0280 AddonInterface::setSubtitleFont, QList<QVariant>() << QVariant(font)); 0281 } 0282 0283 QFont MediaController::subtitleFont() const 0284 { 0285 IFACE QFont(); 0286 return iface->interfaceCall(AddonInterface::SubtitleInterface, 0287 AddonInterface::subtitleFont).value<QFont>(); 0288 } 0289 0290 SubtitleDescription MediaController::currentSubtitle() const 0291 { 0292 IFACE SubtitleDescription(); 0293 return iface->interfaceCall(AddonInterface::SubtitleInterface, 0294 AddonInterface::currentSubtitle).value<SubtitleDescription>(); 0295 } 0296 0297 QList<AudioChannelDescription> MediaController::availableAudioChannels() const 0298 { 0299 QList<AudioChannelDescription> retList; 0300 IFACE retList; 0301 retList = iface->interfaceCall(AddonInterface::AudioChannelInterface, 0302 AddonInterface::availableAudioChannels).value< QList<AudioChannelDescription> >(); 0303 return retList; 0304 } 0305 0306 QList<SubtitleDescription> MediaController::availableSubtitles() const 0307 { 0308 QList<SubtitleDescription> retList; 0309 IFACE retList; 0310 retList = iface->interfaceCall(AddonInterface::SubtitleInterface, 0311 AddonInterface::availableSubtitles) 0312 .value< QList<SubtitleDescription> >(); 0313 return retList; 0314 } 0315 0316 void MediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription &stream) 0317 { 0318 IFACE; 0319 iface->interfaceCall(AddonInterface::AudioChannelInterface, 0320 AddonInterface::setCurrentAudioChannel, QList<QVariant>() << QVariant::fromValue(stream)); 0321 } 0322 0323 void MediaController::setCurrentSubtitle(const Phonon::SubtitleDescription &stream) 0324 { 0325 IFACE; 0326 iface->interfaceCall(AddonInterface::SubtitleInterface, 0327 AddonInterface::setCurrentSubtitle, QList<QVariant>() << QVariant::fromValue(stream)); 0328 } 0329 0330 void MediaController::setCurrentSubtitle(const QUrl &url) 0331 { 0332 IFACE; 0333 iface->interfaceCall(AddonInterface::SubtitleInterface, 0334 AddonInterface::setCurrentSubtitleFile, QList<QVariant>() << url); 0335 } 0336 0337 #undef IFACE 0338 0339 } // namespace Phonon 0340 0341 #endif //QT_NO_PHONON_MEDIACONTROLLER 0342 0343 #include "moc_mediacontroller.cpp" 0344 0345 // vim: sw=4 sts=4 et tw=100