2008-02-19 03:39:43 +00:00
|
|
|
//
|
|
|
|
// RepeatModeTransformer.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 2/18/08.
|
|
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "RepeatTransformers.h"
|
|
|
|
#import "PlaylistController.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
@implementation RepeatModeTransformer
|
|
|
|
|
|
|
|
+ (Class)transformedValueClass { return [NSNumber class]; }
|
2008-02-19 04:02:05 +00:00
|
|
|
+ (BOOL)allowsReverseTransformation { return YES; }
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
- (id)initWithMode:(RepeatMode) r
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
repeatMode = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from RepeatMode to BOOL
|
|
|
|
- (id)transformedValue:(id)value {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
2016-06-30 05:10:29 +00:00
|
|
|
RepeatMode mode = (RepeatMode) [value integerValue];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
if (repeatMode == mode) {
|
|
|
|
return [NSNumber numberWithBool:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [NSNumber numberWithBool:NO];
|
|
|
|
}
|
|
|
|
|
2008-02-19 04:02:05 +00:00
|
|
|
- (id)reverseTransformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
BOOL enabled = [value boolValue];
|
|
|
|
if (enabled) {
|
|
|
|
return [NSNumber numberWithInt:repeatMode];
|
|
|
|
}
|
|
|
|
else if(repeatMode == RepeatNone) {
|
|
|
|
return [NSNumber numberWithInt:RepeatAll];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return [NSNumber numberWithInt:RepeatNone];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RepeatModeImageTransformer
|
|
|
|
|
|
|
|
+ (Class)transformedValueClass { return [NSImage class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return NO; }
|
|
|
|
|
|
|
|
// Convert from string to RepeatMode
|
|
|
|
- (id)transformedValue:(id)value {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
RepeatMode mode = [value integerValue];
|
|
|
|
|
|
|
|
if (mode == RepeatNone) {
|
2013-10-11 14:16:47 +00:00
|
|
|
return [NSImage imageNamed:@"repeatModeOffTemplate"];
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
else if (mode == RepeatOne) {
|
2013-10-11 14:16:47 +00:00
|
|
|
return [NSImage imageNamed:@"repeatModeOneTemplate"];
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
2008-02-19 04:02:05 +00:00
|
|
|
else if (mode == RepeatAlbum) {
|
2013-10-11 14:16:47 +00:00
|
|
|
return [NSImage imageNamed:@"repeatModeAlbumTemplate"];
|
2008-02-19 04:02:05 +00:00
|
|
|
}
|
2008-02-19 03:39:43 +00:00
|
|
|
else if (mode == RepeatAll) {
|
2013-10-11 14:16:47 +00:00
|
|
|
return [NSImage imageNamed:@"repeatModeAllTemplate"];
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|