2 // VLCApplianceController.m
5 // Created by hyei on 06/09/07.
6 // Copyright 2007 __MyCompanyName__. All rights reserved.
9 #import "VLCApplianceController.h"
11 #import <BackRow/BRListControl.h>
12 #import <BackRow/BRTextMenuItemLayer.h>
13 #import <BackRow/BRControllerStack.h>
15 #import "VLCPlayerController.h"
17 @interface VLCApplianceController ()
19 @property(retain, nonatomic) NSString * path;
23 @implementation VLCApplianceController
25 @synthesize path=_path;
27 - initWithPath:(NSString*)path
31 _contents = [[NSMutableArray alloc] init];
35 [[self header] setTitle:[[NSFileManager defaultManager] displayNameAtPath:self.path]];
36 [[self list] setDatasource:self];
48 - (void)setPath:(NSString*)path
52 _path = [path retain];
54 [_contents removeAllObjects];
56 NSArray * contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_path error:NULL];
58 for(NSString * name in contents) {
59 NSString * filepath = [path stringByAppendingPathComponent:name];
62 if([name hasPrefix:@"."]) {
68 if(![[NSFileManager defaultManager] fileExistsAtPath:filepath isDirectory:&directory]) {
77 NSString * type = [[NSWorkspace sharedWorkspace] typeOfFile:filepath error:NULL];
78 if([[NSWorkspace sharedWorkspace] type:type conformsToType:(NSString*)kUTTypeMovie]) {
84 static NSSet * additionalValidExtensions = nil;
85 if(additionalValidExtensions == nil) {
86 additionalValidExtensions = [[NSSet alloc] initWithObjects:
91 NSString * extension = [[name pathExtension] lowercaseString];
92 if([additionalValidExtensions containsObject:extension]) {
98 [_contents addObject:name];
116 #pragma mark Utilities
118 - (NSString*)pathForRow:(NSInteger)row
120 NSString * name = [_contents objectAtIndex:row];
121 return [self.path stringByAppendingPathComponent:name];
124 - (BOOL)isDirectoryAtPath:(NSString*)path
126 NSDictionary * attributes = [[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES];
127 NSString * type = [attributes objectForKey:NSFileType];
128 return [type isEqualToString:NSFileTypeDirectory];
133 #pragma mark Data source
135 - (NSInteger)itemCount
137 return [_contents count];
140 - (CGFloat)heightForRow:(NSInteger)row
145 - (BOOL)rowSelectable:(NSInteger)row
150 - (NSString*)titleForRow:(NSInteger)row
152 return [_contents objectAtIndex:row];
155 - (id)itemForRow:(NSInteger)row
157 NSString * path = [self pathForRow:row];
158 BOOL isDirectory = [self isDirectoryAtPath:path];
160 BRTextMenuItemLayer * item = nil;
163 item = [BRTextMenuItemLayer folderMenuItem];
166 item = [BRTextMenuItemLayer menuItem];
169 [item setTitle:[self titleForRow:row]];
174 - (NSInteger)rowForTitle:(NSString *)title
176 return [_contents indexOfObject:title];
179 - (void)itemSelected:(NSInteger)row
181 NSString * path = [self pathForRow:row];
182 BOOL isDirectory = [self isDirectoryAtPath:path];
184 BRController * controller = nil;
187 controller = [[[VLCApplianceController alloc] initWithPath:path] autorelease];
191 controller = [[[VLCAppPlayerController alloc] initWithPath:path] autorelease];
193 static VLCPlayerController * playerController = nil;
194 if(playerController == nil) {
195 playerController = [[VLCPlayerController alloc] init];
198 playerController.media = [VLCMedia mediaWithPath:path];
199 controller = playerController;
203 if(controller != nil) {
204 [[self stack] pushController:controller];