2019-08-21 03:38:35 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
2019-08-21 03:38:35 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-08-21 03:38:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pausemusicplugin-win.h"
|
|
|
|
|
|
|
|
#include <KPluginFactory>
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_pausemusic_debug.h"
|
2019-08-21 03:38:35 +01:00
|
|
|
|
|
|
|
K_PLUGIN_CLASS_WITH_JSON(PauseMusicPlugin, "kdeconnect_pausemusic.json")
|
|
|
|
|
|
|
|
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
deviceEnumerator = NULL;
|
|
|
|
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
|
|
|
|
defaultDevice = NULL;
|
|
|
|
g_guidMyContext = GUID_NULL;
|
|
|
|
|
|
|
|
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
|
|
|
|
deviceEnumerator->Release();
|
|
|
|
deviceEnumerator = NULL;
|
|
|
|
|
|
|
|
endpointVolume = NULL;
|
|
|
|
defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
|
|
|
|
defaultDevice->Release();
|
|
|
|
defaultDevice = NULL;
|
|
|
|
CoCreateGuid(&g_guidMyContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
PauseMusicPlugin::~PauseMusicPlugin()
|
|
|
|
{
|
|
|
|
endpointVolume->Release();
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
|
|
|
|
{
|
|
|
|
|
2020-09-09 23:24:36 +01:00
|
|
|
bool pauseOnlyWhenTalking = config()->getBool(QStringLiteral("conditionTalking"), false);
|
2019-08-21 03:38:35 +01:00
|
|
|
|
|
|
|
if (pauseOnlyWhenTalking) {
|
2020-09-09 23:34:31 +01:00
|
|
|
if (np.get<QString>(QStringLiteral("event")) != QLatin1String("talking")) {
|
2019-08-21 03:38:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-09 23:34:31 +01:00
|
|
|
if (np.get<QString>(QStringLiteral("event")) != QLatin1String("ringing")
|
|
|
|
&& np.get<QString>(QStringLiteral("event")) != QLatin1String("talking")) {
|
2019-08-21 03:38:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 23:34:31 +01:00
|
|
|
bool pauseConditionFulfilled = !np.get<bool>(QStringLiteral("isCancel"));
|
2019-08-21 03:38:35 +01:00
|
|
|
|
2020-09-09 23:24:36 +01:00
|
|
|
bool pause = config()->getBool(QStringLiteral("actionPause"), false);
|
|
|
|
bool mute = config()->getBool(QStringLiteral("actionMute"), true);
|
2019-08-21 03:38:35 +01:00
|
|
|
|
2020-09-09 23:24:36 +01:00
|
|
|
const bool autoResume = config()->getBool(QStringLiteral("actionResume"), true);
|
2020-05-20 22:44:33 +01:00
|
|
|
|
2019-08-21 03:38:35 +01:00
|
|
|
if (pauseConditionFulfilled) {
|
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Muting music";
|
|
|
|
endpointVolume->SetMute(TRUE, &g_guidMyContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pause) {
|
|
|
|
// TODO PAUSING
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume";
|
2020-05-20 22:44:33 +01:00
|
|
|
if (autoResume) {
|
|
|
|
endpointVolume->SetMute(FALSE, &g_guidMyContext);
|
|
|
|
}
|
2019-08-21 03:38:35 +01:00
|
|
|
}
|
|
|
|
if (pause) {
|
|
|
|
// TODO UNPAUSING
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "pausemusicplugin-win.moc"
|