cog/Playlist/PlaylistController.m

705 lines
16 KiB
Matlab
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// PlaylistController.m
// Cog
2005-06-02 18:16:43 +00:00
//
// Created by Vincent Spader on 3/18/05.
// Copyright 2005 Vincent Spader All rights reserved.
2005-06-02 18:16:43 +00:00
//
#import "PlaylistLoader.h"
2005-06-02 18:16:43 +00:00
#import "PlaylistController.h"
#import "PlaylistEntry.h"
2006-01-20 15:22:03 +00:00
#import "Shuffle.h"
#import "SpotlightWindowController.h"
#import "RepeatTransformers.h"
#import "StatusImageTransformer.h"
#import "CogAudio/AudioPlayer.h"
2006-05-07 13:19:23 +00:00
2005-06-02 18:16:43 +00:00
@implementation PlaylistController
2008-02-23 19:46:23 +00:00
@synthesize currentEntry;
@synthesize totalTime;
2005-06-02 18:16:43 +00:00
+ (void)initialize {
NSValueTransformer *repeatNoneTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatNone] autorelease];
[NSValueTransformer setValueTransformer:repeatNoneTransformer
forName:@"RepeatNoneTransformer"];
NSValueTransformer *repeatOneTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatOne] autorelease];
[NSValueTransformer setValueTransformer:repeatOneTransformer
forName:@"RepeatOneTransformer"];
NSValueTransformer *repeatAlbumTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatAlbum] autorelease];
[NSValueTransformer setValueTransformer:repeatAlbumTransformer
forName:@"RepeatAlbumTransformer"];
NSValueTransformer *repeatAllTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatAll] autorelease];
[NSValueTransformer setValueTransformer:repeatAllTransformer
forName:@"RepeatAllTransformer"];
NSValueTransformer *repeatModeImageTransformer = [[[RepeatModeImageTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:repeatModeImageTransformer
forName:@"RepeatModeImageTransformer"];
NSValueTransformer *statusImageTransformer = [[[StatusImageTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:statusImageTransformer
forName:@"StatusImageTransformer"];
}
2005-06-02 18:16:43 +00:00
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self)
{
shuffleList = [[NSMutableArray alloc] init];
queueList = [[NSMutableArray alloc] init];
2005-06-02 18:16:43 +00:00
}
return self;
}
- (void)dealloc
{
[shuffleList release];
[queueList release];
[super dealloc];
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self addObserver:self forKeyPath:@"arrangedObjects" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"arrangedObjects"])
{
[self updatePlaylistIndexes];
[self updateTotalTime];
}
}
- (void)updatePlaylistIndexes
{
int i;
NSArray *arranged = [self arrangedObjects];
for (i = 0; i < [arranged count]; i++)
{
PlaylistEntry *pe = [arranged objectAtIndex:i];
if (pe.index != i) //Make sure we don't get into some kind of crazy observing loop...
pe.index = i;
}
}
- (void)updateTotalTime
{
double tt = 0;
ldiv_t hoursAndMinutes;
for (PlaylistEntry *pe in [self arrangedObjects]) {
if (!isnan(pe.length))
tt += pe.length;
}
int sec = (int)(tt);
hoursAndMinutes = ldiv(sec/60, 60);
[self setTotalTime:[NSString stringWithFormat:@"%ld hours %ld minutes %d seconds", hoursAndMinutes.quot, hoursAndMinutes.rem, sec%60]];
}
2006-04-29 00:03:28 +00:00
- (void)tableView:(NSTableView *)tableView
didClickTableColumn:(NSTableColumn *)tableColumn
{
2006-04-30 13:01:33 +00:00
if (shuffle == YES)
[self resetShuffleList];
2006-04-29 00:03:28 +00:00
}
- (NSString *)tableView:(NSTableView *)tv toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc row:(int)row mouseLocation:(NSPoint)mouseLocation
{
NSLog(@"GETTING STATUS FOR ROW: %i: %@!", row, [[[self arrangedObjects] objectAtIndex:row] statusMessage]);
return [[[self arrangedObjects] objectAtIndex:row] statusMessage];
}
2008-02-24 15:47:04 +00:00
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet
toIndex:(unsigned int)insertIndex
{
2008-02-24 15:47:04 +00:00
[super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
2008-02-24 15:47:04 +00:00
NSUInteger lowerIndex = insertIndex;
NSUInteger index = insertIndex;
2008-02-24 15:47:04 +00:00
while (NSNotFound != lowerIndex) {
lowerIndex = [indexSet indexLessThanIndex:lowerIndex];
if (lowerIndex != NSNotFound)
index = lowerIndex;
}
2008-02-24 15:47:04 +00:00
}
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
[super tableView:aTableView writeRowsWithIndexes:rowIndexes toPasteboard:pboard];
NSMutableArray *filenames = [NSMutableArray array];
NSInteger row;
for (row = [rowIndexes firstIndex];
row <= [rowIndexes lastIndex];
row = [rowIndexes indexGreaterThanIndex:row])
{
PlaylistEntry *song = [[self arrangedObjects] objectAtIndex:row];
[filenames addObject:[[song path] stringByExpandingTildeInPath]];
}
[pboard addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self];
[pboard setPropertyList:filenames forType:NSFilenamesPboardType];
return YES;
}
2005-06-02 18:16:43 +00:00
- (BOOL)tableView:(NSTableView*)tv
acceptDrop:(id <NSDraggingInfo>)info
row:(int)row
dropOperation:(NSTableViewDropOperation)op
{
2008-02-24 15:47:04 +00:00
//Check if DNDArrayController handles it.
if ([super tableView:tv acceptDrop:info row:row dropOperation:op])
2005-06-02 18:16:43 +00:00
return YES;
if (row < 0)
row = 0;
// Determine the type of object that was dropped
NSArray *supportedtypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil];
NSPasteboard *pboard = [info draggingPasteboard];
NSString *bestType = [pboard availableTypeFromArray:supportedtypes];
// Get files from an file drawer drop
if ([bestType isEqualToString:CogUrlsPboardType]) {
NSArray *urls = [NSUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType:CogUrlsPboardType]];
NSLog(@"URLS: %@", urls);
[playlistLoader insertURLs: urls atIndex:row sort:YES];
}
// Get files from a normal file drop (such as from Finder)
if ([bestType isEqualToString:NSFilenamesPboardType]) {
NSMutableArray *urls = [[NSMutableArray alloc] init];
for (NSString *file in [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType])
{
[urls addObject:[NSURL fileURLWithPath:file]];
}
[playlistLoader insertURLs:urls atIndex:row sort:YES];
[urls release];
}
// Get files from an iTunes drop
if ([bestType isEqualToString:iTunesDropType]) {
NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType];
NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"];
2005-06-02 18:16:43 +00:00
// Convert the iTunes URLs to URLs....MWAHAHAH!
NSMutableArray *urls = [[NSMutableArray alloc] init];
for (NSDictionary *trackInfo in [tracks allValues]) {
[urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]];
}
[playlistLoader insertURLs:urls atIndex:row sort:YES];
[urls release];
}
2005-06-02 18:16:43 +00:00
if (shuffle == YES)
2006-01-20 15:22:03 +00:00
[self resetShuffleList];
2005-06-02 18:16:43 +00:00
return YES;
}
- (NSUndoManager *)undoManager
{
return [entriesController undoManager];
}
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes
{
[super insertObjects:objects atArrangedObjectIndexes:indexes];
if (shuffle == YES)
[self resetShuffleList];
}
2005-06-02 18:16:43 +00:00
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes
{
NSLog(@"Removing indexes: %@", indexes);
2008-02-23 19:46:23 +00:00
NSLog(@"Current index: %i", currentEntry.index);
2008-02-23 19:46:23 +00:00
if (currentEntry.index >= 0 && [indexes containsIndex:currentEntry.index])
2005-06-02 18:16:43 +00:00
{
2008-02-23 19:46:23 +00:00
currentEntry.index = -currentEntry.index - 1;
NSLog(@"Current removed: %i", currentEntry.index);
}
2008-02-23 19:46:23 +00:00
if (currentEntry.index < 0) //Need to update the negative index
{
2008-02-23 19:46:23 +00:00
int i = -currentEntry.index - 1;
NSLog(@"I is %i", i);
int j;
for (j = i - 1; j >= 0; j--)
{
if ([indexes containsIndex:j]) {
NSLog(@"Removing 1");
i--;
}
}
2008-02-23 19:46:23 +00:00
currentEntry.index = -i - 1;
2005-06-02 18:16:43 +00:00
}
[super removeObjectsAtArrangedObjectIndexes:indexes];
2005-06-02 18:16:43 +00:00
if (shuffle == YES)
2006-01-20 15:22:03 +00:00
[self resetShuffleList];
2005-06-02 18:16:43 +00:00
}
2006-05-12 19:23:17 +00:00
- (void)setSortDescriptors:(NSArray *)sortDescriptors
{
NSLog(@"Current: %@, setting: %@", [self sortDescriptors], sortDescriptors);
2006-05-12 19:23:17 +00:00
//Cheap hack so the index column isn't sorted
2007-03-14 03:16:37 +00:00
if (([sortDescriptors count] != 0) && [[[sortDescriptors objectAtIndex:0] key] caseInsensitiveCompare:@"index"] == NSOrderedSame)
2006-05-12 19:23:17 +00:00
{
//Remove the sort descriptors
[super setSortDescriptors:nil];
[self rearrangeObjects];
2006-05-29 23:03:58 +00:00
return;
2006-05-12 19:23:17 +00:00
}
2006-05-29 23:03:58 +00:00
[super setSortDescriptors:sortDescriptors];
[self rearrangeObjects];
2006-05-12 19:23:17 +00:00
}
- (IBAction)sortByPath
2006-04-30 13:01:33 +00:00
{
NSSortDescriptor *s = [[NSSortDescriptor alloc] initWithKey:@"url" ascending:YES selector:@selector(compare:)];
[self setSortDescriptors:[NSArray arrayWithObject:s]];
2006-04-30 13:01:33 +00:00
[s release];
if (shuffle == YES)
[self resetShuffleList];
}
- (IBAction)randomizeList
2006-04-30 13:01:33 +00:00
{
[self setSortDescriptors:nil];
2006-05-12 19:32:01 +00:00
2006-04-30 13:01:33 +00:00
[self setContent:[Shuffle shuffleList:[self content]]];
if (shuffle == YES)
[self resetShuffleList];
}
2005-06-02 18:16:43 +00:00
- (IBAction)takeShuffleFromObject:(id)sender
{
if( [sender respondsToSelector: @selector(boolValue)] )
[self setShuffle: [sender boolValue]];
else
[self setShuffle: [sender state]];
}
- (IBAction)toggleRepeat:(id)sender
2005-06-02 18:16:43 +00:00
{
if (repeat == RepeatNone) {
[self setRepeat: RepeatOne];
}
else if (repeat == RepeatOne) {
[self setRepeat: RepeatAlbum];
}
else if (repeat == RepeatAlbum) {
[self setRepeat: RepeatAll];
}
else if (repeat == RepeatAll) {
[self setRepeat: RepeatNone];
}
2005-06-02 18:16:43 +00:00
}
2006-04-13 02:51:22 +00:00
- (PlaylistEntry *)entryAtIndex:(int)i
{
2006-04-15 13:51:40 +00:00
if (i < 0)
2006-04-13 02:51:22 +00:00
{
2008-02-20 00:12:25 +00:00
if (repeat != RepeatNone)
2006-04-15 13:51:40 +00:00
i += [[self arrangedObjects] count];
else
return nil;
}
else if (i >= [[self arrangedObjects] count])
{
2008-02-20 00:12:25 +00:00
if (repeat != RepeatNone)
2006-04-15 13:51:40 +00:00
i -= [[self arrangedObjects] count];
else
return nil;
}
return [[self arrangedObjects] objectAtIndex:i];
}
2006-04-15 13:51:40 +00:00
- (PlaylistEntry *)shuffledEntryAtIndex:(int)i
{
while (i < 0)
{
2008-02-19 23:49:51 +00:00
if (repeat == RepeatAll)
{
2006-04-15 13:51:40 +00:00
[self addShuffledListToFront];
//change i appropriately
i += [[self arrangedObjects] count];
}
2006-04-15 13:51:40 +00:00
else
{
2006-04-15 13:51:40 +00:00
return nil;
}
2006-04-13 02:51:22 +00:00
}
2006-04-15 13:51:40 +00:00
while (i >= [shuffleList count])
2006-04-13 02:51:22 +00:00
{
2008-02-19 23:49:51 +00:00
if (repeat == RepeatAll)
{
2006-04-15 13:51:40 +00:00
[self addShuffledListToBack];
}
2006-04-15 13:51:40 +00:00
else
{
2006-04-15 13:51:40 +00:00
return nil;
}
2006-04-15 13:51:40 +00:00
}
return [shuffleList objectAtIndex:i];
2006-04-13 02:51:22 +00:00
}
2006-04-15 13:51:40 +00:00
- (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe
{
2008-02-19 23:49:51 +00:00
if (repeat == RepeatOne) {
return pe;
}
if ([queueList count] > 0)
{
pe = [queueList objectAtIndex:0];
[queueList removeObjectAtIndex:0];
2008-02-23 19:46:23 +00:00
pe.status = kCogEntryNormal;
[pe setStatusMessage:nil];
[pe setQueuePosition:-1];
int i;
for (i = 0; i < [queueList count]; i++)
{
PlaylistEntry *queueItem = [queueList objectAtIndex:i];
[queueItem setQueuePosition: i+1];
[queueItem setStatusMessage:[NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
}
return pe;
}
2006-04-15 13:51:40 +00:00
if (shuffle == YES)
{
2008-02-23 19:46:23 +00:00
return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)];
2006-04-15 13:51:40 +00:00
}
else
{
int i;
2008-02-23 19:46:23 +00:00
if (pe.index < 0) //Was a current entry, now removed.
{
2008-02-23 19:46:23 +00:00
i = -pe.index - 1;
}
else
{
2008-02-23 19:46:23 +00:00
i = pe.index + 1;
}
if (repeat == RepeatAlbum)
{
PlaylistEntry *next = [self entryAtIndex:i];
if ((i > [[self arrangedObjects] count]-1) || ([[next album] caseInsensitiveCompare:[pe album]]) || ([next album] == nil))
{
NSArray *filtered = [self filterPlaylistOnAlbum:[pe album]];
if ([pe album] == nil)
i--;
else
i = [(NSNumber *)[[filtered objectAtIndex:0] index] intValue];
}
}
return [self entryAtIndex:i];
2006-04-15 13:51:40 +00:00
}
}
- (NSArray *)filterPlaylistOnAlbum:(NSString *)album
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"album like %@",
album];
return [[self arrangedObjects] filteredArrayUsingPredicate:predicate];
}
2006-04-15 13:51:40 +00:00
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe
{
2008-02-19 23:49:51 +00:00
if (repeat == RepeatOne) {
return pe;
}
2006-04-15 13:51:40 +00:00
if (shuffle == YES)
{
2008-02-23 19:46:23 +00:00
return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)];
2006-04-15 13:51:40 +00:00
}
else
{
int i;
2008-02-23 19:46:23 +00:00
if (pe.index < 0) //Was a current entry, now removed.
2006-04-15 14:17:46 +00:00
{
2008-02-23 19:46:23 +00:00
i = -pe.index - 2;
2006-04-15 14:17:46 +00:00
}
else
{
2008-02-23 19:46:23 +00:00
i = pe.index - 1;
2006-04-15 14:17:46 +00:00
}
return [self entryAtIndex:i];
2006-04-15 13:51:40 +00:00
}
}
2006-01-29 14:57:48 +00:00
- (BOOL)next
2005-06-02 18:16:43 +00:00
{
PlaylistEntry *pe;
2006-04-15 13:51:40 +00:00
pe = [self getNextEntry:[self currentEntry]];
2005-06-02 18:16:43 +00:00
if (pe == nil)
2008-02-19 23:49:51 +00:00
return NO;
2005-06-02 18:16:43 +00:00
2006-01-20 15:22:03 +00:00
[self setCurrentEntry:pe];
2006-01-29 14:57:48 +00:00
return YES;
2005-06-02 18:16:43 +00:00
}
2006-01-29 14:57:48 +00:00
- (BOOL)prev
2005-06-02 18:16:43 +00:00
{
PlaylistEntry *pe;
2006-04-15 13:51:40 +00:00
pe = [self getPrevEntry:[self currentEntry]];
2005-06-02 18:16:43 +00:00
if (pe == nil)
2008-02-19 23:49:51 +00:00
return NO;
2005-06-02 18:16:43 +00:00
2006-01-20 15:22:03 +00:00
[self setCurrentEntry:pe];
2006-01-29 14:57:48 +00:00
return YES;
2005-06-02 18:16:43 +00:00
}
2006-04-14 20:34:14 +00:00
2006-04-15 13:51:40 +00:00
- (void)addShuffledListToFront
2005-06-02 18:16:43 +00:00
{
2006-01-20 15:22:03 +00:00
NSArray *newList = [Shuffle shuffleList:[self arrangedObjects]];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newList count])];
2005-06-02 18:16:43 +00:00
2006-04-05 17:25:51 +00:00
[shuffleList insertObjects:newList atIndexes:indexSet];
2006-04-15 13:51:40 +00:00
int i;
for (i = 0; i < [shuffleList count]; i++)
{
2008-02-23 19:46:23 +00:00
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
2006-04-15 13:51:40 +00:00
}
2005-06-02 18:16:43 +00:00
}
2006-04-15 13:51:40 +00:00
- (void)addShuffledListToBack
2005-06-02 18:16:43 +00:00
{
2006-01-20 15:22:03 +00:00
NSArray *newList = [Shuffle shuffleList:[self arrangedObjects]];
2006-04-05 17:25:51 +00:00
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange([shuffleList count], [newList count])];
2006-04-15 13:51:40 +00:00
2006-04-05 17:25:51 +00:00
[shuffleList insertObjects:newList atIndexes:indexSet];
2006-04-15 13:51:40 +00:00
int i;
for (i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++)
{
2008-02-23 19:46:23 +00:00
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
2006-04-15 13:51:40 +00:00
}
2005-06-02 18:16:43 +00:00
}
2006-01-20 15:22:03 +00:00
- (void)resetShuffleList
2005-06-02 18:16:43 +00:00
{
2006-01-20 15:22:03 +00:00
[shuffleList removeAllObjects];
2006-04-15 13:51:40 +00:00
2006-04-05 17:25:51 +00:00
[self addShuffledListToFront];
2006-04-15 13:51:40 +00:00
2008-02-23 19:46:23 +00:00
if (currentEntry && currentEntry.index >= 0)
2006-04-15 13:51:40 +00:00
{
2006-04-15 14:17:46 +00:00
[shuffleList insertObject:currentEntry atIndex:0];
[currentEntry setShuffleIndex:0];
//Need to rejigger so the current entry is at the start now...
int i;
BOOL found = NO;
2008-02-20 00:12:25 +00:00
for (i = 1; i < [shuffleList count] && !found; i++)
2006-04-15 13:51:40 +00:00
{
2008-02-20 00:12:25 +00:00
if ([shuffleList objectAtIndex:i] == currentEntry)
2006-04-15 14:17:46 +00:00
{
found = YES;
[shuffleList removeObjectAtIndex:i];
}
2008-02-20 00:12:25 +00:00
else {
2008-02-23 19:46:23 +00:00
[[shuffleList objectAtIndex:i] setShuffleIndex: i];
2008-02-20 00:12:25 +00:00
}
2006-04-15 14:17:46 +00:00
}
2006-04-15 13:51:40 +00:00
}
2005-06-02 18:16:43 +00:00
}
- (void)setCurrentEntry:(PlaylistEntry *)pe
2005-06-02 18:16:43 +00:00
{
2008-02-23 19:46:23 +00:00
currentEntry.status = kCogEntryNormal;
[currentEntry setStatusMessage:nil];
2008-02-23 19:46:23 +00:00
pe.status = kCogEntryPlaying;
[pe setStatusMessage:@"Playing..."];
2005-06-02 18:16:43 +00:00
//[tableView scrollRowToVisible:pe.index];
2005-06-02 18:16:43 +00:00
[pe retain];
[currentEntry release];
currentEntry = pe;
}
- (void)setShuffle:(BOOL)s
{
shuffle = s;
if (shuffle == YES)
2006-01-20 15:22:03 +00:00
[self resetShuffleList];
2005-06-02 18:16:43 +00:00
}
- (BOOL)shuffle
{
return shuffle;
}
- (void)setRepeat:(RepeatMode)r
2005-06-02 18:16:43 +00:00
{
NSLog(@"Repeat is now: %i", r);
2005-06-02 18:16:43 +00:00
repeat = r;
}
- (RepeatMode)repeat
2005-06-02 18:16:43 +00:00
{
return repeat;
}
- (IBAction)clear:(id)sender
{
2008-02-10 19:46:45 +00:00
[self setFilterPredicate:nil];
2007-06-05 00:33:30 +00:00
2008-02-10 19:46:45 +00:00
[self removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self arrangedObjects] count])]];
}
- (IBAction)clearFilterPredicate:(id)sender
{
[self setFilterPredicate:nil];
}
2006-04-30 15:31:57 +00:00
- (void)setFilterPredicate:(NSPredicate *)filterPredicate
{
[super setFilterPredicate:filterPredicate];
}
- (IBAction)showEntryInFinder:(id)sender
{
NSWorkspace* ws = [NSWorkspace sharedWorkspace];
if ([self selectionIndex] < 0)
return;
2008-02-20 00:44:40 +00:00
NSURL *url = [[[self selectedObjects] objectAtIndex:0] URL];
if ([url isFileURL])
[ws selectFile:[url path] inFileViewerRootedAtPath:[url path]];
}
- (IBAction)searchByArtist:(id)sender;
{
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
[spotlightWindowController searchForArtist:[entry artist]];
}
- (IBAction)searchByAlbum:(id)sender;
{
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
[spotlightWindowController searchForAlbum:[entry album]];
}
- (NSMutableArray *)queueList
{
return queueList;
}
- (IBAction)emptyQueueList:(id)sender
{
for (PlaylistEntry *queueItem in queueList)
{
2008-02-23 19:46:23 +00:00
queueItem.status = kCogEntryNormal;
[queueItem setStatusMessage:nil];
[queueItem setQueuePosition:-1];
}
[queueList removeAllObjects];
}
- (IBAction)addToQueue:(id)sender
{
for (PlaylistEntry *queueItem in [self selectedObjects])
{
2008-02-23 19:46:23 +00:00
queueItem.status = kCogEntryQueued;
[queueItem setQueuePosition: [queueList count]+1];
[queueItem setStatusMessage: [NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
[queueList addObject:queueItem];
}
}
- (IBAction)removeFromQueue:(id)sender
{
for (PlaylistEntry *queueItem in [self selectedObjects])
{
2008-02-23 19:46:23 +00:00
queueItem.status = kCogEntryNormal;
[queueItem setStatusMessage:nil];
[queueItem setQueuePosition:-1];
[queueList removeObject:queueItem];
}
int i = 1;
for (PlaylistEntry *cur in queueList)
{
[cur setQueuePosition:i++];
[cur setStatusMessage:[NSString stringWithFormat:@"Queued: %i", cur.queuePosition]];
}
}
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem
{
SEL action = [menuItem action];
if (action == @selector(removeFromQueue:))
{
for (PlaylistEntry *q in [self selectedObjects])
if (q.queuePosition > 0)
return YES;
return NO;
}
if (action == @selector(emptyQueueList:) && ([queueList count] < 1))
return NO;
return YES;
}
2005-06-02 18:16:43 +00:00
@end