Added PlaybackEventController.
parent
4bd8f6142c
commit
e2d590c167
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// PlaybackEventController.h
|
||||
// Cog
|
||||
//
|
||||
// Created by Vincent Spader on 3/5/09.
|
||||
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Growl/GrowlApplicationBridge.h>
|
||||
|
||||
@class PlaybackController;
|
||||
@class AudioScrobbler;
|
||||
@interface PlaybackEventController : NSObject <GrowlApplicationBridgeDelegate> {
|
||||
NSOperationQueue *queue;
|
||||
|
||||
AudioScrobbler *scrobbler;
|
||||
IBOutlet PlaybackController *playbackController;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,106 @@
|
|||
//
|
||||
// PlaybackEventController.m
|
||||
// Cog
|
||||
//
|
||||
// Created by Vincent Spader on 3/5/09.
|
||||
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PlaybackEventController.h"
|
||||
|
||||
#import "PlaylistEntry.h"
|
||||
#import "AudioScrobbler.h"
|
||||
#import "PlaybackController.h"
|
||||
|
||||
@implementation PlaybackEventController
|
||||
|
||||
- (void)initDefaults
|
||||
{
|
||||
NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:YES], @"enableAudioScrobbler",
|
||||
[NSNumber numberWithBool:NO], @"automaticallyLaunchLastFM",
|
||||
nil];
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
[self initDefaults];
|
||||
|
||||
queue = [[NSOperationQueue alloc] init];
|
||||
scrobbler = [[AudioScrobbler alloc] init];
|
||||
[GrowlApplicationBridge setGrowlDelegate:self];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[queue release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidBegin:) name:CogPlaybackDidBeginNotficiation object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidPause:) name:CogPlaybackDidPauseNotficiation object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidResume:) name:CogPlaybackDidResumeNotficiation object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidStop:) name:CogPlaybackDidStopNotficiation object:nil];
|
||||
}
|
||||
|
||||
- (void)playbackDidBegin:(NSNotification *)notification
|
||||
{
|
||||
PlaylistEntry *pe = [notification object];
|
||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler start:pe];
|
||||
}
|
||||
|
||||
// Note: We don't want to send a growl notification on resume.
|
||||
[GrowlApplicationBridge notifyWithTitle:[pe title]
|
||||
description:[pe artist]
|
||||
notificationName:@"Stream Changed"
|
||||
iconData:nil
|
||||
priority:0
|
||||
isSticky:NO
|
||||
clickContext:nil];
|
||||
}
|
||||
|
||||
- (void)playbackDidPause:(NSNotification *)notification
|
||||
{
|
||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler pause];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)playbackDidResume:(NSNotification *)notification
|
||||
{
|
||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler resume];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)playbackDidStop:(NSNotification *)notification
|
||||
{
|
||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler stop];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *) registrationDictionaryForGrowl
|
||||
{
|
||||
NSArray *notifications = [NSArray arrayWithObjects:@"Stream Changed", nil];
|
||||
|
||||
return [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"Cog", GROWL_APP_NAME,
|
||||
notifications, GROWL_NOTIFICATIONS_ALL,
|
||||
notifications, GROWL_NOTIFICATIONS_DEFAULT,
|
||||
nil];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue