Entries loaded in new thread, no delay at startup
parent
72a10aef0d
commit
eb290c0cd9
|
@ -135,8 +135,7 @@
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||||
{
|
{
|
||||||
DBLog(@"Adding path: %@", filename);
|
DBLog(@"Adding path: %@", filename);
|
||||||
if ([playlistController addPaths:[NSArray arrayWithObject:filename] sort:NO] != 1)
|
[playlistController addPaths:[NSArray arrayWithObject:filename] sort:NO];
|
||||||
return NO;
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,17 @@
|
||||||
|
|
||||||
//All these return the number of things actually added
|
//All these return the number of things actually added
|
||||||
//Private Methods
|
//Private Methods
|
||||||
- (int)addPath:(NSString *)path;
|
//- (int)addPath:(NSString *)path;
|
||||||
- (int)insertPath:(NSString *)path atIndex:(int)index;
|
//- (int)insertPath:(NSString *)path atIndex:(int)index;
|
||||||
- (int)insertFile:(NSString *)filename atIndex:(int)index;
|
//- (int)insertFile:(NSString *)filename atIndex:(int)index;
|
||||||
- (int)addFile:(NSString *)filename;
|
//- (int)addFile:(NSString *)filename;
|
||||||
- (void)updateIndexesFromRow:(int) row;
|
- (void)updateIndexesFromRow:(int) row;
|
||||||
- (void)updateTotalTime;
|
- (void)updateTotalTime;
|
||||||
|
|
||||||
|
|
||||||
//PUBLIC METHODS
|
//PUBLIC METHODS
|
||||||
- (int)addPaths:(NSArray *)paths sort:(BOOL)sort;
|
- (void)addPaths:(NSArray *)paths sort:(BOOL)sort;
|
||||||
- (int)insertPaths:(NSArray *)paths atIndex:(int)index sort:(BOOL)sort;
|
- (void)insertPaths:(NSArray *)paths atIndex:(int)index sort:(BOOL)sort;
|
||||||
|
|
||||||
- (NSArray *)acceptableFileTypes;
|
- (NSArray *)acceptableFileTypes;
|
||||||
|
|
||||||
|
|
|
@ -37,41 +37,21 @@
|
||||||
[super awakeFromNib];
|
[super awakeFromNib];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)insertFile:(NSString *)filename atIndex:(int)index
|
- (NSArray *)filesAtPath:(NSString *)path
|
||||||
{
|
|
||||||
if ([acceptableFileTypes containsObject:[[filename pathExtension] lowercaseString]] && [[NSFileManager defaultManager] fileExistsAtPath:filename])
|
|
||||||
{
|
|
||||||
PlaylistEntry *pe = [[PlaylistEntry alloc] init];
|
|
||||||
|
|
||||||
[pe setFilename:filename];
|
|
||||||
[pe setIndex:index];
|
|
||||||
[pe readTags];
|
|
||||||
[pe readInfo];
|
|
||||||
|
|
||||||
[self insertObject:pe atArrangedObjectIndex:index];
|
|
||||||
[pe release];
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int)insertPath:(NSString *)path atIndex:(int)index
|
|
||||||
{
|
{
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
NSFileManager *manager;
|
NSFileManager *manager;
|
||||||
|
|
||||||
manager = [NSFileManager defaultManager];
|
manager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
DBLog(@"Checking if path is a directory: %@", path);
|
NSLog(@"Checking if path is a directory: %@", path);
|
||||||
if ([manager fileExistsAtPath:path isDirectory:&isDir] && isDir == YES)
|
if ([manager fileExistsAtPath:path isDirectory:&isDir] && isDir == YES)
|
||||||
{
|
{
|
||||||
DBLog(@"path is directory");
|
DBLog(@"path is directory");
|
||||||
int count;
|
|
||||||
int j;
|
int j;
|
||||||
NSArray *subpaths;
|
NSArray *subpaths;
|
||||||
count = 0;
|
NSMutableArray *validPaths = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
subpaths = [manager subpathsAtPath:path];
|
subpaths = [manager subpathsAtPath:path];
|
||||||
|
|
||||||
DBLog(@"Subpaths: %@", subpaths);
|
DBLog(@"Subpaths: %@", subpaths);
|
||||||
|
@ -80,80 +60,118 @@
|
||||||
NSString *filepath;
|
NSString *filepath;
|
||||||
|
|
||||||
filepath = [NSString pathWithComponents:[NSArray arrayWithObjects:path,[subpaths objectAtIndex:j],nil]];
|
filepath = [NSString pathWithComponents:[NSArray arrayWithObjects:path,[subpaths objectAtIndex:j],nil]];
|
||||||
|
if ([manager fileExistsAtPath:filepath isDirectory:&isDir] && isDir == NO)
|
||||||
count += [self insertFile:filepath atIndex:index+count];
|
{
|
||||||
|
if ([acceptableFileTypes containsObject:[[filepath pathExtension] lowercaseString]] && [[NSFileManager defaultManager] fileExistsAtPath:filepath])
|
||||||
|
{
|
||||||
|
[validPaths addObject:filepath];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return [validPaths autorelease];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// DBLog(@"Adding fiiiiile: %@", path);
|
NSLog(@"path is a file");
|
||||||
DBLog(@"path is a file");
|
if ([acceptableFileTypes containsObject:[[path pathExtension] lowercaseString]] && [[NSFileManager defaultManager] fileExistsAtPath:path])
|
||||||
return [self insertFile:path atIndex:index];
|
{
|
||||||
|
NSLog(@"RETURNING THING");
|
||||||
|
return [NSArray arrayWithObject:path];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)insertPaths:(NSArray *)paths atIndex:(int)index sort:(BOOL)sort
|
- (void)insertPaths:(NSArray *)paths atIndex:(int)index sort:(BOOL)sort
|
||||||
{
|
{
|
||||||
NSArray *sortedFiles;
|
NSArray *sortedFiles;
|
||||||
int count;
|
NSMutableArray *files = [[NSMutableArray alloc] init];
|
||||||
|
NSMutableArray *entries= [[NSMutableArray alloc] init];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!paths)
|
if (!paths)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
count = 0;
|
DBLog(@"Paths sorted: %@", sortedFiles);
|
||||||
|
for(i=0; i < [paths count]; i++)
|
||||||
|
{
|
||||||
|
[files addObjectsFromArray:[self filesAtPath:[paths objectAtIndex:i]]];
|
||||||
|
NSLog(@"files is: %i", [files count]);
|
||||||
|
}
|
||||||
|
|
||||||
DBLog(@"Sorting paths");
|
DBLog(@"Sorting paths");
|
||||||
if (sort == YES)
|
if (sort == YES)
|
||||||
{
|
{
|
||||||
sortedFiles = [paths sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
sortedFiles = [files sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
||||||
|
[files release];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortedFiles = paths;
|
sortedFiles = [files autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
DBLog(@"Paths sorted: %@", sortedFiles);
|
for (i = 0; i < [sortedFiles count]; i++)
|
||||||
for(i=0; i < [sortedFiles count]; i++)
|
|
||||||
{
|
{
|
||||||
int j;
|
PlaylistEntry *pe = [[PlaylistEntry alloc] init];
|
||||||
NSString *f;
|
|
||||||
f = [sortedFiles objectAtIndex:i];
|
|
||||||
|
|
||||||
DBLog(@"Inserting path");
|
[pe setFilename:[files objectAtIndex:i]];
|
||||||
j = [self insertPath:f atIndex:(index+count)];
|
[pe setIndex:index+i];
|
||||||
// DBLog(@"Number added: %i", j);
|
|
||||||
count+=j;
|
// [pe performSelectorOnMainThread:@selector(readTags) withObject:nil waitUntilDone:NO];
|
||||||
|
// [pe performSelectorOnMainThread:@selector(readInfo) withObject:nil waitUntilDone:NO];
|
||||||
|
|
||||||
|
[entries addObject:pe];
|
||||||
|
[pe release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSRange r = NSMakeRange(index, [entries count]);
|
||||||
|
NSLog(@"MAking range from: %i to %i", index, index + [entries count]);
|
||||||
|
NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:r];
|
||||||
|
NSLog(@"INDex set: %@", is);
|
||||||
|
NSLog(@"Adding: %i files", [entries count]);
|
||||||
|
[self insertObjects:entries atArrangedObjectIndexes:is];
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
[self resetShuffleList];
|
[self resetShuffleList];
|
||||||
|
|
||||||
|
|
||||||
[self setSelectionIndex:index];
|
[self setSelectionIndex:index];
|
||||||
[self updateTotalTime];
|
|
||||||
|
|
||||||
return count;
|
//Other thread will release entries....crazy crazy bad idea...whatever
|
||||||
|
[NSThread detachNewThreadSelector:@selector(readMetaData:) toTarget:self withObject:entries];
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)addFile:(NSString *)filename
|
- (void)readMetaData:(id)entries
|
||||||
{
|
{
|
||||||
return [self insertFile:filename atIndex:[[self arrangedObjects] count]];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < [entries count]; i++)
|
||||||
|
{
|
||||||
|
PlaylistEntry *pe =[entries objectAtIndex:i];
|
||||||
|
|
||||||
|
// [pe readInfo];
|
||||||
|
[pe performSelectorOnMainThread:@selector(readInfo) withObject:nil waitUntilDone:YES];
|
||||||
|
// [pe readTags];
|
||||||
|
[pe performSelectorOnMainThread:@selector(readTags) withObject:nil waitUntilDone:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self performSelectorOnMainThread:@selector(updateTotalTime) withObject:nil waitUntilDone:NO];
|
||||||
|
|
||||||
|
[entries release];
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)addPath:(NSString *)path
|
- (void)addPaths:(NSArray *)paths sort:(BOOL)sort
|
||||||
{
|
{
|
||||||
return [self insertPath:path atIndex:[[self arrangedObjects] count]];
|
[self insertPaths:paths atIndex:[[self arrangedObjects] count] sort:sort];
|
||||||
}
|
|
||||||
|
|
||||||
- (int)addPaths:(NSArray *)paths sort:(BOOL)sort
|
|
||||||
{
|
|
||||||
return [self insertPaths:paths atIndex:[[self arrangedObjects] count] sort:sort];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)acceptableFileTypes
|
- (NSArray *)acceptableFileTypes
|
||||||
|
|
Loading…
Reference in New Issue