1 /*****************************************************************************
2 * VLCApplianceController.m: Front Row plugin
3 *****************************************************************************
4 * Copyright (C) 2007 - 2008 the VideoLAN Team
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 "VLCApplianceController.h"
26 #import <BackRow/BRListControl.h>
27 #import <BackRow/BRTextMenuItemLayer.h>
28 #import <BackRow/BRControllerStack.h>
30 #import "VLCPlayerController.h"
32 @interface VLCApplianceController ()
34 @property(retain, nonatomic) NSString * path;
38 @implementation VLCApplianceController
40 @synthesize path=_path;
42 - initWithPath:(NSString*)path
46 _contents = [[NSMutableArray alloc] init];
50 [[self header] setTitle:[[NSFileManager defaultManager] displayNameAtPath:self.path]];
51 [[self list] setDatasource:self];
63 - (void)setPath:(NSString*)path
67 _path = [path retain];
69 [_contents removeAllObjects];
71 NSArray * contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_path error:NULL];
73 for(NSString * name in contents) {
74 NSString * filepath = [path stringByAppendingPathComponent:name];
77 if([name hasPrefix:@"."]) {
83 if(![[NSFileManager defaultManager] fileExistsAtPath:filepath isDirectory:&directory]) {
92 NSString * type = [[NSWorkspace sharedWorkspace] typeOfFile:filepath error:NULL];
93 if([[NSWorkspace sharedWorkspace] type:type conformsToType:(NSString*)kUTTypeMovie]) {
99 static NSSet * additionalValidExtensions = nil;
100 if(additionalValidExtensions == nil) {
101 additionalValidExtensions = [[NSSet alloc] initWithObjects:
106 NSString * extension = [[name pathExtension] lowercaseString];
107 if([additionalValidExtensions containsObject:extension]) {
113 [_contents addObject:name];
131 #pragma mark Utilities
133 - (NSString*)pathForRow:(NSInteger)row
135 NSString * name = [_contents objectAtIndex:row];
136 return [self.path stringByAppendingPathComponent:name];
139 - (BOOL)isDirectoryAtPath:(NSString*)path
141 NSDictionary * attributes = [[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES];
142 NSString * type = [attributes objectForKey:NSFileType];
143 return [type isEqualToString:NSFileTypeDirectory];
148 #pragma mark Data source
150 - (NSInteger)itemCount
152 return [_contents count];
155 - (CGFloat)heightForRow:(NSInteger)row
160 - (BOOL)rowSelectable:(NSInteger)row
165 - (NSString*)titleForRow:(NSInteger)row
167 return [_contents objectAtIndex:row];
170 - (id)itemForRow:(NSInteger)row
172 NSString * path = [self pathForRow:row];
173 BOOL isDirectory = [self isDirectoryAtPath:path];
175 BRTextMenuItemLayer * item = nil;
178 item = [BRTextMenuItemLayer folderMenuItem];
181 item = [BRTextMenuItemLayer menuItem];
184 [item setTitle:[self titleForRow:row]];
189 - (NSInteger)rowForTitle:(NSString *)title
191 return [_contents indexOfObject:title];
194 - (void)itemSelected:(NSInteger)row
196 NSString * path = [self pathForRow:row];
197 BOOL isDirectory = [self isDirectoryAtPath:path];
199 BRController * controller = nil;
202 controller = [[[VLCApplianceController alloc] initWithPath:path] autorelease];
206 controller = [[[VLCAppPlayerController alloc] initWithPath:path] autorelease];
208 static VLCPlayerController * playerController = nil;
209 if(playerController == nil) {
210 playerController = [[VLCPlayerController alloc] init];
213 playerController.media = [VLCMedia mediaWithPath:path];
214 controller = playerController;
218 if(controller != nil) {
219 [[self stack] pushController:controller];