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