2006-09-26 22:22:56 +00:00
|
|
|
//
|
|
|
|
// SmartFolderNode.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 9/25/06.
|
|
|
|
// Copyright 2006 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SmartFolderNode.h"
|
|
|
|
#import "DirectoryNode.h"
|
|
|
|
#import "FileNode.h"
|
2007-10-15 23:18:58 +00:00
|
|
|
#import "FileTreeDataSource.h"
|
2006-09-26 22:22:56 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2006-09-26 22:22:56 +00:00
|
|
|
@implementation SmartFolderNode
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)isLeaf {
|
2006-09-26 22:22:56 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)updatePath {
|
2007-10-16 01:22:57 +00:00
|
|
|
NSDictionary *doc = [NSDictionary dictionaryWithContentsOfFile:[url path]];
|
2007-10-15 03:29:30 +00:00
|
|
|
NSString *rawQuery = [doc objectForKey:@"RawQuery"];
|
|
|
|
NSArray *searchPaths = [[doc objectForKey:@"SearchCriteria"] objectForKey:@"CurrentFolderPath"];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
// Ugh, Carbon from now on...
|
|
|
|
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, (CFStringRef)rawQuery, NULL, NULL);
|
2022-02-07 05:49:27 +00:00
|
|
|
_query = query;
|
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
MDQuerySetSearchScope(query, (CFArrayRef)searchPaths, 0);
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryFinished:) name:(NSString *)kMDQueryDidFinishNotification object:(__bridge id)query];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryUpdate:) name:(NSString *)kMDQueryDidUpdateNotification object:(__bridge id)query];
|
2006-09-26 22:22:56 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Making query!");
|
2007-10-15 03:29:30 +00:00
|
|
|
MDQueryExecute(query, kMDQueryWantsUpdates);
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
// Note: This is asynchronous!
|
2006-09-26 22:22:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setSubpaths:(id)s {
|
2006-09-26 22:22:56 +00:00
|
|
|
subpaths = s;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (unsigned int)countOfSubpaths {
|
|
|
|
return (unsigned int)[[self subpaths] count];
|
2006-09-26 22:22:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (PathNode *)objectInSubpathsAtIndex:(unsigned int)index {
|
2006-09-26 22:22:56 +00:00
|
|
|
return [[self subpaths] objectAtIndex:index];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)queryFinished:(NSNotification *)notification {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Query finished!");
|
2016-05-05 20:05:39 +00:00
|
|
|
MDQueryRef query = (__bridge MDQueryRef)[notification object];
|
2006-09-26 22:22:56 +00:00
|
|
|
|
|
|
|
NSMutableArray *results = [NSMutableArray array];
|
|
|
|
|
2006-09-26 23:23:42 +00:00
|
|
|
MDQueryDisableUpdates(query);
|
2022-02-07 05:49:27 +00:00
|
|
|
int c = (int)MDQueryGetResultCount(query);
|
|
|
|
|
2006-09-26 22:22:56 +00:00
|
|
|
int i;
|
2022-02-07 05:49:27 +00:00
|
|
|
for(i = 0; i < c; i++) {
|
|
|
|
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query, i);
|
|
|
|
|
|
|
|
NSString *itemPath = (NSString *)CFBridgingRelease(MDItemCopyAttribute(item, kMDItemPath));
|
2007-10-15 23:18:58 +00:00
|
|
|
|
2006-09-26 22:22:56 +00:00
|
|
|
[results addObject:itemPath];
|
|
|
|
}
|
2006-09-26 23:23:42 +00:00
|
|
|
|
|
|
|
MDQueryEnableUpdates(query);
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Query update!");
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-15 23:18:58 +00:00
|
|
|
[self processPaths:[results sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-15 22:19:14 +00:00
|
|
|
[dataSource reloadPathNode:self];
|
2006-09-26 22:22:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)queryUpdate:(NSNotification *)notification {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Query update!");
|
2022-02-07 05:49:27 +00:00
|
|
|
[self queryFinished:notification];
|
2006-09-26 22:22:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)dealloc {
|
|
|
|
CFRelease(_query);
|
2016-05-05 20:05:39 +00:00
|
|
|
}
|
|
|
|
|
2006-09-26 22:22:56 +00:00
|
|
|
@end
|