X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/5edc719e9181e04faaa247bfa389471bc57b9402..8a2d5e51312c61db0e315eecb1e6ad4adc98d5da:/ITOSAComponent.m diff --git a/ITOSAComponent.m b/ITOSAComponent.m index 9ab1a7f..0b28ad9 100755 --- a/ITOSAComponent.m +++ b/ITOSAComponent.m @@ -14,22 +14,35 @@ #import "ITOSAComponent.h" +#warning Need to add a constant data store containing all available component instances... could be lazy and build it on class +load. + @implementation ITOSAComponent ++ (ITOSAComponent *)appleScriptComponent +{ + return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease]; +} + ++ (ITOSAComponent *)componentWithCarbonComponent:(Component)component +{ + return [[[ITOSAComponent alloc] initWithComponent:component] autorelease]; +} + + (NSArray *)availableComponents { Component currentComponent = 0; ComponentDescription cd; + NSMutableArray *components = [[NSMutableArray alloc] init]; cd.componentType = kOSAComponentType; cd.componentSubType = 0; cd.componentManufacturer = 0; cd.componentFlags = 0; cd.componentFlagsMask = 0; - - while ((currentComponent = FindNextComponent(0, &cd)) != 0) { + while ((currentComponent = FindNextComponent(currentComponent, &cd)) != 0) { + [components addObject:[ITOSAComponent componentWithCarbonComponent:currentComponent]]; } - return [NSArray array]; + return [NSArray arrayWithArray:[components autorelease]]; } - (id)initWithSubtype:(unsigned long)subtype @@ -63,11 +76,25 @@ } information = [[NSMutableDictionary alloc] init]; - [information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentName"]; - [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITComponentInfo"]; - [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITComponentSubtype"]; - [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITComponentManufacturer"]; + AEDesc name; + Ptr buffer; + Size length; + OSAScriptingComponentName(_componentInstance, &name); + length = AEGetDescDataSize(&name); + buffer = malloc(length); + + AEGetDescData(&name, buffer, length); + AEDisposeDesc(&name); + [information setObject:[NSString stringWithCString:buffer length:length] forKey:@"ITOSAComponentName"]; + free(buffer); + buffer = NULL; + + //[information setObject:[[[NSString alloc] initWithBytes:componentName length:GetHandleSize(componentName) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentName"]; + [information setObject:[[[NSString alloc] initWithBytes:componentInfo length:GetHandleSize(componentInfo) encoding:NSASCIIStringEncoding] autorelease] forKey:@"ITOSAComponentInfo"]; + [information setObject:[NSNumber numberWithUnsignedLong:description.componentSubType] forKey:@"ITOSAComponentSubtype"]; + [information setObject:[NSNumber numberWithUnsignedLong:description.componentManufacturer] forKey:@"ITOSAComponentManufacturer"]; + _information = [information copy]; } return self; } @@ -77,6 +104,11 @@ [_information release]; } +- (NSString *)description +{ + return [_information objectForKey:@"ITOSAComponentName"]; +} + - (Component)component { return _component;