2006-09-02 12:09:20 -04: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 20:24:54 -03:00
|
|
|
#import "CogAudio/AudioPlayer.h"
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
#import "FileTreeDataSource.h"
|
|
|
|
|
|
|
|
#import "UKKQueue.h"
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
@class FileNode;
|
|
|
|
@class DirectoryNode;
|
|
|
|
@class SmartFolderNode;
|
|
|
|
|
2006-09-02 12:09:20 -04:00
|
|
|
@implementation PathNode
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
- (id)initWithDataSource:(FileTreeDataSource *)ds path:(NSString *)p
|
2006-09-02 12:09:20 -04:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2007-10-15 00:29:30 -03:00
|
|
|
dataSource = ds;
|
2007-10-14 20:24:54 -03:00
|
|
|
[self setPath: p];
|
2006-09-02 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
- (void)stopWatching
|
2006-09-02 12:09:20 -04:00
|
|
|
{
|
2007-10-15 00:29:30 -03:00
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
NSLog(@"Stopped watching...: %@", path);
|
|
|
|
|
|
|
|
//Remove all in one go
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
|
|
|
|
|
|
|
|
[[UKKQueue sharedFileWatcher] removePath:path];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startWatching
|
|
|
|
{
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
NSLog(@"WATCHING! %@ %i", path, path);
|
|
|
|
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherRenameNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherWriteNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherDeleteNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherAttributeChangeNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherSizeIncreaseNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherLinkCountChangeNotification object:nil];
|
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(updatePathNotification:) name:UKFileWatcherAccessRevocationNotification object:nil];
|
2007-10-14 20:24:54 -03:00
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
[[UKKQueue sharedFileWatcher] addPath:path];
|
2007-10-14 20:24:54 -03:00
|
|
|
}
|
2006-09-02 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
- (void)setPath:(NSString *)p
|
|
|
|
{
|
|
|
|
[p retain];
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
[self stopWatching];
|
|
|
|
|
|
|
|
[path release];
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
path = p;
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
[self startWatching];
|
|
|
|
|
|
|
|
[displayPath release];
|
|
|
|
displayPath = [[NSFileManager defaultManager] displayNameAtPath:path];
|
|
|
|
[displayPath retain];
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
[icon release];
|
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFile:path];
|
|
|
|
[icon retain];
|
|
|
|
|
|
|
|
[icon setSize: NSMakeSize(16.0, 16.0)];
|
|
|
|
}
|
|
|
|
|
2006-09-02 12:09:20 -04:00
|
|
|
- (NSString *)path
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
- (void)updatePath
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updatePathNotification:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread:@selector(updatePathNotificationMainThread:) withObject:notification waitUntilDone:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updatePathNotificationMainThread:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *p = [[notification userInfo] objectForKey:@"path"];
|
|
|
|
if (p == path)
|
|
|
|
{
|
|
|
|
NSLog(@"Update path notification: %@", [NSThread currentThread]);
|
|
|
|
|
|
|
|
[self updatePath];
|
|
|
|
|
|
|
|
[dataSource reloadPathNode:self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
- (void)processPaths: (NSArray *)contents
|
|
|
|
{
|
|
|
|
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
NSEnumerator *e = [contents objectEnumerator];
|
|
|
|
NSString *s;
|
|
|
|
while ((s = [e nextObject]))
|
|
|
|
{
|
|
|
|
if ([s characterAtIndex:0] == '.')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PathNode *newNode;
|
|
|
|
|
|
|
|
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
|
|
|
{
|
2007-10-15 20:18:58 -03:00
|
|
|
NSLog(@"Smart folder!");
|
|
|
|
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource path:s];
|
2007-10-14 20:24:54 -03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL isDir;
|
|
|
|
|
2007-10-15 20:18:58 -03:00
|
|
|
[[NSFileManager defaultManager] fileExistsAtPath:s isDirectory:&isDir];
|
2007-10-14 20:24:54 -03:00
|
|
|
|
|
|
|
if (!isDir && ![[AudioPlayer fileTypes] containsObject:[s pathExtension]])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDir)
|
2007-10-15 00:29:30 -03:00
|
|
|
{
|
2007-10-15 20:18:58 -03:00
|
|
|
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource path: s];
|
2007-10-15 00:29:30 -03:00
|
|
|
}
|
2007-10-14 20:24:54 -03:00
|
|
|
else
|
2007-10-15 00:29:30 -03:00
|
|
|
{
|
2007-10-15 20:18:58 -03:00
|
|
|
newNode = [[FileNode alloc] initWithDataSource:dataSource path: s];
|
2007-10-15 00:29:30 -03:00
|
|
|
}
|
2007-10-14 20:24:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
[newSubpaths addObject:newNode];
|
|
|
|
|
|
|
|
[newNode release];
|
|
|
|
}
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
[self setSubpaths:newSubpaths];
|
2007-10-14 20:24:54 -03:00
|
|
|
|
|
|
|
[newSubpaths release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)subpaths
|
2006-09-02 12:09:20 -04:00
|
|
|
{
|
2007-10-15 00:29:30 -03:00
|
|
|
if (subpaths == nil)
|
|
|
|
{
|
|
|
|
[self updatePath];
|
|
|
|
}
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
return subpaths;
|
2006-09-02 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
- (void)setSubpaths:(NSArray *)s
|
2006-09-02 12:09:20 -04:00
|
|
|
{
|
2007-10-14 20:24:54 -03:00
|
|
|
[s retain];
|
|
|
|
[subpaths release];
|
|
|
|
subpaths = s;
|
2006-09-02 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
2007-10-14 20:24:54 -03:00
|
|
|
|
|
|
|
- (BOOL)isLeaf
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
- (NSString *)displayPath
|
|
|
|
{
|
|
|
|
return displayPath;
|
|
|
|
}
|
2007-10-14 20:24:54 -03:00
|
|
|
|
|
|
|
- (NSImage *)icon
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2007-10-15 00:29:30 -03:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self stopWatching];
|
|
|
|
|
|
|
|
[path release];
|
|
|
|
[icon release];
|
|
|
|
|
|
|
|
[subpaths release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2007-10-14 20:24:54 -03:00
|
|
|
|
2006-09-02 12:09:20 -04:00
|
|
|
@end
|