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 {
|
2022-02-07 05:49:27 +00:00
|
|
|
RepeatMode repeatMode;
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSNumber class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return YES;
|
|
|
|
}
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (id)initWithMode:(RepeatMode)r {
|
2022-02-07 05:49:27 +00:00
|
|
|
self = [super init];
|
|
|
|
if(self) {
|
|
|
|
repeatMode = r;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return self;
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from RepeatMode to BOOL
|
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
RepeatMode mode = (RepeatMode)[value integerValue];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return @(repeatMode == mode);
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 04:02:05 +00:00
|
|
|
- (id)reverseTransformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSImage class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return NO;
|
|
|
|
}
|
2008-02-19 03:39:43 +00:00
|
|
|
|
|
|
|
// Convert from string to RepeatMode
|
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
DLog(@"Transforming value: %@", value);
|
|
|
|
|
|
|
|
if(value == nil) return nil;
|
|
|
|
|
|
|
|
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
|