mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
Merge pull request #188 from f1ori/master
listen to media key events provided by gnome settings daemon
This commit is contained in:
commit
c03c8b8223
@ -22,6 +22,8 @@ ENDIF()
|
||||
SET( tomahawkSources ${tomahawkSources}
|
||||
AclRegistryImpl.cpp
|
||||
ShortcutHandler.cpp
|
||||
GnomeShortcutHandler.cpp
|
||||
GnomeSettingsDaemonMediaKeysProxy.cpp
|
||||
UbuntuUnityHack.cpp
|
||||
TomahawkApp.cpp
|
||||
main.cpp
|
||||
|
17
src/tomahawk/GnomeSettingsDaemonMediaKeys.xml
Normal file
17
src/tomahawk/GnomeSettingsDaemonMediaKeys.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.gnome.SettingsDaemon.MediaKeys">
|
||||
<method name="ReleaseMediaPlayerKeys">
|
||||
<arg name="application" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="GrabMediaPlayerKeys">
|
||||
<arg name="application" type="s" direction="in"/>
|
||||
<arg name="time" type="u" direction="in"/>
|
||||
</method>
|
||||
<signal name="MediaPlayerKeyPressed">
|
||||
<arg type="s"/>
|
||||
<arg type="s"/>
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
26
src/tomahawk/GnomeSettingsDaemonMediaKeysProxy.cpp
Normal file
26
src/tomahawk/GnomeSettingsDaemonMediaKeysProxy.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.7
|
||||
* Command line was: qdbusxml2cpp -p GnomeSettingsDaemonMediaKeysProxy -c GnomeSettingsDaemonMediaKeysProxy GnomeSettingsDaemonMediaKeys.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "GnomeSettingsDaemonMediaKeysProxy.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class GnomeSettingsDaemonMediaKeysProxy
|
||||
*/
|
||||
|
||||
GnomeSettingsDaemonMediaKeysProxy::GnomeSettingsDaemonMediaKeysProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
|
||||
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
|
||||
{
|
||||
}
|
||||
|
||||
GnomeSettingsDaemonMediaKeysProxy::~GnomeSettingsDaemonMediaKeysProxy()
|
||||
{
|
||||
}
|
||||
|
64
src/tomahawk/GnomeSettingsDaemonMediaKeysProxy.h
Normal file
64
src/tomahawk/GnomeSettingsDaemonMediaKeysProxy.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.7
|
||||
* Command line was: qdbusxml2cpp -p GnomeSettingsDaemonMediaKeysProxy -c GnomeSettingsDaemonMediaKeysProxy GnomeSettingsDaemonMediaKeys.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef GNOMESETTINGSDAEMONMEDIAKEYSPROXY_H_1369414808
|
||||
#define GNOMESETTINGSDAEMONMEDIAKEYSPROXY_H_1369414808
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
/*
|
||||
* Proxy class for interface org.gnome.SettingsDaemon.MediaKeys
|
||||
*/
|
||||
class GnomeSettingsDaemonMediaKeysProxy: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "org.gnome.SettingsDaemon.MediaKeys"; }
|
||||
|
||||
public:
|
||||
GnomeSettingsDaemonMediaKeysProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
|
||||
|
||||
~GnomeSettingsDaemonMediaKeysProxy();
|
||||
|
||||
public Q_SLOTS: // METHODS
|
||||
inline QDBusPendingReply<> GrabMediaPlayerKeys(const QString &application, uint time)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(application) << QVariant::fromValue(time);
|
||||
return asyncCallWithArgumentList(QLatin1String("GrabMediaPlayerKeys"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> ReleaseMediaPlayerKeys(const QString &application)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(application);
|
||||
return asyncCallWithArgumentList(QLatin1String("ReleaseMediaPlayerKeys"), argumentList);
|
||||
}
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
void MediaPlayerKeyPressed(const QString &in0, const QString &in1);
|
||||
};
|
||||
|
||||
namespace org {
|
||||
namespace gnome {
|
||||
namespace SettingsDaemon {
|
||||
typedef ::GnomeSettingsDaemonMediaKeysProxy MediaKeys;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
111
src/tomahawk/GnomeShortcutHandler.cpp
Normal file
111
src/tomahawk/GnomeShortcutHandler.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Florian Richter <mail@f1ori.de>
|
||||
*
|
||||
* Tomahawk 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// implement listen on media keys events provided by the gnome settings daemon
|
||||
// as documented here:
|
||||
// https://github.com/GNOME/gnome-settings-daemon/blob/master/plugins/media-keys/README.media-keys-API
|
||||
|
||||
#include "GnomeShortcutHandler.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
|
||||
#ifdef QT_DBUS_LIB
|
||||
# include <QtDBus>
|
||||
#endif
|
||||
|
||||
#include <QAction>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
const char* GnomeShortcutHandler::kGsdService = "org.gnome.SettingsDaemon";
|
||||
const char* GnomeShortcutHandler::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
|
||||
const char* GnomeShortcutHandler::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
|
||||
|
||||
|
||||
GnomeShortcutHandler::GnomeShortcutHandler(QObject *parent) :
|
||||
Tomahawk::ShortcutHandler(parent),
|
||||
interface_(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool GnomeShortcutHandler::DoRegister() {
|
||||
#ifdef QT_DBUS_LIB
|
||||
tLog(LOGVERBOSE) << "registering for gnome media keys";
|
||||
// Check if the GSD service is available
|
||||
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService)) {
|
||||
tLog(LOGVERBOSE) << "gnome settings daemon not registered";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!interface_) {
|
||||
interface_ = new GnomeSettingsDaemonMediaKeysProxy(
|
||||
kGsdService, kGsdPath, QDBusConnection::sessionBus(), this->parent());
|
||||
}
|
||||
|
||||
QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(
|
||||
QCoreApplication::applicationName(), 0);
|
||||
|
||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
|
||||
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
|
||||
this, SLOT(RegisterFinished(QDBusPendingCallWatcher*)));
|
||||
|
||||
return true;
|
||||
#else // QT_DBUS_LIB
|
||||
tLog(LOGVERBOSE) << "dbus not available";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void GnomeShortcutHandler::RegisterFinished(QDBusPendingCallWatcher* watcher) {
|
||||
#ifdef QT_DBUS_LIB
|
||||
QDBusMessage reply = watcher->reply();
|
||||
watcher->deleteLater();
|
||||
|
||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||
tLog(LOGVERBOSE) << "Failed to grab media keys"
|
||||
<< reply.errorName() <<reply.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
||||
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
||||
|
||||
tLog(LOGVERBOSE) << "gnome media keys registered";
|
||||
#endif // QT_DBUS_LIB
|
||||
}
|
||||
|
||||
void
|
||||
GnomeShortcutHandler::GnomeMediaKeyPressed( const QString& app, const QString& val )
|
||||
{
|
||||
if (app != QCoreApplication::applicationName())
|
||||
return;
|
||||
|
||||
tLog(LOGVERBOSE) << "gnome media key " << val << " pressed";
|
||||
if ( val == "Play" ) {
|
||||
emit playPause();
|
||||
}
|
||||
if ( val == "Next" ) {
|
||||
emit next();
|
||||
}
|
||||
if ( val == "Previous" ) {
|
||||
emit previous();
|
||||
}
|
||||
}
|
||||
|
54
src/tomahawk/GnomeShortcutHandler.h
Normal file
54
src/tomahawk/GnomeShortcutHandler.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Florian Richter <mail@f1ori.de>
|
||||
*
|
||||
* Tomahawk 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GNOMESHORTCUTHANDLER_H
|
||||
#define GNOMESHORTCUTHANDLER_H
|
||||
|
||||
#include "ShortcutHandler.h"
|
||||
#include "GnomeSettingsDaemonMediaKeysProxy.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Tomahawk {
|
||||
|
||||
|
||||
class GnomeShortcutHandler : public ShortcutHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GnomeShortcutHandler(QObject *parent = 0);
|
||||
bool DoRegister();
|
||||
|
||||
static const char* kGsdService;
|
||||
static const char* kGsdPath;
|
||||
static const char* kGsdInterface;
|
||||
|
||||
|
||||
public slots:
|
||||
void RegisterFinished(QDBusPendingCallWatcher* watcher);
|
||||
void GnomeMediaKeyPressed( const QString& application, const QString& key );
|
||||
|
||||
private:
|
||||
GnomeSettingsDaemonMediaKeysProxy* interface_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GNOMESHORTCUTHANDLER_H
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "web/Api_v1.h"
|
||||
#include "SourceList.h"
|
||||
#include "ShortcutHandler.h"
|
||||
#include "GnomeShortcutHandler.h"
|
||||
#include "filemetadata/ScanManager.h"
|
||||
#include "TomahawkSettings.h"
|
||||
#include "GlobalActionManager.h"
|
||||
@ -232,6 +233,12 @@ TomahawkApp::init()
|
||||
increaseMaxFileDescriptors();
|
||||
#endif
|
||||
|
||||
#if !defined(Q_WS_MAC) && !defined(Q_WS_WIN)
|
||||
GnomeShortcutHandler *gnomeShortcutHandler = new GnomeShortcutHandler( this );
|
||||
gnomeShortcutHandler->DoRegister();
|
||||
m_shortcutHandler = QPointer<Tomahawk::ShortcutHandler>( gnomeShortcutHandler );
|
||||
#endif
|
||||
|
||||
// Connect up shortcuts
|
||||
if ( !m_shortcutHandler.isNull() )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user