Permalink
Browse files

progress on the plugin idea, more work than I originally though...

  • Loading branch information...
1 parent 695a107 commit d9cfdab7d9a4657062e5072b86f3b56f0136fc97 @dustinrue committed Aug 14, 2012
@@ -23,8 +23,7 @@
DAD8899D15D5F337009F30A3 /* NotificationCenterAction-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NotificationCenterAction-Prefix.pch"; sourceTree = "<group>"; };
DAD889AB15D5F394009F30A3 /* NotificationCenterAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationCenterAction.h; sourceTree = "<group>"; };
DAD889AC15D5F394009F30A3 /* NotificationCenterAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotificationCenterAction.m; sourceTree = "<group>"; };
- DAD889B315D5F61C009F30A3 /* ActionPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = file; name = ActionPlugin.h; path = ../../Protocols/ActionPlugin.h; sourceTree = "<group>"; };
- DAD889B415D5F61C009F30A3 /* ToggleableActionPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = file; name = ToggleableActionPlugin.h; path = ../../Protocols/ToggleableActionPlugin.h; sourceTree = "<group>"; };
+ DAD889B315D5F61C009F30A3 /* ActionPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ActionPlugin.h; path = ../../Protocols/ActionPlugin.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -79,7 +78,6 @@
isa = PBXGroup;
children = (
DAD889B315D5F61C009F30A3 /* ActionPlugin.h */,
- DAD889B415D5F61C009F30A3 /* ToggleableActionPlugin.h */,
DAD889AB15D5F394009F30A3 /* NotificationCenterAction.h */,
DAD889AC15D5F394009F30A3 /* NotificationCenterAction.m */,
DAD8899815D5F337009F30A3 /* Supporting Files */,
@@ -273,6 +271,7 @@
DAD889A215D5F337009F30A3 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -7,7 +7,7 @@
//
#import "ActionPlugin.h"
-#import "ToggleableActionPlugin.h"
+
@interface NotificationCenterAction : NSObject <ToggleableAction>
@@ -10,6 +10,7 @@
@implementation NotificationCenterAction
+
@synthesize helperToolResponse;
@synthesize type;
@synthesize context;
@@ -18,8 +19,44 @@ @implementation NotificationCenterAction
@synthesize enabled;
@synthesize turnOn;
+
+- (id)initWithDictionary:(NSDictionary *)dict {
+ if (!(self = [super init]))
+ return nil;
+
+ type = [NotificationCenterAction typeForClass:[self class]];
+ context = [[dict valueForKey:@"context"] copy];
+ when = [[dict valueForKey:@"when"] copy];
+ delay = [[dict valueForKey:@"delay"] copy];
+ enabled = [[dict valueForKey:@"enabled"] copy];
+
+ NSObject *val = [dict valueForKey:@"parameter"];
+ if ([val isKindOfClass:[NSNumber class]])
+ turnOn = [[dict valueForKey:@"parameter"] boolValue];
+ else {
+ if ([val isEqual:@"on"] || [val isEqual:@"1"])
+ turnOn = YES;
+ else
+ turnOn = NO;
+ }
+
+ return self;
+}
+
+- (NSMutableDictionary *)dictionary
+{
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+
+ [dict setObject:[NSNumber numberWithBool:turnOn] forKey:@"parameter"];
+
+ return dict;
+}
+
+ (NSString *)typeForClass:(Class)klass {
- return NSLocalizedString(@"NotificationCenterAction", @"");
+ // Hack "Action" off class name (6 chars)
+ // TODO: make this a bit more robust?
+ NSString *className = NSStringFromClass(klass);
+ return [className substringToIndex:([className length] - 6)];
}
+ (Class)classForType:(NSString *)type {
@@ -43,62 +80,23 @@ + (Action *)actionFromDictionary:(NSDictionary *)dict {
}
- (id)init {
- self = [super init];
-
- /*
- if ([[self class] isEqualTo:[self class]]) {
- [NSException raise:@"Abstract Class Exception"
- format:@"Error, attempting to instantiate Action directly."];
- }
- */
-
- if (!self)
- return nil;
-
- type = @"NotificationCenter";
- context = @"";
- when = @"Arrival";
- delay = [[NSNumber alloc] initWithDouble:0];
- enabled = [[NSNumber alloc] initWithBool:YES];
-
- return self;
-}
-
-- (id)initWithDictionary:(NSDictionary *)dict {
-
- if ([[self class] isEqualTo:[self class]]) {
- [NSException raise:@"Abstract Class Exception"
- format:@"Error, attempting to instantiate Action directly."];
- }
-
if (!(self = [super init]))
return nil;
- type = @"NotificationCenter";
- context = [[dict valueForKey:@"context"] copy];
- when = [[dict valueForKey:@"when"] copy];
- delay = [[dict valueForKey:@"delay"] copy];
- enabled = [[dict valueForKey:@"enabled"] copy];
+ type = [NotificationCenterAction typeForClass:[self class]];
+
return self;
}
+
- (void)dealloc {
}
-- (NSMutableDictionary *)dictionary {
- return [NSMutableDictionary dictionaryWithObjectsAndKeys:
- [type copy], @"type",
- [context copy], @"context",
- [when copy], @"when",
- [delay copy], @"delay",
- [enabled copy], @"enabled",
- nil];
-}
+ (NSString *)helpTextForActionOfType:(NSString *)type {
- return @"";
+ return @"help text";
}
- (NSComparisonResult)compareDelay:(Action *)other {
View
@@ -11,19 +11,6 @@
@class Action;
@protocol Action <NSObject>
-/*{
- NSString *type, *context, *when;
- NSNumber *delay, *enabled;
-
- // terrible hack so that an action can
- // have response data from the helper tool
- // but because the helpertool is a category
- // action, it can't define its own ivars
- CFDictionaryRef helperToolResponse;
-
- NSAppleEventDescriptor *appleScriptResult_;
-}
- */
@property (assign) CFDictionaryRef helperToolResponse;
@property (strong) NSString *type;
@@ -32,18 +19,6 @@
@property (strong) NSNumber *delay;
@property (strong) NSNumber *enabled;
-+ (NSString *)typeForClass:(Class)klass;
-+ (Class)classForType:(NSString *)type;
-
-+ (Action *)actionFromDictionary:(NSDictionary *)dict;
-- (id)init;
-- (id)initWithDictionary:(NSDictionary *)dict;
-- (void)dealloc;
-- (NSMutableDictionary *)dictionary;
-+ (NSString *)helpTextForActionOfType:(NSString *)type;
-
-- (NSComparisonResult)compareDelay:(Action *)other;
-
// To be implemented by descendant classes:
- (NSString *)description; // (use present-tense imperative)
- (BOOL)execute:(NSString **)errorString;
@@ -77,3 +52,19 @@
@protocol ActionWithString <Action>
@end
+/**
+ * A Toggleable action
+ */
+@protocol ToggleableAction <Action,ActionWithLimitedOptions>
+
+@property (assign) BOOL turnOn;
+
+- (id)initWithDictionary:(NSDictionary *)dict;
+- (void)dealloc;
+- (NSMutableDictionary *)dictionary;
+
++ (NSArray *)limitedOptions;
+- (id)initWithOption:(NSNumber *)option;
+
+@end
+
@@ -1,23 +0,0 @@
-//
-// ToggleableActionPlugin.h
-// ControlPlane
-//
-// Created by Dustin Rue on 8/10/12.
-//
-//
-
-#import <Foundation/Foundation.h>
-#import "ActionPlugin.h"
-
-@protocol ToggleableAction <Action,ActionWithLimitedOptions>
-
-@property (assign) BOOL turnOn;
-
-- (id)initWithDictionary:(NSDictionary *)dict;
-- (void)dealloc;
-- (NSMutableDictionary *)dictionary;
-
-+ (NSArray *)limitedOptions;
-- (id)initWithOption:(NSNumber *)option;
-
-@end

0 comments on commit d9cfdab

Please sign in to comment.