Split status up into bunches of properties and made it a readonly property.

CQTexperiment
vspader 2008-03-01 03:29:21 +00:00
parent 6c5ecf3701
commit 3cdca94207
6 changed files with 138 additions and 57 deletions

View File

@ -493,7 +493,7 @@
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo; PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
PlaylistEntry *pe; PlaylistEntry *pe;
if (curEntry.status == kCogEntryStoppingAfterCurrent) if (curEntry.stopAfter)
pe = nil; pe = nil;
else else
pe = [playlistController getNextEntry:curEntry]; pe = [playlistController getNextEntry:curEntry];

View File

@ -391,16 +391,14 @@
pe = [queueList objectAtIndex:0]; pe = [queueList objectAtIndex:0];
[queueList removeObjectAtIndex:0]; [queueList removeObjectAtIndex:0];
pe.status = kCogEntryNormal; pe.queued = NO;
[pe setStatusMessage:nil];
[pe setQueuePosition:-1]; [pe setQueuePosition:-1];
int i; int i;
for (i = 0; i < [queueList count]; i++) for (i = 0; i < [queueList count]; i++)
{ {
PlaylistEntry *queueItem = [queueList objectAtIndex:i]; PlaylistEntry *queueItem = [queueList objectAtIndex:i];
[queueItem setQueuePosition: i+1]; [queueItem setQueuePosition: i];
[queueItem setStatusMessage:[NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
} }
return pe; return pe;
@ -559,11 +557,9 @@
- (void)setCurrentEntry:(PlaylistEntry *)pe - (void)setCurrentEntry:(PlaylistEntry *)pe
{ {
currentEntry.status = kCogEntryNormal; currentEntry.current = NO;
[currentEntry setStatusMessage:nil];
pe.status = kCogEntryPlaying; pe.current = YES;
[pe setStatusMessage:@"Playing..."];
//[tableView scrollRowToVisible:pe.index]; //[tableView scrollRowToVisible:pe.index];
@ -641,8 +637,7 @@
{ {
for (PlaylistEntry *queueItem in queueList) for (PlaylistEntry *queueItem in queueList)
{ {
queueItem.status = kCogEntryNormal; queueItem.queued = NO;
[queueItem setStatusMessage:nil];
[queueItem setQueuePosition:-1]; [queueItem setQueuePosition:-1];
} }
@ -654,9 +649,8 @@
{ {
for (PlaylistEntry *queueItem in [self selectedObjects]) for (PlaylistEntry *queueItem in [self selectedObjects])
{ {
queueItem.status = kCogEntryQueued; queueItem.queued = YES;
[queueItem setQueuePosition: [queueList count]+1]; [queueItem setQueuePosition: [queueList count]];
[queueItem setStatusMessage: [NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
[queueList addObject:queueItem]; [queueList addObject:queueItem];
} }
@ -670,26 +664,21 @@
for (PlaylistEntry *queueItem in [self selectedObjects]) for (PlaylistEntry *queueItem in [self selectedObjects])
{ {
queueItem.status = kCogEntryNormal; queueItem.queued = NO;
[queueItem setStatusMessage:nil];
[queueItem setQueuePosition:-1]; [queueItem setQueuePosition:-1];
[queueList removeObject:queueItem]; [queueList removeObject:queueItem];
} }
int i = 1; int i = 0;
for (PlaylistEntry *cur in queueList) for (PlaylistEntry *cur in queueList)
{ {
[cur setQueuePosition:i++]; [cur setQueuePosition:i++];
[cur setStatusMessage:[NSString stringWithFormat:@"Queued: %i", cur.queuePosition]];
} }
} }
- (IBAction)stopAfterCurrent:(id)sender - (IBAction)stopAfterCurrent:(id)sender
{ {
if (currentEntry.status != kCogEntryStoppingAfterCurrent) currentEntry.stopAfter = !currentEntry.stopAfter;
currentEntry.status = kCogEntryStoppingAfterCurrent;
else
currentEntry.status = kCogEntryPlaying;
} }
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem -(BOOL)validateMenuItem:(NSMenuItem*)menuItem
@ -699,7 +688,7 @@
if (action == @selector(removeFromQueue:)) if (action == @selector(removeFromQueue:))
{ {
for (PlaylistEntry *q in [self selectedObjects]) for (PlaylistEntry *q in [self selectedObjects])
if (q.queuePosition > 0) if (q.queuePosition >= 0)
return YES; return YES;
return NO; return NO;
@ -708,7 +697,7 @@
if (action == @selector(emptyQueueList:) && ([queueList count] < 1)) if (action == @selector(emptyQueueList:) && ([queueList count] < 1))
return NO; return NO;
if (action == @selector(stopAfterCurrent:) && (currentEntry.status == kCogEntryNormal)) if (action == @selector(stopAfterCurrent:) && !currentEntry.stopAfter)
return NO; return NO;
// if nothing is selected, gray out these // if nothing is selected, gray out these

View File

@ -8,22 +8,21 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
typedef enum {
kCogEntryNormal = 0,
kCogEntryPlaying,
kCogEntryError,
kCogEntryQueued,
kCogEntryRemoved,
kCogEntryStoppingAfterCurrent,
} PlaylistEntryStatus;
@interface PlaylistEntry : NSObject { @interface PlaylistEntry : NSObject {
int index; int index;
int shuffleIndex; int shuffleIndex;
PlaylistEntryStatus status;
NSString *statusMessage; BOOL current;
BOOL removed;
BOOL stopAfter;
BOOL queued;
int queuePosition; int queuePosition;
BOOL error;
NSString *errorMessage;
NSURL *URL; NSURL *URL;
NSString *artist; NSString *artist;
@ -39,6 +38,8 @@ typedef enum {
int bitsPerSample; int bitsPerSample;
float sampleRate; float sampleRate;
NSString *endian;
BOOL seekable; BOOL seekable;
} }
@ -46,9 +47,12 @@ typedef enum {
+ (NSSet *)keyPathsForValuesAffectingLength; + (NSSet *)keyPathsForValuesAffectingLength;
+ (NSSet *)keyPathsForValuesAffectingPath; + (NSSet *)keyPathsForValuesAffectingPath;
+ (NSSet *)keyPathsForValuesAffectingFilename; + (NSSet *)keyPathsForValuesAffectingFilename;
+ (NSSet *)keyPathsForValuesAffectingStatus;
+ (NSSet *)keyPathsForValuesAffectingStatusMessage;
- (void)readMetadataThread; - (void)setProperties:(NSDictionary *)properties;
- (void)readPropertiesThread; - (void)readPropertiesThread;
- (void)readMetadataThread;
@property(readonly) NSString *display; @property(readonly) NSString *display;
@property(retain, readonly) NSNumber *length; @property(retain, readonly) NSNumber *length;
@ -57,9 +61,21 @@ typedef enum {
@property int index; @property int index;
@property int shuffleIndex; @property int shuffleIndex;
@property PlaylistEntryStatus status;
@property(retain) NSString *statusMessage; @property(readonly) NSString *status;
@property(readonly) NSString *statusMessage;
@property BOOL current;
@property BOOL removed;
@property BOOL stopAfter;
@property BOOL queued;
@property int queuePosition; @property int queuePosition;
@property BOOL error;
@property(retain) NSString *errorMessage;
@property(retain) NSURL *URL; @property(retain) NSURL *URL;
@property(retain) NSString *artist; @property(retain) NSString *artist;
@ -75,6 +91,8 @@ typedef enum {
@property int bitsPerSample; @property int bitsPerSample;
@property float sampleRate; @property float sampleRate;
@property(retain) NSString *endian;
@property BOOL seekable; @property BOOL seekable;
@end @end

View File

@ -14,10 +14,18 @@
@synthesize index; @synthesize index;
@synthesize shuffleIndex; @synthesize shuffleIndex;
@synthesize status;
@synthesize statusMessage; @synthesize current;
@synthesize removed;
@synthesize stopAfter;
@synthesize queued;
@synthesize queuePosition; @synthesize queuePosition;
@synthesize error;
@synthesize errorMessage;
@synthesize URL; @synthesize URL;
@synthesize artist; @synthesize artist;
@ -32,6 +40,8 @@
@synthesize bitsPerSample; @synthesize bitsPerSample;
@synthesize sampleRate; @synthesize sampleRate;
@synthesize endian;
@synthesize seekable; @synthesize seekable;
// The following read-only keys depend on the values of other properties // The following read-only keys depend on the values of other properties
@ -56,17 +66,34 @@
return [NSSet setWithObject:@"URL"]; return [NSSet setWithObject:@"URL"];
} }
- (void)readPropertiesThread + (NSSet *)keyPathsForValuesAffectingStatus
{ {
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL]; return [NSSet setWithObjects:@"current",@"queued", @"error", nil];
if (!properties) { }
self.status = kCogEntryError;
self.statusMessage = @"Failed to read properties!"; + (NSSet *)keyPathsForValuesAffectingStatusMessage
{
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", nil];
}
- (void)setProperties:(NSDictionary *)properties
{
if (properties == nil)
{
self.error = YES;
self.errorMessage = @"Unable to retrieve properties.";
return; return;
} }
[self performSelectorOnMainThread:@selector(setValuesForKeysWithDictionary:) withObject:properties waitUntilDone:YES]; [self setValuesForKeysWithDictionary:properties];
}
- (void)readPropertiesThread
{
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
} }
- (void)readMetadataThread - (void)readMetadataThread
@ -121,4 +148,50 @@
return [[self.URL path] lastPathComponent]; return [[self.URL path] lastPathComponent];
} }
@dynamic status;
- (NSString *)status
{
if (self.stopAfter)
{
return @"stopAfter";
}
else if (self.current)
{
return @"playing";
}
else if (self.queued)
{
return @"queued";
}
else if (self.error)
{
return @"error";
}
return nil;
}
@dynamic statusMessage;
- (NSString *)statusMessage
{
if (self.stopAfter)
{
return @"Stopping once finished...";
}
else if (self.current)
{
return @"Playing...";
}
else if (self.queued)
{
return [NSString stringWithFormat:@"Queued: %i", self.queuePosition + 1];
}
else if (self.error)
{
return errorMessage;
}
return nil;
}
@end @end

View File

@ -13,11 +13,11 @@
NSImage *playImage; NSImage *playImage;
NSImage *queueImage; NSImage *queueImage;
NSImage *errorImage; NSImage *errorImage;
NSImage *stopAfterCurrentImage; NSImage *stopAfterImage;
} }
@property(retain) NSImage *playImage; @property(retain) NSImage *playImage;
@property(retain) NSImage *queueImage; @property(retain) NSImage *queueImage;
@property(retain) NSImage *errorImage; @property(retain) NSImage *errorImage;
@property(retain) NSImage *stopAfterCurrentImage; @property(retain) NSImage *stopAfterImage;
@end @end

View File

@ -15,7 +15,7 @@
@synthesize playImage; @synthesize playImage;
@synthesize queueImage; @synthesize queueImage;
@synthesize errorImage; @synthesize errorImage;
@synthesize stopAfterCurrentImage; @synthesize stopAfterImage;
+ (Class)transformedValueClass { return [NSImage class]; } + (Class)transformedValueClass { return [NSImage class]; }
+ (BOOL)allowsReverseTransformation { return NO; } + (BOOL)allowsReverseTransformation { return NO; }
@ -28,7 +28,7 @@
self.playImage = [NSImage imageNamed:@"play"]; self.playImage = [NSImage imageNamed:@"play"];
self.queueImage = [NSImage imageNamed:@"NSAddTemplate"]; self.queueImage = [NSImage imageNamed:@"NSAddTemplate"];
self.errorImage = [NSImage imageNamed:@"NSStopProgressTemplate"]; self.errorImage = [NSImage imageNamed:@"NSStopProgressTemplate"];
self.stopAfterCurrentImage = [NSImage imageNamed:@"stop_current"]; self.stopAfterImage = [NSImage imageNamed:@"stop_current"];
} }
return self; return self;
@ -38,18 +38,19 @@
- (id)transformedValue:(id)value { - (id)transformedValue:(id)value {
if (value == nil) return nil; if (value == nil) return nil;
PlaylistEntryStatus status = [value integerValue]; if ([value isEqualToString:@"playing"])
if (status == kCogEntryPlaying) { {
return self.playImage; return self.playImage;
} }
else if (status == kCogEntryQueued) { else if ([value isEqualToString:@"queued"])
{
return self.queueImage; return self.queueImage;
} }
else if (status == kCogEntryError) { else if ([value isEqualToString:@"error"]) {
return self.errorImage; return self.errorImage;
} }
else if (status == kCogEntryStoppingAfterCurrent) { else if ([value isEqualToString:@"stopAfter"]) {
return self.stopAfterCurrentImage; return self.stopAfterImage;
} }
return nil; return nil;