12#import "TSXAdditions.h"
15#import "GlobalDefaults.h"
17@interface ComputerBookmark (Private)
18- (void)willChangeValueForKeyPath:(NSString *)keyPath;
19- (void)didChangeValueForKeyPath:(NSString *)keyPath;
24@synthesize parent = _parent, uuid = _uuid, label = _label, image = _image;
25@synthesize params = _connection_params, conntectedViaWLAN = _connected_via_wlan;
29 if (!(
self = [super init]))
32 _uuid = [[NSString stringWithUUID] retain];
34 _connected_via_wlan = NO;
41 if (!(
self = [
self init]))
44 _connection_params = [params copy];
45 _connected_via_wlan = NO;
49+ (BOOL)supportsSecureCoding
54- (id)initWithCoder:(NSCoder *)decoder
56 if (!(
self = [
self init]))
59 if (![decoder allowsKeyedCoding])
60 [NSException raise:NSInvalidArgumentException format:@"coder must support keyed archiving"];
62 if ([decoder containsValueForKey:
@"uuid"])
65 _uuid = [[decoder decodeObjectOfClass:[NSString class] forKey:@"uuid"] retain];
68 if ([decoder containsValueForKey:
@"label"])
69 [self setLabel:[decoder decodeObjectOfClass:[NSString class] forKey:
@"label"]];
71 if ([decoder containsValueForKey:
@"connectionParams"])
73 [_connection_params release];
75 forKey:@"connectionParams"] retain];
81- (id)initWithBaseDefaultParameters
84 initWithBaseDefaultParameters] autorelease]];
90 [copy setLabel:[
self label]];
91 copy->_connection_params = [_connection_params copy];
98 copy->_uuid = [[
self uuid] copy];
102- (void)encodeWithCoder:(NSCoder *)coder
104 if (![coder allowsKeyedCoding])
105 [NSException raise:NSInvalidArgumentException format:@"coder must support keyed archiving"];
107 [coder encodeObject:_uuid forKey:@"uuid"];
108 [coder encodeObject:_label forKey:@"label"];
109 [coder encodeObject:_connection_params forKey:@"connectionParams"];
119 [_connection_params release];
120 _connection_params = nil;
129- (BOOL)isEqual:(
id)object
131 return [object respondsToSelector:@selector(uuid)] && [[object uuid] isEqual:_uuid];
134- (NSString *)description
136 return ([
self label] != nil) ? [
self label] : _uuid;
139- (BOOL)validateValue:(
id *)val forKey:(NSString *)key error:(NSError **)error
141 NSString *string_value = *val;
143 if ([key isEqualToString:
@"label"])
145 if (![[string_value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
151 code:NSKeyValueValidationError
154 dictionaryWithObjectsAndKeys:
156 @"Connection labels cannot be blank",
157 @"Bookmark data validation: label blank title."),
158 NSLocalizedDescriptionKey,
160 @"Please enter the short description of this Connection "
161 @"that will appear in the Connection list.",
162 @"Bookmark data validation: label blank message."),
163 NSLocalizedRecoverySuggestionErrorKey, nil]];
171- (BOOL)validateValue:(
id *)val forKeyPath:(NSString *)keyPath error:(NSError **)error
174 return [
super validateValue:val forKeyPath:keyPath error:error];
189- (BOOL)hasImmutableHost
194#pragma mark Custom KVC
196- (void)setValue:(
id)value forKeyPath:(NSString *)keyPath
198 if ([keyPath isEqualToString:
@"params.resolution"])
201 TSXScreenOptions type;
202 if (ScanScreenResolution(value, &width, &height, &type))
204 [_connection_params willChangeValueForKey:@"resolution"];
205 [[
self params] setInt:type forKey:@"screen_resolution_type"];
207 if (type == TSXScreenOptionFixed)
209 [[
self params] setInt:width forKey:@"width"];
210 [[
self params] setInt:height forKey:@"height"];
212 [_connection_params didChangeValueForKey:@"resolution"];
215 [NSException raise:NSInvalidArgumentException
216 format:@"%s got invalid screen resolution '%@'", __func__, value];
220 [
self willChangeValueForKeyPath:keyPath];
221 [
super setValue:value forKeyPath:keyPath];
222 [
self didChangeValueForKeyPath:keyPath];
226- (id)valueForKeyPath:(NSString *)keyPath
228 if ([keyPath isEqualToString:
@"params.resolution"])
229 return ScreenResolutionDescription([[self params] intForKey:
@"screen_resolution_type"],
230 [[self params] intForKey:
@"width"],
231 [[self params] intForKey:
@"height"]);
233 return [
super valueForKeyPath:keyPath];
236- (void)observeValueForKeyPath:(NSString *)keyPath
238 change:(NSDictionary *)change
239 context:(
void *)context
241 if ([[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
242 [self willChangeValueForKeyPath:keyPath];
244 [
self didChangeValueForKeyPath:keyPath];
247- (NSDictionary *)targetForChangeNotificationForKeyPath:(NSString *)keyPath
249 NSString *changed_key = keyPath;
250 NSObject *changed_object =
self;
252 if ([keyPath rangeOfString:
@"params."].location == 0)
254 changed_key = [keyPath substringFromIndex:[@"params." length]];
255 changed_object = _connection_params;
259 dictionaryWithObjectsAndKeys:changed_key, @"key", changed_object, @"object", nil];
262- (void)willChangeValueForKeyPath:(NSString *)keyPath
264 NSDictionary *target = [
self targetForChangeNotificationForKeyPath:keyPath];
265 [[target objectForKey:@"object"] willChangeValueForKey:[target objectForKey:@"key"]];
268- (void)didChangeValueForKeyPath:(NSString *)keyPath
270 NSDictionary *target = [
self targetForChangeNotificationForKeyPath:keyPath];
271 [[target objectForKey:@"object"] didChangeValueForKey:[target objectForKey:@"key"]];
277 [param_copy setValue:[
self uuid] forKey:@"_bookmark_uuid"];
281#pragma mark No children
282- (NSUInteger)numberOfChildren
286- (NSUInteger)numberOfDescendants
290- (BookmarkBase *)childAtIndex:(NSUInteger)index
294- (NSUInteger)indexOfChild:(BookmarkBase *)child
298- (void)removeChild:(BookmarkBase *)child
301- (void)addChild:(BookmarkBase *)child
304- (void)addChild:(BookmarkBase *)child afterExistingChild:(BookmarkBase *)existingChild
307- (void)addChild:(BookmarkBase *)child atIndex:(NSInteger)index
310- (BOOL)hasDescendant:(BookmarkBase *)needle
314- (BOOL)canContainChildren