source: trunk/SapphireApplianceController.m @ 261

Revision 261, 11.1 KB checked in by gbooker, 7 years ago (diff)

Get around the undefined initWithScene and scene selectors.

RevLine 
[1]1//
2//  SapphireApplianceController.m
3//  Sapphire
4//
5//  Created by pnmerrill on 6/20/07.
[201]6//  Copyright 2007 www.nanopi.net. All rights reserved.
[1]7//
8
9#import "SapphireApplianceController.h"
10#import <BackRow/BackRow.h>
[6]11#import "SapphireBrowser.h"
[4]12#import "SapphireMetaData.h"
[8]13#import "SapphirePredicates.h"
[10]14#import "SapphireSettings.h"
[52]15#import "SapphireTheme.h"
[204]16#import "SapphireTVDirectory.h"
[256]17#import "SapphireMovieDirectory.h"
[1]18
[190]19#import "SapphireImporterDataMenu.h"
20#import "SapphireFileDataImporter.h"
21#import "SapphireTVShowImporter.h"
[218]22#import "SapphireMovieImporter.h"
[190]23#import "SapphireAllImporter.h"
24
[198]25#define BROWSER_MENU_ITEM               BRLocalizedString(@"   Browse", @"Browser Menu Item")
[190]26#define ALL_IMPORT_MENU_ITEM    BRLocalizedString(@"   Import All Data", @"All Importer Menu Item")
[133]27#define SETTINGS_MENU_ITEM              BRLocalizedString(@"   Settings", @"Settings Menu Item")
28#define RESET_MENU_ITEM                 BRLocalizedString(@"   Reset the thing already", @"UI Quit")
29
[2]30@interface SapphireApplianceController (private)
[29]31- (void)setMenuFromSettings;
[210]32- (void)recreateMenu;
[2]33@end
34
[1]35@implementation SapphireApplianceController
36
[190]37static NSArray *predicates = nil;
38
39+ (void)initialize
40{
[198]41        predicates = [[NSArray alloc] initWithObjects:[[SapphireUnwatchedPredicate alloc] init], [[SapphireFavoritePredicate alloc] init], [[SapphireTopShowPredicate alloc] init], nil];
[190]42        [predicates makeObjectsPerformSelector:@selector(release)];
43}
44
[196]45+ (SapphirePredicate *)predicate
[190]46{
[196]47        SapphireSettings *settings = [SapphireSettings sharedSettings];
48        int index = [settings indexOfLastPredicate];
49        if(index == NSNotFound)
[190]50                return nil;
51        return [predicates objectAtIndex:index];
52}
53
[198]54+ (SapphirePredicate *)nextPredicate
55{
56        SapphireSettings *settings = [SapphireSettings sharedSettings];
57        int index = [settings indexOfLastPredicate];
58        int newIndex;
59        switch(index)
60        {
61                case NSNotFound:
62                        newIndex = 0;
63                        if([settings displayUnwatched])
64                                break;
65                case 0:
66                        newIndex = 1;
67                        if([settings displayFavorites])
68                                break;
69                case 1:
70                        newIndex = 2;
71                        if([settings displayTopShows])
72                                break;
73                default:
74                        newIndex = NSNotFound;
75        }
76        [settings setIndexOfLastPredicate:newIndex];
77        if(newIndex == NSNotFound)
78                return nil;
79        return [predicates objectAtIndex:newIndex];
80}
81
[190]82+ (BRTexture *)gemForPredicate:(SapphirePredicate *)predicate
83{
84        SapphireTheme *theme = [SapphireTheme sharedTheme];
85        if(predicate == nil)
86                return [theme gem:RED_GEM_KEY];
87        if([predicate isKindOfClass:[SapphireUnwatchedPredicate class]])
88                return [theme gem:BLUE_GEM_KEY];
89        if([predicate isKindOfClass:[SapphireFavoritePredicate class]])
90                return [theme gem:YELLOW_GEM_KEY];
91        if([predicate isKindOfClass:[SapphireTopShowPredicate class]])
92                return [theme gem:GREEN_GEM_KEY];
93        return nil;
94}
95                                                               
[1]96+ (NSString *) rootMenuLabel
97{
[6]98        return (@"net.pmerrill.Sapphire" );
[1]99}
100
[199]101- (SapphireImporterDataMenu *)allImporterForCollection:(SapphireMetaDataCollection *)collection
[190]102{
103        SapphireFileDataImporter *fileImp = [[SapphireFileDataImporter alloc] init];
[191]104        SapphireTVShowImporter *tvImp = [[SapphireTVShowImporter alloc] initWithSavedSetting:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/tvdata.plist"]];
[257]105//      SapphireMovieImporter *movImp = [[SapphireMovieImporter alloc] initWithSavedSetting:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/movieData.plist"]];
106        SapphireAllImporter *allImp = [[SapphireAllImporter alloc] initWithImporters:[NSArray arrayWithObjects:fileImp, tvImp,nil]];
[190]107        [fileImp release];
108        [tvImp release];
[257]109//      [movImp release];
[199]110        SapphireImporterDataMenu *ret = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] metaDataCollection:collection importer:allImp];
[190]111        return [ret autorelease];
112}
113
[261]114- (id) initWithScene: (BRRenderScene *) scene
[1]115{
[261]116        self = [super initWithScene:scene];
117       
[80]118        //Setup the theme's scene
119        SapphireTheme *theme = [SapphireTheme sharedTheme];
120        [theme setScene:[self scene]];
[259]121       
[148]122        metaCollection = [[SapphireMetaDataCollection alloc] initWithFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.plist"]];
[5]123       
[199]124        settings                                                                = [[SapphireSettings alloc] initWithScene:[self scene] settingsPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/settings.plist"] metaDataCollection:metaCollection] ;
125        [self setListTitle:                                             BRLocalizedString(@"Main Menu", @"")];
[133]126        [settings setListTitle:                                 BRLocalizedString(@"Settings", @"Settings Menu Item")] ;
[199]127        [settings setListIcon:                                  [theme gem:GEAR_GEM_KEY]];
[210]128        [[self list] setDatasource:self];
[259]129       
[210]130        return self;
131}
132
133- (void)dealloc
134{
135        [names release];
136        [controllers release];
137        [masterNames release];
138        [masterControllers release];
139        [metaCollection release];
140        [SapphireSettings relinquishSettings];
141        [settings release];
142        [super dealloc];
143}
144
145- (void)recreateMenu
146{
147        SapphireImporterDataMenu *allImporter   = [self allImporterForCollection:metaCollection];
[199]148        NSMutableArray *mutableMasterNames = [[NSMutableArray alloc] init];
149        NSMutableArray *mutableMasterControllers = [[NSMutableArray alloc] init];
[204]150        BRTexture *predicateGem = [SapphireApplianceController gemForPredicate:[SapphireApplianceController predicate]];
151       
[231]152        SapphireTVDirectory *tvDir = [[SapphireTVDirectory alloc] initWithCollection:metaCollection];
[204]153        SapphireBrowser *tvBrowser = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:tvDir];
154        [tvBrowser setListTitle:BRLocalizedString(@"TV Shows", nil)];
155        [tvBrowser setListIcon:predicateGem];
156        [mutableMasterNames addObject:BRLocalizedString(@"   TV Shows", nil)];
157        [mutableMasterControllers addObject:tvBrowser];
158        [tvBrowser release];
159       
[256]160        SapphireMovieDirectory *movieDir = [[SapphireMovieDirectory alloc] initWithCollection:metaCollection];
161        SapphireBrowser *movieBrowser = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:movieDir];
162        [movieBrowser setListTitle:BRLocalizedString(@"Movies", nil)];
163        [movieBrowser setListIcon:predicateGem];
164        [mutableMasterNames addObject:BRLocalizedString(@"   Movies", nil)];
165        [mutableMasterControllers addObject:movieBrowser];
166        [movieBrowser release];
167       
[199]168        NSEnumerator *browserPointsEnum = [[metaCollection collectionDirectories] objectEnumerator];
169        NSString *browserPoint = nil;
170        while((browserPoint = [browserPointsEnum nextObject]) != nil)
171        {
[204]172                if(![metaCollection skipCollection:browserPoint])
173                        [[metaCollection directoryForPath:browserPoint] loadMetaData];
[200]174                if([metaCollection hideCollection:browserPoint])
175                        continue;
[199]176                SapphireBrowser *browser = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:[metaCollection directoryForPath:browserPoint]];
177                [browser setListTitle:[browserPoint lastPathComponent]];
[204]178                [browser setListIcon:predicateGem];
[199]179                [mutableMasterNames addObject:[NSString stringWithFormat:@"   %@", browserPoint]];
180                [mutableMasterControllers addObject:browser];
181                [browser release];
182        }
183        [mutableMasterNames addObjectsFromArray:[NSArray arrayWithObjects:
184                ALL_IMPORT_MENU_ITEM,
185                SETTINGS_MENU_ITEM,
186                RESET_MENU_ITEM,
187                nil]];
188        [mutableMasterControllers addObjectsFromArray:[NSArray arrayWithObjects:
189                allImporter,
190                settings,
191                nil]];
192        masterNames = [[NSArray alloc] initWithArray:mutableMasterNames];
193        masterControllers = [[NSArray alloc] initWithArray:mutableMasterControllers];
194        [mutableMasterNames release];
195        [mutableMasterControllers release];
[210]196       
[29]197        names = [[NSMutableArray alloc] init];
198        controllers = [[NSMutableArray alloc] init];
199        [self setMenuFromSettings];
[5]200}
201
[29]202- (void)setMenuFromSettings
203{
204        [names removeAllObjects];
205        [controllers removeAllObjects];
[198]206        [names addObjectsFromArray:masterNames];
207        [controllers addObjectsFromArray:masterControllers];
208        if([settings disableUIQuit])
209                [names removeLastObject];
[29]210}
211
[1]212- (void) willBePushed
213{
214    // We're about to be placed on screen, but we're not yet there
[210]215    [self recreateMenu];
216        [[self list] reload];
[1]217    // always call super
218    [super willBePushed];
219}
220
221- (void) wasPushed
222{
223    // We've just been put on screen, the user can see this controller's content now
224   
225    // always call super
226    [super wasPushed];
227}
228
229- (void) willBePopped
230{
231    // The user pressed Menu, but we've not been removed from the screen yet
232   
233    // always call super
234    [super willBePopped];
235}
236
237- (void) wasPopped
238{
239    // The user pressed Menu, removing us from the screen
240   
241    // always call super
242    [super wasPopped];
243}
244
245- (void) willBeBuried
246{
247    // The user just chose an option, and we will be taken off the screen
248   
249    // always call super
250    [super willBeBuried];
251}
252
253- (void) wasBuriedByPushingController: (BRLayerController *) controller
254{
255    // The user chose an option and this controller os no longer on screen
256   
257    // always call super
258    [super wasBuriedByPushingController: controller];
259}
260
261- (void) willBeExhumed
262{
263    // the user pressed Menu, but we've not been revealed yet
264   
265    // always call super
266    [super willBeExhumed];
[29]267        [self setMenuFromSettings];
268        [[self list] reload];
269        [[self scene] renderScene];
[1]270}
271
272- (void) wasExhumedByPoppingController: (BRLayerController *) controller
273{
274    // handle being revealed when the user presses Menu
275   
276    // always call super
277    [super wasExhumedByPoppingController: controller];
278}
279
280- (long) itemCount
281{
282    // return the number of items in your menu list here
[6]283        return ( [ names count]);
[1]284}
285
286- (id<BRMenuItemLayer>) itemForRow: (long) row
287{
288/*
289    // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here
290    // return that object, it will be used to display the list item.
291*/
[6]292        if( row > [names count] ) return ( nil ) ;
[1]293       
294        BRAdornedMenuItemLayer * result = nil ;
[6]295        NSString *name = [names objectAtIndex:row];
296        result = [BRAdornedMenuItemLayer adornedFolderMenuItemWithScene: [self scene]] ;
[52]297       
[79]298        SapphireTheme *theme = [SapphireTheme sharedTheme];
[190]299        if([name isEqual: ALL_IMPORT_MENU_ITEM]) [result setLeftIcon:[theme gem:GEAR_GEM_KEY]];
[218]300//      else if([name isEqual: AGENT_IMPORT_MENU_ITEM]) [result setLeftIcon:[theme gem:GEAR_GEM_KEY]];
[198]301        else if([name isEqual: SETTINGS_MENU_ITEM]) [result setLeftIcon:[theme gem:GEAR_GEM_KEY]];
302        else if([name isEqual: RESET_MENU_ITEM]) [result setLeftIcon:[theme gem:CONE_GEM_KEY]];
303        else [result setLeftIcon:[SapphireApplianceController gemForPredicate:[SapphireApplianceController predicate]]];
304       
[1]305        // add text
306        [[result textItem] setTitle: name] ;
307                               
308        return ( result ) ;
309}
310
311- (NSString *) titleForRow: (long) row
312{
313
[6]314        if ( row > [ names count] ) return ( nil );
[1]315       
[6]316        NSString *result = [ names objectAtIndex: row] ;
[1]317        return ( result ) ;
318/*
319    // return the title for the list item at the given index here
320    return ( @"Sapphire" );
321*/
322}
323
324- (long) rowForTitle: (NSString *) title
325{
326    long result = -1;
327    long i, count = [self itemCount];
328    for ( i = 0; i < count; i++ )
329    {
330        if ( [title isEqualToString: [self titleForRow: i]] )
331        {
332            result = i;
333            break;
334        }
335    }
336   
337    return ( result );
338}
339
340- (void) itemSelected: (long) row
341{
342    // This is called when the user presses play/pause on a list item
343       
[62]344        if(row == [controllers count])
345                [[NSApplication sharedApplication] terminate:self];
[6]346        id controller = [controllers objectAtIndex:row];
347        [[self stack] pushController:controller];
[1]348}
349
350- (id<BRMediaPreviewController>) previewControllerForItem: (long) item
351{
352    // If subclassing BRMediaMenuController, this function is called when the selection cursor
353    // passes over an item.
354    return ( nil );
355}
356
357@end
Note: See TracBrowser for help on using the repository browser.