PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems-objc/YTFS/YTFS_Controller.m

http://macfuse.googlecode.com/
Objective C | 86 lines | 54 code | 10 blank | 22 comment | 0 complexity | c6fdc9175b496d8ddeec16be8f8ffe72 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//  YTFS_Controller.m
18//  YTFS
19//
20//  Created by ted on 12/7/08.
21//
22#import "YTFS_Controller.h"
23#import "YTFS_Filesystem.h"
24#import "YTVideo.h"
25#import <MacFUSE/MacFUSE.h>
26
27@implementation YTFS_Controller
28
29- (void)mountFailed:(NSNotification *)notification {
30  NSDictionary* userInfo = [notification userInfo];
31  NSError* error = [userInfo objectForKey:kGMUserFileSystemErrorKey];
32  NSLog(@"kGMUserFileSystem Error: %@, userInfo=%@", error, [error userInfo]);  
33  NSRunAlertPanel(@"Mount Failed", [error localizedDescription], nil, nil, nil);
34  [[NSApplication sharedApplication] terminate:nil];
35}
36
37- (void)didMount:(NSNotification *)notification {
38  NSDictionary* userInfo = [notification userInfo];
39  NSString* mountPath = [userInfo objectForKey:kGMUserFileSystemMountPathKey];
40  NSString* parentPath = [mountPath stringByDeletingLastPathComponent];
41  [[NSWorkspace sharedWorkspace] selectFile:mountPath
42                   inFileViewerRootedAtPath:parentPath];
43}
44
45- (void)didUnmount:(NSNotification*)notification {
46  [[NSApplication sharedApplication] terminate:nil];
47}
48
49- (void)applicationDidFinishLaunching:(NSNotification *)notification {
50  // Pump up our url cache.
51  NSURLCache* cache = [NSURLCache sharedURLCache];
52  [cache setDiskCapacity:(1024 * 1024 * 500)];
53  [cache setMemoryCapacity:(1024 * 1024 * 40)];
54  
55  NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
56  [center addObserver:self selector:@selector(mountFailed:)
57                 name:kGMUserFileSystemMountFailed object:nil];
58  [center addObserver:self selector:@selector(didMount:)
59                 name:kGMUserFileSystemDidMount object:nil];
60  [center addObserver:self selector:@selector(didUnmount:)
61                 name:kGMUserFileSystemDidUnmount object:nil];
62  
63  NSString* mountPath = @"/Volumes/YTFS";
64  fs_delegate_ = 
65    [[YTFS_Filesystem alloc] initWithVideos:[YTVideo fetchTopRatedVideos]];
66  fs_ = [[GMUserFileSystem alloc] initWithDelegate:fs_delegate_ isThreadSafe:YES];
67
68  NSMutableArray* options = [NSMutableArray array];
69  NSString* volArg = 
70    [NSString stringWithFormat:@"volicon=%@", 
71     [[NSBundle mainBundle] pathForResource:@"YTFS" ofType:@"icns"]];
72  [options addObject:volArg];
73  [options addObject:@"volname=YTFS"];
74  [options addObject:@"rdonly"];
75  [fs_ mountAtPath:mountPath withOptions:options];
76}
77
78- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
79  [[NSNotificationCenter defaultCenter] removeObserver:self];
80  [fs_ unmount];
81  [fs_ release];
82  [fs_delegate_ release];
83  return NSTerminateNow;
84}
85
86@end