This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
GrowlHub.m
90 lines (74 loc) · 2.62 KB
/
GrowlHub.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// GrowlHub.m
// ScrobblePod
//
// Created by Ben Gummer on 22/05/08.
// Copyright 2008 Ben Gummer. All rights reserved.
//
#import "GrowlHub.h"
#import "Defines.h"
static GrowlHub *sharedGrowlHub = nil;
@implementation GrowlHub
+(GrowlHub *)sharedManager {
@synchronized(self) {
if (sharedGrowlHub == nil) {
[[self alloc] init]; // assignment not done here
}
}
return sharedGrowlHub;
}
+(id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedGrowlHub == nil) {
sharedGrowlHub = [super allocWithZone:zone];
return sharedGrowlHub; // assignment and return on first allocation
}
}
return nil; //on subsequent allocation attempts return nil
}
-(id)copyWithZone:(NSZone *)zone {
return self;
}
-(id)retain {
return self;
}
- (unsigned)retainCount {
return UINT_MAX; //denotes an object that cannot be released
}
-(void)release {
//do nothing
}
-(id)autorelease {
return self;
}
-(id)init {
self = [super init];
if (self != nil) {
[GrowlApplicationBridge setGrowlDelegate:self];
}
return self;
}
-(NSDictionary *)registrationDictionaryForGrowl {
NSArray *growlNotifications = [NSArray arrayWithObjects:SP_Growl_StartedScrobbling,
SP_Growl_FinishedScrobbling,
SP_Growl_FailedScrobbling,
SP_Growl_TrackChanged,
SP_Growl_DecisionChanged,
SP_Growl_LoginComplete, nil];
return [NSDictionary dictionaryWithObjectsAndKeys:growlNotifications, GROWL_NOTIFICATIONS_ALL, growlNotifications, GROWL_NOTIFICATIONS_DEFAULT, nil];
}
-(void)postGrowlNotificationWithName:(NSString *)postName andTitle:(NSString *)postTitle andDescription:(NSString *)postDescription andImage:(NSData *)postImage andIdentifier:(NSString *)postIdentifier {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL shouldPost = NO;
if ([postName isEqualToString:SP_Growl_TrackChanged]) {
shouldPost = [defaults boolForKey:BGPref_Growl_SongChange];
} else if ([postName isEqualToString:SP_Growl_DecisionChanged]) {
shouldPost = [defaults boolForKey:BGPref_Growl_ScrobbleDecisionChanged];
} else if ([postName isEqualToString:SP_Growl_StartedScrobbling] || [postName isEqualToString:SP_Growl_FinishedScrobbling] || [postName isEqualToString:SP_Growl_FailedScrobbling]) {
shouldPost = [defaults boolForKey:BGPref_Growl_ScrobbleFail];
} else if ([postName isEqualToString:SP_Growl_LoginComplete]) {
shouldPost = YES;
}
if (shouldPost) [GrowlApplicationBridge notifyWithTitle:postTitle description:postDescription notificationName:postName iconData:postImage priority:0 isSticky:NO clickContext:nil identifier:postIdentifier];
}
@end