Rename global shortcuts classes

This commit is contained in:
Jonas Kvinge
2021-01-26 19:13:29 +01:00
parent bf7c8df353
commit 2a92ce867a
26 changed files with 210 additions and 212 deletions

View File

@@ -51,7 +51,7 @@ GlobalShortcut::GlobalShortcut(QObject *parent) : QObject(parent),
}
GlobalShortcut::GlobalShortcut(QKeySequence shortcut, GlobalShortcutBackend *backend, QObject *parent) : QObject(parent),
GlobalShortcut::GlobalShortcut(QKeySequence shortcut, GlobalShortcutsBackend *backend, QObject *parent) : QObject(parent),
backend_(backend),
shortcut_(shortcut),
qt_key_(Qt::Key(0)),

View File

@@ -32,17 +32,17 @@
#include <QByteArray>
#include <QString>
class GlobalShortcutBackend;
class GlobalShortcutsBackend;
class GlobalShortcut : public QObject, QAbstractNativeEventFilter {
Q_OBJECT
public:
explicit GlobalShortcut(QObject *parent = nullptr);
explicit GlobalShortcut(QKeySequence shortcut, GlobalShortcutBackend *backend, QObject *parent = nullptr);
explicit GlobalShortcut(QKeySequence shortcut, GlobalShortcutsBackend *backend, QObject *parent = nullptr);
~GlobalShortcut() override;
GlobalShortcutBackend *backend() const { return backend_; }
GlobalShortcutsBackend *backend() const { return backend_; }
QKeySequence shortcut() const { return shortcut_; }
bool setShortcut(const QKeySequence &shortcut);
@@ -71,7 +71,7 @@ class GlobalShortcut : public QObject, QAbstractNativeEventFilter {
static QHash<QPair<quint32, quint32>, GlobalShortcut*> internal_shortcuts_;
static const QVector<quint32> mask_modifiers_;
GlobalShortcutBackend *backend_;
GlobalShortcutsBackend *backend_;
QKeySequence shortcut_;
Qt::Key qt_key_;
Qt::KeyboardModifiers qt_mods_;

View File

@@ -34,20 +34,20 @@
#include <QtDebug>
#include "core/logging.h"
#include "globalshortcuts.h"
#include "globalshortcutbackend.h"
#include "globalshortcutbackend-gsd.h"
#include "globalshortcutsmanager.h"
#include "globalshortcutsbackend.h"
#include "globalshortcutsbackend-gsd.h"
const char *GlobalShortcutBackendGSD::kGsdService = "org.gnome.SettingsDaemon.MediaKeys";
const char *GlobalShortcutBackendGSD::kGsdService2 = "org.gnome.SettingsDaemon";
const char *GlobalShortcutBackendGSD::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
const char *GlobalShortcutsBackendGSD::kGsdService = "org.gnome.SettingsDaemon.MediaKeys";
const char *GlobalShortcutsBackendGSD::kGsdService2 = "org.gnome.SettingsDaemon";
const char *GlobalShortcutsBackendGSD::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
GlobalShortcutBackendGSD::GlobalShortcutBackendGSD(GlobalShortcuts *parent)
: GlobalShortcutBackend(parent),
GlobalShortcutsBackendGSD::GlobalShortcutsBackendGSD(GlobalShortcutsManager *parent)
: GlobalShortcutsBackend(parent),
interface_(nullptr),
is_connected_(false) {}
bool GlobalShortcutBackendGSD::DoRegister() {
bool GlobalShortcutsBackendGSD::DoRegister() {
qLog(Debug) << "Registering";
@@ -68,13 +68,13 @@ bool GlobalShortcutBackendGSD::DoRegister() {
QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toSecsSinceEpoch());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutBackendGSD::RegisterFinished);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendGSD::RegisterFinished);
return true;
}
void GlobalShortcutBackendGSD::RegisterFinished(QDBusPendingCallWatcher *watcher) {
void GlobalShortcutsBackendGSD::RegisterFinished(QDBusPendingCallWatcher *watcher) {
QDBusMessage reply = watcher->reply();
watcher->deleteLater();
@@ -84,14 +84,14 @@ void GlobalShortcutBackendGSD::RegisterFinished(QDBusPendingCallWatcher *watcher
return;
}
QObject::connect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutBackendGSD::GnomeMediaKeyPressed);
QObject::connect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendGSD::GnomeMediaKeyPressed);
is_connected_ = true;
qLog(Debug) << "Registered";
}
void GlobalShortcutBackendGSD::DoUnregister() {
void GlobalShortcutsBackendGSD::DoUnregister() {
qLog(Debug) << "Unregister";
@@ -103,11 +103,11 @@ void GlobalShortcutBackendGSD::DoUnregister() {
is_connected_ = false;
interface_->ReleaseMediaPlayerKeys(QCoreApplication::applicationName());
QObject::disconnect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutBackendGSD::GnomeMediaKeyPressed);
QObject::disconnect(interface_, &OrgGnomeSettingsDaemonMediaKeysInterface::MediaPlayerKeyPressed, this, &GlobalShortcutsBackendGSD::GnomeMediaKeyPressed);
}
void GlobalShortcutBackendGSD::GnomeMediaKeyPressed(const QString&, const QString& key) {
void GlobalShortcutsBackendGSD::GnomeMediaKeyPressed(const QString&, const QString& key) {
if (key == "Play") manager_->shortcuts()["play_pause"].action->trigger();
if (key == "Stop") manager_->shortcuts()["stop"].action->trigger();
if (key == "Next") manager_->shortcuts()["next_track"].action->trigger();

View File

@@ -18,25 +18,25 @@
*
*/
#ifndef GLOBALSHORTCUTBACKEND_GSD_H
#define GLOBALSHORTCUTBACKEND_GSD_H
#ifndef GLOBALSHORTCUTSBACKEND_GSD_H
#define GLOBALSHORTCUTSBACKEND_GSD_H
#include "config.h"
#include <QObject>
#include <QString>
#include "globalshortcutbackend.h"
#include "globalshortcutsbackend.h"
class QDBusPendingCallWatcher;
class GlobalShortcuts;
class GlobalShortcutsManager;
class OrgGnomeSettingsDaemonMediaKeysInterface;
class GlobalShortcutBackendGSD : public GlobalShortcutBackend {
class GlobalShortcutsBackendGSD : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutBackendGSD(GlobalShortcuts *parent);
explicit GlobalShortcutsBackendGSD(GlobalShortcutsManager *parent);
static const char *kGsdService;
static const char *kGsdService2;
@@ -58,4 +58,4 @@ class GlobalShortcutBackendGSD : public GlobalShortcutBackend {
};
#endif // GLOBALSHORTCUTBACKEND_GSD_H
#endif // GLOBALSHORTCUTSBACKEND_GSD_H

View File

@@ -36,14 +36,14 @@
#include "core/logging.h"
#include "globalshortcutbackend-kde.h"
#include "globalshortcutsbackend-kde.h"
const char *GlobalShortcutBackendKDE::kKdeService = "org.kde.kglobalaccel";
const char *GlobalShortcutBackendKDE::kKdePath = "/kglobalaccel";
const char *GlobalShortcutsBackendKDE::kKdeService = "org.kde.kglobalaccel";
const char *GlobalShortcutsBackendKDE::kKdePath = "/kglobalaccel";
GlobalShortcutBackendKDE::GlobalShortcutBackendKDE(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), interface_(nullptr), component_(nullptr) {}
GlobalShortcutsBackendKDE::GlobalShortcutsBackendKDE(GlobalShortcutsManager *parent) : GlobalShortcutsBackend(parent), interface_(nullptr), component_(nullptr) {}
bool GlobalShortcutBackendKDE::DoRegister() {
bool GlobalShortcutsBackendKDE::DoRegister() {
qLog(Debug) << "Registering";
@@ -56,19 +56,19 @@ bool GlobalShortcutBackendKDE::DoRegister() {
interface_ = new OrgKdeKGlobalAccelInterface(kKdeService, kKdePath, QDBusConnection::sessionBus(), this);
}
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) {
for (const GlobalShortcutsManager::Shortcut &shortcut : manager_->shortcuts().values()) {
RegisterShortcut(shortcut);
}
QDBusPendingReply<QDBusObjectPath> reply = interface_->getComponent(QCoreApplication::applicationName());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutBackendKDE::RegisterFinished);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendKDE::RegisterFinished);
return true;
}
void GlobalShortcutBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watcher) {
void GlobalShortcutsBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watcher) {
QDBusReply<QDBusObjectPath> reply = watcher->reply();
watcher->deleteLater();
@@ -89,19 +89,19 @@ void GlobalShortcutBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watcher
return;
}
QObject::connect(component_, &org::kde::kglobalaccel::Component::globalShortcutPressed, this, &GlobalShortcutBackendKDE::GlobalShortcutPressed, Qt::UniqueConnection);
QObject::connect(component_, &org::kde::kglobalaccel::Component::globalShortcutPressed, this, &GlobalShortcutsBackendKDE::GlobalShortcutPressed, Qt::UniqueConnection);
qLog(Debug) << "Registered";
}
void GlobalShortcutBackendKDE::DoUnregister() {
void GlobalShortcutsBackendKDE::DoUnregister() {
if (!interface_ || !interface_->isValid()) return;
qLog(Debug) << "Unregistering";
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts()) {
for (const GlobalShortcutsManager::Shortcut &shortcut : manager_->shortcuts()) {
if (actions_.contains(shortcut.id)) {
interface_->unRegister(GetActionId(shortcut.id, shortcut.action));
actions_.remove(shortcut.id, shortcut.action);
@@ -115,7 +115,7 @@ void GlobalShortcutBackendKDE::DoUnregister() {
}
bool GlobalShortcutBackendKDE::RegisterShortcut(const GlobalShortcuts::Shortcut &shortcut) {
bool GlobalShortcutsBackendKDE::RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut) {
if (!interface_ || !interface_->isValid() || shortcut.id.isEmpty() || !shortcut.action || shortcut.action->shortcut().isEmpty()) return false;
@@ -150,7 +150,7 @@ bool GlobalShortcutBackendKDE::RegisterShortcut(const GlobalShortcuts::Shortcut
}
QStringList GlobalShortcutBackendKDE::GetActionId(const QString &id, const QAction *action) {
QStringList GlobalShortcutsBackendKDE::GetActionId(const QString &id, const QAction *action) {
QStringList ret;
ret << QCoreApplication::applicationName();
@@ -163,7 +163,7 @@ QStringList GlobalShortcutBackendKDE::GetActionId(const QString &id, const QActi
}
QList<int> GlobalShortcutBackendKDE::ToIntList(const QList<QKeySequence> &sequence_list) {
QList<int> GlobalShortcutsBackendKDE::ToIntList(const QList<QKeySequence> &sequence_list) {
QList<int> ret;
for (const QKeySequence &sequence : sequence_list) {
@@ -178,7 +178,7 @@ QList<int> GlobalShortcutBackendKDE::ToIntList(const QList<QKeySequence> &sequen
}
QList<QKeySequence> GlobalShortcutBackendKDE::ToKeySequenceList(const QList<int> &sequence_list) {
QList<QKeySequence> GlobalShortcutsBackendKDE::ToKeySequenceList(const QList<int> &sequence_list) {
QList<QKeySequence> ret;
for (int sequence : sequence_list) {
@@ -189,7 +189,7 @@ QList<QKeySequence> GlobalShortcutBackendKDE::ToKeySequenceList(const QList<int>
}
void GlobalShortcutBackendKDE::GlobalShortcutPressed(const QString &component_unique, const QString &shortcut_unique, qlonglong) {
void GlobalShortcutsBackendKDE::GlobalShortcutPressed(const QString &component_unique, const QString &shortcut_unique, qlonglong) {
if (QCoreApplication::applicationName() == component_unique && actions_.contains(shortcut_unique)) {
for (QAction *action : actions_.values(shortcut_unique)) {

View File

@@ -17,8 +17,8 @@
*
*/
#ifndef GLOBALSHORTCUTBACKEND_KDE_H
#define GLOBALSHORTCUTBACKEND_KDE_H
#ifndef GLOBALSHORTCUTSBACKEND_KDE_H
#define GLOBALSHORTCUTSBACKEND_KDE_H
#include "config.h"
@@ -28,8 +28,8 @@
#include <QStringList>
#include <QKeySequence>
#include "globalshortcutbackend.h"
#include "globalshortcuts.h"
#include "globalshortcutsbackend.h"
#include "globalshortcutsmanager.h"
class QDBusPendingCallWatcher;
class QAction;
@@ -37,11 +37,11 @@ class QAction;
class OrgKdeKGlobalAccelInterface;
class OrgKdeKglobalaccelComponentInterface;
class GlobalShortcutBackendKDE : public GlobalShortcutBackend {
class GlobalShortcutsBackendKDE : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutBackendKDE(GlobalShortcuts *parent);
explicit GlobalShortcutsBackendKDE(GlobalShortcutsManager *parent);
static const char *kKdeService;
@@ -50,7 +50,7 @@ class GlobalShortcutBackendKDE : public GlobalShortcutBackend {
void DoUnregister() override;
private:
bool RegisterShortcut(const GlobalShortcuts::Shortcut &shortcut);
bool RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut);
static QStringList GetActionId(const QString &id, const QAction *action);
static QList<int> ToIntList(const QList<QKeySequence> &sequence_list);
static QList<QKeySequence> ToKeySequenceList(const QList<int> &sequence_list);
@@ -67,4 +67,4 @@ class GlobalShortcutBackendKDE : public GlobalShortcutBackend {
QMultiHash<QString, QAction*> actions_;
};
#endif // GLOBALSHORTCUTBACKEND_KDE_H
#endif // GLOBALSHORTCUTSBACKEND_KDE_H

View File

@@ -18,14 +18,14 @@
*
*/
#ifndef GLOBALSHORTCUTBACKEND_MACOS_H
#define GLOBALSHORTCUTBACKEND_MACOS_H
#ifndef GLOBALSHORTCUTSBACKEND_MACOS_H
#define GLOBALSHORTCUTSBACKEND_MACOS_H
#include "config.h"
#include <memory>
#include "globalshortcutbackend.h"
#include "globalshortcutsbackend.h"
#include <QObject>
#include <QMap>
@@ -34,14 +34,14 @@
class GlobalShortcut;
class GlobalShortcutBackendMacOSPrivate;
class GlobalShortcutsBackendMacOSPrivate;
class GlobalShortcutBackendMacOS : public GlobalShortcutBackend {
class GlobalShortcutsBackendMacOS : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutBackendMacOS(GlobalShortcuts* parent);
virtual ~GlobalShortcutBackendMacOS();
explicit GlobalShortcutsBackendMacOS(GlobalShortcutsManager* parent);
virtual ~GlobalShortcutsBackendMacOS();
bool IsAccessibilityEnabled() const;
void ShowAccessibilityDialog();
@@ -57,8 +57,8 @@ class GlobalShortcutBackendMacOS : public GlobalShortcutBackend {
QMap<QKeySequence, QAction*> shortcuts_;
friend class GlobalShortcutBackendMacOSPrivate;
std::unique_ptr<GlobalShortcutBackendMacOSPrivate> p_;
friend class GlobalShortcutsBackendMacOSPrivate;
std::unique_ptr<GlobalShortcutsBackendMacOSPrivate> p_;
};
#endif // GLOBALSHORTCUTBACKEND_MACOS_H
#endif // GLOBALSHORTCUTSBACKEND_MACOS_H

View File

@@ -20,7 +20,7 @@
#include "config.h"
#include "globalshortcutbackend-macos.h"
#include "globalshortcutsbackend-macos.h"
#include <boost/noncopyable.hpp>
@@ -37,7 +37,7 @@
#include <QtDebug>
#include "config.h"
#include "globalshortcuts.h"
#include "globalshortcutsmanager.h"
#include "core/logging.h"
#include "core/mac_startup.h"
#include "core/utilities.h"
@@ -45,9 +45,9 @@
#import "core/mac_utilities.h"
#import "core/SBSystemPreferences.h"
class GlobalShortcutBackendMacOSPrivate : boost::noncopyable {
class GlobalShortcutsBackendMacOSPrivate : boost::noncopyable {
public:
explicit GlobalShortcutBackendMacOSPrivate(GlobalShortcutBackendMacOS* backend)
explicit GlobalShortcutsBackendMacOSPrivate(GlobalShortcutsBackendMacOS* backend)
: global_monitor_(nil), local_monitor_(nil), backend_(backend) {}
bool Register() {
@@ -74,21 +74,21 @@ class GlobalShortcutBackendMacOSPrivate : boost::noncopyable {
id global_monitor_;
id local_monitor_;
GlobalShortcutBackendMacOS* backend_;
GlobalShortcutsBackendMacOS* backend_;
};
GlobalShortcutBackendMacOS::GlobalShortcutBackendMacOS(GlobalShortcuts* parent)
: GlobalShortcutBackend(parent),
p_(new GlobalShortcutBackendMacOSPrivate(this)) {}
GlobalShortcutsBackendMacOS::GlobalShortcutsBackendMacOS(GlobalShortcutsManager* parent)
: GlobalShortcutsBackend(parent),
p_(new GlobalShortcutsBackendMacOSPrivate(this)) {}
GlobalShortcutBackendMacOS::~GlobalShortcutBackendMacOS() {}
GlobalShortcutsBackendMacOS::~GlobalShortcutsBackendMacOS() {}
bool GlobalShortcutBackendMacOS::DoRegister() {
bool GlobalShortcutsBackendMacOS::DoRegister() {
// Always enable media keys.
mac::SetShortcutHandler(this);
for (const GlobalShortcuts::Shortcut& shortcut : manager_->shortcuts().values()) {
for (const GlobalShortcutsManager::Shortcut& shortcut : manager_->shortcuts().values()) {
shortcuts_[shortcut.action->shortcut()] = shortcut.action;
}
@@ -96,14 +96,14 @@ bool GlobalShortcutBackendMacOS::DoRegister() {
}
void GlobalShortcutBackendMacOS::DoUnregister() {
void GlobalShortcutsBackendMacOS::DoUnregister() {
p_->Unregister();
shortcuts_.clear();
}
void GlobalShortcutBackendMacOS::MacMediaKeyPressed(int key) {
void GlobalShortcutsBackendMacOS::MacMediaKeyPressed(int key) {
switch (key) {
case NX_KEYTYPE_PLAY:
@@ -119,7 +119,7 @@ void GlobalShortcutBackendMacOS::MacMediaKeyPressed(int key) {
}
bool GlobalShortcutBackendMacOS::KeyPressed(const QKeySequence& sequence) {
bool GlobalShortcutsBackendMacOS::KeyPressed(const QKeySequence& sequence) {
if (sequence.isEmpty()) {
return false;
@@ -133,14 +133,14 @@ bool GlobalShortcutBackendMacOS::KeyPressed(const QKeySequence& sequence) {
}
bool GlobalShortcutBackendMacOS::IsAccessibilityEnabled() const {
bool GlobalShortcutsBackendMacOS::IsAccessibilityEnabled() const {
NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
}
void GlobalShortcutBackendMacOS::ShowAccessibilityDialog() {
void GlobalShortcutsBackendMacOS::ShowAccessibilityDialog() {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPreferencePanesDirectory, NSSystemDomainMask, YES);
if ([paths count] == 1) {

View File

@@ -19,7 +19,7 @@
#include "config.h"
#include "globalshortcutbackend-system.h"
#include "globalshortcutsbackend-system.h"
#include "core/logging.h"
@@ -29,21 +29,21 @@
#include <QKeySequence>
#include <QtAlgorithms>
#include "globalshortcuts.h"
#include "globalshortcutbackend.h"
#include "globalshortcutsmanager.h"
#include "globalshortcutsbackend.h"
#include "globalshortcut.h"
GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), gshortcut_init_(nullptr) {}
GlobalShortcutsBackendSystem::GlobalShortcutsBackendSystem(GlobalShortcutsManager *parent) : GlobalShortcutsBackend(parent), gshortcut_init_(nullptr) {}
GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem() { DoUnregister(); }
GlobalShortcutsBackendSystem::~GlobalShortcutsBackendSystem() { DoUnregister(); }
bool GlobalShortcutBackendSystem::DoRegister() {
bool GlobalShortcutsBackendSystem::DoRegister() {
qLog(Debug) << "Registering";
if (!gshortcut_init_) gshortcut_init_ = new GlobalShortcut(this);
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) {
for (const GlobalShortcutsManager::Shortcut &shortcut : manager_->shortcuts().values()) {
AddShortcut(shortcut.action);
}
@@ -51,7 +51,7 @@ bool GlobalShortcutBackendSystem::DoRegister() {
}
bool GlobalShortcutBackendSystem::AddShortcut(QAction *action) {
bool GlobalShortcutsBackendSystem::AddShortcut(QAction *action) {
if (action->shortcut().isEmpty()) return false;
@@ -62,7 +62,7 @@ bool GlobalShortcutBackendSystem::AddShortcut(QAction *action) {
}
void GlobalShortcutBackendSystem::DoUnregister() {
void GlobalShortcutsBackendSystem::DoUnregister() {
qLog(Debug) << "Unregistering";
@@ -75,4 +75,3 @@ void GlobalShortcutBackendSystem::DoUnregister() {
}
}

View File

@@ -17,8 +17,8 @@
*
*/
#ifndef GLOBALSHORTCUTBACKEND_SYSTEM_H
#define GLOBALSHORTCUTBACKEND_SYSTEM_H
#ifndef GLOBALSHORTCUTSBACKEND_SYSTEM_H
#define GLOBALSHORTCUTSBACKEND_SYSTEM_H
#include "config.h"
@@ -28,18 +28,18 @@
#include <QList>
#include <QString>
#include "globalshortcutbackend.h"
#include "globalshortcutsbackend.h"
class QAction;
class GlobalShortcuts;
class GlobalShortcutsManager;
class GlobalShortcut;
class GlobalShortcutBackendSystem : public GlobalShortcutBackend {
class GlobalShortcutsBackendSystem : public GlobalShortcutsBackend {
Q_OBJECT
public:
explicit GlobalShortcutBackendSystem(GlobalShortcuts *parent = nullptr);
~GlobalShortcutBackendSystem() override;
explicit GlobalShortcutsBackendSystem(GlobalShortcutsManager *parent = nullptr);
~GlobalShortcutsBackendSystem() override;
protected:
bool DoRegister() override;
@@ -54,4 +54,4 @@ class GlobalShortcutBackendSystem : public GlobalShortcutBackend {
};
#endif // GLOBALSHORTCUTBACKEND_SYSTEM_H
#endif // GLOBALSHORTCUTSBACKEND_SYSTEM_H

View File

@@ -22,19 +22,19 @@
#include <QObject>
#include "globalshortcutbackend.h"
#include "globalshortcuts.h"
#include "globalshortcutsbackend.h"
#include "globalshortcutsmanager.h"
GlobalShortcutBackend::GlobalShortcutBackend(GlobalShortcuts *parent)
GlobalShortcutsBackend::GlobalShortcutsBackend(GlobalShortcutsManager *parent)
: QObject(parent), manager_(parent), active_(false) {}
bool GlobalShortcutBackend::Register() {
bool GlobalShortcutsBackend::Register() {
bool ret = DoRegister();
if (ret) active_ = true;
return ret;
}
void GlobalShortcutBackend::Unregister() {
void GlobalShortcutsBackend::Unregister() {
DoUnregister();
active_ = false;
}

View File

@@ -18,21 +18,21 @@
*
*/
#ifndef GLOBALSHORTCUTBACKEND_H
#define GLOBALSHORTCUTBACKEND_H
#ifndef GLOBALSHORTCUTSBACKEND_H
#define GLOBALSHORTCUTSBACKEND_H
#include "config.h"
#include <QObject>
#include <QString>
class GlobalShortcuts;
class GlobalShortcutsManager;
class GlobalShortcutBackend : public QObject {
class GlobalShortcutsBackend : public QObject {
Q_OBJECT
public:
explicit GlobalShortcutBackend(GlobalShortcuts *parent = nullptr);
explicit GlobalShortcutsBackend(GlobalShortcutsManager *parent = nullptr);
bool is_active() const { return active_; }
@@ -46,9 +46,9 @@ class GlobalShortcutBackend : public QObject {
virtual bool DoRegister() = 0;
virtual void DoUnregister() = 0;
GlobalShortcuts *manager_;
GlobalShortcutsManager *manager_;
bool active_;
};
#endif // GLOBALSHORTCUTBACKEND_H
#endif // GLOBALSHORTCUTSBACKEND_H

View File

@@ -34,23 +34,23 @@
# include <QX11Info>
#endif
#include "globalshortcuts.h"
#include "globalshortcutbackend.h"
#include "globalshortcutsmanager.h"
#include "globalshortcutsbackend.h"
#ifdef HAVE_DBUS
# include "globalshortcutbackend-gsd.h"
# include "globalshortcutbackend-kde.h"
# include "globalshortcutsbackend-gsd.h"
# include "globalshortcutsbackend-kde.h"
#endif
#if defined(HAVE_X11EXTRAS) || defined(Q_OS_WIN)
# include "globalshortcutbackend-system.h"
# include "globalshortcutsbackend-system.h"
#endif
#ifdef Q_OS_MACOS
# include "globalshortcutbackend-macos.h"
# include "globalshortcutsbackend-macos.h"
#endif
#include "settings/shortcutssettingspage.h"
#include "settings/globalshortcutssettingspage.h"
GlobalShortcuts::GlobalShortcuts(QWidget *parent)
GlobalShortcutsManager::GlobalShortcutsManager(QWidget *parent)
: QWidget(parent),
gsd_backend_(nullptr),
kde_backend_(nullptr),
@@ -85,28 +85,28 @@ GlobalShortcuts::GlobalShortcuts(QWidget *parent)
// Create backends - these do the actual shortcut registration
#ifdef HAVE_DBUS
gsd_backend_ = new GlobalShortcutBackendGSD(this);
kde_backend_ = new GlobalShortcutBackendKDE(this);
gsd_backend_ = new GlobalShortcutsBackendGSD(this);
kde_backend_ = new GlobalShortcutsBackendKDE(this);
#endif
#ifdef Q_OS_MACOS
if (!system_backend_)
system_backend_ = new GlobalShortcutBackendMacOS(this);
system_backend_ = new GlobalShortcutsBackendMacOS(this);
#endif
#if defined(Q_OS_WIN)
if (!system_backend_)
system_backend_ = new GlobalShortcutBackendSystem(this);
system_backend_ = new GlobalShortcutsBackendSystem(this);
#endif
#if defined(HAVE_X11EXTRAS)
if (!system_backend_ && IsX11Available())
system_backend_ = new GlobalShortcutBackendSystem(this);
system_backend_ = new GlobalShortcutsBackendSystem(this);
#endif
ReloadSettings();
}
void GlobalShortcuts::ReloadSettings() {
void GlobalShortcutsManager::ReloadSettings() {
// The actual shortcuts have been set in our actions for us by the config dialog already - we just need to reread the gnome settings.
use_gsd_ = settings_.value("use_gsd", true).toBool();
@@ -118,14 +118,14 @@ void GlobalShortcuts::ReloadSettings() {
}
void GlobalShortcuts::AddShortcut(const QString &id, const QString &name, const char *signal, const QKeySequence &default_key) {
void GlobalShortcutsManager::AddShortcut(const QString &id, const QString &name, const char *signal, const QKeySequence &default_key) {
Shortcut shortcut = AddShortcut(id, name, default_key);
QObject::connect(shortcut.action, SIGNAL(triggered()), this, signal);
}
GlobalShortcuts::Shortcut GlobalShortcuts::AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key) {
GlobalShortcutsManager::Shortcut GlobalShortcutsManager::AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key) {
Shortcut shortcut;
shortcut.action = new QAction(name, this);
@@ -144,27 +144,27 @@ GlobalShortcuts::Shortcut GlobalShortcuts::AddShortcut(const QString &id, const
}
bool GlobalShortcuts::IsGsdAvailable() const {
bool GlobalShortcutsManager::IsGsdAvailable() const {
#ifdef HAVE_DBUS
return QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutBackendGSD::kGsdService) || QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutBackendGSD::kGsdService2);
return QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutsBackendGSD::kGsdService) || QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutsBackendGSD::kGsdService2);
#else
return false;
#endif
}
bool GlobalShortcuts::IsKdeAvailable() const {
bool GlobalShortcutsManager::IsKdeAvailable() const {
#ifdef HAVE_DBUS
return QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutBackendKDE::kKdeService);
return QDBusConnection::sessionBus().interface()->isServiceRegistered(GlobalShortcutsBackendKDE::kKdeService);
#else
return false;
#endif
}
bool GlobalShortcuts::IsX11Available() const {
bool GlobalShortcutsManager::IsX11Available() const {
#ifdef HAVE_X11EXTRAS
return QX11Info::isPlatformX11();
@@ -174,7 +174,7 @@ bool GlobalShortcuts::IsX11Available() const {
}
void GlobalShortcuts::Register() {
void GlobalShortcutsManager::Register() {
if (use_gsd_ && gsd_backend_ && gsd_backend_->Register()) return;
if (use_kde_ && kde_backend_ && kde_backend_->Register()) return;
@@ -189,7 +189,7 @@ void GlobalShortcuts::Register() {
}
void GlobalShortcuts::Unregister() {
void GlobalShortcutsManager::Unregister() {
if (gsd_backend_ && gsd_backend_->is_active()) gsd_backend_->Unregister();
if (kde_backend_ && kde_backend_->is_active()) kde_backend_->Unregister();
@@ -197,17 +197,17 @@ void GlobalShortcuts::Unregister() {
}
bool GlobalShortcuts::IsMacAccessibilityEnabled() const {
bool GlobalShortcutsManager::IsMacAccessibilityEnabled() const {
#ifdef Q_OS_MACOS
if (system_backend_) return qobject_cast<GlobalShortcutBackendMacOS*>(system_backend_)->IsAccessibilityEnabled();
if (system_backend_) return qobject_cast<GlobalShortcutsBackendMacOS*>(system_backend_)->IsAccessibilityEnabled();
else return false;
#else
return true;
#endif
}
void GlobalShortcuts::ShowMacAccessibilityDialog() {
void GlobalShortcutsManager::ShowMacAccessibilityDialog() {
#ifdef Q_OS_MACOS
if (system_backend_) qobject_cast<GlobalShortcutBackendMacOS*>(system_backend_)->ShowAccessibilityDialog();
if (system_backend_) qobject_cast<GlobalShortcutsBackendMacOS*>(system_backend_)->ShowAccessibilityDialog();
#endif
}

View File

@@ -19,8 +19,8 @@
*
*/
#ifndef GLOBALSHORTCUTS_H
#define GLOBALSHORTCUTS_H
#ifndef GLOBALSHORTCUTSMANAGER_H
#define GLOBALSHORTCUTSMANAGER_H
#include "config.h"
@@ -33,13 +33,13 @@
class QShortcut;
class QAction;
class GlobalShortcutBackend;
class GlobalShortcutsBackend;
class GlobalShortcuts : public QWidget {
class GlobalShortcutsManager : public QWidget {
Q_OBJECT
public:
explicit GlobalShortcuts(QWidget *parent = nullptr);
explicit GlobalShortcutsManager(QWidget *parent = nullptr);
struct Shortcut {
QString id;
@@ -88,9 +88,9 @@ class GlobalShortcuts : public QWidget {
Shortcut AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key);
private:
GlobalShortcutBackend *gsd_backend_;
GlobalShortcutBackend *kde_backend_;
GlobalShortcutBackend *system_backend_;
GlobalShortcutsBackend *gsd_backend_;
GlobalShortcutsBackend *kde_backend_;
GlobalShortcutsBackend *system_backend_;
QMap<QString, Shortcut> shortcuts_;
QSettings settings_;
@@ -100,4 +100,4 @@ class GlobalShortcuts : public QWidget {
bool use_x11_;
};
#endif // GLOBALSHORTCUTS_H
#endif // GLOBALSHORTCUTSMANAGER_H