File indexing completed on 2024-05-12 05:38:16

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Matthias Kretz <kretz@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #include "kdeplatformplugin.h"
0008 
0009 #include <QCoreApplication>
0010 #include <QDir>
0011 #include <QFile>
0012 #include <QtPlugin>
0013 
0014 #include <KAboutData>
0015 #include <KConfigGroup>
0016 #include <KLocalizedString>
0017 #include <KMessageBox>
0018 #include <KNotification>
0019 #include <KSharedConfig>
0020 
0021 #include "debug.h"
0022 #include "kiomediastream.h"
0023 
0024 namespace Phonon
0025 {
0026 KdePlatformPlugin::KdePlatformPlugin()
0027 {
0028 }
0029 
0030 KdePlatformPlugin::~KdePlatformPlugin()
0031 {
0032 }
0033 
0034 AbstractMediaStream *KdePlatformPlugin::createMediaStream(const QUrl &url, QObject *parent)
0035 {
0036     return new KioMediaStream(url, parent);
0037 }
0038 
0039 QIcon KdePlatformPlugin::icon(const QString &name) const
0040 {
0041     return QIcon::fromTheme(name);
0042 }
0043 
0044 void KdePlatformPlugin::notification(const char *notificationName,
0045                                      const QString &text,
0046                                      const QStringList &actions,
0047                                      QObject *receiver,
0048                                      const char *actionSlot) const
0049 {
0050     KNotification *notification = new KNotification(notificationName);
0051     notification->setComponentName(QLatin1String("phonon"));
0052     notification->setText(text);
0053     if (!actions.isEmpty() && receiver && actionSlot) {
0054         int actionIndex = 1;
0055         for (const QString &actionName : actions) {
0056             KNotificationAction *action = notification->addAction(actionName);
0057 
0058             connect(action, &KNotificationAction::activated, this, [receiver, actionSlot, actionIndex] {
0059                 QMetaObject::invokeMethod(receiver, actionSlot, actionIndex);
0060             });
0061 
0062             ++actionIndex;
0063         }
0064     }
0065     notification->sendEvent();
0066 }
0067 
0068 QString KdePlatformPlugin::applicationName() const
0069 {
0070     KAboutData aboutData = KAboutData::applicationData();
0071     if (!aboutData.displayName().isEmpty()) {
0072         return aboutData.displayName();
0073     }
0074     if (!aboutData.componentName().isEmpty()) {
0075         return aboutData.componentName();
0076     }
0077     // FIXME: why was this not localized?
0078     return QLatin1String("Qt Application");
0079 }
0080 
0081 // Phonon4Qt5 internally implements backend lookup an creation. Driving it
0082 // through KService is not practical because Phonon4Qt5 lacks appropriate
0083 // wiring to frameworks.
0084 
0085 QObject *KdePlatformPlugin::createBackend()
0086 {
0087     return nullptr;
0088 }
0089 
0090 QObject *KdePlatformPlugin::createBackend(const QString & /*library*/, const QString & /*version*/)
0091 {
0092     return nullptr;
0093 }
0094 
0095 bool KdePlatformPlugin::isMimeTypeAvailable(const QString & /*mimeType*/) const
0096 {
0097     // Static mimetype based support reporting is utter nonsense, so always say
0098     // everything is supported.
0099     // In particular there's two problems
0100     // 1. mimetypes do not map well to actual formats because the majority of
0101     //    files these days are containers that can contain arbitrary content
0102     //    streams, so mimetypes are too generic to properly define supportedness.
0103     // 2. just about every multimedia library in the world draws format support
0104     //    from a plugin based architecture which means that technically everything
0105     //    can support anything as long as there is a plugin and/or the means to
0106     //    install a plugin.
0107     // So, always say every mimetype is supported.
0108     // Phonon5 will do away with all mentionings of mimetypes as well.
0109     return true;
0110 }
0111 
0112 // Volume restoration is a capability that will also be removed in Phonon5.
0113 // For proper restoration capabilities the actual platform will be used (e.g.
0114 // PulseAudio on Linux will remember streams and correctly restore the volume).
0115 
0116 void KdePlatformPlugin::saveVolume(const QString &outputName, qreal volume)
0117 {
0118     KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("Phonon::AudioOutput"));
0119     config.writeEntry(outputName + "_Volume", volume);
0120 }
0121 
0122 qreal KdePlatformPlugin::loadVolume(const QString &outputName) const
0123 {
0124     KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("Phonon::AudioOutput"));
0125     return config.readEntry<qreal>(outputName + "_Volume", 1.0);
0126 }
0127 
0128 QList<int> KdePlatformPlugin::objectDescriptionIndexes(ObjectDescriptionType type) const
0129 {
0130     switch (type) {
0131     case AudioOutputDeviceType:
0132     case AudioCaptureDeviceType:
0133     case VideoCaptureDeviceType:
0134     default:
0135         return QList<int>();
0136     }
0137 }
0138 
0139 QHash<QByteArray, QVariant> KdePlatformPlugin::objectDescriptionProperties(ObjectDescriptionType type, int index) const
0140 {
0141     Q_UNUSED(index);
0142     switch (type) {
0143     case AudioOutputDeviceType:
0144     case AudioCaptureDeviceType:
0145     case VideoCaptureDeviceType:
0146     default:
0147         return QHash<QByteArray, QVariant>();
0148     }
0149 }
0150 
0151 } // namespace Phonon