Permalink
Browse files

More Cocoa-like parser loading delegate methods.

  • Loading branch information...
1 parent 216b81b commit e00c4a031e918a7136770c777e4805f6095359d6 @mikeabdullah mikeabdullah committed Sep 12, 2011
Showing with 23 additions and 21 deletions.
  1. +14 −4 IMBParserController.h
  2. +9 −17 IMBParserController.m
View
@@ -135,13 +135,23 @@
@optional
-// Called once on main thread early in app lifetime, when all parsers are registered and loaded.
-// Return NO to suppress loading a particular parser...
+// Return NO to suppress loading a particular parser. Default (if you don't implement this method) is to return:
+// [parser canBeUsed]
+// You likely want to replicate that check in your implementation
+// Handy place to finish setting up a parser such as Flickr
+- (BOOL)parserController:(IMBParserController *)controller shouldLoadParser:(IMBParser *)parser;
+
+// Used to return a BOOL so that delegate could cancel the load. Now goes ignored, use one of the should methods instead
+- (void) parserController:(IMBParserController*)inController didLoadParser:(IMBParser*)inParser forMediaType:(NSString*)inMediaType;
-- (BOOL) parserController:(IMBParserController*)inController shouldLoadParser:(NSString*)inParserClassName forMediaType:(NSString*)inMediaType;
-- (BOOL) parserController:(IMBParserController*)inController didLoadParser:(IMBParser*)inParser forMediaType:(NSString*)inMediaType;
- (void) parserController:(IMBParserController*)inController willUnloadParser:(IMBParser*)inParser forMediaType:(NSString*)inMediaType;
+
+#pragma mark Deprecated
+// Called before loading of registered parsers, but NOT for custom or dynamic parsers
+- (BOOL) parserController:(IMBParserController*)inController shouldLoadParser:(NSString*)inParserClassName forMediaType:(NSString*)inMediaType;
+
+
@end
View
@@ -456,16 +456,14 @@ - (BOOL)addParser:(IMBParser *)parser;
}
// Ask the delegate if we are allowed to load the parser...
-
- if ([_delegate respondsToSelector:@selector(parserController:shouldLoadParser:forMediaType:)])
- {
- if (![_delegate parserController:self
- shouldLoadParser:NSStringFromClass([parser class])
- forMediaType:mediaType])
- {
- return NO;
- }
- }
+ if ([_delegate respondsToSelector:@selector(parserController:shouldLoadParser:)])
+ {
+ if (![_delegate parserController:self shouldLoadParser:parser]) return NO;
+ }
+ else
+ {
+ if (![parser canBeUsed]) return NO;
+ }
// Add it to the list
@@ -484,13 +482,7 @@ - (BOOL)addParser:(IMBParser *)parser;
// Tell the delegate...
if ([_delegate respondsToSelector:@selector(parserController:didLoadParser:forMediaType:)])
{
- BOOL loaded = [_delegate parserController:self didLoadParser:parser forMediaType:mediaType];
- if (loaded) loaded = [parser canBeUsed];
- if (!loaded)
- {
- [parsers removeLastObject];
- return NO;
- }
+ [_delegate parserController:self didLoadParser:parser forMediaType:mediaType];
}
return YES;

0 comments on commit e00c4a0

Please sign in to comment.