Actually fix formatting
This commit is contained in:
parent
0b6519bad4
commit
a3531d749a
@ -43,7 +43,8 @@ GlobalShortcuts::GlobalShortcuts(QWidget* parent)
|
|||||||
gnome_backend_(nullptr),
|
gnome_backend_(nullptr),
|
||||||
system_backend_(nullptr),
|
system_backend_(nullptr),
|
||||||
use_gnome_(false),
|
use_gnome_(false),
|
||||||
have_kglobalaccel_(KGlobalAccelShortcutBackend::isKGlobalAccelAvailable()) {
|
have_kglobalaccel_(
|
||||||
|
KGlobalAccelShortcutBackend::isKGlobalAccelAvailable()) {
|
||||||
settings_.beginGroup(kSettingsGroup);
|
settings_.beginGroup(kSettingsGroup);
|
||||||
|
|
||||||
// Create actions
|
// Create actions
|
||||||
@ -166,7 +167,7 @@ void GlobalShortcuts::Unregister() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GlobalShortcuts::Register() {
|
void GlobalShortcuts::Register() {
|
||||||
if(have_kglobalaccel_ && kglobalaccel_backend_->Register()) return;
|
if (have_kglobalaccel_ && kglobalaccel_backend_->Register()) return;
|
||||||
if (use_gnome_ && gnome_backend_->Register()) return;
|
if (use_gnome_ && gnome_backend_->Register()) return;
|
||||||
system_backend_->Register();
|
system_backend_->Register();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "kglobalaccelglobalshortcutbackend.h"
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
#include "kglobalaccelglobalshortcutbackend.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
@ -25,9 +25,9 @@ QString compDisplayName() {
|
|||||||
|
|
||||||
QString compUniqueName() { return QCoreApplication::applicationName(); }
|
QString compUniqueName() { return QCoreApplication::applicationName(); }
|
||||||
|
|
||||||
const QString &id_ActionUnique(const QStringList &id) { return id.at(1); }
|
const QString& id_ActionUnique(const QStringList& id) { return id.at(1); }
|
||||||
|
|
||||||
bool isCorrectMediaKeyShortcut(const GlobalShortcuts::Shortcut &shortcut) {
|
bool isCorrectMediaKeyShortcut(const GlobalShortcuts::Shortcut& shortcut) {
|
||||||
if (shortcut.id == QStringLiteral("play_pause")) {
|
if (shortcut.id == QStringLiteral("play_pause")) {
|
||||||
return shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay);
|
return shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay);
|
||||||
} else if (shortcut.id == QStringLiteral("stop")) {
|
} else if (shortcut.id == QStringLiteral("stop")) {
|
||||||
@ -46,13 +46,15 @@ bool isCorrectMediaKeyShortcut(const GlobalShortcuts::Shortcut &shortcut) {
|
|||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
|
|
||||||
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
|
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
|
||||||
GlobalShortcuts *parent)
|
GlobalShortcuts* parent)
|
||||||
: GlobalShortcutBackend(parent), iface_(nullptr), component_(nullptr),
|
: GlobalShortcutBackend(parent),
|
||||||
|
iface_(nullptr),
|
||||||
|
component_(nullptr),
|
||||||
nameToAction_() {}
|
nameToAction_() {}
|
||||||
|
|
||||||
#else // HAVE_DBUS
|
#else // HAVE_DBUS
|
||||||
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
|
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
|
||||||
GlobalShortcuts *parent)
|
GlobalShortcuts* parent)
|
||||||
: GlobalShortcutBackend(parent) {}
|
: GlobalShortcutBackend(parent) {}
|
||||||
#endif // HAVE_DBUS
|
#endif // HAVE_DBUS
|
||||||
|
|
||||||
@ -69,21 +71,17 @@ bool KGlobalAccelShortcutBackend::DoRegister() {
|
|||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
qLog(Debug) << "Registering shortcuts";
|
qLog(Debug) << "Registering shortcuts";
|
||||||
|
|
||||||
if (!acquireInterface())
|
if (!acquireInterface()) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
bool complete = true;
|
bool complete = true;
|
||||||
for (const GlobalShortcuts::Shortcut &shortcut :
|
for (const GlobalShortcuts::Shortcut& shortcut :
|
||||||
manager_->shortcuts().values()) {
|
manager_->shortcuts().values()) {
|
||||||
if (shortcut.action->shortcut().isEmpty())
|
if (shortcut.action->shortcut().isEmpty()) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!registerShortcut(shortcut))
|
if (!registerShortcut(shortcut)) complete = false;
|
||||||
complete = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!acquireComponent())
|
if (!acquireComponent()) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
QObject::connect(component_,
|
QObject::connect(component_,
|
||||||
&OrgKdeKglobalaccelComponentInterface::globalShortcutPressed,
|
&OrgKdeKglobalaccelComponentInterface::globalShortcutPressed,
|
||||||
@ -98,21 +96,19 @@ bool KGlobalAccelShortcutBackend::DoRegister() {
|
|||||||
|
|
||||||
void KGlobalAccelShortcutBackend::DoUnregister() {
|
void KGlobalAccelShortcutBackend::DoUnregister() {
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
if (!acquireInterface())
|
if (!acquireInterface()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (!acquireComponent())
|
if (!acquireComponent()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts())
|
for (const GlobalShortcuts::Shortcut& shortcut : manager_->shortcuts())
|
||||||
unregisterAction(shortcut.id, shortcut.action);
|
unregisterAction(shortcut.id, shortcut.action);
|
||||||
#endif // HAVE_DBUS
|
#endif // HAVE_DBUS
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
|
|
||||||
const char *KGlobalAccelShortcutBackend::Service = "org.kde.kglobalaccel";
|
const char* KGlobalAccelShortcutBackend::Service = "org.kde.kglobalaccel";
|
||||||
const char *KGlobalAccelShortcutBackend::Path = "/kglobalaccel";
|
const char* KGlobalAccelShortcutBackend::Path = "/kglobalaccel";
|
||||||
|
|
||||||
bool KGlobalAccelShortcutBackend::acquireComponent() {
|
bool KGlobalAccelShortcutBackend::acquireComponent() {
|
||||||
Q_ASSERT(iface_ && iface_->isValid());
|
Q_ASSERT(iface_ && iface_->isValid());
|
||||||
@ -143,16 +139,14 @@ bool KGlobalAccelShortcutBackend::acquireComponent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool KGlobalAccelShortcutBackend::acquireInterface() {
|
bool KGlobalAccelShortcutBackend::acquireInterface() {
|
||||||
if (iface_ && iface_->isValid())
|
if (iface_ && iface_->isValid()) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
if (isKGlobalAccelAvailable()) {
|
if (isKGlobalAccelAvailable()) {
|
||||||
iface_ = new OrgKdeKGlobalAccelInterface(
|
iface_ = new OrgKdeKGlobalAccelInterface(
|
||||||
Service, Path, QDBusConnection::sessionBus(), this);
|
Service, Path, QDBusConnection::sessionBus(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iface_ && iface_->isValid())
|
if (iface_ && iface_->isValid()) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!iface_)
|
if (!iface_)
|
||||||
qLog(Warning) << "KGlobalAccel daemon not registered";
|
qLog(Warning) << "KGlobalAccel daemon not registered";
|
||||||
@ -161,8 +155,8 @@ bool KGlobalAccelShortcutBackend::acquireInterface() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList KGlobalAccelShortcutBackend::id(const QString &name,
|
QStringList KGlobalAccelShortcutBackend::id(const QString& name,
|
||||||
const QAction *action) {
|
const QAction* action) {
|
||||||
Q_ASSERT(action);
|
Q_ASSERT(action);
|
||||||
|
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
@ -170,15 +164,14 @@ QStringList KGlobalAccelShortcutBackend::id(const QString &name,
|
|||||||
ret << name;
|
ret << name;
|
||||||
ret << compDisplayName();
|
ret << compDisplayName();
|
||||||
ret << action->text().replace(QLatin1Char('&'), QStringLiteral(""));
|
ret << action->text().replace(QLatin1Char('&'), QStringLiteral(""));
|
||||||
if (ret.back().isEmpty())
|
if (ret.back().isEmpty()) ret.back() = name;
|
||||||
ret.back() = name;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int>
|
QList<int> KGlobalAccelShortcutBackend::intList(
|
||||||
KGlobalAccelShortcutBackend::intList(const QList<QKeySequence> &seq) {
|
const QList<QKeySequence>& seq) {
|
||||||
QList<int> ret;
|
QList<int> ret;
|
||||||
for (const QKeySequence &sequence : seq) {
|
for (const QKeySequence& sequence : seq) {
|
||||||
ret.append(sequence[0]);
|
ret.append(sequence[0]);
|
||||||
}
|
}
|
||||||
while (!ret.isEmpty() && ret.last() == 0) {
|
while (!ret.isEmpty() && ret.last() == 0) {
|
||||||
@ -187,9 +180,9 @@ KGlobalAccelShortcutBackend::intList(const QList<QKeySequence> &seq) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
|
bool KGlobalAccelShortcutBackend::registerAction(const QString& name,
|
||||||
QAction *action,
|
QAction* action,
|
||||||
QStringList &actionId) {
|
QStringList& actionId) {
|
||||||
Q_ASSERT(action);
|
Q_ASSERT(action);
|
||||||
|
|
||||||
if (name.isEmpty() &&
|
if (name.isEmpty() &&
|
||||||
@ -207,10 +200,9 @@ bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool KGlobalAccelShortcutBackend::registerShortcut(
|
bool KGlobalAccelShortcutBackend::registerShortcut(
|
||||||
const GlobalShortcuts::Shortcut &shortcut) {
|
const GlobalShortcuts::Shortcut& shortcut) {
|
||||||
QStringList actionId;
|
QStringList actionId;
|
||||||
if (!registerAction(shortcut.id, shortcut.action, actionId))
|
if (!registerAction(shortcut.id, shortcut.action, actionId)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
QList<QKeySequence> activeShortcut;
|
QList<QKeySequence> activeShortcut;
|
||||||
activeShortcut << shortcut.action->shortcut();
|
activeShortcut << shortcut.action->shortcut();
|
||||||
@ -239,8 +231,8 @@ bool KGlobalAccelShortcutBackend::registerShortcut(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QKeySequence>
|
QList<QKeySequence> KGlobalAccelShortcutBackend::shortcutList(
|
||||||
KGlobalAccelShortcutBackend::shortcutList(const QList<int> &seq) {
|
const QList<int>& seq) {
|
||||||
QList<QKeySequence> ret;
|
QList<QKeySequence> ret;
|
||||||
for (int i : seq) {
|
for (int i : seq) {
|
||||||
ret.append(i);
|
ret.append(i);
|
||||||
@ -248,8 +240,8 @@ KGlobalAccelShortcutBackend::shortcutList(const QList<int> &seq) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KGlobalAccelShortcutBackend::unregisterAction(const QString &name,
|
void KGlobalAccelShortcutBackend::unregisterAction(const QString& name,
|
||||||
QAction *action) {
|
QAction* action) {
|
||||||
Q_ASSERT(action);
|
Q_ASSERT(action);
|
||||||
|
|
||||||
QStringList actionId = id(name, action);
|
QStringList actionId = id(name, action);
|
||||||
@ -258,18 +250,17 @@ void KGlobalAccelShortcutBackend::unregisterAction(const QString &name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KGlobalAccelShortcutBackend::onShortcutPressed(
|
void KGlobalAccelShortcutBackend::onShortcutPressed(
|
||||||
const QString &componentUnique, const QString &actionUnique,
|
const QString& componentUnique, const QString& actionUnique,
|
||||||
qlonglong timestamp) const {
|
qlonglong timestamp) const {
|
||||||
QAction *action = nullptr;
|
QAction* action = nullptr;
|
||||||
const QList<QAction *> candidates = nameToAction_.values(actionUnique);
|
const QList<QAction*> candidates = nameToAction_.values(actionUnique);
|
||||||
for (QAction *a : candidates) {
|
for (QAction* a : candidates) {
|
||||||
if (compUniqueName() == componentUnique) {
|
if (compUniqueName() == componentUnique) {
|
||||||
action = a;
|
action = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action && action->isEnabled())
|
if (action && action->isEnabled()) action->trigger();
|
||||||
action->trigger();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_DBUS
|
#endif // HAVE_DBUS
|
||||||
|
@ -17,17 +17,17 @@ class OrgKdeKglobalaccelComponentInterface;
|
|||||||
class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
|
class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KGlobalAccelShortcutBackend(GlobalShortcuts *parent);
|
explicit KGlobalAccelShortcutBackend(GlobalShortcuts* parent);
|
||||||
|
|
||||||
static bool isKGlobalAccelAvailable();
|
static bool isKGlobalAccelAvailable();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool DoRegister() override;
|
bool DoRegister() override;
|
||||||
|
|
||||||
void DoUnregister() override;
|
void DoUnregister() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8 };
|
enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8 };
|
||||||
|
|
||||||
@ -35,32 +35,32 @@ private:
|
|||||||
|
|
||||||
bool acquireInterface();
|
bool acquireInterface();
|
||||||
|
|
||||||
static QStringList id(const QString &name, const QAction *action);
|
static QStringList id(const QString& name, const QAction* action);
|
||||||
|
|
||||||
static QList<int> intList(const QList<QKeySequence> &seq);
|
static QList<int> intList(const QList<QKeySequence>& seq);
|
||||||
|
|
||||||
bool registerAction(const QString &name, QAction *action,
|
bool registerAction(const QString& name, QAction* action,
|
||||||
QStringList &actionId);
|
QStringList& actionId);
|
||||||
|
|
||||||
bool registerShortcut(const GlobalShortcuts::Shortcut &shortcut);
|
bool registerShortcut(const GlobalShortcuts::Shortcut& shortcut);
|
||||||
|
|
||||||
static QList<QKeySequence> shortcutList(const QList<int> &seq);
|
static QList<QKeySequence> shortcutList(const QList<int>& seq);
|
||||||
|
|
||||||
void unregisterAction(const QString &name, QAction *action);
|
void unregisterAction(const QString& name, QAction* action);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void onShortcutPressed(const QString &componentUnique,
|
void onShortcutPressed(const QString& componentUnique,
|
||||||
const QString &actionUnique,
|
const QString& actionUnique,
|
||||||
qlonglong timestamp) const;
|
qlonglong timestamp) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char *Service;
|
static const char* Service;
|
||||||
static const char *Path;
|
static const char* Path;
|
||||||
|
|
||||||
OrgKdeKGlobalAccelInterface *iface_;
|
OrgKdeKGlobalAccelInterface* iface_;
|
||||||
OrgKdeKglobalaccelComponentInterface *component_;
|
OrgKdeKglobalaccelComponentInterface* component_;
|
||||||
QMultiHash<QString, QAction *> nameToAction_;
|
QMultiHash<QString, QAction*> nameToAction_;
|
||||||
#endif // HAVE_DBUS
|
#endif // HAVE_DBUS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user