2009-02-28 20:54:36 -03:00
|
|
|
//
|
|
|
|
// DockIconController.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 2/28/09.
|
|
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DockIconController.h"
|
|
|
|
#import <CogAudio/Status.h>
|
|
|
|
|
|
|
|
@implementation DockIconController
|
|
|
|
|
|
|
|
static NSString *DockIconPlaybackStatusObservationContext = @"DockIconPlaybackStatusObservationContext";
|
|
|
|
|
|
|
|
- (void)startObserving
|
|
|
|
{
|
|
|
|
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:DockIconPlaybackStatusObservationContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopObserving
|
|
|
|
{
|
|
|
|
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
|
|
|
{
|
|
|
|
if ([DockIconPlaybackStatusObservationContext isEqual:context])
|
|
|
|
{
|
|
|
|
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
|
|
|
|
|
|
|
NSImage *badgeImage = nil;
|
|
|
|
|
|
|
|
if (playbackStatus == kCogStatusPlaying) {
|
2013-10-11 11:16:47 -03:00
|
|
|
badgeImage = [NSImage imageNamed:@"playDockBadge"];
|
2009-02-28 20:54:36 -03:00
|
|
|
}
|
|
|
|
else if (playbackStatus == kCogStatusPaused) {
|
2013-10-11 11:16:47 -03:00
|
|
|
badgeImage = [NSImage imageNamed:@"pauseDockBadge"];
|
2009-02-28 20:54:36 -03:00
|
|
|
}
|
|
|
|
else {
|
2013-10-11 11:16:47 -03:00
|
|
|
badgeImage = [NSImage imageNamed:@"stopDockBadge"];
|
2009-02-28 20:54:36 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
NSSize badgeSize = [badgeImage size];
|
|
|
|
|
|
|
|
NSImage *newDockImage = [dockImage copy];
|
|
|
|
[newDockImage lockFocus];
|
2013-10-11 11:16:47 -03:00
|
|
|
[badgeImage drawInRect:NSMakeRect(0, 0, 128, 128) fromRect:NSMakeRect(0, 0, badgeSize.width, badgeSize.height) operation:NSCompositeSourceOver fraction:1.0];
|
2009-02-28 20:54:36 -03:00
|
|
|
[newDockImage unlockFocus];
|
|
|
|
[NSApp setApplicationIconImage:newDockImage];
|
2009-03-01 03:28:37 -03:00
|
|
|
[newDockImage release];
|
2009-02-28 20:54:36 -03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2013-10-11 11:16:47 -03:00
|
|
|
dockImage = [[NSImage imageNamed:@"icon_blank"] copy];
|
2009-02-28 20:54:36 -03:00
|
|
|
[self startObserving];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self stopObserving];
|
|
|
|
[dockImage release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|