Skip to content

Commit

Permalink
Continued reformatting ...
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Gorbach committed Dec 9, 2009
1 parent 3ea5950 commit 129b488
Show file tree
Hide file tree
Showing 35 changed files with 823 additions and 1,293 deletions.
34 changes: 17 additions & 17 deletions MFClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,38 @@
@class MFClientFS, MFClientPlugin, MFClientRecent;

@interface MFClient : NSObject <MFClientProtocol> {
NSMutableDictionary* filesystemsDictionary;
NSMutableArray* persistentFilesystems;
NSMutableArray* temporaryFilesystems;
NSMutableDictionary* pluginsDictionary;
NSMutableArray* plugins;
NSMutableArray* recents;
NSMutableDictionary *filesystemsDictionary;
NSMutableArray *persistentFilesystems;
NSMutableArray *temporaryFilesystems;
NSMutableDictionary *pluginsDictionary;
NSMutableArray *plugins;
NSMutableArray *recents;
id <MFServerProtocol> server;
id<MFClientDelegateProtocol> delegate;
NSConnection* connection;
NSConnection *connection;
}

+ (MFClient*)sharedClient;
+ (MFClient *)sharedClient;

// Initialization
- (BOOL)setup;
- (void)fillInitialStatus;
- (BOOL)establishCommunication;

// Action methods
- (MFClientFS *)newFilesystemWithPlugin:(MFClientPlugin*)plugin;
- (MFClientFS *)quickMountFilesystemWithURL:(NSURL*)url error:(NSError**)error;
- (MFClientFS *)mountRecent:(MFClientRecent*)recent error:(NSError**)error;
- (void)deleteFilesystem:(MFClientFS*)fs;
- (MFClientFS *)newFilesystemWithPlugin:(MFClientPlugin *)plugin;
- (MFClientFS *)quickMountFilesystemWithURL:(NSURL *)url error:(NSError **)error;
- (MFClientFS *)mountRecent:(MFClientRecent *)recent error:(NSError **)error;
- (void)deleteFilesystem:(MFClientFS *)fs;

// Accessors
- (MFClientFS *)filesystemWithUUID:(NSString*)uuid;
- (MFClientPlugin *)pluginWithID:(NSString*)id;
- (MFClientFS *)filesystemWithUUID:(NSString *)uuid;
- (MFClientPlugin *)pluginWithID:(NSString *)id;

@property(retain) id delegate;

// All filesystems, including temporary ones
@property(readonly) NSArray* filesystems;
@property(readonly) NSArray *filesystems;

// Only filesystems that are not temporary
@property(readonly) NSArray *persistentFilesystems;
Expand All @@ -64,7 +64,7 @@
@property(readonly) NSArray *recents;

// UI Stuff
- (void)moveUUIDS:(NSArray*)uuid toRow:(NSUInteger)row;
- (NSString*)createMountIconForFilesystem:(MFClientFS*)fs atPath:(NSURL*)path;
- (void)moveUUIDS:(NSArray *)uuid toRow:(NSUInteger)row;
- (NSString *)createMountIconForFilesystem:(MFClientFS *)fs atPath:(NSURL *)path;

@end
82 changes: 39 additions & 43 deletions MFClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,34 @@
#define ORDERING_FILE_PATH @"~/Library/Application Support/Macfusion/Ordering.plist"

@interface MFClient(PrivateAPI)
- (void)storeFilesystem:(MFClientFS*)fs;
- (void)storePlugin:(MFClientPlugin*)plugin;
- (void)removeFilesystem:(MFClientFS*)fs;
- (void)storeFilesystem:(MFClientFS *)fs;
- (void)storePlugin:(MFClientPlugin *)plugin;
- (void)removeFilesystem:(MFClientFS *)fs;
- (void)loadOrdering;
- (void)setupKeychainMonitoring;
- (void)writeOrdering;
- (void)initializeIvars;
// Security monitoring

@property(readwrite, retain) NSMutableArray* persistentFilesystems;
@property(readwrite, retain) NSMutableArray* temporaryFilesystems;
@property(readwrite, retain) NSMutableArray* plugins;
@property(readwrite, retain) NSMutableArray* recents;
@property(readwrite, retain) NSMutableArray *persistentFilesystems;
@property(readwrite, retain) NSMutableArray *temporaryFilesystems;
@property(readwrite, retain) NSMutableArray *plugins;
@property(readwrite, retain) NSMutableArray *recents;
@end

@implementation MFClient

static MFClient* sharedClient = nil;
static MFClient *sharedClient = nil;

