From 4ed6f942113da5ee4d76b59a7157a64e7179bd31 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 2 Apr 2014 16:12:03 +0200 Subject: [PATCH] Open the right part of the system preferences for global shortcuts on Mavericks. --- src/CMakeLists.txt | 1 + src/core/macglobalshortcutbackend.mm | 56 ++++++--- src/mac/SBSystemPreferences.h | 171 +++++++++++++++++++++++++++ 3 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 src/mac/SBSystemPreferences.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5e50dbb3..a9bfeec85 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1297,6 +1297,7 @@ if (APPLE) /System/Library/Frameworks/DiskArbitration.framework /System/Library/Frameworks/Foundation.framework /System/Library/Frameworks/IOKit.framework + /System/Library/Frameworks/ScriptingBridge.framework ) target_link_libraries(clementine_lib ${SPMEDIAKEYTAP_LIBRARIES}) if (HAVE_SPARKLE) diff --git a/src/core/macglobalshortcutbackend.mm b/src/core/macglobalshortcutbackend.mm index 575421084..566a93cc9 100644 --- a/src/core/macglobalshortcutbackend.mm +++ b/src/core/macglobalshortcutbackend.mm @@ -17,23 +17,27 @@ #include "macglobalshortcutbackend.h" -#include "config.h" -#include "globalshortcuts.h" -#include "mac_startup.h" -#import "mac_utilities.h" - #include +#include +#include +#include +#include + #include #include #include #include #include -#include -#include -#include -#include +#include "config.h" +#include "core/globalshortcuts.h" +#include "core/logging.h" +#include "core/mac_startup.h" +#include "core/utilities.h" + +#import "core/mac_utilities.h" +#import "mac/SBSystemPreferences.h" class MacGlobalShortcutBackendPrivate : boost::noncopyable { public: @@ -134,10 +138,34 @@ void MacGlobalShortcutBackend::ShowAccessibilityDialog() { 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]; + NSURL* prefpane_url = nil; + if (Utilities::GetMacVersion() < 9) { + prefpane_url = + [NSURL fileURLWithPath:[[paths objectAtIndex:0] + stringByAppendingPathComponent: + @"UniversalAccessPref.prefPane"]]; + [[NSWorkspace sharedWorkspace] openURL:prefpane_url]; + } else { + SBSystemPreferencesApplication* system_prefs = [SBApplication + applicationWithBundleIdentifier:@"com.apple.systempreferences"]; + [system_prefs activate]; + + SBElementArray* panes = [system_prefs panes]; + SBSystemPreferencesPane* security_pane = nil; + for (SBSystemPreferencesPane* pane : panes) { + if ([[pane id] isEqualToString:@"com.apple.preference.security"]) { + security_pane = pane; + break; + } + } + [system_prefs setCurrentPane:security_pane]; + + SBElementArray* anchors = [security_pane anchors]; + for (SBSystemPreferencesAnchor* anchor : anchors) { + if ([[anchor name] isEqualToString:@"Privacy_Accessibility"]) { + [anchor reveal]; + } + } + } } } diff --git a/src/mac/SBSystemPreferences.h b/src/mac/SBSystemPreferences.h new file mode 100644 index 000000000..387d30025 --- /dev/null +++ b/src/mac/SBSystemPreferences.h @@ -0,0 +1,171 @@ +/* + * SBSystemPreferences.h + * + * Generated with: + * sdef "/Applications/System Preferences.app" | sdp -fh --basename + *SBSystemPreferences -o SBSystemPreferences.h + */ + +#import +#import + +@class SBSystemPreferencesApplication, SBSystemPreferencesDocument, + SBSystemPreferencesWindow, SBSystemPreferencesPane, + SBSystemPreferencesAnchor; + +enum SBSystemPreferencesSaveOptions { + SBSystemPreferencesSaveOptionsYes = 'yes ' /* Save the file. */, + SBSystemPreferencesSaveOptionsNo = 'no ' /* Do not save the file. */, + SBSystemPreferencesSaveOptionsAsk = + 'ask ' /* Ask the user whether or not to save the file. */ +}; +typedef enum SBSystemPreferencesSaveOptions SBSystemPreferencesSaveOptions; + +enum SBSystemPreferencesPrintingErrorHandling { + SBSystemPreferencesPrintingErrorHandlingStandard = + 'lwst' /* Standard PostScript error handling */, + SBSystemPreferencesPrintingErrorHandlingDetailed = + 'lwdt' /* print a detailed report of PostScript errors */ +}; +typedef enum SBSystemPreferencesPrintingErrorHandling + SBSystemPreferencesPrintingErrorHandling; + +/* + * Standard Suite + */ + +// The application's top-level scripting object. +@interface SBSystemPreferencesApplication : SBApplication + +- (SBElementArray*)documents; +- (SBElementArray*)windows; + +@property(copy, readonly) NSString* name; // The name of the application. +@property(readonly) BOOL frontmost; // Is this the active application? +@property(copy, readonly) + NSString* version; // The version number of the application. + +- (id)open:(id)x; // Open a document. +- (void)print:(id)x + withProperties:(NSDictionary*)withProperties + printDialog:(BOOL)printDialog; // Print a document. +- (void)quitSaving: + (SBSystemPreferencesSaveOptions)saving; // Quit the application. +- (BOOL)exists:(id)x; // Verify that an object exists. + +@end + +// A document. +@interface SBSystemPreferencesDocument : SBObject + +@property(copy, readonly) NSString* name; // Its name. +@property(readonly) BOOL modified; // Has it been modified since the last save? +@property(copy, readonly) NSURL* file; // Its location on disk, if it has one. + +- (void)closeSaving:(SBSystemPreferencesSaveOptions)saving + savingIn:(NSURL*)savingIn; // Close a document. +- (void)saveIn:(NSURL*)in_ as:(id)as; // Save a document. +- (void)printWithProperties:(NSDictionary*)withProperties + printDialog:(BOOL)printDialog; // Print a document. +- (void) delete; // Delete an object. +- (void)duplicateTo:(SBObject*)to + withProperties:(NSDictionary*)withProperties; // Copy an object. +- (void)moveTo:(SBObject*)to; // Move an object to a new location. + +@end + +// A window. +@interface SBSystemPreferencesWindow : SBObject + +@property(copy, readonly) NSString* name; // The title of the window. +- (NSInteger)id; // The unique identifier of the window. +@property NSInteger index; // The index of the window, ordered front to back. +@property NSRect bounds; // The bounding rectangle of the window. +@property(readonly) BOOL closeable; // Does the window have a close button? +@property(readonly) + BOOL miniaturizable; // Does the window have a minimize button? +@property BOOL miniaturized; // Is the window minimized right now? +@property(readonly) BOOL resizable; // Can the window be resized? +@property BOOL visible; // Is the window visible right now? +@property(readonly) BOOL zoomable; // Does the window have a zoom button? +@property BOOL zoomed; // Is the window zoomed right now? +@property(copy, readonly) SBSystemPreferencesDocument* + document; // The document whose contents are displayed in the window. + +- (void)closeSaving:(SBSystemPreferencesSaveOptions)saving + savingIn:(NSURL*)savingIn; // Close a document. +- (void)saveIn:(NSURL*)in_ as:(id)as; // Save a document. +- (void)printWithProperties:(NSDictionary*)withProperties + printDialog:(BOOL)printDialog; // Print a document. +- (void) delete; // Delete an object. +- (void)duplicateTo:(SBObject*)to + withProperties:(NSDictionary*)withProperties; // Copy an object. +- (void)moveTo:(SBObject*)to; // Move an object to a new location. + +@end + +/* + * System Preferences + */ + +// System Preferences top level scripting object +@interface SBSystemPreferencesApplication (SystemPreferences) + +- (SBElementArray*)panes; + +@property(copy) + SBSystemPreferencesPane* currentPane; // the currently selected pane +@property(copy, readonly) SBSystemPreferencesWindow* + preferencesWindow; // the main preferences window +@property BOOL showAll; // Is SystemPrefs in show all view. (Setting to false + // will do nothing) + +@end + +// a preference pane +@interface SBSystemPreferencesPane : SBObject + +- (SBElementArray*)anchors; + +- (NSString*)id; // locale independent name of the preference pane; can refer + // to a pane using the expression: pane id "" +@property(copy, readonly) + NSString* localizedName; // localized name of the preference pane +@property(copy, readonly) NSString* name; // name of the preference pane as it + // appears in the title bar; can + // refer to a pane using the + // expression: pane "" + +- (void)closeSaving:(SBSystemPreferencesSaveOptions)saving + savingIn:(NSURL*)savingIn; // Close a document. +- (void)saveIn:(NSURL*)in_ as:(id)as; // Save a document. +- (void)printWithProperties:(NSDictionary*)withProperties + printDialog:(BOOL)printDialog; // Print a document. +- (void) delete; // Delete an object. +- (void)duplicateTo:(SBObject*)to + withProperties:(NSDictionary*)withProperties; // Copy an object. +- (void)moveTo:(SBObject*)to; // Move an object to a new location. +- (id)reveal; // Reveals an anchor within a preference pane or preference pane + // itself + +@end + +// an anchor within a preference pane +@interface SBSystemPreferencesAnchor : SBObject + +@property(copy, readonly) + NSString* name; // name of the anchor within a preference pane + +- (void)closeSaving:(SBSystemPreferencesSaveOptions)saving + savingIn:(NSURL*)savingIn; // Close a document. +- (void)saveIn:(NSURL*)in_ as:(id)as; // Save a document. +- (void)printWithProperties:(NSDictionary*)withProperties + printDialog:(BOOL)printDialog; // Print a document. +- (void) delete; // Delete an object. +- (void)duplicateTo:(SBObject*)to + withProperties:(NSDictionary*)withProperties; // Copy an object. +- (void)moveTo:(SBObject*)to; // Move an object to a new location. +- (id)reveal; // Reveals an anchor within a preference pane or preference pane + // itself + +@end