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"
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
#import "CogAudio/AudioPlayer.h"
|
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
#import "FileTreeDataSource.h"
|
|
|
|
|
2008-02-17 18:59:54 +00:00
|
|
|
#import "FileNode.h"
|
|
|
|
#import "DirectoryNode.h"
|
|
|
|
#import "SmartFolderNode.h"
|
|
|
|
#import "ContainerNode.h"
|
2007-10-14 23:24:54 +00:00
|
|
|
|
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
|
2007-10-16 01:22:57 +00:00
|
|
|
NSURL *resolveAliases(NSURL *url)
|
2007-10-15 23:37:49 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
FSRef fsRef;
|
|
|
|
if (CFURLGetFSRef((CFURLRef)url, &fsRef))
|
2007-10-15 23:37:49 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
Boolean targetIsFolder, wasAliased;
|
2007-10-15 23:37:49 +00:00
|
|
|
|
2007-10-16 01:22:57 +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
|
|
|
{
|
2009-08-16 16:49:34 +00:00
|
|
|
//NSLog(@"Resolved...");
|
2007-10-16 01:22:57 +00:00
|
|
|
return [(NSURL *)resolvedUrl autorelease];
|
2007-10-15 23:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-16 16:49:34 +00:00
|
|
|
//NSLog(@"Not resolved");
|
2007-10-16 01:22:57 +00:00
|
|
|
return url;
|
2007-10-15 23:37:49 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
- (id)initWithDataSource:(FileTreeDataSource *)ds url:(NSURL *)u
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2007-10-15 03:29:30 +00:00
|
|
|
dataSource = ds;
|
2007-10-16 01:22:57 +00:00
|
|
|
[self setURL: u];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
- (void)setURL:(NSURL *)u
|
2007-10-14 23:24:54 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
[u retain];
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
[url release];
|
2007-10-15 03:29:30 +00:00
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
url = u;
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
[display release];
|
2009-08-16 16:49:34 +00:00
|
|
|
display = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
2007-10-16 01:22:57 +00:00
|
|
|
[display retain];
|
2007-10-15 03:29:30 +00:00
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
[icon release];
|
2007-10-16 01:22:57 +00:00
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
|
2007-10-14 23:24:54 +00:00
|
|
|
[icon retain];
|
|
|
|
|
|
|
|
[icon setSize: NSMakeSize(16.0, 16.0)];
|
|
|
|
}
|
|
|
|
|
2008-02-20 01:01:15 +00:00
|
|
|
- (NSURL *)URL
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
return url;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
- (void)updatePath
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
- (void)processPaths: (NSArray *)contents
|
|
|
|
{
|
2013-10-09 18:30:09 +00:00
|
|
|
NSMutableArray *newSubpathsDirs = [[NSMutableArray alloc] init];
|
2007-10-14 23:24:54 +00:00
|
|
|
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
|
|
|
|
|
2013-10-10 08:44:45 +00:00
|
|
|
for (NSString *s in contents)
|
2007-10-14 23:24:54 +00:00
|
|
|
{
|
|
|
|
if ([s characterAtIndex:0] == '.')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
NSURL *u = [NSURL fileURLWithPath:s];
|
2009-08-16 16:49:34 +00:00
|
|
|
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
2007-10-16 01:22:57 +00:00
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
PathNode *newNode;
|
|
|
|
|
2009-08-16 16:49:34 +00:00
|
|
|
//NSLog(@"Before: %@", u);
|
2007-10-16 01:22:57 +00:00
|
|
|
u = resolveAliases(u);
|
2009-08-16 16:49:34 +00:00
|
|
|
//NSLog(@"After: %@", u);
|
2007-10-16 01:27:15 +00:00
|
|
|
|
2013-10-09 18:30:09 +00:00
|
|
|
BOOL isDir;
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
|
|
|
{
|
2007-10-15 23:18:58 +00:00
|
|
|
NSLog(@"Smart folder!");
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource url:u];
|
2013-10-09 18:30:09 +00:00
|
|
|
isDir = NO;
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
[[NSFileManager defaultManager] fileExistsAtPath:[u path] isDirectory:&isDir];
|
|
|
|
|
2007-10-16 01:27:15 +00:00
|
|
|
if (!isDir && ![[AudioPlayer fileTypes] containsObject:[[[u path] pathExtension] lowercaseString]])
|
2007-10-14 23:24:54 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDir)
|
2007-10-15 03:29:30 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource url:u];
|
|
|
|
}
|
|
|
|
else if ([[AudioPlayer containerTypes] containsObject:[[[u path] pathExtension] lowercaseString]])
|
|
|
|
{
|
|
|
|
newNode = [[ContainerNode alloc] initWithDataSource:dataSource url:u];
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
else
|
2007-10-15 03:29:30 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[FileNode alloc] initWithDataSource:dataSource url:u];
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
2009-08-16 16:49:34 +00:00
|
|
|
|
|
|
|
[newNode setDisplay:displayName];
|
2013-10-09 18:30:09 +00:00
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
[newSubpathsDirs addObject:newNode];
|
|
|
|
else
|
|
|
|
[newSubpaths addObject:newNode];
|
2007-10-14 23:24:54 +00:00
|
|
|
|
|
|
|
[newNode release];
|
|
|
|
}
|
|
|
|
|
2013-10-09 18:30:09 +00:00
|
|
|
[newSubpathsDirs addObjectsFromArray:newSubpaths];
|
|
|
|
[self setSubpaths:newSubpathsDirs];
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2013-10-09 18:30:09 +00:00
|
|
|
[newSubpathsDirs release];
|
2007-10-14 23:24:54 +00:00
|
|
|
[newSubpaths release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)subpaths
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2007-10-15 03:29:30 +00:00
|
|
|
if (subpaths == nil)
|
|
|
|
{
|
|
|
|
[self updatePath];
|
|
|
|
}
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
return subpaths;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
- (void)setSubpaths:(NSArray *)s
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2007-10-14 23:24:54 +00:00
|
|
|
[s retain];
|
|
|
|
[subpaths release];
|
|
|
|
subpaths = s;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
|
|
|
|
- (BOOL)isLeaf
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2009-08-16 16:49:34 +00:00
|
|
|
- (void)setDisplay:(NSString *)s
|
|
|
|
{
|
|
|
|
[display release];
|
|
|
|
display = s;
|
|
|
|
[display retain];
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
- (NSString *)display
|
2007-10-15 03:29:30 +00:00
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
return display;
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
|
|
|
|
- (NSImage *)icon
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2007-10-16 01:22:57 +00:00
|
|
|
[url release];
|
2007-10-15 03:29:30 +00:00
|
|
|
[icon release];
|
|
|
|
|
|
|
|
[subpaths release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
@end
|