/filesystems-objc/AccessibilityFS/Source/AccessibilityController.m

http://macfuse.googlecode.com/ · Objective C · 84 lines · 52 code · 11 blank · 21 comment · 1 complexity · 5fca4de3e8d2327bce4da54148c5d72b MD5 · raw file

  1. // ================================================================
  2. // Copyright (C) 2008 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // ================================================================
  16. //
  17. // AccessibilityController.m
  18. // AccessibilityFS
  19. //
  20. #import "AccessibilityController.h"
  21. #import "AccessibilityFS.h"
  22. #import <MacFUSE/GMUserFileSystem.h>
  23. #import "GTMAXUIElement.h"
  24. NSString *const kMountPath = @"/Volumes/Accessibility";
  25. @implementation AccessibilityController
  26. - (void)applicationDidBecomeActive:(NSNotification *)notification {
  27. NSString* parentPath = [kMountPath stringByDeletingLastPathComponent];
  28. [[NSWorkspace sharedWorkspace] selectFile:kMountPath
  29. inFileViewerRootedAtPath:parentPath];
  30. }
  31. - (void)didMount:(NSNotification *)notification {
  32. [self applicationDidBecomeActive:notification];
  33. }
  34. - (void)didUnmount:(NSNotification*)notification {
  35. [[NSApplication sharedApplication] terminate:nil];
  36. }
  37. - (void)applicationDidFinishLaunching:(NSNotification *)notification {
  38. if (![GTMAXUIElement isAccessibilityEnabled]) {
  39. NSAlert *alert = [[[NSAlert alloc] init] autorelease];
  40. [alert setMessageText:NSLocalizedString(@"Can't start AccessibilityFS",
  41. @"Can't start error")];
  42. [alert setInformativeText:NSLocalizedString(@"Please 'Enable access for assistive devices' in the 'Universal Access' System preference panel.",
  43. @"Can't start help")];
  44. [alert runModal];
  45. [NSApp terminate:self];
  46. }
  47. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  48. [center addObserver:self selector:@selector(didMount:)
  49. name:kGMUserFileSystemDidMount object:nil];
  50. [center addObserver:self selector:@selector(didUnmount:)
  51. name:kGMUserFileSystemDidUnmount object:nil];
  52. fs_ = [[GMUserFileSystem alloc] initWithDelegate:[[AccessibilityFS alloc] init]
  53. isThreadSafe:NO];
  54. NSMutableArray* options = [NSMutableArray array];
  55. NSString* volArg =
  56. [NSString stringWithFormat:@"volicon=%@",
  57. [[NSBundle mainBundle] pathForResource:@"AccessibilityFSMount" ofType:@"icns"]];
  58. [options addObject:volArg];
  59. [options addObject:@"volname=Accessibility"];
  60. // Turn on for tons of fun debugging spew
  61. // [options addObject:@"debug"];
  62. [fs_ mountAtPath:kMountPath
  63. withOptions:options];
  64. }
  65. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
  66. [[NSNotificationCenter defaultCenter] removeObserver:self];
  67. [fs_ unmount];
  68. id delegate = [fs_ delegate];
  69. [fs_ release];
  70. [delegate release];
  71. return NSTerminateNow;
  72. }
  73. @end