#pragma mark Singleton methods
+ (MFClient*)sharedClient {
+ (MFClient *)sharedClient {
if (sharedClient == nil) {
[[self alloc] init];
}

return sharedClient;
}

+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString *)key {
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
if ([key isEqualToString:@"filesystems"] || [key isEqualToString:@"mountedFilesystems"]) {
return [NSSet setWithObjects:@"persistentFilesystems", @"temporaryFilesystems", nil];
} else {
Expand All @@ -74,18 +73,17 @@ + (MFClient *)allocWithZone:(NSZone *)zone {
}

- (void)registerForGeneralNotifications {
NSDistributedNotificationCenter* dnc = [NSDistributedNotificationCenter defaultCenter];
NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(handleRecentsUpdatedNotification:) name:kMFRecentsUpdatedNotification object:kMFDNCObject];

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleApplicationTerminatingNotification:) name:NSApplicationWillTerminateNotification object:nil];

}

- (id)init {
self = [super init];
if (self != nil) {
[[MFLogging sharedLogging] setDelegate: self];
[[MFLogging sharedLogging] setDelegate:self];
[self registerForGeneralNotifications];
[self initializeIvars];
[self setupKeychainMonitoring];
Expand Down Expand Up @@ -121,16 +119,15 @@ - (void)fillInitialStatus {
MFClientPlugin *plugin = [[PluginClientClass alloc] initWithRemotePlugin:remotePlugin];
if (plugin) {
[self storePlugin: plugin];
}
else {
} else {
MFLogS(self, @"Could not init client plugin from server plugin %@", remotePlugin);
}
}

// Fill filesystems
filesystemsDictionary = [NSMutableDictionary dictionaryWithCapacity:10];
for(id remoteFS in remoteFilesystems) {
Class FSClientClass = NSClassFromString( [[remoteFS plugin] subclassNameForClassName: NSStringFromClass([MFClientFS class])]);
Class FSClientClass = NSClassFromString([[remoteFS plugin] subclassNameForClassName:NSStringFromClass([MFClientFS class])]);
if (!FSClientClass) {
MFLogS(self, @"Problem getting client fs class for fs %@", remoteFS);
FSClientClass = [MFClientFS class];
Expand Down Expand Up @@ -195,7 +192,7 @@ - (void)noteParametersChangedForFSWithUUID:(NSString *)uuid {
[fs noteParametersChanged];
}

- (void)noteFilesystemAddedWithUUID:(NSString*)uuid {
- (void)noteFilesystemAddedWithUUID:(NSString *)uuid {
MFLogS(self, @"Note fs added with uuid %@", uuid);
id remoteFilesystem = [server filesystemWithUUID: uuid];
if (![self filesystemWithUUID:uuid]) {
Expand All @@ -206,13 +203,13 @@ - (void)noteFilesystemAddedWithUUID:(NSString*)uuid {
}
}

- (void)noteFilesystemRemovedWithUUID:(NSString*)uuid {
- (void)noteFilesystemRemovedWithUUID:(NSString *)uuid {
MFLogS(self, @"Note fs removed with uuid %@", uuid);
MFClientFS* fs = [self filesystemWithUUID: uuid];
MFClientFS *fs = [self filesystemWithUUID: uuid];
[self removeFilesystem: fs];
}

- (void)noteRecentAdded:(NSDictionary*)recentParameters {
- (void)noteRecentAdded:(NSDictionary *)recentParameters {
[[self mutableArrayValueForKey:@"recents"] addObject:[[MFClientRecent alloc] initWithParameterDictionary: recentParameters ]];

if ([[self recents] count] > 10) {
Expand All @@ -221,13 +218,13 @@ - (void)noteRecentAdded:(NSDictionary*)recentParameters {
}

#pragma mark Action methods
- (MFClientFS*)newFilesystemWithPlugin:(MFClientPlugin*)plugin {
- (MFClientFS *)newFilesystemWithPlugin:(MFClientPlugin *)plugin {
NSAssert(plugin, @"MFClient asked to make new filesystem with nil plugin");
id newRemoteFS = [server newFilesystemWithPluginName: plugin.ID];
return [self filesystemWithUUID: [newRemoteFS uuid]];
}

- (MFClientFS*)quickMountFilesystemWithURL:(NSURL*)url error:(NSError**)error {
- (MFClientFS *)quickMountFilesystemWithURL:(NSURL *)url error:(NSError **)error {
id remoteFS = [server quickMountWithURL:url];
if (!remoteFS) {
NSError *serverError = [server recentError];
Expand Down Expand Up @@ -261,13 +258,13 @@ - (void)handleConnectionDied:(NSNotification *)note {
#pragma mark Recents


- (MFClientFS*)mountRecent:(MFClientRecent*)recent error:(NSError**)error {
- (MFClientFS *)mountRecent:(MFClientRecent *)recent error:(NSError **)error {
NSURL* url = [NSURL URLWithString: recent.descriptionString];
if (url) {
MFClientFS* fs = [self quickMountFilesystemWithURL: url
error: error ];
if (fs)
MFClientFS* fs = [self quickMountFilesystemWithURL:url error:error];
if (fs) {
return fs;
}
}

return nil;
Expand Down Expand Up @@ -328,7 +325,7 @@ - (void)storeFilesystem:(MFClientFS *)fs {
NSAssert(fs && fs.uuid, @"FS or fs.uuid is nil when storing fs in MFClient");
[filesystemsDictionary setObject: fs forKey: fs.uuid];
if ([fs isPersistent] && [persistentFilesystems indexOfObject: fs] == NSNotFound) {
[[self mutableArrayValueForKey:@"persistentFilesystems"] addObject: fs];
[[self mutableArrayValueForKey:@"persistentFilesystems"] addObject:fs];
} else if ( (![fs isPersistent]) && [temporaryFilesystems indexOfObject: fs] == NSNotFound) {
[[self mutableArrayValueForKey:@"temporaryFilesystems"] addObject: fs];
}
Expand Down Expand Up @@ -406,13 +403,13 @@ - (void)writeOrdering {
}

- (void)loadOrdering {
NSString* fullPath = [ORDERING_FILE_PATH stringByExpandingTildeInPath];
NSArray* uuidOrdering = [NSArray arrayWithContentsOfFile: fullPath];
NSString *fullPath = [ORDERING_FILE_PATH stringByExpandingTildeInPath];
NSArray *uuidOrdering = [NSArray arrayWithContentsOfFile:fullPath];
if (uuidOrdering) {
for(NSString* uuid in uuidOrdering)
if ([self filesystemWithUUID: uuid])
[[self filesystemWithUUID: uuid] setDisplayOrder:
[uuidOrdering indexOfObject: uuid]];
for(NSString *uuid in uuidOrdering)
if ([self filesystemWithUUID: uuid]) {
[[self filesystemWithUUID: uuid] setDisplayOrder:[uuidOrdering indexOfObject: uuid]];
}
}

[self willChangeValueForKey: @"persistentFilesystems"];
Expand All @@ -424,20 +421,19 @@ - (void)handleApplicationTerminatingNotification:(NSNotification *)note {
[server unregisterClient: self];
}

- (NSString*)createMountIconForFilesystem:(MFClientFS *)fs atPath:(NSURL*)dirPathURL {
- (NSString *)createMountIconForFilesystem:(MFClientFS *)fs atPath:(NSURL *)dirPathURL {
if (![fs isPersistent]) {
// We shouldn't be creating a mount icon for a non-persistent fs
return nil;
}

NSString* dirPath = [dirPathURL path];
NSString* filename = [NSString stringWithFormat: @"%@.fusion", [fs name]];
NSString* fullPath = [dirPath stringByAppendingPathComponent: filename];
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
[fs uuid], KMFFSUUIDParameter, nil];
NSString *dirPath = [dirPathURL path];
NSString *filename = [NSString stringWithFormat: @"%@.fusion", [fs name]];
NSString *fullPath = [dirPath stringByAppendingPathComponent: filename];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[fs uuid], KMFFSUUIDParameter, nil];
[dict writeToFile: fullPath atomically: YES];
NSImage* iconImage = [NSImage imageNamed:@"macfusionIcon.icns"];
[[NSWorkspace sharedWorkspace] setIcon: iconImage forFile:fullPath options:0];
NSImage *iconImage = [NSImage imageNamed:@"macfusionIcon.icns"];
[[NSWorkspace sharedWorkspace] setIcon:iconImage forFile:fullPath options:0];
return filename;
}

Expand Down
24 changes: 11 additions & 13 deletions MFClientFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@

@interface MFClientFS : MFFilesystem {
id<MFServerFSProtocol> remoteFilesystem;
MFClientPlugin* plugin;
MFClientPlugin *plugin;

// For Undo
NSDictionary* backupParameters;
NSDictionary* backupSecrets;
NSDictionary *backupParameters;
NSDictionary *backupSecrets;

BOOL isEditing;
NSInteger displayOrder;
id<MFClientFSDelegateProtocol> clientFSDelegate;

// UI references
NSArray* viewControllers;
NSViewController* topViewController;
NSTabView* editingTabView;
NSArray *viewControllers;
NSViewController *topViewController;
NSTabView *editingTabView;
}

+ (MFClientFS*)clientFSWithRemoteFS:(id)remoteFS
clientPlugin:(MFClientPlugin*)plugin;
+ (MFClientFS *)clientFSWithRemoteFS:(id)remoteFS clientPlugin:(MFClientPlugin*)plugin;

- (id)initWithRemoteFS:(id)remoteFS
clientPlugin:(MFClientPlugin*)p;
- (id)initWithRemoteFS:(id)remoteFS clientPlugin:(MFClientPlugin*)p;

// Notification handling
- (void)noteStatusInfoChanged;
Expand All @@ -57,10 +55,10 @@
- (BOOL)canDoEditing;

// UI
- (void)setIconImage:(NSImage*)image;
- (NSImage*)coloredImage;
- (void)setIconImage:(NSImage *)image;
- (NSImage *)coloredImage;

@property(readwrite, assign) NSInteger displayOrder;
@property(readwrite, retain) id<MFClientFSDelegateProtocol> clientFSDelegate;
@property(readonly) NSImage* iconImage;
@property(readonly) NSImage *iconImage;
@end
Loading

0 comments on commit 129b488

Please sign in to comment.