forked from tomcool420/SMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMFEventConfiguration.m
144 lines (131 loc) · 3.72 KB
/
SMFEventConfiguration.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// SMFEventConfiguration.m
// SMFramework
//
// Created by Thomas Cool on 11/4/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFEventConfiguration.h"
#import "SMFMenuItem.h"
@implementation SMFEventConfiguration
-(id)init
{
self=[super init];
_listeners=[[[SMFEventManager sharedManager] listeners] retain];
[self setListTitle:@"Event Manager"];
for(id<SMFEventDelegate> l in _listeners)
{
SMFMenuItem *it = [SMFMenuItem folderMenuItem];
[it setTitle:[l displayName]];
[_items addObject:it];
[_options addObject:l];
}
return self;
}
-(void)itemSelected:(long)row
{
SMFListenerConfiguration *l = [[SMFListenerConfiguration alloc] initForListener:[_options objectAtIndex:row]];
[[self stack] pushController:l];
[l release];
}
@end
@implementation SMFListenerConfiguration
-(id)initForListener:(id<SMFEventDelegate>)l
{
self=[super init];
[self setListTitle:[l displayName]];
listener=l;
_events=[[SMFEventManager sharedManager] eventsForListener:listener];
for(NSString *e in _events)
{
SMFMenuItem *it = [SMFMenuItem folderMenuItem];
[it setTitle:e];
[_items addObject:it];
[_options addObject:e];
}
return self;
}
-(void)itemSelected:(long)selected
{
SMFKeySelectMenu *k = [[SMFKeySelectMenu alloc] init];
[k setPrimaryText:[_options objectAtIndex:selected]];
[k setEvent:[_options objectAtIndex:selected]];
[k setSecondaryText:@"Please press a key"];
[[self stack] pushController:[k autorelease]];
}
@end
@implementation SMFKeySelectMenu
-(void)setEvent:(NSString *)event
{
_event=[event retain];
}
-(id)init
{
self=[super init];
currentAction=0;
return self;
}
-(void)wasPushed
{
NSLog(@"was Pushed");
[[SMFEventManager sharedManager]startLearning];
}
-(void)wasPopped
{
NSLog(@"was Popped");
[[SMFEventManager sharedManager]stopLearning];
}
-(BOOL)brEventAction:(BREvent *)action
{
int c=[action remoteAction];
NSString *str=nil;
if (action.value==0x01) {
if (c==47)
{
str=[[action eventDictionary] objectForKey:@"kBRKeyEventCharactersKey"];
if (str!=nil)
{
if (_currentKey!=nil && [_currentKey isEqualToString:str] && currentAction==47) {
//register key here
if (_event!=nil) {
NSLog(@"event: %@",_event);
[[SMFEventManager sharedManager]setKey:str forName:_event];
}
NSLog(@"final key = %@",str);
[[self stack]popController];
}
else {
[_currentKey release];
_currentKey=nil;
currentAction=47;
_currentKey=[str retain];
[self setSecondaryText:@"Please press same key again"];
}
}
else
{
[_currentKey release];
_currentKey=nil;
currentAction=0;
}
}
else {
if (currentAction==c) {
if (_event!=nil) {
NSLog(@"event: %@",_event);
[[SMFEventManager sharedManager] setRemoteAction:c forName:_event];
}
NSLog(@"final remoteAction: %d",c);
[[self stack] popController];
}
else
{
currentAction=c;
[self setSecondaryText:@"Please press same key again"];
}
}
}
NSLog(@"Action Pressed: %d",[action remoteAction]);
return NO;
}
@end