From 7a7550388d4b4704017b60f850d0f81aeaf4282c Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 12 Nov 2024 23:03:57 +0100 Subject: [PATCH] Rename KDE global shortcuts to KGlobalAccel --- CMakeLists.txt | 12 ++--- debian/copyright | 6 +-- src/config.h.in | 2 +- src/constants/globalshortcutssettings.h | 2 +- ...> globalshortcutsbackend-kglobalaccel.cpp} | 46 +++++++++---------- ... => globalshortcutsbackend-kglobalaccel.h} | 6 +-- .../globalshortcutsbackend.cpp | 4 +- src/globalshortcuts/globalshortcutsbackend.h | 2 +- .../globalshortcutsmanager.cpp | 20 ++++---- src/globalshortcuts/globalshortcutsmanager.h | 2 +- src/settings/globalshortcutssettingspage.cpp | 46 ++++++++----------- src/settings/globalshortcutssettingspage.h | 1 - src/settings/globalshortcutssettingspage.ui | 6 +-- 13 files changed, 71 insertions(+), 84 deletions(-) rename src/globalshortcuts/{globalshortcutsbackend-kde.cpp => globalshortcutsbackend-kglobalaccel.cpp} (75%) rename src/globalshortcuts/{globalshortcutsbackend-kde.h => globalshortcutsbackend-kglobalaccel.h} (90%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c513015f..738dcb80c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,7 +312,7 @@ optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" DEPENDS "QX11Application" HAVE_QX11APPLICATION ) -optional_component(KDE_GLOBALSHORTCUTS ON "KDE global shortcuts" +optional_component(KGLOBALACCEL_GLOBALSHORTCUTS ON "KGlobalAccel global shortcuts" DEPENDS "D-Bus support" HAVE_DBUS ) @@ -362,7 +362,7 @@ if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ) set(HAVE_CHROMAPRINT ON) endif() -if(HAVE_X11_GLOBALSHORTCUTS OR HAVE_KDE_GLOBALSHORTCUTS OR APPLE OR WIN32) +if(HAVE_X11_GLOBALSHORTCUTS OR HAVE_KGLOBALACCEL_GLOBALSHORTCUTS OR APPLE OR WIN32) set(HAVE_GLOBALSHORTCUTS ON) endif() @@ -1226,10 +1226,10 @@ if(HAVE_GLOBALSHORTCUTS) UI src/globalshortcuts/globalshortcutgrabber.ui src/settings/globalshortcutssettingspage.ui ) - if(HAVE_KDE_GLOBALSHORTCUTS) - optional_source(HAVE_KDE_GLOBALSHORTCUTS - SOURCES src/globalshortcuts/globalshortcutsbackend-kde.cpp - HEADERS src/globalshortcuts/globalshortcutsbackend-kde.h + if(HAVE_KGLOBALACCEL_GLOBALSHORTCUTS) + optional_source(HAVE_KGLOBALACCEL_GLOBALSHORTCUTS + SOURCES src/globalshortcuts/globalshortcutsbackend-kglobalaccel.cpp + HEADERS src/globalshortcuts/globalshortcutsbackend-kglobalaccel.h ) qt_add_dbus_interface(SOURCES src/globalshortcuts/org.kde.KGlobalAccel.xml kglobalaccel) qt_add_dbus_interface(SOURCES src/globalshortcuts/org.kde.KGlobalAccel.Component.xml kglobalaccelcomponent) diff --git a/debian/copyright b/debian/copyright index 011541775..5b2e00b3b 100644 --- a/debian/copyright +++ b/debian/copyright @@ -75,10 +75,8 @@ Files: src/core/main.h src/covermanager/spotifycoverprovider.h src/covermanager/musixmatchcoverprovider.cpp src/covermanager/musixmatchcoverprovider.h - src/globalshortcuts/globalshortcutsbackend-kde.cpp - src/globalshortcuts/globalshortcutsbackend-kde.h - src/globalshortcuts/globalshortcutsbackend-mate.cpp - src/globalshortcuts/globalshortcutsbackend-mate.h + src/globalshortcuts/globalshortcutsbackend-kglobalaccel.cpp + src/globalshortcuts/globalshortcutsbackend-kglobalaccel.h src/globalshortcuts/globalshortcutsbackend-x11.cpp src/globalshortcuts/globalshortcutsbackend-x11.h src/globalshortcuts/globalshortcutsbackend-win.cpp diff --git a/src/config.h.in b/src/config.h.in index 14f0364fd..4b5371acd 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -25,7 +25,7 @@ #cmakedefine HAVE_EBUR128 #cmakedefine HAVE_GLOBALSHORTCUTS #cmakedefine HAVE_X11_GLOBALSHORTCUTS -#cmakedefine HAVE_KDE_GLOBALSHORTCUTS +#cmakedefine HAVE_KGLOBALACCEL_GLOBALSHORTCUTS #cmakedefine HAVE_SUBSONIC #cmakedefine HAVE_TIDAL #cmakedefine HAVE_SPOTIFY diff --git a/src/constants/globalshortcutssettings.h b/src/constants/globalshortcutssettings.h index 047f88681..c50309aa6 100644 --- a/src/constants/globalshortcutssettings.h +++ b/src/constants/globalshortcutssettings.h @@ -23,7 +23,7 @@ namespace GlobalShortcutsSettings { constexpr char kSettingsGroup[] = "GlobalShortcuts"; -constexpr char kUseKDE[] = "use_kde"; +constexpr char kUseKGlobalAccel[] = "use_kglobalaccel"; constexpr char kUseX11[] = "use_x11"; } // namespace diff --git a/src/globalshortcuts/globalshortcutsbackend-kde.cpp b/src/globalshortcuts/globalshortcutsbackend-kglobalaccel.cpp similarity index 75% rename from src/globalshortcuts/globalshortcutsbackend-kde.cpp rename to src/globalshortcuts/globalshortcutsbackend-kglobalaccel.cpp index 664c19d5c..abdc67a7e 100644 --- a/src/globalshortcuts/globalshortcutsbackend-kde.cpp +++ b/src/globalshortcuts/globalshortcutsbackend-kglobalaccel.cpp @@ -33,7 +33,7 @@ #include "core/logging.h" -#include "globalshortcutsbackend-kde.h" +#include "globalshortcutsbackend-kglobalaccel.h" #include "kglobalaccel.h" #include "kglobalaccelcomponent.h" @@ -41,28 +41,28 @@ using namespace Qt::Literals::StringLiterals; namespace { -constexpr char kKdeService[] = "org.kde.kglobalaccel"; -constexpr char kKdePath[] = "/kglobalaccel"; +constexpr char kKGlobalAccelService[] = "org.kde.kglobalaccel"; +constexpr char kKGlobalAccelPath[] = "/kglobalaccel"; } -GlobalShortcutsBackendKDE::GlobalShortcutsBackendKDE(GlobalShortcutsManager *manager, QObject *parent) - : GlobalShortcutsBackend(manager, GlobalShortcutsBackend::Type::KDE, parent), +GlobalShortcutsBackendKGlobalAccel::GlobalShortcutsBackendKGlobalAccel(GlobalShortcutsManager *manager, QObject *parent) + : GlobalShortcutsBackend(manager, GlobalShortcutsBackend::Type::KGlobalAccel, parent), interface_(nullptr), component_(nullptr) {} -bool GlobalShortcutsBackendKDE::IsKDEAvailable() { +bool GlobalShortcutsBackendKGlobalAccel::IsKGlobalAccelAvailable() { - return QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kKdeService)); + return QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kKGlobalAccelService)); } -bool GlobalShortcutsBackendKDE::IsAvailable() const { +bool GlobalShortcutsBackendKGlobalAccel::IsAvailable() const { - return IsKDEAvailable(); + return IsKGlobalAccelAvailable(); } -bool GlobalShortcutsBackendKDE::IsMediaShortcut(const GlobalShortcutsManager::Shortcut &shortcut) const { +bool GlobalShortcutsBackendKGlobalAccel::IsMediaShortcut(const GlobalShortcutsManager::Shortcut &shortcut) const { return (shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay) || shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaStop) || @@ -72,17 +72,17 @@ bool GlobalShortcutsBackendKDE::IsMediaShortcut(const GlobalShortcutsManager::Sh } -bool GlobalShortcutsBackendKDE::DoRegister() { +bool GlobalShortcutsBackendKGlobalAccel::DoRegister() { qLog(Debug) << "Registering"; - if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kKdeService))) { + if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(kKGlobalAccelService))) { qLog(Warning) << "KGlobalAccel is not registered"; return false; } if (!interface_) { - interface_ = new OrgKdeKGlobalAccelInterface(QLatin1String(kKdeService), QLatin1String(kKdePath), QDBusConnection::sessionBus(), this); + interface_ = new OrgKdeKGlobalAccelInterface(QLatin1String(kKGlobalAccelService), QLatin1String(kKGlobalAccelPath), QDBusConnection::sessionBus(), this); } const QList shortcuts = manager_->shortcuts().values(); @@ -92,13 +92,13 @@ bool GlobalShortcutsBackendKDE::DoRegister() { QDBusPendingReply reply = interface_->getComponent(QCoreApplication::applicationName()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendKDE::RegisterFinished); + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendKGlobalAccel::RegisterFinished); return true; } -void GlobalShortcutsBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watcher) { +void GlobalShortcutsBackendKGlobalAccel::RegisterFinished(QDBusPendingCallWatcher *watcher) { QDBusReply reply = watcher->reply(); watcher->deleteLater(); @@ -111,7 +111,7 @@ void GlobalShortcutsBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watche } if (!component_) { - component_ = new org::kde::kglobalaccel::Component(QLatin1String(kKdeService), reply.value().path(), QDBusConnection::sessionBus(), interface_); + component_ = new org::kde::kglobalaccel::Component(QLatin1String(kKGlobalAccelService), reply.value().path(), QDBusConnection::sessionBus(), interface_); } if (!component_->isValid()) { @@ -119,13 +119,13 @@ void GlobalShortcutsBackendKDE::RegisterFinished(QDBusPendingCallWatcher *watche return; } - QObject::connect(component_, &org::kde::kglobalaccel::Component::globalShortcutPressed, this, &GlobalShortcutsBackendKDE::GlobalShortcutPressed, Qt::UniqueConnection); + QObject::connect(component_, &org::kde::kglobalaccel::Component::globalShortcutPressed, this, &GlobalShortcutsBackendKGlobalAccel::GlobalShortcutPressed, Qt::UniqueConnection); qLog(Debug) << "Registered."; } -void GlobalShortcutsBackendKDE::DoUnregister() { +void GlobalShortcutsBackendKGlobalAccel::DoUnregister() { if (!interface_ || !interface_->isValid()) return; @@ -146,7 +146,7 @@ void GlobalShortcutsBackendKDE::DoUnregister() { } -bool GlobalShortcutsBackendKDE::RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut) { +bool GlobalShortcutsBackendKGlobalAccel::RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut) { if (!interface_ || !interface_->isValid() || shortcut.id.isEmpty() || !shortcut.action || shortcut.action->shortcut().isEmpty()) return false; @@ -172,7 +172,7 @@ bool GlobalShortcutsBackendKDE::RegisterShortcut(const GlobalShortcutsManager::S } -QStringList GlobalShortcutsBackendKDE::GetActionId(const QString &id, const QAction *action) { +QStringList GlobalShortcutsBackendKGlobalAccel::GetActionId(const QString &id, const QAction *action) { QStringList ret; ret << QCoreApplication::applicationName(); @@ -185,7 +185,7 @@ QStringList GlobalShortcutsBackendKDE::GetActionId(const QString &id, const QAct } -QList GlobalShortcutsBackendKDE::ToIntList(const QList &sequence_list) { +QList GlobalShortcutsBackendKGlobalAccel::ToIntList(const QList &sequence_list) { QList ret; ret.reserve(sequence_list.count()); @@ -197,7 +197,7 @@ QList GlobalShortcutsBackendKDE::ToIntList(const QList &seque } -QList GlobalShortcutsBackendKDE::ToKeySequenceList(const QList &sequence_list) { +QList GlobalShortcutsBackendKGlobalAccel::ToKeySequenceList(const QList &sequence_list) { QList ret; ret.reserve(sequence_list.count()); @@ -209,7 +209,7 @@ QList GlobalShortcutsBackendKDE::ToKeySequenceList(const QList shortcuts() const { return shortcuts_; } #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS) - static bool IsKdeAvailable(); + static bool IsKGlobalAccelAvailable(); #endif #ifdef HAVE_X11_GLOBALSHORTCUTS diff --git a/src/settings/globalshortcutssettingspage.cpp b/src/settings/globalshortcutssettingspage.cpp index 3b4585f72..524cd6d0e 100644 --- a/src/settings/globalshortcutssettingspage.cpp +++ b/src/settings/globalshortcutssettingspage.cpp @@ -41,7 +41,6 @@ #include "core/iconloader.h" #include "core/logging.h" #include "core/settings.h" -#include "utilities/envutils.h" #include "constants/globalshortcutssettings.h" #include "globalshortcuts/globalshortcutgrabber.h" #include "globalshortcuts/globalshortcutsmanager.h" @@ -72,10 +71,10 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog, QObject::connect(ui_->radio_custom, &QRadioButton::clicked, this, &GlobalShortcutsSettingsPage::ChangeClicked); QObject::connect(ui_->button_change, &QPushButton::clicked, this, &GlobalShortcutsSettingsPage::ChangeClicked); -#ifdef HAVE_KDE_GLOBALSHORTCUTS - QObject::connect(ui_->checkbox_kde, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged); +#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS + QObject::connect(ui_->checkbox_kglobalaccel, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged); #else - ui_->widget_kde->hide(); + ui_->widget_kglobalaccel->hide(); #endif #ifdef HAVE_X11_GLOBALSHORTCUTS @@ -100,21 +99,20 @@ void GlobalShortcutsSettingsPage::Load() { if (!initialized_) { initialized_ = true; - de_ = Utilities::DesktopEnvironment(); ui_->widget_warning->hide(); #ifdef Q_OS_MACOS QObject::connect(ui_->button_macos_preferences, &QPushButton::clicked, global_shortcuts_manager_, &GlobalShortcutsManager::ShowMacAccessibilityDialog); #endif -#ifdef HAVE_KDE_GLOBALSHORTCUTS - if (GlobalShortcutsManager::IsKdeAvailable()) { - qLog(Debug) << "KDE (KGlobalAccel) backend is available."; - ui_->widget_kde->show(); +#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS + if (GlobalShortcutsManager::IsKGlobalAccelAvailable()) { + qLog(Debug) << "KGlobalAccel backend is available."; + ui_->widget_kglobalaccel->show(); } else { - qLog(Debug) << "KDE (KGlobalAccel) backend is unavailable."; - ui_->widget_kde->hide(); + qLog(Debug) << "KGlobalAccel backend is unavailable."; + ui_->widget_kglobalaccel->hide(); } #endif @@ -148,9 +146,9 @@ void GlobalShortcutsSettingsPage::Load() { SetShortcut(shortcut.s.id, shortcut.s.action->shortcut()); } -#ifdef HAVE_KDE_GLOBALSHORTCUTS - if (ui_->widget_kde->isVisibleTo(this)) { - ui_->checkbox_kde->setChecked(s.value(kUseKDE, true).toBool()); +#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS + if (ui_->widget_kglobalaccel->isVisibleTo(this)) { + ui_->checkbox_kglobalaccel->setChecked(s.value(kUseKGlobalAccel, true).toBool()); } #endif @@ -160,7 +158,7 @@ void GlobalShortcutsSettingsPage::Load() { } #endif -#if defined(HAVE_KDE_GLOBALSHORTCUTS) || defined(HAVE_X11_GLOBALSHORTCUTS) +#if defined(HAVE_KGLOBALACCEL_GLOBALSHORTCUTS) || defined(HAVE_X11_GLOBALSHORTCUTS) ShortcutOptionsChanged(); #endif @@ -188,8 +186,8 @@ void GlobalShortcutsSettingsPage::Save() { s.setValue(shortcut.s.id, shortcut.key.toString()); } -#ifdef HAVE_KDE_GLOBALSHORTCUTS - s.setValue(kUseKDE, ui_->checkbox_kde->isChecked()); +#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS + s.setValue(kUseKGlobalAccel, ui_->checkbox_kglobalaccel->isChecked()); #endif #ifdef HAVE_X11_GLOBALSHORTCUTS @@ -204,7 +202,7 @@ void GlobalShortcutsSettingsPage::Save() { void GlobalShortcutsSettingsPage::ShortcutOptionsChanged() { - bool configure_shortcuts = (ui_->widget_kde->isVisibleTo(this) && ui_->checkbox_kde->isChecked()) || + bool configure_shortcuts = (ui_->widget_kglobalaccel->isVisibleTo(this) && ui_->checkbox_kglobalaccel->isChecked()) || (ui_->widget_x11->isVisibleTo(this) && ui_->checkbox_x11->isChecked()); ui_->list->setEnabled(configure_shortcuts); @@ -289,15 +287,7 @@ void GlobalShortcutsSettingsPage::ChangeClicked() { void GlobalShortcutsSettingsPage::X11Warning() { - QString de = de_.toLower(); - if (de == "kde"_L1 || de == "gnome"_L1 || de == "x-cinnamon"_L1 || de == "mate"_L1) { - QString text(tr("Using X11 shortcuts on %1 is not recommended and can cause keyboard to become unresponsive!").arg(de_)); - text += tr(" Shortcuts on %1 are usually used through MPRIS and KGlobalAccel.").arg(de_); - ui_->label_warn_text->setText(text); - ui_->widget_warning->show(); - } - else { - ui_->widget_warning->hide(); - } + ui_->label_warn_text->setText(tr("Using X11 shortcuts is not recommended and can cause keyboard to become unresponsive! Shortcuts on should usually be used through MPRIS2 / KGlobalAccel.")); + ui_->widget_warning->show(); } diff --git a/src/settings/globalshortcutssettingspage.h b/src/settings/globalshortcutssettingspage.h index 5364d63ea..9a31e4771 100644 --- a/src/settings/globalshortcutssettingspage.h +++ b/src/settings/globalshortcutssettingspage.h @@ -78,7 +78,6 @@ class GlobalShortcutsSettingsPage : public SettingsPage { QMap shortcuts_; QString current_id_; - QString de_; }; #endif // GLOBALSHORTCUTSSETTINGSPAGE_H diff --git a/src/settings/globalshortcutssettingspage.ui b/src/settings/globalshortcutssettingspage.ui index d5430d3f2..506d63ada 100644 --- a/src/settings/globalshortcutssettingspage.ui +++ b/src/settings/globalshortcutssettingspage.ui @@ -19,7 +19,7 @@ - + 0 @@ -34,9 +34,9 @@ 0 - + - Use KDE (KGlobalAccel) shortcuts when available + Use KGlobalAccel shortcuts when available