From 25be0a1465fc49de7bbe41251d3f7fed13ba0540 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 17 Jun 2010 21:33:16 +0000 Subject: [PATCH] *Catch global shortcuts when clementine is focused. *Automatically ask the user to enable assistive devices. --- src/core/macglobalshortcutbackend.h | 8 ++- src/core/macglobalshortcutbackend.mm | 81 +++++++++++++++++++++++++--- src/translations/ar.po | 15 ++++++ src/translations/cs.po | 15 ++++++ src/translations/da.po | 15 ++++++ src/translations/de.po | 15 ++++++ src/translations/el.po | 15 ++++++ src/translations/en_CA.po | 15 ++++++ src/translations/en_GB.po | 15 ++++++ src/translations/es.po | 15 ++++++ src/translations/fi.po | 15 ++++++ src/translations/fr.po | 15 ++++++ src/translations/gl.po | 15 ++++++ src/translations/it.po | 15 ++++++ src/translations/kk.po | 15 ++++++ src/translations/nb.po | 15 ++++++ src/translations/oc.po | 15 ++++++ src/translations/pl.po | 15 ++++++ src/translations/pt.po | 15 ++++++ src/translations/pt_BR.po | 15 ++++++ src/translations/ro.po | 15 ++++++ src/translations/ru.po | 15 ++++++ src/translations/sk.po | 15 ++++++ src/translations/sv.po | 15 ++++++ src/translations/tr.po | 15 ++++++ src/translations/zh_CN.po | 15 ++++++ src/translations/zh_TW.po | 15 ++++++ 27 files changed, 455 insertions(+), 9 deletions(-) diff --git a/src/core/macglobalshortcutbackend.h b/src/core/macglobalshortcutbackend.h index 029e3d45a..97a3d8ef0 100644 --- a/src/core/macglobalshortcutbackend.h +++ b/src/core/macglobalshortcutbackend.h @@ -40,11 +40,17 @@ protected: private: void KeyPressed(const QKeySequence& sequence); + bool CheckAccessibilityEnabled(); QMap shortcuts_; - friend class MacGlobalShortcutBackendPrivate; + enum AccessibilityStatus { + NOT_CHECKED, + ENABLED, + DISABLED + } accessibility_status_; + friend class MacGlobalShortcutBackendPrivate; MacGlobalShortcutBackendPrivate* p_; }; diff --git a/src/core/macglobalshortcutbackend.mm b/src/core/macglobalshortcutbackend.mm index 4f4a55df0..e34a4510f 100644 --- a/src/core/macglobalshortcutbackend.mm +++ b/src/core/macglobalshortcutbackend.mm @@ -23,26 +23,34 @@ #include #include +#include +#include #include #include +#include #include #include class MacGlobalShortcutBackendPrivate : boost::noncopyable { public: explicit MacGlobalShortcutBackendPrivate(MacGlobalShortcutBackend* backend) - : monitor_(nil), + : global_monitor_(nil), + local_monitor_(nil), backend_(backend) { } bool Register() { #ifdef NS_BLOCKS_AVAILABLE - monitor_ = [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask + global_monitor_ = [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent* event) { - qDebug() << __PRETTY_FUNCTION__; HandleKeyEvent(event); }]; + local_monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask + handler:^(NSEvent* event) { + HandleKeyEvent(event); + return event; + }]; return true; #else return false; @@ -50,7 +58,45 @@ class MacGlobalShortcutBackendPrivate : boost::noncopyable { } void Unregister() { - [NSEvent removeMonitor:monitor_]; + [NSEvent removeMonitor:global_monitor_]; + [NSEvent removeMonitor:local_monitor_]; + } + + // See UIElementInspector example. + bool CheckAccessibilityEnabled() { + if (AXAPIEnabled()) { + return true; + } + + QMessageBox box( + QMessageBox::Question, + QObject::tr("Accessibility API required for global shortcuts"), + QObject::tr("Would you like to launch System Preferences so that you can turn on" + " \"Enable access for assistive devices\"?\n" + "This is required to use global shortcuts in Clementine.")); + QPushButton* default_button = + box.addButton(QObject::tr("Open System Preferences"), QMessageBox::AcceptRole); + QPushButton* continue_button = + box.addButton(QObject::tr("Continue anyway"), QMessageBox::RejectRole); + box.setDefaultButton(default_button); + + box.exec(); + QPushButton* clicked_button = static_cast(box.clickedButton()); + if (clicked_button == default_button) { + NSArray* paths = NSSearchPathForDirectoriesInDomains( + NSPreferencePanesDirectory, NSSystemDomainMask, YES); + if ([paths count] == 1) { + NSURL* prefpane_url = [NSURL fileURLWithPath: + [[paths objectAtIndex:0] stringByAppendingPathComponent:@"UniversalAccessPref.prefPane"]]; + [[NSWorkspace sharedWorkspace] openURL:prefpane_url]; + } + // We assume the user actually clicks the button in the preference pane here... + return true; + } else if (clicked_button == continue_button) { + return false; + } + + return false; } private: @@ -81,12 +127,14 @@ class MacGlobalShortcutBackendPrivate : boost::noncopyable { backend_->KeyPressed(sequence); } - id monitor_; + id global_monitor_; + id local_monitor_; MacGlobalShortcutBackend* backend_; }; MacGlobalShortcutBackend::MacGlobalShortcutBackend(GlobalShortcuts* parent) : GlobalShortcutBackend(parent), + accessibility_status_(NOT_CHECKED), p_(new MacGlobalShortcutBackendPrivate(this)) { } @@ -95,15 +143,28 @@ MacGlobalShortcutBackend::~MacGlobalShortcutBackend() { } bool MacGlobalShortcutBackend::DoRegister() { + // Always enable media keys. mac::SetShortcutHandler(this); - foreach (const GlobalShortcuts::Shortcut& shortcut, manager_->shortcuts().values()) { - shortcuts_[shortcut.action->shortcut()] = shortcut.action; + + // Check whether universal access is enabled so that global shortcuts will work. + // This may pop up a modal dialog so only ask once per session. + if (accessibility_status_ == NOT_CHECKED) { + accessibility_status_ = CheckAccessibilityEnabled() ? ENABLED : DISABLED; } - return p_->Register(); + + if (accessibility_status_ == ENABLED && AXAPIEnabled()) { + foreach (const GlobalShortcuts::Shortcut& shortcut, manager_->shortcuts().values()) { + shortcuts_[shortcut.action->shortcut()] = shortcut.action; + } + return p_->Register(); + } + + return false; } void MacGlobalShortcutBackend::DoUnregister() { p_->Unregister(); + shortcuts_.clear(); } void MacGlobalShortcutBackend::MacMediaKeyPressed(int key) { @@ -126,3 +187,7 @@ void MacGlobalShortcutBackend::KeyPressed(const QKeySequence& sequence) { action->trigger(); } } + +bool MacGlobalShortcutBackend::CheckAccessibilityEnabled() { + return p_->CheckAccessibilityEnabled(); +} diff --git a/src/translations/ar.po b/src/translations/ar.po index 2e44201dd..1e73ba42d 100644 --- a/src/translations/ar.po +++ b/src/translations/ar.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/cs.po b/src/translations/cs.po index e8f039e1e..e965aeea3 100644 --- a/src/translations/cs.po +++ b/src/translations/cs.po @@ -875,6 +875,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Pokročilé řazení knihoven" diff --git a/src/translations/da.po b/src/translations/da.po index 621af2621..9f50e0afc 100644 --- a/src/translations/da.po +++ b/src/translations/da.po @@ -878,6 +878,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Avanceret bibliotektsgruppering" diff --git a/src/translations/de.po b/src/translations/de.po index 013223b22..bcda69668 100644 --- a/src/translations/de.po +++ b/src/translations/de.po @@ -877,6 +877,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Benutzerdefiniertes Gruppieren" diff --git a/src/translations/el.po b/src/translations/el.po index 45d3e932b..4fc32afc4 100644 --- a/src/translations/el.po +++ b/src/translations/el.po @@ -880,6 +880,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Προχωρημένη ομαδοποίηση βιβλιοθήκης" diff --git a/src/translations/en_CA.po b/src/translations/en_CA.po index e0907ae75..90130809e 100644 --- a/src/translations/en_CA.po +++ b/src/translations/en_CA.po @@ -877,6 +877,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Library advanced grouping" diff --git a/src/translations/en_GB.po b/src/translations/en_GB.po index 00654f36c..bc93c4251 100644 --- a/src/translations/en_GB.po +++ b/src/translations/en_GB.po @@ -874,6 +874,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Library advanced grouping" diff --git a/src/translations/es.po b/src/translations/es.po index 0367faa43..b2f6e5aad 100644 --- a/src/translations/es.po +++ b/src/translations/es.po @@ -880,6 +880,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Agrupamiento avanzado de la colección" diff --git a/src/translations/fi.po b/src/translations/fi.po index 842adf77f..e7ce58fcb 100644 --- a/src/translations/fi.po +++ b/src/translations/fi.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/fr.po b/src/translations/fr.po index 2ebe978cb..fcb7e3e5b 100644 --- a/src/translations/fr.po +++ b/src/translations/fr.po @@ -877,6 +877,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Groupement avancé de la bibliothèque" diff --git a/src/translations/gl.po b/src/translations/gl.po index 44dd28068..22a218c63 100644 --- a/src/translations/gl.po +++ b/src/translations/gl.po @@ -875,6 +875,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/it.po b/src/translations/it.po index 05be7a44f..4825f9fa5 100644 --- a/src/translations/it.po +++ b/src/translations/it.po @@ -880,6 +880,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Raggruppamento avanzato della raccolta" diff --git a/src/translations/kk.po b/src/translations/kk.po index 130ebfc63..0eb4a5649 100644 --- a/src/translations/kk.po +++ b/src/translations/kk.po @@ -875,6 +875,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/nb.po b/src/translations/nb.po index ce7350ae8..8320cd3d0 100644 --- a/src/translations/nb.po +++ b/src/translations/nb.po @@ -875,6 +875,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Avansert biblioteksgruppering" diff --git a/src/translations/oc.po b/src/translations/oc.po index 88552baa8..b14a9c3cc 100644 --- a/src/translations/oc.po +++ b/src/translations/oc.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/pl.po b/src/translations/pl.po index 1026f1116..9730c28c1 100644 --- a/src/translations/pl.po +++ b/src/translations/pl.po @@ -875,6 +875,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Zaawansowanie grupowanie Biblioteki" diff --git a/src/translations/pt.po b/src/translations/pt.po index 94821693b..fbe72d770 100644 --- a/src/translations/pt.po +++ b/src/translations/pt.po @@ -878,6 +878,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Agrupamento avançado da biblioteca" diff --git a/src/translations/pt_BR.po b/src/translations/pt_BR.po index 8b37c1f18..d94c1b815 100644 --- a/src/translations/pt_BR.po +++ b/src/translations/pt_BR.po @@ -880,6 +880,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Organização avançada de biblioteca" diff --git a/src/translations/ro.po b/src/translations/ro.po index 7b2782b51..a8504f66a 100644 --- a/src/translations/ro.po +++ b/src/translations/ro.po @@ -874,6 +874,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/ru.po b/src/translations/ru.po index c62606353..cd2c928f1 100644 --- a/src/translations/ru.po +++ b/src/translations/ru.po @@ -878,6 +878,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Расширенная сортировка коллекции" diff --git a/src/translations/sk.po b/src/translations/sk.po index ea8c2b966..8664f78c8 100644 --- a/src/translations/sk.po +++ b/src/translations/sk.po @@ -878,6 +878,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Pokročilé zoraďovanie zbierky" diff --git a/src/translations/sv.po b/src/translations/sv.po index 04d38025c..a3cc4dd55 100644 --- a/src/translations/sv.po +++ b/src/translations/sv.po @@ -876,6 +876,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "Bibliotek avancerad gruppering" diff --git a/src/translations/tr.po b/src/translations/tr.po index 6cb2d4258..9365f1f43 100644 --- a/src/translations/tr.po +++ b/src/translations/tr.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/zh_CN.po b/src/translations/zh_CN.po index bd9382ae5..c346c326f 100644 --- a/src/translations/zh_CN.po +++ b/src/translations/zh_CN.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr "" diff --git a/src/translations/zh_TW.po b/src/translations/zh_TW.po index 52b6f9c48..7ca143e14 100644 --- a/src/translations/zh_TW.po +++ b/src/translations/zh_TW.po @@ -873,6 +873,21 @@ msgstr "" msgid "Select None" msgstr "" +msgid "Accessibility API required for global shortcuts" +msgstr "" + +msgid "" +"Would you like to launch System Preferences so that you can turn on \"Enable " +"access for assistive devices\"?\n" +"This is required to use global shortcuts in Clementine." +msgstr "" + +msgid "Open System Preferences" +msgstr "" + +msgid "Continue anyway" +msgstr "" + msgid "Library advanced grouping" msgstr ""