source: trunk/SapphireApplianceController.m @ 20

Revision 20, 6.5 KB checked in by pmerrill, 7 years ago (diff)

Added Controller for Populating Show Data
Added icon update to settings menu options
Code Cleanup

Line 
1//
2//  SapphireApplianceController.m
3//  Sapphire
4//
5//  Created by pnmerrill on 6/20/07.
6//  Copyright 2007 __MyCompanyName__. All rights reserved.
7//
8
9#import "SapphireApplianceController.h"
10#import <BackRow/BackRow.h>
11#import "SapphireBrowser.h"
12#import "SapphireMetaData.h"
13#import "SapphirePredicates.h"
14#import "SapphireSettings.h"
15
16@interface SapphireApplianceController (private)
17- (void)processFiles:(NSArray *)files;
18- (void)filesProcessed:(NSDictionary *)files;
19- (NSMutableDictionary *)metaDataForPath:(NSString *)path;
20@end
21
22@implementation SapphireApplianceController
23
24+ (NSString *) rootMenuLabel
25{
26        return (@"net.pmerrill.Sapphire" );
27}
28
29//
30- (id) initWithScene: (BRRenderScene *) scene
31{
32        self = [super initWithScene:scene];
33        metaCollection = [[SapphireMetaDataCollection alloc] initWithFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.plist"] path:[NSHomeDirectory() stringByAppendingPathComponent:@"Movies"]];
34
35        names = [[NSArray alloc] initWithObjects:       @"   Unwatched",
36                                                                                                @"   Favorite Shows",
37                                                                                                @"   Top Shows",
38                                                                                                @"   Browse Shows",
39                                                                                                @"   Settings", nil];
40       
41        SapphireBrowser *unwatchedBrowser               = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:[metaCollection rootDirectory] predicate:[[[SapphireUnwatchedPredicate alloc] init] autorelease]];
42        SapphireBrowser *favoriteShowsBrowser   = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:[metaCollection rootDirectory] predicate:[[[SapphireFavoritePredicate alloc] init] autorelease]];
43        SapphireBrowser *topShowsBrowser                = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:[metaCollection rootDirectory] predicate:[[[SapphireTopShowPredicate alloc] init] autorelease]];
44        SapphireBrowser *playBrowser                    = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:[metaCollection rootDirectory]];
45        SapphireSettings *settingsMenu                  = [[SapphireSettings alloc] initWithScene:[self scene]] ;
46//      BRHeaderControl *settingsMenu                   =[[BRHeaderControl alloc] initWithScene:[self scene]] ;         
47        [self setListTitle:                                                     @"Main Menu"];
48        [unwatchedBrowser setListTitle:                 @"Unwatched Shows"];
49        [favoriteShowsBrowser setListTitle:             @"Favorite Shows"];
50        [topShowsBrowser setListTitle:                  @"Favorite Shows"];
51        [playBrowser setListTitle:                              @"Show Browser"];
52        [settingsMenu setListTitle:                             @"Settings"] ;
53//      [settingsMenu setTitle:@"Settings"];
54       
55        [settingsMenu  setListIcon:[[BRThemeInfo sharedTheme] gearImageForScene:[self scene]]] ;
56//      [settingsMenu setIcon:[[BRThemeInfo sharedTheme] gearImageForScene:[self scene]] horizontalOffset:0 kerningFactor:0 ] ;
57        [playBrowser  setListIcon:[[BRThemeInfo sharedTheme] errorIconForScene:[self scene]]] ;
58        [topShowsBrowser setListIcon:[[BRThemeInfo sharedTheme] errorIconForScene:[self scene]]] ;
59        [favoriteShowsBrowser setListIcon:[[BRThemeInfo sharedTheme] errorIconForScene:[self scene]]] ;
60        [unwatchedBrowser setListIcon:[[BRThemeInfo sharedTheme] errorIconForScene:[self scene]]] ;
61        controllers = [[NSArray alloc] initWithObjects:unwatchedBrowser,favoriteShowsBrowser,topShowsBrowser,playBrowser,settingsMenu,nil];
62        [unwatchedBrowser release];
63        [favoriteShowsBrowser release];
64        [topShowsBrowser release];
65        [playBrowser release];
66        [settingsMenu release];
67        [[self list] setDatasource:self];
68
69        return self;
70}
71
72- (void)dealloc
73{
74        [names release];
75        [controllers release];
76        [metaCollection release];
77        [super dealloc];
78}
79
80- (void) willBePushed
81{
82    // We're about to be placed on screen, but we're not yet there
83   
84    // always call super
85    [super willBePushed];
86}
87
88- (void) wasPushed
89{
90    // We've just been put on screen, the user can see this controller's content now
91   
92    // always call super
93    [super wasPushed];
94}
95
96- (void) willBePopped
97{
98    // The user pressed Menu, but we've not been removed from the screen yet
99   
100    // always call super
101    [super willBePopped];
102}
103
104- (void) wasPopped
105{
106    // The user pressed Menu, removing us from the screen
107   
108    // always call super
109    [super wasPopped];
110}
111
112- (void) willBeBuried
113{
114    // The user just chose an option, and we will be taken off the screen
115   
116    // always call super
117    [super willBeBuried];
118}
119
120- (void) wasBuriedByPushingController: (BRLayerController *) controller
121{
122    // The user chose an option and this controller os no longer on screen
123   
124    // always call super
125    [super wasBuriedByPushingController: controller];
126}
127
128- (void) willBeExhumed
129{
130    // the user pressed Menu, but we've not been revealed yet
131   
132    // always call super
133    [super willBeExhumed];
134}
135
136- (void) wasExhumedByPoppingController: (BRLayerController *) controller
137{
138    // handle being revealed when the user presses Menu
139   
140    // always call super
141    [super wasExhumedByPoppingController: controller];
142}
143
144- (long) itemCount
145{
146    // return the number of items in your menu list here
147        return ( [ names count]);
148}
149
150- (id<BRMenuItemLayer>) itemForRow: (long) row
151{
152/*
153    // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here
154    // return that object, it will be used to display the list item.
155*/
156        if( row > [names count] ) return ( nil ) ;
157       
158        BRAdornedMenuItemLayer * result = nil ;
159        NSString *name = [names objectAtIndex:row];
160        result = [BRAdornedMenuItemLayer adornedFolderMenuItemWithScene: [self scene]] ;
161        [result setLeftIcon:[[BRThemeInfo sharedTheme] errorIconForScene:[self scene]]];
162                       
163        // add text
164        [[result textItem] setTitle: name] ;
165                               
166        return ( result ) ;
167}
168
169- (NSString *) titleForRow: (long) row
170{
171
172        if ( row > [ names count] ) return ( nil );
173       
174        NSString *result = [ names objectAtIndex: row] ;
175        return ( result ) ;
176/*
177    // return the title for the list item at the given index here
178    return ( @"Sapphire" );
179*/
180}
181
182- (long) rowForTitle: (NSString *) title
183{
184    long result = -1;
185    long i, count = [self itemCount];
186    for ( i = 0; i < count; i++ )
187    {
188        if ( [title isEqualToString: [self titleForRow: i]] )
189        {
190            result = i;
191            break;
192        }
193    }
194   
195    return ( result );
196}
197
198- (void) itemSelected: (long) row
199{
200    // This is called when the user presses play/pause on a list item
201       
202        id controller = [controllers objectAtIndex:row];
203        [[self stack] pushController:controller];
204}
205
206- (id<BRMediaPreviewController>) previewControllerForItem: (long) item
207{
208    // If subclassing BRMediaMenuController, this function is called when the selection cursor
209    // passes over an item.
210    return ( nil );
211}
212
213- (void)updateComplete
214{
215        BRListControl *list = [self list];
216        long selection = [list selection];
217        [list reload];
218        [list setSelection:selection]; 
219}
220
221@end
Note: See TracBrowser for help on using the repository browser.