Remove deprecated gnome/mate SettingsDaemon global shortcuts

This commit is contained in:
Jonas Kvinge
2024-11-12 22:38:21 +01:00
parent deaeab3cbb
commit f2845b6632
16 changed files with 8 additions and 666 deletions

View File

@@ -1,130 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QObject>
#include <QCoreApplication>
#include <QDateTime>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QAction>
#include "core/logging.h"
#include "globalshortcutsmanager.h"
#include "globalshortcutsbackend.h"
#include "globalshortcutsbackend-gnome.h"
#include "gnomesettingsdaemon.h"
using namespace Qt::Literals::StringLiterals;
namespace {
constexpr char kService1[] = "org.gnome.SettingsDaemon.MediaKeys";
constexpr char kService2[] = "org.gnome.SettingsDaemon";
constexpr char kPath[] = "/org/gnome/SettingsDaemon/MediaKeys";
} // namespace
GlobalShortcutsBackendGnome::GlobalShortcutsBackendGnome(GlobalShortcutsManager *manager, QObject *parent)
: GlobalShortcutsBackend(manager, GlobalShortcutsBackend::Type::Gnome, parent),
interface_(nullptr),
is_connected_(false) {}
bool GlobalShortcutsBackendGnome::IsAvailable() const {
return IsGnomeAvailable();
}
bool GlobalShortcutsBackendGnome::IsGnomeAvailable() {
return QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService1)) || QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService2));
}
bool GlobalShortcutsBackendGnome::DoRegister() {
qLog(Debug) << "Registering";
if (!interface_) {
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService1))) {
interface_ = new OrgGnomeSettingsDaemonMediaKeysInterface(QLatin1String(kService1), QLatin1String(kPath), QDBusConnection::sessionBus(), this);
}
else if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService2))) {
interface_ = new OrgGnomeSettingsDaemonMediaKeysInterface(QLatin1String(kService2), QLatin1String(kPath), QDBusConnection::sessionBus(), this);
}
}
if (!interface_) {
qLog(Warning) << "Gnome settings daemon not registered";
return false;
}
QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentSecsSinceEpoch());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendGnome::RegisterFinished);
return true;
}
void GlobalShortcutsBackendGnome::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;
}
QObject::connect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendGnome::GnomeMediaKeyPressed);
is_connected_ = true;
qLog(Debug) << "Registered.";
}
void GlobalShortcutsBackendGnome::DoUnregister() {
qLog(Debug) << "Unregister";
if (!IsAvailable() || !interface_ || !is_connected_) return;
is_connected_ = false;
interface_->ReleaseMediaPlayerKeys(QCoreApplication::applicationName());
QObject::disconnect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendGnome::GnomeMediaKeyPressed);
}
void GlobalShortcutsBackendGnome::GnomeMediaKeyPressed(const QString &application, const QString &key) {
Q_UNUSED(application)
auto shortcuts = manager_->shortcuts();
if (key == "Play"_L1) shortcuts[u"play_pause"_s].action->trigger();
if (key == "Stop"_L1) shortcuts[u"stop"_s].action->trigger();
if (key == "Next"_L1) shortcuts[u"next_track"_s].action->trigger();
if (key == "Previous"_L1) shortcuts[u"prev_track"_s].action->trigger();
}

View File

@@ -1,59 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GLOBALSHORTCUTSBACKEND_GNOME_H
#define GLOBALSHORTCUTSBACKEND_GNOME_H
#include "config.h"
#include <QObject>
#include <QString>
#include "globalshortcutsbackend.h"
class QDBusPendingCallWatcher;
class GlobalShortcutsManager;
class OrgGnomeSettingsDaemonMediaKeysInterface;
class GlobalShortcutsBackendGnome : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutsBackendGnome(GlobalShortcutsManager *manager, QObject *parent = nullptr);
bool IsAvailable() const override;
static bool IsGnomeAvailable();
protected:
bool DoRegister() override;
void DoUnregister() override;
private Q_SLOTS:
void RegisterFinished(QDBusPendingCallWatcher *watcher);
void GnomeMediaKeyPressed(const QString &application, const QString &key);
private:
OrgGnomeSettingsDaemonMediaKeysInterface *interface_;
bool is_connected_;
};
#endif // GLOBALSHORTCUTSBACKEND_GNOME_H

