1 /*****************************************************************************
2 * VLCMediaListController.m: Front Row plugin
3 *****************************************************************************
4 * Copyright (C) 2007 - 2008 the VideoLAN Team
7 * Authors: Pierre d'Herbemont <pdherbemont at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #import "VLCMediaListController.h"
25 #import "VLCPlayerController.h"
27 #import <BackRow/BRListControl.h>
28 #import <BackRow/BRTextMenuItemLayer.h>
29 #import <BackRow/BRControllerStack.h>
30 #import <BackRow/BRHeaderControl.h>
32 @interface VLCMediaListController ()
34 @property(retain, nonatomic) VLCMediaListAspect * mediaListAspect;
38 @implementation VLCMediaListController
40 @synthesize mediaListAspect;
42 - initWithMediaListAspect:(VLCMediaListAspect *)aMediaListAspect
44 return [self initWithMediaListAspect:aMediaListAspect andTitle:nil];
47 - initWithMediaListAspect:(VLCMediaListAspect *)aMediaListAspect andTitle:(NSString *)title
49 if( self = [super init] )
51 self.mediaListAspect = aMediaListAspect;
52 [self.mediaListAspect addObserver:self forKeyPath:@"media" options:NSKeyValueChangeRemoval|NSKeyValueChangeInsertion|NSKeyValueChangeSetting context:nil];
53 [[self list] setDatasource:self];
57 [[self header] setTitle: title];
65 [self.mediaListAspect removeObserver:self forKeyPath:@"media"];
66 [mediaListAspect release];
70 - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
72 if ([keyPath isEqualToString:@"media"]) {
76 [self performSelector:@selector(reload) withObject:nil afterDelay: [[self list] itemCount] > 10 ? 2. : [[self list] itemCount] ? 0.3 : 0.0];
80 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
95 #pragma mark Reload hack
104 #pragma mark Data source
106 - (NSInteger)itemCount
108 return [mediaListAspect count];
111 - (CGFloat)heightForRow:(NSInteger)row
116 - (BOOL)rowSelectable:(NSInteger)row
121 - (NSString*)titleForRow:(NSInteger)row
123 return [[mediaListAspect mediaAtIndex:row] valueForKeyPath:@"metaDictionary.title"];
126 - (id)itemForRow:(NSInteger)row
128 BOOL isDirectory = ![[mediaListAspect nodeAtIndex:row] isLeaf];
130 BRTextMenuItemLayer * item = nil;
133 item = [BRTextMenuItemLayer folderMenuItem];
136 item = [BRTextMenuItemLayer menuItem];
139 [item setTitle:[self titleForRow:row]];
144 - (void)itemSelected:(NSInteger)row
146 VLCMediaListAspectNode * node = [mediaListAspect nodeAtIndex:row];
147 BOOL isDirectory = ![node isLeaf];
149 BRController * controller = nil;
152 controller = [[[VLCMediaListController alloc] initWithMediaListAspect:[node children] andTitle:[[node media] valueForKeyPath:@"metaDictionary.title"]] autorelease];
155 static VLCPlayerController * playerController = nil;
156 if(playerController == nil) {
157 playerController = [[VLCPlayerController alloc] init];
160 playerController.media = [mediaListAspect mediaAtIndex:row];
161 controller = playerController;
164 if(controller != nil) {
165 [[self stack] pushController:controller];