File indexing completed on 2024-03-03 05:48:31

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
0003     SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "plugin.h"
0009 
0010 #include <QQmlEngine>
0011 
0012 #include "client.h"
0013 #include "context.h"
0014 #include "modulemanager.h"
0015 #include "port.h"
0016 #include "profile.h"
0017 #include "pulseaudio.h"
0018 #include "sink.h"
0019 #include "source.h"
0020 #include "volumemonitor.h"
0021 
0022 #include "globalactioncollection.h"
0023 #include "globalconfig.h"
0024 #include "listitemmenu.h"
0025 #include "microphoneindicator.h"
0026 #include "speakertest.h"
0027 #include "volumefeedback.h"
0028 #include "volumeosd.h"
0029 
0030 static QJSValue pulseaudio_singleton(QQmlEngine *engine, QJSEngine *scriptEngine)
0031 {
0032     Q_UNUSED(engine)
0033 
0034     QJSValue object = scriptEngine->newObject();
0035     object.setProperty(QStringLiteral("NormalVolume"), (double)QPulseAudio::Context::NormalVolume);
0036     object.setProperty(QStringLiteral("MinimalVolume"), (double)QPulseAudio::Context::MinimalVolume);
0037     object.setProperty(QStringLiteral("MaximalVolume"), (double)QPulseAudio::Context::MaximalVolume);
0038     return object;
0039 }
0040 
0041 void Plugin::registerTypes(const char *uri)
0042 {
0043     QPulseAudio::Context::setApplicationId(QStringLiteral("org.kde.plasma-pa"));
0044 
0045     qmlRegisterType<QPulseAudio::CardModel>(uri, 0, 1, "CardModel");
0046     qmlRegisterType<QPulseAudio::SinkModel>(uri, 0, 1, "SinkModel");
0047     qmlRegisterType<QPulseAudio::SinkInputModel>(uri, 0, 1, "SinkInputModel");
0048     qmlRegisterType<QPulseAudio::SourceModel>(uri, 0, 1, "SourceModel");
0049     qmlRegisterType<QPulseAudio::ModuleManager>(uri, 0, 1, "ModuleManager");
0050     qmlRegisterType<QPulseAudio::SourceOutputModel>(uri, 0, 1, "SourceOutputModel");
0051     qmlRegisterType<QPulseAudio::StreamRestoreModel>(uri, 0, 1, "StreamRestoreModel");
0052     qmlRegisterType<QPulseAudio::ModuleModel>(uri, 0, 1, "ModuleModel");
0053     qmlRegisterType<QPulseAudio::VolumeMonitor>(uri, 0, 1, "VolumeMonitor");
0054     qmlRegisterUncreatableType<QPulseAudio::VolumeObject>(uri, 0, 1, "VolumeObject", QString());
0055     qmlRegisterUncreatableType<QPulseAudio::PulseObject>(uri, 0, 1, "PulseObject", QString());
0056     qmlRegisterUncreatableType<QPulseAudio::Profile>(uri, 0, 1, "Profile", QString());
0057     qmlRegisterUncreatableType<QPulseAudio::Port>(uri, 0, 1, "Port", QString());
0058     qmlRegisterType<GlobalAction>(uri, 0, 1, "GlobalAction");
0059     qmlRegisterType<GlobalActionCollection>(uri, 0, 1, "GlobalActionCollection");
0060     qmlRegisterType<ListItemMenu>(uri, 0, 1, "ListItemMenu");
0061     qmlRegisterType<VolumeOSD>(uri, 0, 1, "VolumeOSD");
0062     qmlRegisterType<VolumeFeedback>(uri, 0, 1, "VolumeFeedback");
0063     qmlRegisterType<SpeakerTest>(uri, 0, 1, "SpeakerTest");
0064     qmlRegisterType<GlobalConfig>(uri, 0, 1, "GlobalConfig");
0065     qmlRegisterSingletonType(uri, 0, 1, "PulseAudio", pulseaudio_singleton);
0066     qmlRegisterSingletonType<MicrophoneIndicator>(uri, 0, 1, "MicrophoneIndicator", [](QQmlEngine *engine, QJSEngine *jsEngine) -> QObject * {
0067         Q_UNUSED(engine);
0068         Q_UNUSED(jsEngine);
0069         return new MicrophoneIndicator();
0070     });
0071     qmlRegisterAnonymousType<QPulseAudio::Client>(uri, 1);
0072     qmlRegisterAnonymousType<QPulseAudio::Sink>(uri, 1);
0073     qmlRegisterAnonymousType<QPulseAudio::Source>(uri, 1);
0074 }