Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (hide annotations) (download)
Mon Jan 11 01:21:19 2010 UTC (14 years, 3 months ago) by masaki
File size: 6689 byte(s)
[New] 条件にラベルを使用出来るようにした。
1 masaki 120 //
2     // XspfMRuleEditorDelegate.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/28.
6     // Copyright 2009 masakih. All rights reserved.
7     //
8    
9     #import "XspfMRuleEditorDelegate.h"
10    
11     #import "XspfMRuleEditorRow.h"
12    
13     @implementation XspfMRuleEditorDelegate
14 masaki 125
15     static NSString *XspfMREDPredicateRowsKey = @"predicateRows";
16    
17 masaki 124 - (NSDictionary *)buildRows:(NSArray *)template
18     {
19     NSMutableDictionary *result = [NSMutableDictionary dictionary];
20     for(id row in template) {
21 masaki 159 id name = [row valueForKey:@"name"];
22 masaki 152 id rule = [XspfMRule ruleWithPlist:row];
23     [result setObject:rule forKey:name];
24 masaki 124 }
25 masaki 152 rowTemplate = [result retain];
26 masaki 124 return result;
27     }
28 masaki 126 - (id)criteriaWithKeyPath:(NSString *)keypath
29     {
30     NSString *key = nil;
31     if([keypath isEqualToString:@"title"]) {
32     key = @"String";
33     } else if([keypath isEqualToString:@"rating"]) {
34     key = @"Rate";
35 masaki 152 } else if([[NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil] containsObject:keypath]) {
36     key = @"AbDate";
37 masaki 243 } else if([keypath isEqualToString:@"label"]) {
38     key = @"Label";
39 masaki 126 }
40     if(key) {
41     id row = [rowTemplate valueForKey:key];
42 masaki 152 id c = [[[row childAtIndex:0] copy] autorelease];
43     [c setValue:keypath];
44 masaki 126 return [NSArray arrayWithObject:c];
45     }
46    
47     return nil;
48     }
49 masaki 120 - (void)awakeFromNib
50     {
51 masaki 124 NSBundle *m = [NSBundle mainBundle];
52     NSString *path = [m pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
53     NSArray *rowsTemplate = [NSArray arrayWithContentsOfFile:path];
54     if(!rowsTemplate) {
55     exit(12345);
56 masaki 120 }
57 masaki 124
58 masaki 152 [self buildRows:rowsTemplate];
59    
60 masaki 124 NSMutableArray *newRows = [NSMutableArray array];
61    
62 masaki 243 for(id keyPath in [NSArray arrayWithObjects:@"title",
63     @"lastPlayDate", @"modificationDate", @"creationDate",
64     @"rating",
65     @"label",
66     nil]) {
67     id c = [self criteriaWithKeyPath:keyPath];
68 masaki 126 if(c) [newRows addObjectsFromArray:c];
69 masaki 124 }
70 masaki 243
71 masaki 152 simples = [newRows retain];
72 masaki 166
73     compounds = [[XspfMRule compoundRule] retain];
74 masaki 152
75 masaki 125 ////
76     predicateRows = [[NSMutableArray alloc] init];
77 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
78 masaki 120 }
79    
80 masaki 150 - (void)resolveExpression:(id)exp
81     {
82     NSString *message = nil;
83    
84     switch([exp expressionType]) {
85     case NSConstantValueExpressionType:
86     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
87     break;
88     case NSEvaluatedObjectExpressionType:
89     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
90     break;
91     case NSVariableExpressionType:
92     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
93     break;
94     case NSKeyPathExpressionType:
95     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
96     break;
97     case NSFunctionExpressionType:
98 masaki 154 message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
99 masaki 150 [exp operand], NSStringFromClass([[exp operand] class]),
100     [exp function], [exp arguments]];
101     break;
102     case NSAggregateExpressionType:
103     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
104     break;
105     }
106    
107     fprintf(stderr, "%s\n", [message UTF8String]);
108     }
109     - (void)resolvePredicate:(id)predicate
110     {
111     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
112     NSArray *sub = [predicate subpredicates];
113     for(id p in sub) {
114     [self resolvePredicate:p];
115     }
116     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
117     id left = [predicate leftExpression];
118     id right = [predicate rightExpression];
119     SEL sel = Nil;
120     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
121     sel = [predicate customSelector];
122     }
123     fprintf(stderr, "left ->\t");
124     [self resolveExpression:left];
125     if(sel) {
126     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
127     } else {
128     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
129     }
130     fprintf(stderr, "right ->\t");
131     [self resolveExpression:right];
132     fprintf(stderr, "end resolve.\n");
133     }
134     }
135    
136 masaki 123 - (void)setPredicate:(id)predicate
137     {
138 masaki 187 HMLog(HMLogLevelDebug, @"predicate -> (%@) %@", NSStringFromClass([predicate class]), predicate);
139 masaki 243 // [self resolvePredicate:predicate];
140 masaki 123
141 masaki 153 id new = [XspfMRule ruleEditorRowsFromPredicate:predicate withRowTemplate:rowTemplate];
142 masaki 125
143     [self willChangeValueForKey:XspfMREDPredicateRowsKey];
144     [predicateRows release];
145     predicateRows = [new retain];
146     [self didChangeValueForKey:XspfMREDPredicateRowsKey];
147 masaki 146 // [ruleEditor reloadCriteria];
148 masaki 123 }
149 masaki 125 - (void)setPredicateRows:(id)p
150     {
151 masaki 187 // HMLog(HMLogLevelDebug, @"new -> %@", p);
152 masaki 125 [predicateRows release];
153     predicateRows = [p retain];
154     }
155    
156     #pragma mark#### NSRleEditor Delegate ####
157 masaki 152
158 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
159     numberOfChildrenForCriterion:(id)criterion
160     withRowType:(NSRuleEditorRowType)rowType
161     {
162     NSInteger result = 0;
163    
164     if(!criterion) {
165 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
166     result = [compounds count];
167     } else {
168     result = [simples count];
169     }
170 masaki 143 } else {
171 masaki 152 result = [criterion numberOfChildren];
172 masaki 124 }
173    
174 masaki 187 // HMLog(HMLogLevelDebug, @"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
175 masaki 124
176     return result;
177     }
178    
179     - (id)ruleEditor:(NSRuleEditor *)editor
180     child:(NSInteger)index
181     forCriterion:(id)criterion
182     withRowType:(NSRuleEditorRowType)rowType
183     {
184     id result = nil;
185    
186     if(!criterion) {
187 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
188     result = [compounds objectAtIndex:index];
189     } else {
190     result = [simples objectAtIndex:index];
191     }
192 masaki 143 } else {
193 masaki 152 result = [criterion childAtIndex:index];
194 masaki 124 }
195    
196 masaki 187 // HMLog(HMLogLevelDebug, @"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
197 masaki 124
198     return result;
199     }
200     - (id)ruleEditor:(NSRuleEditor *)editor
201     displayValueForCriterion:(id)criterion
202     inRow:(NSInteger)row
203     {
204     id result = nil;
205 masaki 143
206     if(!criterion) {
207     //
208     } else {
209 masaki 152 result = [criterion displayValueForRuleEditor:editor inRow:row];
210 masaki 143 }
211    
212 masaki 187 // HMLog(HMLogLevelDebug, @"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
213 masaki 143
214 masaki 124 return result;
215     }
216     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
217     predicatePartsForCriterion:(id)criterion
218     withDisplayValue:(id)displayValue
219     inRow:(NSInteger)row
220     {
221     id result = nil;
222    
223 masaki 152 result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
224 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tresult -> %@", result);
225 masaki 143
226 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, displayValue, row, result);
227 masaki 143
228 masaki 124 return result;
229     }
230     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
231     {
232     //
233     }
234 masaki 150 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26