View File

@@ -1,130 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QObject>
#include <QCoreApplication>
#include <QDateTime>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QAction>
#include "core/logging.h"
#include "globalshortcutsmanager.h"
#include "globalshortcutsbackend.h"
#include "globalshortcutsbackend-mate.h"
#include "matesettingsdaemon.h"
using namespace Qt::Literals::StringLiterals;
namespace {
constexpr char kService1[] = "org.mate.SettingsDaemon.MediaKeys";
constexpr char kService2[] = "org.mate.SettingsDaemon";
constexpr char kPath[] = "/org/mate/SettingsDaemon/MediaKeys";
}
GlobalShortcutsBackendMate::GlobalShortcutsBackendMate(GlobalShortcutsManager *manager, QObject *parent)
: GlobalShortcutsBackend(manager, GlobalShortcutsBackend::Type::Mate, parent),
interface_(nullptr),
is_connected_(false) {}
bool GlobalShortcutsBackendMate::IsAvailable() const {
return IsMateAvailable();
}
bool GlobalShortcutsBackendMate::IsMateAvailable() {
return QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService1)) || QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService2));
}
bool GlobalShortcutsBackendMate::DoRegister() {
qLog(Debug) << "Registering";
if (!interface_) {
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService1))) {
interface_ = new OrgMateSettingsDaemonMediaKeysInterface(QLatin1String(kService1), QLatin1String(kPath), QDBusConnection::sessionBus(), this);
}
else if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kService2))) {
interface_ = new OrgMateSettingsDaemonMediaKeysInterface(QLatin1String(kService2), QLatin1String(kPath), QDBusConnection::sessionBus(), this);
}
}
if (!interface_) {
qLog(Warning) << "Mate settings daemon not registered";
return false;
}
QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentSecsSinceEpoch());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendMate::RegisterFinished);
return true;
}
void GlobalShortcutsBackendMate::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;
}
QObject::connect(interface_, &OrgMateSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendMate::MateMediaKeyPressed);
is_connected_ = true;
qLog(Debug) << "Registered.";
}
void GlobalShortcutsBackendMate::DoUnregister() {
qLog(Debug) << "Unregister";
if (!IsAvailable() || !interface_ || !is_connected_) return;
is_connected_ = false;
interface_->ReleaseMediaPlayerKeys(QCoreApplication::applicationName());
QObject::disconnect(interface_, &OrgMateSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendMate::MateMediaKeyPressed);
}
void GlobalShortcutsBackendMate::MateMediaKeyPressed(const QString &application, const QString &key) {
Q_UNUSED(application)
auto shortcuts = manager_->shortcuts();
if (key == "Play"_L1) shortcuts[u"play_pause"_s].action->trigger();
if (key == "Stop"_L1) shortcuts[u"stop"_s].action->trigger();
if (key == "Next"_L1) shortcuts[u"next_track"_s].action->trigger();
if (key == "Previous"_L1) shortcuts[u"prev_track"_s].action->trigger();
}

View File

