PageRenderTime 38ms CodeModel.GetById 18ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/filesystems-objc/SpotlightFS/Source/SpotlightFSController.m

http://macfuse.googlecode.com/
Objective C | 69 lines | 39 code | 8 blank | 22 comment | 0 complexity | 7924c762a5c47ea4eec2ce48011383ed 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//  SpotlightFSController.m
18//  SpotlightFS
19//
20//  Created by ted on 1/3/08.
21//
22
23#import "SpotlightFSController.h"
24#import "SpotlightFS.h"
25#import <MacFUSE/GMUserFileSystem.h>
26
27@implementation SpotlightFSController
28
29- (void)didMount:(NSNotification *)notification {
30  // Show the mount point in Finder window 
31  NSDictionary* userInfo = [notification userInfo];
32  NSString* mountPath = [userInfo objectForKey:kGMUserFileSystemMountPathKey];
33  NSString* parentPath = [mountPath stringByDeletingLastPathComponent];
34  [[NSWorkspace sharedWorkspace] selectFile:mountPath
35                   inFileViewerRootedAtPath:parentPath];
36}
37
38- (void)didUnmount:(NSNotification*)notification {
39  [[NSApplication sharedApplication] terminate:nil];
40}
41
42- (void)applicationDidFinishLaunching:(NSNotification *)notification {  
43  NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
44  [center addObserver:self selector:@selector(didMount:)
45                 name:kGMUserFileSystemDidMount object:nil];
46  [center addObserver:self selector:@selector(didUnmount:)
47                 name:kGMUserFileSystemDidUnmount object:nil];
48  
49  NSString* mountPath = @"/Volumes/SpotlightFS";
50  SpotlightFS* spotlightfs = [[SpotlightFS alloc] init];
51  fs_ = [[GMUserFileSystem alloc] initWithDelegate:spotlightfs isThreadSafe:YES];
52  NSMutableArray* options = [NSMutableArray array];
53  NSString* volArg = 
54  [NSString stringWithFormat:@"volicon=%@", 
55   [[NSBundle mainBundle] pathForResource:@"SpotlightFSMount" ofType:@"icns"]];
56  [options addObject:volArg];  
57  [options addObject:@"volname=SpotlightFS"];
58  [fs_ mountAtPath:mountPath withOptions:options];
59}
60
61- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
62  [[NSNotificationCenter defaultCenter] removeObserver:self];
63  [fs_ unmount];  // Just in case we need to unmount;
64  [[fs_ delegate] release];  // Clean up SpotlightFS
65  [fs_ release];
66  return NSTerminateNow;
67}
68
69@end