Warning, file /plasma/plasma-workspace/phonon/platform_kde/kdeplatformplugin.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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     notification->addContext(QLatin1String("Application"), KAboutData::applicationData().componentName());
0054     if (!actions.isEmpty() && receiver && actionSlot) {
0055         notification->setActions(actions);
0056         QObject::connect(notification, SIGNAL(activated(unsigned int)), receiver, actionSlot);
0057     }
0058     notification->sendEvent();
0059 }
0060 
0061 QString KdePlatformPlugin::applicationName() const
0062 {
0063     KAboutData aboutData = KAboutData::applicationData();
0064     if (!aboutData.displayName().isEmpty()) {
0065         return aboutData.displayName();
0066     }
0067     if (!aboutData.componentName().isEmpty()) {
0068         return aboutData.componentName();
0069     }
0070     // FIXME: why was this not localized?
0071     return QLatin1String("Qt Application");
0072 }
0073 
0074 // Phonon4Qt5 internally implements backend lookup an creation. Driving it
0075 // through KService is not practical because Phonon4Qt5 lacks appropriate
0076 // wiring to frameworks.
0077 
0078 QObject *KdePlatformPlugin::createBackend()
0079 {
0080     return nullptr;
0081 }
0082 
0083 QObject *KdePlatformPlugin::createBackend(const QString & /*library*/, const QString & /*version*/)
0084 {
0085     return nullptr;
0086 }
0087 
0088 bool KdePlatformPlugin::isMimeTypeAvailable(const QString & /*mimeType*/) const
0089 {
0090     // Static mimetype based support reporting is utter nonsense, so always say
0091     // everything is supported.
0092     // In particular there's two problems
0093     // 1. mimetypes do not map well to actual formats because the majority of
0094     //    files these days are containers that can contain arbitrary content
0095     //    streams, so mimetypes are too generic to properly define supportedness.
0096     // 2. just about every multimedia library in the world draws format support
0097     //    from a plugin based architecture which means that technically everything
0098     //    can support anything as long as there is a plugin and/or the means to
0099     //    install a plugin.
0100     // So, always say every mimetype is supported.
0101     // Phonon5 will do away with all mentionings of mimetypes as well.
0102     return true;
0103 }
0104 
0105 // Volume restoration is a capability that will also be removed in Phonon5.
0106 // For proper restoration capabilities the actual platform will be used (e.g.
0107 // PulseAudio on Linux will remember streams and correctly restore the volume).
0108 
0109 void KdePlatformPlugin::saveVolume(const QString &outputName, qreal volume)
0110 {
0111     KConfigGroup config(KSharedConfig::openConfig(), "Phonon::AudioOutput");
0112     config.writeEntry(outputName + "_Volume", volume);
0113 }
0114 
0115 qreal KdePlatformPlugin::loadVolume(const QString &outputName) const
0116 {
0117     KConfigGroup config(KSharedConfig::openConfig(), "Phonon::AudioOutput");
0118     return config.readEntry<qreal>(outputName + "_Volume", 1.0);
0119 }
0120 
0121 QList<int> KdePlatformPlugin::objectDescriptionIndexes(ObjectDescriptionType type) const
0122 {
0123     switch (type) {
0124     case AudioOutputDeviceType:
0125     case AudioCaptureDeviceType:
0126     case VideoCaptureDeviceType:
0127     default:
0128         return QList<int>();
0129     }
0130 }
0131 
0132 QHash<QByteArray, QVariant> KdePlatformPlugin::objectDescriptionProperties(ObjectDescriptionType type, int index) const
0133 {
0134     Q_UNUSED(index);
0135     switch (type) {
0136     case AudioOutputDeviceType:
0137     case AudioCaptureDeviceType:
0138     case VideoCaptureDeviceType:
0139     default:
0140         return QHash<QByteArray, QVariant>();
0141     }
0142 }
0143 
0144 } // namespace Phonon