mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Register and unregister for media key notifications properly from the gnome settings daemon
This commit is contained in:
parent
dea15c91ba
commit
2bffe1fa82
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "gnomeglobalshortcutbackend.h"
|
#include "gnomeglobalshortcutbackend.h"
|
||||||
#include "globalshortcuts.h"
|
#include "globalshortcuts.h"
|
||||||
|
#include "core/closure.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
|
||||||
#ifdef QT_DBUS_LIB
|
#ifdef QT_DBUS_LIB
|
||||||
@ -24,6 +25,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#ifdef QT_DBUS_LIB
|
#ifdef QT_DBUS_LIB
|
||||||
@ -36,10 +39,12 @@ const char* GnomeGlobalShortcutBackend::kGsdInterface = "org.gnome.SettingsDaemo
|
|||||||
|
|
||||||
GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
|
GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
|
||||||
: GlobalShortcutBackend(parent),
|
: GlobalShortcutBackend(parent),
|
||||||
interface_(NULL)
|
interface_(NULL),
|
||||||
|
is_connected_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GnomeGlobalShortcutBackend::DoRegister() {
|
bool GnomeGlobalShortcutBackend::DoRegister() {
|
||||||
#ifdef QT_DBUS_LIB
|
#ifdef QT_DBUS_LIB
|
||||||
qLog(Debug) << "registering";
|
qLog(Debug) << "registering";
|
||||||
@ -54,10 +59,14 @@ bool GnomeGlobalShortcutBackend::DoRegister() {
|
|||||||
kGsdService, kGsdPath, QDBusConnection::sessionBus(), this);
|
kGsdService, kGsdPath, QDBusConnection::sessionBus(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
QDBusPendingReply<> reply =
|
||||||
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(),
|
||||||
|
QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
qLog(Debug) << "registered";
|
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
|
||||||
|
NewClosure(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
|
||||||
|
this, SLOT(RegisterFinished(QDBusPendingCallWatcher*)),
|
||||||
|
watcher);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else // QT_DBUS_LIB
|
#else // QT_DBUS_LIB
|
||||||
@ -66,15 +75,35 @@ bool GnomeGlobalShortcutBackend::DoRegister() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GnomeGlobalShortcutBackend::RegisterFinished(QDBusPendingCallWatcher* watcher) {
|
||||||
|
QDBusMessage reply = watcher->reply();
|
||||||
|
watcher->deleteLater();
|
||||||
|
|
||||||
|
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||||
|
qLog(Warning) << "Failed to grab media keys"
|
||||||
|
<< reply.errorName() <<reply.errorMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
||||||
|
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
||||||
|
is_connected_ = true;
|
||||||
|
|
||||||
|
qLog(Debug) << "registered";
|
||||||
|
}
|
||||||
|
|
||||||
void GnomeGlobalShortcutBackend::DoUnregister() {
|
void GnomeGlobalShortcutBackend::DoUnregister() {
|
||||||
qLog(Debug) << "unregister";
|
qLog(Debug) << "unregister";
|
||||||
#ifdef QT_DBUS_LIB
|
#ifdef QT_DBUS_LIB
|
||||||
// Check if the GSD service is available
|
// Check if the GSD service is available
|
||||||
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
|
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
|
||||||
return;
|
return;
|
||||||
if (!interface_)
|
if (!interface_ || !is_connected_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
is_connected_ = false;
|
||||||
|
|
||||||
|
interface_->ReleaseMediaPlayerKeys(QCoreApplication::applicationName());
|
||||||
disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
||||||
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
class OrgGnomeSettingsDaemonMediaKeysInterface;
|
class OrgGnomeSettingsDaemonMediaKeysInterface;
|
||||||
|
|
||||||
|
class QDBusPendingCallWatcher;
|
||||||
|
|
||||||
class GnomeGlobalShortcutBackend : public GlobalShortcutBackend {
|
class GnomeGlobalShortcutBackend : public GlobalShortcutBackend {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -38,10 +40,13 @@ protected:
|
|||||||
void DoUnregister();
|
void DoUnregister();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void RegisterFinished(QDBusPendingCallWatcher* watcher);
|
||||||
|
|
||||||
void GnomeMediaKeyPressed(const QString& application, const QString& key);
|
void GnomeMediaKeyPressed(const QString& application, const QString& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OrgGnomeSettingsDaemonMediaKeysInterface* interface_;
|
OrgGnomeSettingsDaemonMediaKeysInterface* interface_;
|
||||||
|
bool is_connected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GNOMEGLOBALSHORTCUTBACKEND_H
|
#endif // GNOMEGLOBALSHORTCUTBACKEND_H
|
||||||
|
Loading…
Reference in New Issue
Block a user