| 1 | /* |
|---|
| 2 | * SapphireAppliance.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by pnmerrill on Jun. 20, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #import "SapphireAppliance.h" |
|---|
| 23 | #import "SapphireApplianceController.h" |
|---|
| 24 | #import <BackRow/BackRow.h> |
|---|
| 25 | #import <objc/objc-class.h> |
|---|
| 26 | #import <SapphireCompatClasses/SapphireFrontRowCompat.h> |
|---|
| 27 | |
|---|
| 28 | #import <SapphireCompatClasses/BackRowUtils.h> |
|---|
| 29 | |
|---|
| 30 | #define TV_SHOW_IDENTIFIER @"tv-shows" |
|---|
| 31 | #define MOVIES_IDENTIFIER @"movies" |
|---|
| 32 | #define COLLECTIONS_IDENTIFIER @"mounts" |
|---|
| 33 | #define IMPORTER_IDENTIFIER @"importer" |
|---|
| 34 | #define SETTINGS_IDENTIFIER @"settings" |
|---|
| 35 | |
|---|
| 36 | // BRAppliance protocol |
|---|
| 37 | @interface BRApplianceInfo |
|---|
| 38 | +(id)infoForApplianceBundle:(id)bundle; |
|---|
| 39 | -(id)applianceCategoryDescriptors; |
|---|
| 40 | @end |
|---|
| 41 | |
|---|
| 42 | @interface BRApplianceCategory |
|---|
| 43 | +(id)categoryWithName:(NSString *)name identifier:(NSString *)identifier preferredOrder:(float)order; |
|---|
| 44 | -(void)setIsStoreCategory:(BOOL)isStoreCategory; |
|---|
| 45 | -(void)setIsDefaultCategory:(BOOL)isDefaultCategory; |
|---|
| 46 | -(void)setShouldDisplayOnStartup:(BOOL)shouldDisplayOnStartup; |
|---|
| 47 | @end |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | @implementation SapphireAppliance |
|---|
| 51 | |
|---|
| 52 | + (void) initialize |
|---|
| 53 | { |
|---|
| 54 | NSString *myBundlePath = [[NSBundle bundleForClass:[self class]] bundlePath]; |
|---|
| 55 | NSString *frameworkPath = [myBundlePath stringByAppendingPathComponent:@"Contents/Frameworks"]; |
|---|
| 56 | SapphireLoadFramework(frameworkPath); |
|---|
| 57 | Class cls = NSClassFromString( @"BRFeatureManager" ); |
|---|
| 58 | if ( cls == Nil ) |
|---|
| 59 | return; |
|---|
| 60 | [[cls sharedInstance] enableFeatureNamed: [[NSBundle bundleForClass: self] bundleIdentifier]]; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | + (NSString *) className |
|---|
| 64 | { |
|---|
| 65 | // get around the whitelist |
|---|
| 66 | // this function will get the real class name from the runtime, and |
|---|
| 67 | // will assuredly not recurse back to here |
|---|
| 68 | NSString * className = NSStringFromClass( self ); |
|---|
| 69 | |
|---|
| 70 | // BackRow has its own exception class which provides backtrace |
|---|
| 71 | // helpers. It returns a parsed trace, with function names. We'll |
|---|
| 72 | // look for the name of the function which is known to call this |
|---|
| 73 | // function to check against the whitelist, and if we find it we'll |
|---|
| 74 | // lie about our name, purely to escape that check. |
|---|
| 75 | // Also, the backtracer method is a class routine, meaning that we |
|---|
| 76 | // don't have to even generate an exception - woohoo! |
|---|
| 77 | NSString *backtrace = [BRBacktracingException backtrace]; |
|---|
| 78 | NSRange range = [backtrace rangeOfString: @"_loadApplianceInfoAtPath:"]; |
|---|
| 79 | if ( range.location != NSNotFound ) |
|---|
| 80 | { |
|---|
| 81 | // this is the whitelist check -- tell a Great Big Fib |
|---|
| 82 | className = @"RUIMoviesAppliance"; // could be anything in the whitelist, really |
|---|
| 83 | } |
|---|
| 84 | if (range.location == NSNotFound) |
|---|
| 85 | { |
|---|
| 86 | //code from ATVFiles. Thx! |
|---|
| 87 | range = [backtrace rangeOfString: @"(in BackRow)"]; |
|---|
| 88 | if(range.location != NSNotFound) { |
|---|
| 89 | NSLog(@"+[%@ className] called for Leopard/ATV2 whitelist check, so I'm lying, m'kay?", className); |
|---|
| 90 | // 10.5/ATV2 (and 1.1, but that's handled above) |
|---|
| 91 | className = @"RUIDVDAppliance"; |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | return ( className ); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | -(NSString *)applianceKey { |
|---|
| 98 | return @"SapphireAppliance"; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | -(NSString *)applianceName { |
|---|
| 102 | return @"SapphireAppliance"; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | - (NSString *) moduleIconName |
|---|
| 106 | { |
|---|
| 107 | // replace this with your own icon name |
|---|
| 108 | return ( @"SapphireIcon.png" ); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | - (NSString *) moduleName |
|---|
| 112 | { |
|---|
| 113 | // this doesn't appear to be actually *used*, but even so: |
|---|
| 114 | return ( BRLocalizedString(@"Sapphire", @"Main Menu item name") ); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | + (NSString *) moduleKey |
|---|
| 118 | { |
|---|
| 119 | // change this to match your CFBundleIdentifier |
|---|
| 120 | return ( @"Nanopi.net.UCIJoker.Sapphire" ); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | - (NSString *) moduleKey |
|---|
| 124 | { |
|---|
| 125 | return ( [SapphireAppliance moduleKey] ); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | - (id)applianceController |
|---|
| 129 | { |
|---|
| 130 | SapphireApplianceController *cont = nil; |
|---|
| 131 | @try { |
|---|
| 132 | cont = [[[SapphireApplianceController alloc] initWithScene: nil] autorelease]; |
|---|
| 133 | } |
|---|
| 134 | @catch (NSException * e) { |
|---|
| 135 | [SapphireApplianceController logException:e]; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | return cont; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | - (id) applianceControllerWithScene: (id) scene |
|---|
| 142 | { |
|---|
| 143 | // this function is called when your item is selected on the main menu |
|---|
| 144 | return ( [[[SapphireApplianceController alloc] initWithScene: scene] autorelease] ); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * This implements the BRAppliance protocol from ATV2. |
|---|
| 149 | */ |
|---|
| 150 | -(id)applianceInfo { |
|---|
| 151 | BRApplianceInfo* p = [BRApplianceInfo infoForApplianceBundle:[NSBundle bundleForClass:[self class]]]; |
|---|
| 152 | NSMutableArray *categories = [NSMutableArray array]; |
|---|
| 153 | |
|---|
| 154 | NSEnumerator *enumerator = [[p applianceCategoryDescriptors] objectEnumerator]; |
|---|
| 155 | id obj; |
|---|
| 156 | while((obj = [enumerator nextObject]) != nil) { |
|---|
| 157 | BRApplianceCategory *category = [BRApplianceCategory categoryWithName:[obj valueForKey:@"name"] identifier:[obj valueForKey:@"identifier"] preferredOrder:[[obj valueForKey:@"preferred-order"] floatValue]]; |
|---|
| 158 | [categories addObject:category]; |
|---|
| 159 | } |
|---|
| 160 | [[self applianceController] setToMountsOnly]; |
|---|
| 161 | return [BRApplianceInfo infoForApplianceBundle:[NSBundle bundleForClass:[self class]]]; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | -(id)applianceCategories { |
|---|
| 165 | NSMutableArray *categories = [NSMutableArray array]; |
|---|
| 166 | |
|---|
| 167 | NSEnumerator *enumerator = [[[self applianceInfo] applianceCategoryDescriptors] objectEnumerator]; |
|---|
| 168 | id obj; |
|---|
| 169 | while((obj = [enumerator nextObject]) != nil) { |
|---|
| 170 | BRApplianceCategory *category = [BRApplianceCategory categoryWithName:[obj valueForKey:@"name"] identifier:[obj valueForKey:@"identifier"] preferredOrder:[[obj valueForKey:@"preferred-order"] floatValue]]; |
|---|
| 171 | [categories addObject:category]; |
|---|
| 172 | } |
|---|
| 173 | return categories; |
|---|
| 174 | [[self applianceController] setToMountsOnly]; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | -(id)identifierForContentAlias:(id)fp8 { |
|---|
| 178 | return @"mounts"; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | -(id)controllerForIdentifier:(id)ident |
|---|
| 182 | { |
|---|
| 183 | NSString *identifier = (NSString *)ident; |
|---|
| 184 | SapphireApplianceController *controller = [self applianceController]; |
|---|
| 185 | if([identifier isEqualToString:TV_SHOW_IDENTIFIER]) |
|---|
| 186 | return [controller tvBrowser]; |
|---|
| 187 | if([identifier isEqualToString:MOVIES_IDENTIFIER]) |
|---|
| 188 | return [controller movieBrowser]; |
|---|
| 189 | if([identifier isEqualToString:IMPORTER_IDENTIFIER]) |
|---|
| 190 | return [controller allImporter]; |
|---|
| 191 | if([identifier isEqualToString:SETTINGS_IDENTIFIER]) |
|---|
| 192 | return [controller settings]; |
|---|
| 193 | |
|---|
| 194 | return controller; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | -(id)initWithSettings:(id)settings { |
|---|
| 198 | return [super init]; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | -(id)version { |
|---|
| 202 | return @"1.0"; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | @end |
|---|