2 // VLCMediaListController.m
5 // Created by Pierre d'Herbemont on 2/11/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "VLCMediaListController.h"
10 #import "VLCPlayerController.h"
12 #import <BackRow/BRListControl.h>
13 #import <BackRow/BRTextMenuItemLayer.h>
14 #import <BackRow/BRControllerStack.h>
15 #import <BackRow/BRHeaderControl.h>
17 @interface VLCMediaListController ()
19 @property(retain, nonatomic) VLCMediaListAspect * mediaListAspect;
23 @implementation VLCMediaListController
25 @synthesize mediaListAspect;
27 - initWithMediaListAspect:(VLCMediaListAspect *)aMediaListAspect
29 return [self initWithMediaListAspect:aMediaListAspect andTitle:nil];
32 - initWithMediaListAspect:(VLCMediaListAspect *)aMediaListAspect andTitle:(NSString *)title
34 if( self = [super init] )
36 self.mediaListAspect = aMediaListAspect;
37 [self.mediaListAspect addObserver:self forKeyPath:@"media" options:NSKeyValueChangeRemoval|NSKeyValueChangeInsertion|NSKeyValueChangeSetting context:nil];
38 [[self list] setDatasource:self];
42 [[self header] setTitle: title];
50 [self.mediaListAspect removeObserver:self forKeyPath:@"media"];
51 [mediaListAspect release];
55 - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
57 if ([keyPath isEqualToString:@"media"]) {
61 [self performSelector:@selector(reload) withObject:nil afterDelay: [[self list] itemCount] > 10 ? 2. : [[self list] itemCount] ? 0.3 : 0.0];
65 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
80 #pragma mark Reload hack
89 #pragma mark Data source
91 - (NSInteger)itemCount
93 return [mediaListAspect count];
96 - (CGFloat)heightForRow:(NSInteger)row
101 - (BOOL)rowSelectable:(NSInteger)row
106 - (NSString*)titleForRow:(NSInteger)row
108 return [[mediaListAspect mediaAtIndex:row] valueForKeyPath:@"metaDictionary.title"];
111 - (id)itemForRow:(NSInteger)row
113 BOOL isDirectory = ![[mediaListAspect nodeAtIndex:row] isLeaf];
115 BRTextMenuItemLayer * item = nil;
118 item = [BRTextMenuItemLayer folderMenuItem];
121 item = [BRTextMenuItemLayer menuItem];
124 [item setTitle:[self titleForRow:row]];
129 - (void)itemSelected:(NSInteger)row
131 VLCMediaListAspectNode * node = [mediaListAspect nodeAtIndex:row];
132 BOOL isDirectory = ![node isLeaf];
134 BRController * controller = nil;
137 controller = [[[VLCMediaListController alloc] initWithMediaListAspect:[node children] andTitle:[[node media] valueForKeyPath:@"metaDictionary.title"]] autorelease];
140 static VLCPlayerController * playerController = nil;
141 if(playerController == nil) {
142 playerController = [[VLCPlayerController alloc] init];
145 playerController.media = [mediaListAspect mediaAtIndex:row];
146 controller = playerController;
149 if(controller != nil) {
150 [[self stack] pushController:controller];