Add DBUS support for media keys
This commit is contained in:
@@ -68,8 +68,15 @@ unix:!macx {
|
|||||||
SOURCES += src/keyboard_input/input_sender_dummy.cpp
|
SOURCES += src/keyboard_input/input_sender_dummy.cpp
|
||||||
}
|
}
|
||||||
|
|
||||||
SOURCES += src/tabcontrollers/audiomanager/AudioManagerDummy.cpp \
|
!noDBUS {
|
||||||
src/media_keys/media_keys_dummy.cpp
|
SOURCES += src/media_keys/media_keys_dbus.cpp
|
||||||
|
QT += dbus
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SOURCES += src/media_keys/media_keys_dummy.cpp
|
||||||
|
}
|
||||||
|
|
||||||
|
SOURCES += src/tabcontrollers/audiomanager/AudioManagerDummy.cpp
|
||||||
HEADERS += src/tabcontrollers/audiomanager/AudioManagerDummy.h
|
HEADERS += src/tabcontrollers/audiomanager/AudioManagerDummy.h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <easylogging++.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#include "media_keys.h"
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtDBus/QtDBus>
|
||||||
|
|
||||||
|
namespace keyboardinput
|
||||||
|
{
|
||||||
|
void callMethodForAllMediaPlayerAvailableServices( const QString& method )
|
||||||
|
{
|
||||||
|
if ( !QDBusConnection::sessionBus().isConnected() )
|
||||||
|
{
|
||||||
|
LOG( ERROR ) << "Media Keys: Unable to connect to DBUS session bus.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDBusReply<QStringList> names
|
||||||
|
= QDBusConnection::sessionBus().interface()->registeredServiceNames();
|
||||||
|
if ( !names.isValid() )
|
||||||
|
{
|
||||||
|
LOG( ERROR )
|
||||||
|
<< "Media Keys: Error getting DBUS registered service names:";
|
||||||
|
LOG( ERROR ) << names.error().message();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( QString name, names.value() )
|
||||||
|
{
|
||||||
|
if ( name.contains( "org.mpris.MediaPlayer2" ) )
|
||||||
|
{
|
||||||
|
QDBusInterface iface( name,
|
||||||
|
"/org/mpris/MediaPlayer2",
|
||||||
|
"org.mpris.MediaPlayer2.Player",
|
||||||
|
QDBusConnection::sessionBus() );
|
||||||
|
iface.call( method );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMediaNextSong()
|
||||||
|
{
|
||||||
|
callMethodForAllMediaPlayerAvailableServices( "Next" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMediaPreviousSong()
|
||||||
|
{
|
||||||
|
callMethodForAllMediaPlayerAvailableServices( "Previous" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMediaPausePlay()
|
||||||
|
{
|
||||||
|
callMethodForAllMediaPlayerAvailableServices( "PlayPause" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMediaStopSong()
|
||||||
|
{
|
||||||
|
callMethodForAllMediaPlayerAvailableServices( "Stop" );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace keyboardinput
|
||||||
Reference in New Issue
Block a user