pause music plugin for Win32

This commit is contained in:
Piyush Aggarwal 2019-08-21 02:38:35 +00:00
parent 4e459f0b30
commit c22c670fee
4 changed files with 178 additions and 3 deletions

View file

@ -32,7 +32,7 @@ if(NOT SAILFISHOS)
add_subdirectory(sftp) add_subdirectory(sftp)
endif() endif()
if(KF5PulseAudioQt_FOUND) if(KF5PulseAudioQt_FOUND OR WIN32)
add_subdirectory(pausemusic) add_subdirectory(pausemusic)
endif() endif()

View file

@ -1,11 +1,25 @@
kdeconnect_add_plugin(kdeconnect_pausemusic JSON kdeconnect_pausemusic.json SOURCES pausemusicplugin.cpp) if(WIN32)
set(kdeconnect_pausemusic_SRCS
pausemusicplugin-win.cpp
)
else()
set(kdeconnect_pausemusic_SRCS
pausemusicplugin.cpp
)
endif()
kdeconnect_add_plugin(kdeconnect_pausemusic JSON kdeconnect_pausemusic.json SOURCES ${kdeconnect_pausemusic_SRCS})
target_link_libraries(kdeconnect_pausemusic target_link_libraries(kdeconnect_pausemusic
kdeconnectcore kdeconnectcore
Qt5::Core Qt5::Core
Qt5::DBus Qt5::DBus
KF5::PulseAudioQt
) )
if (NOT WIN32)
target_link_libraries(kdeconnect_pausemusic
KF5::PulseAudioQt
)
endif()
####################################### #######################################
# Config # Config

View file

@ -0,0 +1,103 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
* Copyright 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "pausemusicplugin-win.h"
#include <KPluginFactory>
K_PLUGIN_CLASS_WITH_JSON(PauseMusicPlugin, "kdeconnect_pausemusic.json")
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PAUSEMUSIC, "kdeconnect.plugin.pausemusic")
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)
{
bool pauseOnlyWhenTalking = config()->get(QStringLiteral("conditionTalking"), false);
if (pauseOnlyWhenTalking) {
if (np.get<QString>(QStringLiteral("event")) != QLatin1String("talking")) {
return true;
}
} else {
if (np.get<QString>(QStringLiteral("event")) != QLatin1String("ringing")
&& np.get<QString>(QStringLiteral("event")) != QLatin1String("talking")) {
return true;
}
}
bool pauseConditionFulfilled = !np.get<bool>(QStringLiteral("isCancel"));
bool pause = config()->get(QStringLiteral("actionPause"), false);
bool mute = config()->get(QStringLiteral("actionMute"), true);
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";
endpointVolume->SetMute(FALSE, &g_guidMyContext);
}
if (pause) {
// TODO UNPAUSING
}
}
return true;
}
#include "pausemusicplugin-win.moc"

View file

@ -0,0 +1,58 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
* Copyright 2019 Piyush Aggarwal <piyushaggarwal002@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PAUSEMUSICPLUGINWIN_H
#define PAUSEMUSICPLUGINWIN_H
#include <QObject>
#include <QSet>
#include <QString>
#include <core/kdeconnectplugin.h>
#include <QLoggingCategory>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PAUSEMUSIC)
class PauseMusicPlugin
: public KdeConnectPlugin
{
Q_OBJECT
public:
explicit PauseMusicPlugin(QObject* parent, const QVariantList& args);
~PauseMusicPlugin();
bool receivePacket(const NetworkPacket& np) override;
void connected() override { }
private:
IMMDeviceEnumerator *deviceEnumerator;
IMMDevice *defaultDevice;
GUID g_guidMyContext;
IAudioEndpointVolume *endpointVolume;
};
#endif // PAUSEMUSICPLUGINWIN_H