source: trunk/SapphireApplianceController.m @ 204

Last change on this file since 204 was 204, checked in by gbooker, 10 years ago

Activate the tv directory. Seems to work now. Only issue, how to deal with non-existant files which still show up in the meta data?
A bug fix or two

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