cog/FileTree/PathNode.m

182 lines
3.3 KiB
Matlab
Raw Normal View History

2006-09-02 16:09:20 +00:00
//
// Node.m
// Cog
//
// Created by Vincent Spader on 8/20/2006.
// Copyright 2006 Vincent Spader. All rights reserved.
//
#import "PathNode.h"
#import "CogAudio/AudioPlayer.h"
#import "FileTreeDataSource.h"
2008-02-17 18:59:54 +00:00
#import "FileNode.h"
#import "DirectoryNode.h"
#import "SmartFolderNode.h"
#import "ContainerNode.h"
#import "Logging.h"
2006-09-02 16:09:20 +00:00
@implementation PathNode
2007-10-15 23:37:49 +00:00
//From http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
NSURL *resolveAliases(NSURL *url)
2007-10-15 23:37:49 +00:00
{
FSRef fsRef;
if (CFURLGetFSRef((CFURLRef)url, &fsRef))
2007-10-15 23:37:49 +00:00
{
Boolean targetIsFolder, wasAliased;
2007-10-15 23:37:49 +00:00
if (FSResolveAliasFile (&fsRef, true /*resolveAliasChains*/, &targetIsFolder, &wasAliased) == noErr && wasAliased)
{
CFURLRef resolvedUrl = CFURLCreateFromFSRef(NULL, &fsRef);
if (resolvedUrl != NULL)
2007-10-15 23:37:49 +00:00
{
//DLog(@"Resolved...");
return (NSURL *)CFBridgingRelease(resolvedUrl);
2007-10-15 23:37:49 +00:00
}
}
}
//DLog(@"Not resolved");
return url;
2007-10-15 23:37:49 +00:00
}
- (id)initWithDataSource:(FileTreeDataSource *)ds url:(NSURL *)u
2006-09-02 16:09:20 +00:00
{
self = [super init];
if (self)
{
dataSource = ds;
[self setURL: u];
2006-09-02 16:09:20 +00:00
}
return self;
}
- (void)setURL:(NSURL *)u
{
url = u;
display = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
[icon setSize: NSMakeSize(16.0, 16.0)];
}
- (NSURL *)URL
2006-09-02 16:09:20 +00:00
{
return url;
2006-09-02 16:09:20 +00:00
}
- (void)updatePath
{
}
- (void)processPaths: (NSArray *)contents
{
2013-10-09 18:30:09 +00:00
NSMutableArray *newSubpathsDirs = [[NSMutableArray alloc] init];
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
for (NSString *s in contents)
{
if ([s characterAtIndex:0] == '.')
{
continue;
}
NSURL *u = [NSURL fileURLWithPath:s];
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
PathNode *newNode;
//DLog(@"Before: %@", u);
u = resolveAliases(u);
//DLog(@"After: %@", u);
2007-10-16 01:27:15 +00:00
2013-10-09 18:30:09 +00:00
BOOL isDir;
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
{
DLog(@"Smart folder!");
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource url:u];
2013-10-09 18:30:09 +00:00
isDir = NO;
}
else
{
[[NSFileManager defaultManager] fileExistsAtPath:[u path] isDirectory:&isDir];
if (!isDir && ![[AudioPlayer fileTypes] containsObject:[[u pathExtension] lowercaseString]])
{
continue;
}
if (isDir)
{
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource url:u];
}
else if ([[AudioPlayer containerTypes] containsObject:[[u pathExtension] lowercaseString]])
{
newNode = [[ContainerNode alloc] initWithDataSource:dataSource url:u];
}
else
{
newNode = [[FileNode alloc] initWithDataSource:dataSource url:u];
}
}
[newNode setDisplay:displayName];
2013-10-09 18:30:09 +00:00
if (isDir)
[newSubpathsDirs addObject:newNode];
else
[newSubpaths addObject:newNode];
}
2013-10-09 18:30:09 +00:00
[newSubpathsDirs addObjectsFromArray:newSubpaths];
[self setSubpaths:newSubpathsDirs];
}
- (NSArray *)subpaths
2006-09-02 16:09:20 +00:00
{
if (subpaths == nil)
{
[self updatePath];
}
return subpaths;
2006-09-02 16:09:20 +00:00
}
- (void)setSubpaths:(NSArray *)s
2006-09-02 16:09:20 +00:00
{
subpaths = s;
2006-09-02 16:09:20 +00:00
}
- (BOOL)isLeaf
{
return YES;
}
- (void)setDisplay:(NSString *)s
{
display = s;
}
- (NSString *)display
{
return display;
}
- (NSImage *)icon
{
return icon;
}
2006-09-02 16:09:20 +00:00
@end