| 1 | // |
|---|
| 2 | // SapphireVirtualDirectory.m |
|---|
| 3 | // Sapphire |
|---|
| 4 | // |
|---|
| 5 | // Created by Graham Booker on 11/18/07. |
|---|
| 6 | // Copyright 2007 __MyCompanyName__. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SapphireVirtualDirectory.h" |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | @interface SapphireDirectoryMetaData (privateFunctions) |
|---|
| 13 | - (id)initWithDictionary:(NSDictionary *)dict parent:(SapphireMetaData *)myParent path:(NSString *)myPath; |
|---|
| 14 | @end |
|---|
| 15 | |
|---|
| 16 | @implementation SapphireVirtualDirectory |
|---|
| 17 | - (id)initWithParent:(SapphireVirtualDirectory *)myParent path:(NSString *)myPath |
|---|
| 18 | { |
|---|
| 19 | self = [super initWithDictionary:nil parent:myParent path:myPath]; |
|---|
| 20 | if(self == nil) |
|---|
| 21 | return nil; |
|---|
| 22 | |
|---|
| 23 | directory = [[NSMutableDictionary alloc] init]; |
|---|
| 24 | reloadTimer = nil; |
|---|
| 25 | scannedDirectory = YES; |
|---|
| 26 | |
|---|
| 27 | return self; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | - (void) dealloc |
|---|
| 31 | { |
|---|
| 32 | [directory release]; |
|---|
| 33 | [reloadTimer invalidate]; |
|---|
| 34 | [super dealloc]; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | - (void)reloadDirectoryContents |
|---|
| 38 | { |
|---|
| 39 | [files removeAllObjects]; |
|---|
| 40 | [directories removeAllObjects]; |
|---|
| 41 | [metaFiles removeAllObjects]; |
|---|
| 42 | [metaDirs removeAllObjects]; |
|---|
| 43 | [cachedMetaFiles removeAllObjects]; |
|---|
| 44 | [cachedMetaDirs removeAllObjects]; |
|---|
| 45 | [reloadTimer invalidate]; |
|---|
| 46 | reloadTimer = nil; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | - (void)setReloadTimer |
|---|
| 50 | { |
|---|
| 51 | [reloadTimer invalidate]; |
|---|
| 52 | reloadTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(reloadDirectoryContents) userInfo:nil repeats:NO]; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | - (void)processFile:(SapphireFileMetaData *)file |
|---|
| 56 | { |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | - (void)removeFile:(SapphireFileMetaData *)file |
|---|
| 60 | { |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | - (void)childDisplayChanged |
|---|
| 64 | { |
|---|
| 65 | /*The way the timings work out, if the timer exists already, it is more efficient to leave it set rather than set a new one*/ |
|---|
| 66 | if(reloadTimer == nil) |
|---|
| 67 | [self setReloadTimer]; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | - (NSMutableDictionary *)directoryEntries |
|---|
| 71 | { |
|---|
| 72 | NSMutableDictionary *ret = [NSMutableDictionary dictionary]; |
|---|
| 73 | NSEnumerator *pathEnum = [directory keyEnumerator]; |
|---|
| 74 | NSString *subPath = nil; |
|---|
| 75 | while((subPath = [pathEnum nextObject]) != nil) |
|---|
| 76 | { |
|---|
| 77 | SapphireMetaData *data = [directory objectForKey:subPath]; |
|---|
| 78 | if([data isKindOfClass:[SapphireVirtualDirectory class]]) |
|---|
| 79 | [ret setObject:[(SapphireVirtualDirectory *)data directoryEntries] forKey:subPath]; |
|---|
| 80 | else |
|---|
| 81 | [ret setObject:[data path] forKey:subPath]; |
|---|
| 82 | } |
|---|
| 83 | return ret; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | - (void)writeToFile:(NSString *)filePath |
|---|
| 87 | { |
|---|
| 88 | NSMutableDictionary *fileData = [self directoryEntries]; |
|---|
| 89 | [fileData writeToFile:filePath atomically:YES]; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | - (BOOL)isDisplayEmpty |
|---|
| 93 | { |
|---|
| 94 | return [files count] == 0 && [directories count] == 0; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | - (BOOL)isEmpty |
|---|
| 98 | { |
|---|
| 99 | return [directory count] == 0; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | @end |
|---|