Split status up into bunches of properties and made it a readonly property.
parent
6c5ecf3701
commit
3cdca94207
|
@ -493,7 +493,7 @@
|
|||
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
|
||||
PlaylistEntry *pe;
|
||||
|
||||
if (curEntry.status == kCogEntryStoppingAfterCurrent)
|
||||
if (curEntry.stopAfter)
|
||||
pe = nil;
|
||||
else
|
||||
pe = [playlistController getNextEntry:curEntry];
|
||||
|
|
|
@ -391,16 +391,14 @@
|
|||
|
||||
pe = [queueList objectAtIndex:0];
|
||||
[queueList removeObjectAtIndex:0];
|
||||
pe.status = kCogEntryNormal;
|
||||
[pe setStatusMessage:nil];
|
||||
pe.queued = NO;
|
||||
[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]];
|
||||
[queueItem setQueuePosition: i];
|
||||
}
|
||||
|
||||
return pe;
|
||||
|
@ -559,11 +557,9 @@
|
|||
|
||||
- (void)setCurrentEntry:(PlaylistEntry *)pe
|
||||
{
|
||||
currentEntry.status = kCogEntryNormal;
|
||||
[currentEntry setStatusMessage:nil];
|
||||
currentEntry.current = NO;
|
||||
|
||||
pe.status = kCogEntryPlaying;
|
||||
[pe setStatusMessage:@"Playing..."];
|
||||
pe.current = YES;
|
||||
|
||||
//[tableView scrollRowToVisible:pe.index];
|
||||
|
||||
|
@ -641,8 +637,7 @@
|
|||
{
|
||||
for (PlaylistEntry *queueItem in queueList)
|
||||
{
|
||||
queueItem.status = kCogEntryNormal;
|
||||
[queueItem setStatusMessage:nil];
|
||||
queueItem.queued = NO;
|
||||
[queueItem setQueuePosition:-1];
|
||||
}
|
||||
|
||||
|
@ -654,9 +649,8 @@
|
|||
{
|
||||
for (PlaylistEntry *queueItem in [self selectedObjects])
|
||||
{
|
||||
queueItem.status = kCogEntryQueued;
|
||||
[queueItem setQueuePosition: [queueList count]+1];
|
||||
[queueItem setStatusMessage: [NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
|
||||
queueItem.queued = YES;
|
||||
[queueItem setQueuePosition: [queueList count]];
|
||||
|
||||
[queueList addObject:queueItem];
|
||||
}
|
||||
|
@ -670,26 +664,21 @@
|
|||
|
||||
for (PlaylistEntry *queueItem in [self selectedObjects])
|
||||
{
|
||||
queueItem.status = kCogEntryNormal;
|
||||
[queueItem setStatusMessage:nil];
|
||||
queueItem.queued = NO;
|
||||
[queueItem setQueuePosition:-1];
|
||||
[queueList removeObject:queueItem];
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
int i = 0;
|
||||
for (PlaylistEntry *cur in queueList)
|
||||
{
|
||||
[cur setQueuePosition:i++];
|
||||
[cur setStatusMessage:[NSString stringWithFormat:@"Queued: %i", cur.queuePosition]];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)stopAfterCurrent:(id)sender
|
||||
{
|
||||
if (currentEntry.status != kCogEntryStoppingAfterCurrent)
|
||||
currentEntry.status = kCogEntryStoppingAfterCurrent;
|
||||
else
|
||||
currentEntry.status = kCogEntryPlaying;
|
||||
currentEntry.stopAfter = !currentEntry.stopAfter;
|
||||
}
|
||||
|
||||
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
||||
|
@ -699,7 +688,7 @@
|
|||
if (action == @selector(removeFromQueue:))
|
||||
{
|
||||
for (PlaylistEntry *q in [self selectedObjects])
|
||||
if (q.queuePosition > 0)
|
||||
if (q.queuePosition >= 0)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
|
@ -708,7 +697,7 @@
|
|||
if (action == @selector(emptyQueueList:) && ([queueList count] < 1))
|
||||
return NO;
|
||||
|
||||
if (action == @selector(stopAfterCurrent:) && (currentEntry.status == kCogEntryNormal))
|
||||
if (action == @selector(stopAfterCurrent:) && !currentEntry.stopAfter)
|
||||
return NO;
|
||||
|
||||
// if nothing is selected, gray out these
|
||||
|
|
|
@ -8,22 +8,21 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
typedef enum {
|
||||
kCogEntryNormal = 0,
|
||||
kCogEntryPlaying,
|
||||
kCogEntryError,
|
||||
kCogEntryQueued,
|
||||
kCogEntryRemoved,
|
||||
kCogEntryStoppingAfterCurrent,
|
||||
} PlaylistEntryStatus;
|
||||
|
||||
@interface PlaylistEntry : NSObject {
|
||||
int index;
|
||||
int shuffleIndex;
|
||||
PlaylistEntryStatus status;
|
||||
NSString *statusMessage;
|
||||
|
||||
BOOL current;
|
||||
BOOL removed;
|
||||
|
||||
BOOL stopAfter;
|
||||
|
||||
BOOL queued;
|
||||
int queuePosition;
|
||||
|
||||
BOOL error;
|
||||
NSString *errorMessage;
|
||||
|
||||
NSURL *URL;
|
||||
|
||||
NSString *artist;
|
||||
|
@ -39,6 +38,8 @@ typedef enum {
|
|||
int bitsPerSample;
|
||||
float sampleRate;
|
||||
|
||||
NSString *endian;
|
||||
|
||||
BOOL seekable;
|
||||
}
|
||||
|
||||
|
@ -46,9 +47,12 @@ typedef enum {
|
|||
+ (NSSet *)keyPathsForValuesAffectingLength;
|
||||
+ (NSSet *)keyPathsForValuesAffectingPath;
|
||||
+ (NSSet *)keyPathsForValuesAffectingFilename;
|
||||
+ (NSSet *)keyPathsForValuesAffectingStatus;
|
||||
+ (NSSet *)keyPathsForValuesAffectingStatusMessage;
|
||||
|
||||
- (void)readMetadataThread;
|
||||
- (void)setProperties:(NSDictionary *)properties;
|
||||
- (void)readPropertiesThread;
|
||||
- (void)readMetadataThread;
|
||||
|
||||
@property(readonly) NSString *display;
|
||||
@property(retain, readonly) NSNumber *length;
|
||||
|
@ -57,9 +61,21 @@ typedef enum {
|
|||
|
||||
@property int index;
|
||||
@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 BOOL error;
|
||||
@property(retain) NSString *errorMessage;
|
||||
|
||||
@property(retain) NSURL *URL;
|
||||
|
||||
@property(retain) NSString *artist;
|
||||
|
@ -75,6 +91,8 @@ typedef enum {
|
|||
@property int bitsPerSample;
|
||||
@property float sampleRate;
|
||||
|
||||
@property(retain) NSString *endian;
|
||||
|
||||
@property BOOL seekable;
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,10 +14,18 @@
|
|||
|
||||
@synthesize index;
|
||||
@synthesize shuffleIndex;
|
||||
@synthesize status;
|
||||
@synthesize statusMessage;
|
||||
|
||||
@synthesize current;
|
||||
@synthesize removed;
|
||||
|
||||
@synthesize stopAfter;
|
||||
|
||||
@synthesize queued;
|
||||
@synthesize queuePosition;
|
||||
|
||||
@synthesize error;
|
||||
@synthesize errorMessage;
|
||||
|
||||
@synthesize URL;
|
||||
|
||||
@synthesize artist;
|
||||
|
@ -32,6 +40,8 @@
|
|||
@synthesize bitsPerSample;
|
||||
@synthesize sampleRate;
|
||||
|
||||
@synthesize endian;
|
||||
|
||||
@synthesize seekable;
|
||||
|
||||
// The following read-only keys depend on the values of other properties
|
||||
|
@ -56,17 +66,34 @@
|
|||
return [NSSet setWithObject:@"URL"];
|
||||
}
|
||||
|
||||
- (void)readPropertiesThread
|
||||
+ (NSSet *)keyPathsForValuesAffectingStatus
|
||||
{
|
||||
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
|
||||
if (!properties) {
|
||||
self.status = kCogEntryError;
|
||||
self.statusMessage = @"Failed to read properties!";
|
||||
return [NSSet setWithObjects:@"current",@"queued", @"error", nil];
|
||||
}
|
||||
|
||||
+ (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;
|
||||
}
|
||||
|
||||
[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
|
||||
|
@ -121,4 +148,50 @@
|
|||
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
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
NSImage *playImage;
|
||||
NSImage *queueImage;
|
||||
NSImage *errorImage;
|
||||
NSImage *stopAfterCurrentImage;
|
||||
NSImage *stopAfterImage;
|
||||
}
|
||||
|
||||
@property(retain) NSImage *playImage;
|
||||
@property(retain) NSImage *queueImage;
|
||||
@property(retain) NSImage *errorImage;
|
||||
@property(retain) NSImage *stopAfterCurrentImage;
|
||||
@property(retain) NSImage *stopAfterImage;
|
||||
@end
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
@synthesize playImage;
|
||||
@synthesize queueImage;
|
||||
@synthesize errorImage;
|
||||
@synthesize stopAfterCurrentImage;
|
||||
@synthesize stopAfterImage;
|
||||
|
||||
+ (Class)transformedValueClass { return [NSImage class]; }
|
||||
+ (BOOL)allowsReverseTransformation { return NO; }
|
||||
|
@ -28,7 +28,7 @@
|
|||
self.playImage = [NSImage imageNamed:@"play"];
|
||||
self.queueImage = [NSImage imageNamed:@"NSAddTemplate"];
|
||||
self.errorImage = [NSImage imageNamed:@"NSStopProgressTemplate"];
|
||||
self.stopAfterCurrentImage = [NSImage imageNamed:@"stop_current"];
|
||||
self.stopAfterImage = [NSImage imageNamed:@"stop_current"];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -38,18 +38,19 @@
|
|||
- (id)transformedValue:(id)value {
|
||||
if (value == nil) return nil;
|
||||
|
||||
PlaylistEntryStatus status = [value integerValue];
|
||||
if (status == kCogEntryPlaying) {
|
||||
if ([value isEqualToString:@"playing"])
|
||||
{
|
||||
return self.playImage;
|
||||
}
|
||||
else if (status == kCogEntryQueued) {
|
||||
else if ([value isEqualToString:@"queued"])
|
||||
{
|
||||
return self.queueImage;
|
||||
}
|
||||
else if (status == kCogEntryError) {
|
||||
else if ([value isEqualToString:@"error"]) {
|
||||
return self.errorImage;
|
||||
}
|
||||
else if (status == kCogEntryStoppingAfterCurrent) {
|
||||
return self.stopAfterCurrentImage;
|
||||
else if ([value isEqualToString:@"stopAfter"]) {
|
||||
return self.stopAfterImage;
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
|
Loading…
Reference in New Issue