Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 207 lines (176 sloc) 4.37 kB
776b18b Adding a few missing files
Michael Gorbach authored
1 //
2 // MFClientFS.m
3 // MacFusion2
4 //
5 // Created by Michael Gorbach on 1/5/08.
6 // Copyright 2008 Michael Gorbach. All rights reserved.
7 //
8
9 #import "MFClientFS.h"
10 #import "MFConstants.h"
11 #import "MFClientPlugin.h"
12
13 @interface MFClientFS (PrivateAPI)
14 - (void)fillInitialData;
15 - (void)registerNotifications;
d82328f Many, many changes. Moving along
Michael Gorbach authored
16 - (void)copyParameters;
17 - (void)copyStatusInfo;
776b18b Adding a few missing files
Michael Gorbach authored
18 @end
19
20 @implementation MFClientFS
21
22 + (MFClientFS*)clientFSWithRemoteFS:(id)remoteFS
23 clientPlugin:(MFClientPlugin*)plugin
24 {
25 MFClientFS* fs = nil;
26
d82328f Many, many changes. Moving along
Michael Gorbach authored
27 fs = [[MFClientFS alloc] initWithRemoteFS: remoteFS
28 clientPlugin: plugin];
776b18b Adding a few missing files
Michael Gorbach authored
29 return fs;
30 }
31
d82328f Many, many changes. Moving along
Michael Gorbach authored
32 + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key
33 {
34 if ([key isEqualToString: @"displayDictionary"])
35 return [NSSet setWithObjects:
36 KMFStatusDict, kMFParameterDict, nil];
37 else
38 return [super keyPathsForValuesAffectingValueForKey: key];
39 }
40
776b18b Adding a few missing files
Michael Gorbach authored
41 - (id)initWithRemoteFS:(id)remoteFS
42 clientPlugin:(MFClientPlugin*)p
43 {
44 self = [super init];
45 if (self != nil)
46 {
47 remoteFilesystem = remoteFS;
48 plugin = p;
d82328f Many, many changes. Moving along
Michael Gorbach authored
49 delegate = [plugin delegate];
776b18b Adding a few missing files
Michael Gorbach authored
50 [self fillInitialData];
51 [self registerNotifications];
52 }
53
54 return self;
55 }
56
57
58 - (void)registerNotifications
59 {
60 }
61
d82328f Many, many changes. Moving along
Michael Gorbach authored
62 - (void)copyStatusInfo
776b18b Adding a few missing files
Michael Gorbach authored
63 {
d82328f Many, many changes. Moving along
Michael Gorbach authored
64 [self willChangeValueForKey:KMFStatusDict];
776b18b Adding a few missing files
Michael Gorbach authored
65 statusInfo = [[remoteFilesystem statusInfo] mutableCopy];
d82328f Many, many changes. Moving along
Michael Gorbach authored
66 NSAssert(![statusInfo isProxy], @"Status Info from DO is a Proxy. Oh shit.");
67 [self didChangeValueForKey:KMFStatusDict];
68 }
69
70 - (void)copyParameters
71 {
72 [self willChangeValueForKey:kMFParameterDict];
73 parameters = [[remoteFilesystem parameters] mutableCopy];
74 NSAssert(![parameters isProxy], @"Parameters from DO is a Proxy. Oh shit.");
75 [self didChangeValueForKey:kMFParameterDict];
76 }
77
78 - (void)fillInitialData
79 {
80 [self copyStatusInfo];
81 [self copyParameters];
776b18b Adding a few missing files
Michael Gorbach authored
82 }
83
84 - (void)toggleMount:(id)sender
85 {
86 [remoteFilesystem mount];
87 }
88
dc563f0 Error handling and further on the menuling UI
Michael Gorbach authored
89 #pragma mark Notifications To Clients
90 - (void)sendNotificationForStatusChangeFrom:(NSString*)previousStatus
91 to:(NSString*)newStatus
92 {
93 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
94 if ([previousStatus isEqualToString: newStatus])
95 {
96 // Send No Notification
97 }
98 if ([previousStatus isEqualToString: kMFStatusFSWaiting]
99 && [newStatus isEqualToString: kMFStatusFSMounted])
100 {
101 [nc postNotificationName: kMFClientFSMountedNotification
102 object:self
103 userInfo:nil];
104 }
105 else if ([previousStatus isEqualToString: kMFStatusFSWaiting]
106 && [newStatus isEqualToString: kMFStatusFSFailed])
107 {
108 [nc postNotificationName: kMFClientFSFailedNotification
109 object:self
110 userInfo:nil];
111 }
112 }
113
776b18b Adding a few missing files
Michael Gorbach authored
114 #pragma mark Synchronization across IPC
115 - (void)handleStatusInfoChangedNotification:(NSNotification*)note
116 {
dc563f0 Error handling and further on the menuling UI
Michael Gorbach authored
117 NSString* previousStatus = self.status;
d82328f Many, many changes. Moving along
Michael Gorbach authored
118 [self copyStatusInfo];
dc563f0 Error handling and further on the menuling UI
Michael Gorbach authored
119 NSString* newStatus = self.status;
120 [self sendNotificationForStatusChangeFrom:previousStatus
121 to:newStatus];
776b18b Adding a few missing files
Michael Gorbach authored
122 }
123
124 - (void)handleParametersChangedNotification:(NSNotification*)note
125 {
d82328f Many, many changes. Moving along
Michael Gorbach authored
126 [self copyParameters];
776b18b Adding a few missing files
Michael Gorbach authored
127 }
128
d82328f Many, many changes. Moving along
Michael Gorbach authored
129 - (NSDictionary*)displayDictionary
776b18b Adding a few missing files
Michael Gorbach authored
130 {
d82328f Many, many changes. Moving along
Michael Gorbach authored
131 NSMutableDictionary* dict = [NSMutableDictionary dictionary];
132 [dict addEntriesFromDictionary: parameters];
133 [dict addEntriesFromDictionary: statusInfo];
134 return [dict copy];
776b18b Adding a few missing files
Michael Gorbach authored
135 }
136
d82328f Many, many changes. Moving along
Michael Gorbach authored
137 # pragma mark Action Methods
776b18b Adding a few missing files
Michael Gorbach authored
138 - (void)mount
139 {
140 [remoteFilesystem mount];
141 }
142
143 - (void)unmount
144 {
145 [remoteFilesystem unmount];
146 }
147
d82328f Many, many changes. Moving along
Michael Gorbach authored
148
149 #pragma mark Editing
150
151 - (void)setParameters:(NSMutableDictionary*)p
152 {
153 parameters = p;
154 }
155
156 - (void)beginEditing
157 {
158 isEditing = YES;
159 backupParameters = [NSDictionary dictionaryWithDictionary:
160 [self parameters]];
161 }
162
163 - (NSError*)endEditingAndCommitChanges:(BOOL)commit
164 {
165 if (!isEditing)
166 {
167 [[NSException exceptionWithName:kMFBadAPIUsageException
dc563f0 Error handling and further on the menuling UI
Michael Gorbach authored
168 reason:@"Calling endEditing without previous call to beginEditing"
d82328f Many, many changes. Moving along
Michael Gorbach authored
169 userInfo:nil] raise];
170 }
171
172 if (commit)
173 {
174 NSError* result = [remoteFilesystem validateAndSetParameters: parameters];
175 if (result)
176 {
177 return result;
178 }
179 else
180 {
181 isEditing = NO;
182 return nil;
183 }
184 }
185 else
186 {
187 isEditing = NO;
188 [self setParameters: [backupParameters mutableCopy] ];
189 }
190
191 return nil;
192 }
193
194 - (void)willChangeValueForKey:(NSString*)key
776b18b Adding a few missing files
Michael Gorbach authored
195 {
d82328f Many, many changes. Moving along
Michael Gorbach authored
196 if ([key isLike:@"parameters.*"] && !isEditing)
197 {
dc563f0 Error handling and further on the menuling UI
Michael Gorbach authored
198 [[NSException exceptionWithName:kMFBadAPIUsageException
d82328f Many, many changes. Moving along
Michael Gorbach authored
199 reason:@"Trying to modify parameters without beginEditing"
200 userInfo:nil] raise];
201 }
202
203 [super willChangeValueForKey:key];
776b18b Adding a few missing files
Michael Gorbach authored
204 }
205
206 @end
Something went wrong with that request. Please try again.