File indexing completed on 2024-04-21 04:43:18

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation 
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public 
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #include "platform_p.h"
0024 #include "platformplugin.h"
0025 #include "factory_p.h"
0026 #include <QCoreApplication>
0027 #include <QUrl>
0028 #include <QIcon>
0029 #include <QStyle>
0030 #include <QApplication>
0031 
0032 namespace Phonon
0033 {
0034 
0035 void Platform::saveVolume(const QString &outputName, qreal volume)
0036 {
0037 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0038     PlatformPlugin *f = Factory::platformPlugin();
0039     if (f) {
0040         f->saveVolume(outputName, volume);
0041     }
0042 #else
0043     Q_UNUSED(outputName);
0044     Q_UNUSED(volume);
0045 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0046 }
0047 
0048 qreal Platform::loadVolume(const QString &outputName)
0049 {
0050 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0051     const PlatformPlugin *f = Factory::platformPlugin();
0052     if (f) {
0053         return f->loadVolume(outputName);
0054     }
0055 #else
0056     Q_UNUSED(outputName);
0057 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0058     return 1.0;
0059 }
0060 
0061 AbstractMediaStream *Platform::createMediaStream(const QUrl &url, QObject *parent)
0062 {
0063 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0064     PlatformPlugin *f = Factory::platformPlugin();
0065     if (f) {
0066         return f->createMediaStream(url, parent);
0067     }
0068 #else
0069     Q_UNUSED(url);
0070     Q_UNUSED(parent);
0071 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0072     return nullptr;
0073 }
0074 
0075 QIcon Platform::icon(const QString &name, QStyle *style)
0076 {
0077     QIcon ret;
0078 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0079     if (const PlatformPlugin *f = Factory::platformPlugin()) {
0080         ret = f->icon(name);
0081     }
0082 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0083 
0084     // No platform plugin present. Use internal versions.
0085     if (ret.isNull()) {
0086         if (!style) {
0087             style = QApplication::style();
0088         }
0089         if (name == QLatin1String("player-volume")) {
0090             ret = style->standardPixmap(QStyle::SP_MediaVolume);
0091         } else if (name == QLatin1String("player-volume-muted")) {
0092             ret = style->standardPixmap(QStyle::SP_MediaVolumeMuted);
0093         }
0094     }
0095 
0096     // Still no icon set. Use QIcon to access the platform theme.
0097     if (ret.isNull())
0098         ret = QIcon::fromTheme(name);
0099 
0100     // Now we are getting angry... keep dropping '-foo' parts from the end of
0101     // the name until we get something usable or run out of substrings.
0102     // (this is a simplified version of fallback lookup as done by KIconLoader;
0103     //  essentially audio-card-pci can also be provided by audio-card which is
0104     //  the more generic version).
0105     QString choppedName = name;
0106     while (ret.isNull() && !choppedName.isEmpty()) {
0107         choppedName.resize(choppedName.lastIndexOf(QChar('-')));
0108         ret = QIcon::fromTheme(choppedName);
0109     }
0110 
0111     return ret;
0112 }
0113 
0114 void Platform::notification(const char *notificationName, const QString &text,
0115         const QStringList &actions, QObject *receiver,
0116         const char *actionSlot)
0117 {
0118 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0119     const PlatformPlugin *f = Factory::platformPlugin();
0120     if (f) {
0121         f->notification(notificationName, text, actions, receiver, actionSlot);
0122     }
0123 #else
0124     Q_UNUSED(notificationName);
0125     Q_UNUSED(text);
0126     Q_UNUSED(actions);
0127     Q_UNUSED(receiver);
0128     Q_UNUSED(actionSlot);
0129 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0130 }
0131 
0132 QString Platform::applicationName()
0133 {
0134 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0135     const PlatformPlugin *f = Factory::platformPlugin();
0136     if (f) {
0137         return f->applicationName();
0138     }
0139 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0140     QString ret = QCoreApplication::applicationName();
0141     if (ret.isEmpty())
0142         ret = QCoreApplication::applicationFilePath();
0143     return ret;
0144 }
0145 
0146 QList<QPair<QByteArray, QString> > Platform::deviceAccessListFor(const Phonon::AudioOutputDevice &deviceDesc)
0147 {
0148 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
0149     const PlatformPlugin *f = Factory::platformPlugin();
0150     if (f) {
0151         return f->deviceAccessListFor(deviceDesc);
0152     }
0153 #endif //QT_NO_PHONON_PLATFORMPLUGIN
0154     return QList<QPair<QByteArray, QString> >();
0155 }
0156 
0157 } // namespace Phonon