Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 319 - (hide annotations) (download)
Sun Feb 7 00:38:28 2010 UTC (14 years, 2 months ago) by masaki
File size: 6953 byte(s)
[Mod] スマートライブラリの条件を増やした。
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 319 } else if([keypath isEqualToString:@"information.voiceActorsList"]) {
40     key = @"VoiceActors";
41     } else if([keypath isEqualToString:@"information.productsList"]) {
42     key = @"Products";
43     }
44    
45 masaki 126 if(key) {
46     id row = [rowTemplate valueForKey:key];
47 masaki 152 id c = [[[row childAtIndex:0] copy] autorelease];
48     [c setValue:keypath];
49 masaki 126 return [NSArray arrayWithObject:c];
50     }
51    
52     return nil;
53     }
54 masaki 120 - (void)awakeFromNib
55     {
56 masaki 124 NSBundle *m = [NSBundle mainBundle];
57     NSString *path = [m pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
58     NSArray *rowsTemplate = [NSArray arrayWithContentsOfFile:path];
59     if(!rowsTemplate) {
60     exit(12345);
61 masaki 120 }
62 masaki 124
63 masaki 152 [self buildRows:rowsTemplate];
64    
65 masaki 124 NSMutableArray *newRows = [NSMutableArray array];
66    
67 masaki 243 for(id keyPath in [NSArray arrayWithObjects:@"title",
68     @"lastPlayDate", @"modificationDate", @"creationDate",
69     @"rating",
70     @"label",
71 masaki 319 @"information.voiceActorsList",
72     @"information.productsList",
73 masaki 243 nil]) {
74     id c = [self criteriaWithKeyPath:keyPath];
75 masaki 126 if(c) [newRows addObjectsFromArray:c];
76 masaki 124 }
77 masaki 243
78 masaki 152 simples = [newRows retain];
79 masaki 166
80     compounds = [[XspfMRule compoundRule] retain];
81 masaki 152
82 masaki 125 ////
83     predicateRows = [[NSMutableArray alloc] init];
84 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
85 masaki 120 }
86    
87 masaki 150 - (void)resolveExpression:(id)exp
88     {
89     NSString *message = nil;
90    
91     switch([exp expressionType]) {
92     case NSConstantValueExpressionType:
93     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
94     break;
95     case NSEvaluatedObjectExpressionType:
96     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
97     break;
98     case NSVariableExpressionType:
99     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
100     break;
101     case NSKeyPathExpressionType:
102     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
103     break;
104     case NSFunctionExpressionType:
105 masaki 154 message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
106 masaki 150 [exp operand], NSStringFromClass([[exp operand] class]),
107     [exp function], [exp arguments]];
108     break;
109     case NSAggregateExpressionType:
110     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
111     break;
112     }
113    
114     fprintf(stderr, "%s\n", [message UTF8String]);
115     }
116     - (void)resolvePredicate:(id)predicate
117     {
118     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
119     NSArray *sub = [predicate subpredicates];
120     for(id p in sub) {
121     [self resolvePredicate:p];
122     }
123     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
124     id left = [predicate leftExpression];
125     id right = [predicate rightExpression];
126     SEL sel = Nil;
127     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
128     sel = [predicate customSelector];
129     }
130     fprintf(stderr, "left ->\t");
131     [self resolveExpression:left];
132     if(sel) {
133     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
134     } else {
135     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
136     }
137     fprintf(stderr, "right ->\t");
138     [self resolveExpression:right];
139     fprintf(stderr, "end resolve.\n");
140     }
141     }
142    
143 masaki 123 - (void)setPredicate:(id)predicate
144     {
145 masaki 187 HMLog(HMLogLevelDebug, @"predicate -> (%@) %@", NSStringFromClass([predicate class]), predicate);
146 masaki 243 // [self resolvePredicate:predicate];
147 masaki 123
148 masaki 153 id new = [XspfMRule ruleEditorRowsFromPredicate:predicate withRowTemplate:rowTemplate];
149 masaki 125
150     [self willChangeValueForKey:XspfMREDPredicateRowsKey];
151     [predicateRows release];
152     predicateRows = [new retain];
153     [self didChangeValueForKey:XspfMREDPredicateRowsKey];
154 masaki 146 // [ruleEditor reloadCriteria];
155 masaki 123 }
156 masaki 125 - (void)setPredicateRows:(id)p
157     {
158 masaki 187 // HMLog(HMLogLevelDebug, @"new -> %@", p);
159 masaki 125 [predicateRows release];
160     predicateRows = [p retain];
161     }
162    
163     #pragma mark#### NSRleEditor Delegate ####
164 masaki 152
165 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
166     numberOfChildrenForCriterion:(id)criterion
167     withRowType:(NSRuleEditorRowType)rowType
168     {
169     NSInteger result = 0;
170    
171     if(!criterion) {
172 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
173     result = [compounds count];
174     } else {
175     result = [simples count];
176     }
177 masaki 143 } else {
178 masaki 152 result = [criterion numberOfChildren];
179 masaki 124 }
180    
181 masaki 187 // HMLog(HMLogLevelDebug, @"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
182 masaki 124
183     return result;
184     }
185    
186     - (id)ruleEditor:(NSRuleEditor *)editor
187     child:(NSInteger)index
188     forCriterion:(id)criterion
189     withRowType:(NSRuleEditorRowType)rowType
190     {
191     id result = nil;
192    
193     if(!criterion) {
194 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
195     result = [compounds objectAtIndex:index];
196     } else {
197     result = [simples objectAtIndex:index];
198     }
199 masaki 143 } else {
200 masaki 152 result = [criterion childAtIndex:index];
201 masaki 124 }
202    
203 masaki 187 // HMLog(HMLogLevelDebug, @"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
204 masaki 124
205     return result;
206     }
207     - (id)ruleEditor:(NSRuleEditor *)editor
208     displayValueForCriterion:(id)criterion
209     inRow:(NSInteger)row
210     {
211     id result = nil;
212 masaki 143
213     if(!criterion) {
214     //
215     } else {
216 masaki 152 result = [criterion displayValueForRuleEditor:editor inRow:row];
217 masaki 143 }
218    
219 masaki 187 // HMLog(HMLogLevelDebug, @"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
220 masaki 143
221 masaki 124 return result;
222     }
223     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
224     predicatePartsForCriterion:(id)criterion
225     withDisplayValue:(id)displayValue
226     inRow:(NSInteger)row
227     {
228     id result = nil;
229    
230 masaki 152 result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
231 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tresult -> %@", result);
232 masaki 143
233 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, displayValue, row, result);
234 masaki 143
235 masaki 124 return result;
236     }
237     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
238     {
239     //
240     }
241 masaki 150 @end

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