Fix formatting

This commit is contained in:
Luis Caceres 2019-12-06 23:53:40 +00:00
parent 24a571769a
commit 8cab8fe180
2 changed files with 78 additions and 95 deletions

View File

@ -1,8 +1,5 @@
#include "config.h"
#include "core/closure.h"
#include "core/logging.h"
#include "globalshortcuts.h"
#include "kglobalaccelglobalshortcutbackend.h"
#include "core/logging.h"
#include <QAction>
#include <QGuiApplication>
@ -17,7 +14,6 @@
// Most of this file is based on the KGlobalAccel sources
// (https://phabricator.kde.org/source/kglobalaccel)
namespace {
QString compDisplayName() {
if (!QGuiApplication::applicationDisplayName().isEmpty()) {
@ -26,13 +22,9 @@ namespace {
return QCoreApplication::applicationName();
}
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) {
if (shortcut.id == QStringLiteral("play_pause")) {
@ -47,19 +39,18 @@ namespace {
return false;
}
}
}
} // namespace
#ifdef HAVE_DBUS
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
GlobalShortcuts *parent)
: GlobalShortcutBackend(parent),
iface_(nullptr),
component_(nullptr),
: GlobalShortcutBackend(parent), iface_(nullptr), component_(nullptr),
nameToAction_() {}
#else // HAVE_DBUS
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(GlobalShortcuts *parent)
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
GlobalShortcuts *parent)
: GlobalShortcutBackend(parent) {}
#endif // HAVE_DBUS
@ -80,7 +71,8 @@ bool KGlobalAccelShortcutBackend::DoRegister() {
return false;
bool complete = true;
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) {
for (const GlobalShortcuts::Shortcut &shortcut :
manager_->shortcuts().values()) {
if (shortcut.action->shortcut().isEmpty())
continue;
@ -93,8 +85,7 @@ bool KGlobalAccelShortcutBackend::DoRegister() {
QObject::connect(component_,
&OrgKdeKglobalaccelComponentInterface::globalShortcutPressed,
this,
&KGlobalAccelShortcutBackend::onShortcutPressed);
this, &KGlobalAccelShortcutBackend::onShortcutPressed);
return complete;
#else // HAVE_DBUS
@ -133,10 +124,8 @@ bool KGlobalAccelShortcutBackend::acquireComponent() {
return false;
}
component_ = new org::kde::kglobalaccel::Component(Service,
reply.value().path(),
QDBusConnection::sessionBus(),
iface_);
component_ = new org::kde::kglobalaccel::Component(
Service, reply.value().path(), QDBusConnection::sessionBus(), iface_);
if (!component_->isValid()) {
qLog(Warning) << "Failed to get KGlobalAccel component:"
@ -154,9 +143,8 @@ bool KGlobalAccelShortcutBackend::acquireInterface() {
return true;
if (isKGlobalAccelAvailable()) {
iface_ = new OrgKdeKGlobalAccelInterface(Service, Path,
QDBusConnection::sessionBus(),
this);
iface_ = new OrgKdeKGlobalAccelInterface(
Service, Path, QDBusConnection::sessionBus(), this);
}
if (iface_ && iface_->isValid())
@ -183,8 +171,8 @@ QStringList KGlobalAccelShortcutBackend::id(const QString &name,
return ret;
}
QList<int> KGlobalAccelShortcutBackend::intList(
const QList<QKeySequence> &seq) {
QList<int>
KGlobalAccelShortcutBackend::intList(const QList<QKeySequence> &seq) {
QList<int> ret;
for (const QKeySequence &sequence : seq) {
ret.append(sequence[0]);
@ -200,9 +188,9 @@ bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
QStringList &actionId) {
Q_ASSERT(action);
if (name.isEmpty() && (action->objectName().isEmpty() ||
action->objectName().startsWith(
QLatin1String("unnamed-")))) {
if (name.isEmpty() &&
(action->objectName().isEmpty() ||
action->objectName().startsWith(QLatin1String("unnamed-")))) {
qLog(Warning) << "Cannot register shortcut for unnamed action";
return false;
}
@ -214,7 +202,8 @@ bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
return true;
}
bool KGlobalAccelShortcutBackend::registerShortcut(const GlobalShortcuts::Shortcut &shortcut) {
bool KGlobalAccelShortcutBackend::registerShortcut(
const GlobalShortcuts::Shortcut &shortcut) {
QStringList actionId;
if (!registerAction(shortcut.id, shortcut.action, actionId))
return false;
@ -222,9 +211,8 @@ bool KGlobalAccelShortcutBackend::registerShortcut(const GlobalShortcuts::Shortc
QList<QKeySequence> activeShortcut;
activeShortcut << shortcut.action->shortcut();
const QList<int> result = iface_->setShortcut(actionId,
intList(activeShortcut),
SetShortcutFlag::SetPresent);
const QList<int> result = iface_->setShortcut(
actionId, intList(activeShortcut), SetShortcutFlag::SetPresent);
const QList<QKeySequence> resultSequence = shortcutList(result);
if (resultSequence != activeShortcut) {
@ -247,8 +235,8 @@ bool KGlobalAccelShortcutBackend::registerShortcut(const GlobalShortcuts::Shortc
return true;
}
QList<QKeySequence> KGlobalAccelShortcutBackend::shortcutList(
const QList<int> &seq) {
QList<QKeySequence>
KGlobalAccelShortcutBackend::shortcutList(const QList<int> &seq) {
QList<QKeySequence> ret;
for (int i : seq) {
ret.append(i);
@ -266,8 +254,7 @@ void KGlobalAccelShortcutBackend::unregisterAction(const QString &name,
}
void KGlobalAccelShortcutBackend::onShortcutPressed(
const QString &componentUnique,
const QString &actionUnique,
const QString &componentUnique, const QString &actionUnique,
qlonglong timestamp) const {
QAction *action = nullptr;
const QList<QAction *> candidates = nameToAction_.values(actionUnique);

View File

@ -1,7 +1,9 @@
#ifndef CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
#define CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
#include "config.h"
#include "globalshortcutbackend.h"
#include "globalshortcuts.h"
#include <QSet>
#include <QStringList>
@ -12,14 +14,12 @@ class OrgKdeKGlobalAccelInterface;
class OrgKdeKglobalaccelComponentInterface;
class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
Q_OBJECT
public:
explicit KGlobalAccelShortcutBackend(GlobalShortcuts *parent);
static bool isKGlobalAccelAvailable();
protected:
@ -29,11 +29,7 @@ class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
private:
#ifdef HAVE_DBUS
enum SetShortcutFlag {
SetPresent = 2,
NoAutoloading = 4,
IsDefault = 8
};
enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8 };
bool acquireComponent();