1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-02-03 12:47:31 +01:00

Actually fix formatting

This commit is contained in:
Luis Caceres 2019-12-07 19:30:10 +00:00
parent 0b6519bad4
commit a3531d749a
3 changed files with 75 additions and 83 deletions

View File

@ -43,7 +43,8 @@ GlobalShortcuts::GlobalShortcuts(QWidget* parent)
gnome_backend_(nullptr),
system_backend_(nullptr),
use_gnome_(false),
have_kglobalaccel_(KGlobalAccelShortcutBackend::isKGlobalAccelAvailable()) {
have_kglobalaccel_(
KGlobalAccelShortcutBackend::isKGlobalAccelAvailable()) {
settings_.beginGroup(kSettingsGroup);
// Create actions
@ -166,7 +167,7 @@ void GlobalShortcuts::Unregister() {
}
void GlobalShortcuts::Register() {
if(have_kglobalaccel_ && kglobalaccel_backend_->Register()) return;
if (have_kglobalaccel_ && kglobalaccel_backend_->Register()) return;
if (use_gnome_ && gnome_backend_->Register()) return;
system_backend_->Register();
}

View File

@ -1,5 +1,5 @@
#include "kglobalaccelglobalshortcutbackend.h"
#include "core/logging.h"
#include "kglobalaccelglobalshortcutbackend.h"
#include <QAction>
#include <QGuiApplication>
@ -25,9 +25,9 @@ QString compDisplayName() {
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")) {
return shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay);
} else if (shortcut.id == QStringLiteral("stop")) {
@ -40,79 +40,75 @@ bool isCorrectMediaKeyShortcut(const GlobalShortcuts::Shortcut &shortcut) {
return false;
}
}
#endif // HAVE_DBUS
} // namespace
#endif // HAVE_DBUS
} // namespace
#ifdef HAVE_DBUS
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
GlobalShortcuts *parent)
: GlobalShortcutBackend(parent), iface_(nullptr), component_(nullptr),
GlobalShortcuts* parent)
: GlobalShortcutBackend(parent),
iface_(nullptr),
component_(nullptr),
nameToAction_() {}
#else // HAVE_DBUS
#else // HAVE_DBUS
KGlobalAccelShortcutBackend::KGlobalAccelShortcutBackend(
GlobalShortcuts *parent)
GlobalShortcuts* parent)
: GlobalShortcutBackend(parent) {}
#endif // HAVE_DBUS
#endif // HAVE_DBUS
bool KGlobalAccelShortcutBackend::isKGlobalAccelAvailable() {
#ifdef HAVE_DBUS
return QDBusConnection::sessionBus().interface()->isServiceRegistered(
Service);
#else // HAVE_DBUS
#else // HAVE_DBUS
return false;
#endif // HAVE_DBUS
#endif // HAVE_DBUS
}
bool KGlobalAccelShortcutBackend::DoRegister() {
#ifdef HAVE_DBUS
qLog(Debug) << "Registering shortcuts";
if (!acquireInterface())
return false;
if (!acquireInterface()) return false;
bool complete = true;
for (const GlobalShortcuts::Shortcut &shortcut :
for (const GlobalShortcuts::Shortcut& shortcut :
manager_->shortcuts().values()) {
if (shortcut.action->shortcut().isEmpty())
continue;
if (shortcut.action->shortcut().isEmpty()) continue;
if (!registerShortcut(shortcut))
complete = false;
if (!registerShortcut(shortcut)) complete = false;
}
if (!acquireComponent())
return false;
if (!acquireComponent()) return false;
QObject::connect(component_,
&OrgKdeKglobalaccelComponentInterface::globalShortcutPressed,
this, &KGlobalAccelShortcutBackend::onShortcutPressed);
return complete;
#else // HAVE_DBUS
#else // HAVE_DBUS
qLog(Warning) << "dbus not available";
return false;
#endif // HAVE_DBUS
#endif // HAVE_DBUS
}
void KGlobalAccelShortcutBackend::DoUnregister() {
#ifdef HAVE_DBUS
if (!acquireInterface())
return;
if (!acquireInterface()) return;
if (!acquireComponent())
return;
if (!acquireComponent()) return;
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts())
for (const GlobalShortcuts::Shortcut& shortcut : manager_->shortcuts())
unregisterAction(shortcut.id, shortcut.action);
#endif // HAVE_DBUS
#endif // HAVE_DBUS
}
#ifdef HAVE_DBUS
const char *KGlobalAccelShortcutBackend::Service = "org.kde.kglobalaccel";
const char *KGlobalAccelShortcutBackend::Path = "/kglobalaccel";
const char* KGlobalAccelShortcutBackend::Service = "org.kde.kglobalaccel";
const char* KGlobalAccelShortcutBackend::Path = "/kglobalaccel";
bool KGlobalAccelShortcutBackend::acquireComponent() {
Q_ASSERT(iface_ && iface_->isValid());
@ -143,16 +139,14 @@ bool KGlobalAccelShortcutBackend::acquireComponent() {
}
bool KGlobalAccelShortcutBackend::acquireInterface() {
if (iface_ && iface_->isValid())
return true;
if (iface_ && iface_->isValid()) return true;
if (isKGlobalAccelAvailable()) {
iface_ = new OrgKdeKGlobalAccelInterface(
Service, Path, QDBusConnection::sessionBus(), this);
}
if (iface_ && iface_->isValid())
return true;
if (iface_ && iface_->isValid()) return true;
if (!iface_)
qLog(Warning) << "KGlobalAccel daemon not registered";
@ -161,8 +155,8 @@ bool KGlobalAccelShortcutBackend::acquireInterface() {
return false;
}
QStringList KGlobalAccelShortcutBackend::id(const QString &name,
const QAction *action) {
QStringList KGlobalAccelShortcutBackend::id(const QString& name,
const QAction* action) {
Q_ASSERT(action);
QStringList ret;
@ -170,15 +164,14 @@ QStringList KGlobalAccelShortcutBackend::id(const QString &name,
ret << name;
ret << compDisplayName();
ret << action->text().replace(QLatin1Char('&'), QStringLiteral(""));
if (ret.back().isEmpty())
ret.back() = name;
if (ret.back().isEmpty()) ret.back() = 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) {
for (const QKeySequence& sequence : seq) {
ret.append(sequence[0]);
}
while (!ret.isEmpty() && ret.last() == 0) {
@ -187,9 +180,9 @@ KGlobalAccelShortcutBackend::intList(const QList<QKeySequence> &seq) {
return ret;
}
bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
QAction *action,
QStringList &actionId) {
bool KGlobalAccelShortcutBackend::registerAction(const QString& name,
QAction* action,
QStringList& actionId) {
Q_ASSERT(action);
if (name.isEmpty() &&
@ -207,10 +200,9 @@ bool KGlobalAccelShortcutBackend::registerAction(const QString &name,
}
bool KGlobalAccelShortcutBackend::registerShortcut(
const GlobalShortcuts::Shortcut &shortcut) {
const GlobalShortcuts::Shortcut& shortcut) {
QStringList actionId;
if (!registerAction(shortcut.id, shortcut.action, actionId))
return false;
if (!registerAction(shortcut.id, shortcut.action, actionId)) return false;
QList<QKeySequence> activeShortcut;
activeShortcut << shortcut.action->shortcut();
@ -239,8 +231,8 @@ bool KGlobalAccelShortcutBackend::registerShortcut(
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);
@ -248,8 +240,8 @@ KGlobalAccelShortcutBackend::shortcutList(const QList<int> &seq) {
return ret;
}
void KGlobalAccelShortcutBackend::unregisterAction(const QString &name,
QAction *action) {
void KGlobalAccelShortcutBackend::unregisterAction(const QString& name,
QAction* action) {
Q_ASSERT(action);
QStringList actionId = id(name, action);
@ -258,18 +250,17 @@ 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);
for (QAction *a : candidates) {
QAction* action = nullptr;
const QList<QAction*> candidates = nameToAction_.values(actionUnique);
for (QAction* a : candidates) {
if (compUniqueName() == componentUnique) {
action = a;
}
}
if (action && action->isEnabled())
action->trigger();
if (action && action->isEnabled()) action->trigger();
}
#endif // HAVE_DBUS
#endif // HAVE_DBUS

View File

@ -17,17 +17,17 @@ class OrgKdeKglobalaccelComponentInterface;
class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
Q_OBJECT
public:
explicit KGlobalAccelShortcutBackend(GlobalShortcuts *parent);
public:
explicit KGlobalAccelShortcutBackend(GlobalShortcuts* parent);
static bool isKGlobalAccelAvailable();
protected:
protected:
bool DoRegister() override;
void DoUnregister() override;
private:
private:
#ifdef HAVE_DBUS
enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8 };
@ -35,33 +35,33 @@ private:
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,
QStringList &actionId);
bool registerAction(const QString& name, QAction* action,
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,
const QString &actionUnique,
void onShortcutPressed(const QString& componentUnique,
const QString& actionUnique,
qlonglong timestamp) const;
private:
static const char *Service;
static const char *Path;
private:
static const char* Service;
static const char* Path;
OrgKdeKGlobalAccelInterface *iface_;
OrgKdeKglobalaccelComponentInterface *component_;
QMultiHash<QString, QAction *> nameToAction_;
#endif // HAVE_DBUS
OrgKdeKGlobalAccelInterface* iface_;
OrgKdeKglobalaccelComponentInterface* component_;
QMultiHash<QString, QAction*> nameToAction_;
#endif // HAVE_DBUS
};
#endif // CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
#endif // CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_