-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWLGrowlBridge.m
127 lines (114 loc) · 4.63 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
118
119
120
121
122
123
124
125
126
127
//
// 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";
typedef struct WLClickContext {
id context, identifier;
SEL selector;
} WLClickContext;
@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;
}
+ (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 {
// 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
clickContext:(id)clickContext
clickSelector:(SEL)clickSelector
identifier:(id)identifier {
[self notifyWithTitle:title
description:description
notificationName:notifName
iconData:nil
priority:0
isSticky:isSticky
clickContext:clickContext
clickSelector:clickSelector
identifier:identifier];
}
+ (void)notifyWithTitle:(NSString *)title
description:(NSString *)description
notificationName:(NSString *)notifName
iconData:(NSData *)iconData
priority:(signed int)priority
isSticky:(BOOL)isSticky
clickContext:(id)clickContext
clickSelector:(SEL)clickSelector
identifier:(id)identifier {
WLClickContext *c = malloc(sizeof(WLClickContext));
c->context = clickContext;
c->selector = clickSelector;
c->identifier = identifier;
// workaround: clickContext must be plist-encodable
NSNumber* contextId = [NSNumber numberWithLong:(long)c];
// 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:NO
clickContext:contextId
identifier:stringId];
}
- (void)growlNotificationWasClicked:(id)contextId {
// get context
WLClickContext *c = (WLClickContext *)[(NSNumber *)contextId longValue];
[c->context performSelector:c->selector withObject:c->identifier];
free(c);
}
- (void)growlNotificationTimedOut:(id)contextId {
// deal with the event that the notification disappear
WLClickContext *c = (WLClickContext *)[(NSNumber *)contextId longValue];
free(c);
}
@end