source: trunk/SapphireApplianceController.m @ 8

Revision 8, 4.6 KB checked in by gbooker, 8 years ago (diff)

Predicate matching.

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