PageRenderTime 35ms CodeModel.GetById 20ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/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
21#import "AccessibilityController.h"
22#import "AccessibilityFS.h"
23#import <MacFUSE/GMUserFileSystem.h>
24#import "GTMAXUIElement.h"
25
26NSString *const kMountPath = @"/Volumes/Accessibility";
27
28@implementation AccessibilityController
29
30- (void)applicationDidBecomeActive:(NSNotification *)notification {
31  NSString* parentPath = [kMountPath stringByDeletingLastPathComponent];
32  [[NSWorkspace sharedWorkspace] selectFile:kMountPath
33                   inFileViewerRootedAtPath:parentPath];
34}
35
36- (void)didMount:(NSNotification *)notification {
37  [self applicationDidBecomeActive:notification];
38}
39
40- (void)didUnmount:(NSNotification*)notification {  
41  [[NSApplication sharedApplication] terminate:nil];
42}
43
44- (void)applicationDidFinishLaunching:(NSNotification *)notification {
45  if (![GTMAXUIElement isAccessibilityEnabled]) {
46    NSAlert *alert = [[[NSAlert alloc] init] autorelease];
47    [alert setMessageText:NSLocalizedString(@"Can't start AccessibilityFS", 
48                                            @"Can't start error")];
49    [alert setInformativeText:NSLocalizedString(@"Please 'Enable access for assistive devices' in the 'Universal Access' System preference panel.", 
50                                                @"Can't start help")];
51    [alert runModal];
52    [NSApp terminate:self];
53  }
54  NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
55  [center addObserver:self selector:@selector(didMount:)
56                 name:kGMUserFileSystemDidMount object:nil];
57  [center addObserver:self selector:@selector(didUnmount:)
58                 name:kGMUserFileSystemDidUnmount object:nil];
59  
60  fs_ = [[GMUserFileSystem alloc] initWithDelegate:[[AccessibilityFS alloc] init]
61                                      isThreadSafe:NO];
62  
63  NSMutableArray* options = [NSMutableArray array];
64  NSString* volArg = 
65  [NSString stringWithFormat:@"volicon=%@", 
66   [[NSBundle mainBundle] pathForResource:@"AccessibilityFSMount" ofType:@"icns"]];
67  [options addObject:volArg];
68  [options addObject:@"volname=Accessibility"];
69  // Turn on for tons of fun debugging spew
70  // [options addObject:@"debug"];
71  [fs_ mountAtPath:kMountPath 
72       withOptions:options];
73}
74
75- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
76  [[NSNotificationCenter defaultCenter] removeObserver:self];
77  [fs_ unmount];
78  id delegate = [fs_ delegate];
79  [fs_ release];
80  [delegate release];
81  return NSTerminateNow;
82}
83
84@end