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"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
@implementation RepeatModeTransformer {
|
|
|
|
RepeatMode repeatMode;
|
|
|
|
}
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
+ (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
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (id)initWithMode:(RepeatMode)r {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
repeatMode = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from RepeatMode to BOOL
|
|
|
|
- (id)transformedValue:(id)value {
|
2021-01-30 23:14:08 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
if (value == nil) return nil;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
RepeatMode mode = (RepeatMode) [value integerValue];
|
|
|
|
|
|
|
|
return @(repeatMode == mode);
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 04:02:05 +00:00
|
|
|
- (id)reverseTransformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
BOOL enabled = [value boolValue];
|
|
|
|
if (enabled) {
|
|
|
|
return @(repeatMode);
|
|
|
|
} else if (repeatMode == RepeatModeNoRepeat) {
|
|
|
|
return @(RepeatModeRepeatAll);
|
|
|
|
} else {
|
|
|
|
return @(RepeatModeNoRepeat);
|
|
|
|
}
|
2008-02-19 04:02:05 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2021-01-30 23:14:08 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
if (value == nil) return nil;
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
RepeatMode mode = (RepeatMode) [value integerValue];
|
|
|
|
|
|
|
|
if (mode == RepeatModeNoRepeat) {
|
|
|
|
return [NSImage imageNamed:@"repeatModeOffTemplate"];
|
|
|
|
}
|
|
|
|
else if (mode == RepeatModeRepeatOne) {
|
|
|
|
return [NSImage imageNamed:@"repeatModeOneTemplate"];
|
|
|
|
}
|
|
|
|
else if (mode == RepeatModeRepeatAlbum) {
|
|
|
|
return [NSImage imageNamed:@"repeatModeAlbumTemplate"];
|
|
|
|
}
|
|
|
|
else if (mode == RepeatModeRepeatAll) {
|
|
|
|
return [NSImage imageNamed:@"repeatModeAllTemplate"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|