2009-02-28 21:13:06 +00:00
|
|
|
//
|
|
|
|
// PlaybackButtons.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 2/28/09.
|
|
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlaybackButtons.h"
|
|
|
|
#import "PlaybackController.h"
|
|
|
|
|
|
|
|
#import <CogAudio/Status.h>
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2009-02-28 21:13:06 +00:00
|
|
|
@implementation PlaybackButtons
|
|
|
|
|
|
|
|
static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackButtonsPlaybackStatusObservationContext";
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)dealloc {
|
2009-02-28 21:13:06 +00:00
|
|
|
[self stopObserving];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)awakeFromNib {
|
2009-02-28 21:13:06 +00:00
|
|
|
[self startObserving];
|
2022-02-10 09:18:34 +00:00
|
|
|
|
|
|
|
if(@available(macOS 11.0, *)) {
|
|
|
|
playImage = [NSImage imageWithSystemSymbolName:@"play.fill" accessibilityDescription:NSLocalizedString(@"PlayButtonTooltip", @"")];
|
|
|
|
pauseImage = [NSImage imageWithSystemSymbolName:@"pause.fill" accessibilityDescription:NSLocalizedString(@"PauseButtonTooltip", @"")];
|
|
|
|
stopImage = [NSImage imageWithSystemSymbolName:@"stop.fill" accessibilityDescription:NSLocalizedString(@"StopButtonTooltip", @"")];
|
|
|
|
prevImage = [NSImage imageWithSystemSymbolName:@"backward.fill" accessibilityDescription:NSLocalizedString(@"PrevButtonTooltip", @"")];
|
|
|
|
nextImage = [NSImage imageWithSystemSymbolName:@"forward.fill" accessibilityDescription:NSLocalizedString(@"NextButtonTooltip", @"")];
|
|
|
|
} else {
|
|
|
|
playImage = [NSImage imageNamed:@"playTemplate"];
|
|
|
|
pauseImage = [NSImage imageNamed:@"pauseTemplate"];
|
|
|
|
stopImage = [NSImage imageNamed:@"stopTemplate"];
|
|
|
|
prevImage = [NSImage imageNamed:@"previousTemplate"];
|
|
|
|
nextImage = [NSImage imageNamed:@"nextTemplate"];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setImage:prevImage forSegment:0];
|
|
|
|
[self setImage:playImage forSegment:1];
|
|
|
|
|
|
|
|
BOOL segmentEnabled = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableStopButton"];
|
|
|
|
if(segmentEnabled) {
|
|
|
|
[self setSegmentCount:4];
|
|
|
|
[self setImage:stopImage forSegment:2];
|
|
|
|
[self setImage:nextImage forSegment:3];
|
|
|
|
if(@available(macOS 10.13, *)) {
|
|
|
|
[self setToolTip:NSLocalizedString(@"StopButtonTooltip", @"") forSegment:2];
|
|
|
|
[self setToolTip:NSLocalizedString(@"NextButtonTooltip", @"") forSegment:3];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[self setSegmentCount:3];
|
|
|
|
[self setImage:nextImage forSegment:2];
|
|
|
|
if(@available(macOS 10.13, *)) {
|
|
|
|
[self setToolTip:NSLocalizedString(@"NextButtonTooltip", @"") forSegment:2];
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)startObserving {
|
|
|
|
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void *_Nullable)(PlaybackButtonsPlaybackStatusObservationContext)];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.enableStopButton" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void *_Nullable)(PlaybackButtonsPlaybackStatusObservationContext)];
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)stopObserving {
|
2009-02-28 21:13:06 +00:00
|
|
|
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.enableStopButton"];
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
|
|
if([PlaybackButtonsPlaybackStatusObservationContext isEqual:(__bridge id)(context)]) {
|
|
|
|
if([keyPath isEqualToString:@"playbackStatus"]) {
|
|
|
|
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
|
|
|
|
|
|
|
NSImage *image = nil;
|
|
|
|
|
|
|
|
if(playbackStatus == CogStatusPlaying) {
|
2022-02-10 09:18:34 +00:00
|
|
|
image = pauseImage;
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-02-10 09:18:34 +00:00
|
|
|
image = playImage;
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self setImage:image forSegment:1];
|
|
|
|
} else if([keyPath isEqualToString:@"values.enableStopButton"]) {
|
|
|
|
BOOL segmentEnabled = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableStopButton"];
|
|
|
|
if(segmentEnabled) {
|
|
|
|
[self setSegmentCount:4];
|
2022-02-10 09:18:34 +00:00
|
|
|
[self setImage:stopImage forSegment:2];
|
|
|
|
[self setImage:nextImage forSegment:3];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(@available(macOS 10.13, *)) {
|
|
|
|
[self setToolTip:NSLocalizedString(@"StopButtonTooltip", @"") forSegment:2];
|
|
|
|
[self setToolTip:NSLocalizedString(@"NextButtonTooltip", @"") forSegment:3];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[self setSegmentCount:3];
|
2022-02-10 09:18:34 +00:00
|
|
|
[self setImage:nextImage forSegment:2];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(@available(macOS 10.13, *)) {
|
|
|
|
[self setToolTip:NSLocalizedString(@"NextButtonTooltip", @"") forSegment:2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-02-28 21:13:06 +00:00
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Mouse down!");
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
int clickedSegment = (int)[self selectedSegment];
|
|
|
|
int segmentCount = (int)[self segmentCount];
|
|
|
|
if(segmentCount == 3 && clickedSegment == 2)
|
|
|
|
clickedSegment = 3;
|
|
|
|
|
|
|
|
if(clickedSegment == 0) // Previous
|
2009-02-28 21:13:06 +00:00
|
|
|
{
|
|
|
|
[playbackController prev:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(clickedSegment == 1) // Play
|
2009-02-28 21:13:06 +00:00
|
|
|
{
|
|
|
|
[playbackController playPauseResume:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(clickedSegment == 2) // Stop
|
|
|
|
{
|
|
|
|
[playbackController stop:self];
|
|
|
|
} else if(clickedSegment == 3) // Next
|
2009-02-28 21:13:06 +00:00
|
|
|
{
|
|
|
|
[playbackController next:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2009-02-28 21:13:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2009-02-28 21:13:06 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|