-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathWLGrowlBridge.m
117 lines (102 loc) · 4.52 KB
/
WLGrowlBridge.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// WLGrowlBridge.m
// Welly
//
// Created by aqua9 on 20/3/2008.
// Copyright 2008 TANG Yang. All rights reserved.
//
// Modified by boost @ 9#
// Extend for convenience.
#import "WLGrowlBridge.h"
NSString *const WLGrowlNotificationNameFileTransfer = @"File Transfer";
NSString *const WLGrowlNotificationNameEXIFInformation = @"EXIF Information";
NSString *const WLGrowlNotificationNameNewMessageReceived = @"New Message Received";
NSString *const WLGrowlClickTargetKeyName = @"ClickTarget";
NSString *const WLGrowlClickSelectorKeyName = @"ClickSelector";
NSString *const WLGrowlClickObjectKeyName = @"ClickRepresentedObject";
@implementation WLGrowlBridge
+ (void)initialize {
static WLGrowlBridge *sTYGrowlBridge = nil;
if (sTYGrowlBridge == nil) {
sTYGrowlBridge = [[WLGrowlBridge alloc] init];
[GrowlApplicationBridge setGrowlDelegate:sTYGrowlBridge];
}
}
- (NSDictionary *)registrationDictionaryForGrowl {
NSArray *notifications = [NSArray arrayWithObjects:kGrowlNotificationNameFileTransfer, kGrowlNotificationNameEXIFInformation, kGrowlNotificationNameNewMessageReceived, nil];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:notifications forKey: GROWL_NOTIFICATIONS_ALL];
[dict setObject:notifications forKey: GROWL_NOTIFICATIONS_DEFAULT];
return dict;
}
+ (BOOL)isMistEnabled {
return [GrowlApplicationBridge isMistEnabled];
}
+ (void)notifyWithTitle:(NSString *)title
description:(NSString *)description
notificationName:(NSString *)notifName {
[GrowlApplicationBridge notifyWithTitle:title
description:description
notificationName:notifName
iconData:nil
priority:0
isSticky:NO
clickContext:nil];
}
+ (void)notifyWithTitle:(NSString *)title
description:(NSString *)description
notificationName:(NSString *)notifName
isSticky:(BOOL)isSticky
identifier:(id)identifier {
if ([GrowlApplicationBridge isMistEnabled]) {
NSLog(@"isMistEnabled");
} else {
NSLog(@"no");
}
// hack identifier that must be a string
NSString *stringId = [[NSNumber numberWithLong:(long)identifier] stringValue];
[GrowlApplicationBridge notifyWithTitle:title
description:description
notificationName:notifName
iconData:nil
priority:0
isSticky:isSticky
clickContext:nil
identifier:stringId];
}
+ (void)notifyWithTitle:(NSString *)title
description:(NSString *)description
notificationName:(NSString *)notifName
isSticky:(BOOL)isSticky
clickTarget:(id)target
clickSelector:(SEL)selector
identifier:(id)identifier {
// capsulate target, selector and object.
// Note: Growl only accepts pure p-list contents as click context
// i.e. only occurs NSDictionary, NSString, NSNumber, NSArray
NSDictionary *clickContext = @{WLGrowlClickTargetKeyName:[NSNumber numberWithUnsignedLong:target], WLGrowlClickSelectorKeyName:NSStringFromSelector(selector), WLGrowlClickObjectKeyName:[NSNumber numberWithUnsignedLong:identifier]};
// hack identifier that must be a string
NSString *stringId = [[NSNumber numberWithLong:(long)identifier] stringValue];
[GrowlApplicationBridge notifyWithTitle:title
description:description
notificationName:notifName
iconData:nil
priority:0
isSticky:isSticky
clickContext:clickContext
identifier:stringId];
}
- (void)growlNotificationWasClicked:(id)contextId {
NSDictionary *context = (NSDictionary *)contextId;
// encapsulate target/selector/object
id target = [[context objectForKey:WLGrowlClickTargetKeyName] unsignedLongValue];
SEL selector = NSSelectorFromString([context objectForKey:WLGrowlClickSelectorKeyName]);
id object = [[context objectForKey:WLGrowlClickObjectKeyName] unsignedLongValue];
// perform action
[target performSelector:selector withObject:object];
}
- (void)growlNotificationTimedOut:(id)contextId {
// deal with the event that the notification disappear
// Just do nothing
}
@end