@@ -1,57 +0,0 @@
/*
* Strawberry Music Player
* Copyright 2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GLOBALSHORTCUTSBACKEND_MATE_H
#define GLOBALSHORTCUTSBACKEND_MATE_H
#include "config.h"
#include <QObject>
#include <QString>
#include "globalshortcutsbackend.h"
class QDBusPendingCallWatcher;
class GlobalShortcutsManager;
class OrgMateSettingsDaemonMediaKeysInterface;
class GlobalShortcutsBackendMate : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutsBackendMate(GlobalShortcutsManager *manager, QObject *parent = nullptr);
bool IsAvailable() const override;
static bool IsMateAvailable();
protected:
bool DoRegister() override;
void DoUnregister() override;
private Q_SLOTS:
void RegisterFinished(QDBusPendingCallWatcher *watcher);
void MateMediaKeyPressed(const QString &application, const QString &key);
private:
OrgMateSettingsDaemonMediaKeysInterface *interface_;
bool is_connected_;
};
#endif // GLOBALSHORTCUTSBACKEND_Mate_H

View File

@@ -40,10 +40,6 @@ QString GlobalShortcutsBackend::name() const {
return u"None"_s;
case Type::KDE:
return u"KDE"_s;
case Type::Gnome:
return u"Gnome"_s;
case Type::Mate:
return u"Mate"_s;
case Type::X11:
return u"X11"_s;
case Type::macOS:

View File

@@ -35,8 +35,6 @@ class GlobalShortcutsBackend : public QObject {
enum class Type {
None = 0,
KDE,
Gnome,
Mate,
X11,
macOS,
Win

View File

@@ -40,14 +40,6 @@
#include "globalshortcutsbackend-kde.h"
#endif
#ifdef HAVE_GNOME_GLOBALSHORTCUTS
#include "globalshortcutsbackend-gnome.h"
#endif
#ifdef HAVE_MATE_GLOBALSHORTCUTS
#include "globalshortcutsbackend-mate.h"
#endif
#ifdef HAVE_X11_GLOBALSHORTCUTS
# include "globalshortcutsbackend-x11.h"
#endif
@@ -96,14 +88,6 @@ GlobalShortcutsManager::GlobalShortcutsManager(QWidget *parent) : QWidget(parent
backends_ << new GlobalShortcutsBackendKDE(this, this);
#endif
#ifdef HAVE_GNOME_GLOBALSHORTCUTS
backends_ << new GlobalShortcutsBackendGnome(this, this);
#endif
#ifdef HAVE_MATE_GLOBALSHORTCUTS
backends_ << new GlobalShortcutsBackendMate(this, this);
#endif
#ifdef Q_OS_MACOS
backends_ << new GlobalShortcutsBackendMacOS(this, this);
#endif
@@ -138,18 +122,6 @@ void GlobalShortcutsManager::ReloadSettings() {
}
#endif
#ifdef HAVE_GNOME_GLOBALSHORTCUTS
if (settings_.value(GlobalShortcutsSettings::kUseGnome, true).toBool()) {
backends_enabled_ << GlobalShortcutsBackend::Type::Gnome;
}
#endif
#ifdef HAVE_MATE_GLOBALSHORTCUTS
if (settings_.value(GlobalShortcutsSettings::kUseMate, true).toBool()) {
backends_enabled_ << GlobalShortcutsBackend::Type::Mate;
}
#endif
#ifdef HAVE_X11_GLOBALSHORTCUTS
if (settings_.value(GlobalShortcutsSettings::kUseX11, false).toBool()) {
backends_enabled_ << GlobalShortcutsBackend::Type::X11;
@@ -197,26 +169,6 @@ bool GlobalShortcutsManager::IsKdeAvailable() {
#endif
#ifdef HAVE_GNOME_GLOBALSHORTCUTS
bool GlobalShortcutsManager::IsGnomeAvailable() {
return GlobalShortcutsBackendGnome::IsGnomeAvailable();
}
#endif
#ifdef HAVE_MATE_GLOBALSHORTCUTS
bool GlobalShortcutsManager::IsMateAvailable() {
return GlobalShortcutsBackendMate::IsMateAvailable();
}
#endif
#ifdef HAVE_X11_GLOBALSHORTCUTS
bool GlobalShortcutsManager::IsX11Available() {

View File

@@ -58,17 +58,15 @@ class GlobalShortcutsManager : public QWidget {
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
static bool IsKdeAvailable();
static bool IsGnomeAvailable();
static bool IsMateAvailable();
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
#endif
#ifdef HAVE_X11_GLOBALSHORTCUTS
static bool IsX11Available();
#endif // HAVE_X11_GLOBALSHORTCUTS
#endif
#ifdef Q_OS_MACOS
static bool IsMacAccessibilityEnabled();
#endif // Q_OS_MACOS
#endif
bool Register();
void Unregister();

View File

@@ -1,17 +0,0 @@
<!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>

View File

@@ -1,17 +0,0 @@
<!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.mate.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>