|
boredzo@1385
|
1 |
//
|
|
boredzo@2501
|
2 |
// GrowlNotificationTicket.m
|
|
boredzo@1385
|
3 |
// Growl
|
|
boredzo@1385
|
4 |
//
|
|
boredzo@1385
|
5 |
// Created by Karl Adam on 01.10.05.
|
|
ingmarstein@3040
|
6 |
// Copyright 2005-2006 matrixPointer. All rights reserved.
|
|
boredzo@1385
|
7 |
//
|
|
boredzo@1385
|
8 |
|
|
boredzo@2501
|
9 |
#import "GrowlNotificationTicket.h"
|
|
ingmarstein@1720
|
10 |
#import "GrowlApplicationTicket.h"
|
|
ingmarstein@1583
|
11 |
#import "GrowlPluginController.h"
|
|
ingmarstein@2695
|
12 |
#import "GrowlDisplayPlugin.h"
|
|
ingmarstein@2641
|
13 |
#include "CFDictionaryAdditions.h"
|
|
ingmarstein@2641
|
14 |
#include "CFMutableDictionaryAdditions.h"
|
|
boredzo@1385
|
15 |
|
|
boredzo@2501
|
16 |
@implementation GrowlNotificationTicket
|
|
boredzo@2439
|
17 |
|
|
boredzo@2501
|
18 |
+ (GrowlNotificationTicket *) notificationWithName:(NSString *)theName {
|
|
boredzo@2501
|
19 |
return [[[GrowlNotificationTicket alloc] initWithName:theName] autorelease];
|
|
boredzo@1385
|
20 |
}
|
|
boredzo@1385
|
21 |
|
|
boredzo@2501
|
22 |
+ (GrowlNotificationTicket *) notificationWithDictionary:(NSDictionary *)dict {
|
|
boredzo@2501
|
23 |
return [[[GrowlNotificationTicket alloc] initWithDictionary:dict] autorelease];
|
|
ingmarstein@1610
|
24 |
}
|
|
ingmarstein@1610
|
25 |
|
|
boredzo@2501
|
26 |
- (GrowlNotificationTicket *) initWithDictionary:(NSDictionary *)dict {
|
|
ingmarstein@2641
|
27 |
NSString *inName = getObjectForKey(dict, @"Name");
|
|
boredzo@2439
|
28 |
|
|
evands@2920
|
29 |
NSString *inHumanReadableName = getObjectForKey(dict, @"HumanReadableName");
|
|
evands@2920
|
30 |
|
|
evands@2923
|
31 |
NSString *inNotificationDescription = getObjectForKey(dict, @"NotificationDescription");
|
|
ingmarstein@2943
|
32 |
|
|
ingmarstein@2641
|
33 |
id value = getObjectForKey(dict, @"Priority");
|
|
boredzo@2439
|
34 |
enum GrowlPriority inPriority = value ? [value intValue] : GrowlPriorityUnset;
|
|
boredzo@2439
|
35 |
|
|
ingmarstein@2641
|
36 |
BOOL inEnabled = getBooleanForKey(dict, @"Enabled");
|
|
boredzo@2439
|
37 |
|
|
ingmarstein@2641
|
38 |
int inSticky = getIntegerForKey(dict, @"Sticky");
|
|
ingmarstein@1583
|
39 |
inSticky = (inSticky >= 0 ? (inSticky > 0 ? NSOnState : NSOffState) : NSMixedState);
|
|
boredzo@2439
|
40 |
|
|
ingmarstein@1628
|
41 |
NSString *inDisplay = [dict objectForKey:@"Display"];
|
|
ingmarstein@3168
|
42 |
NSString *inSound = [dict objectForKey:@"Sound"];
|
|
ingmarstein@1610
|
43 |
|
|
boredzo@2439
|
44 |
return [self initWithName:inName
|
|
evands@2920
|
45 |
humanReadableName:inHumanReadableName
|
|
evands@2923
|
46 |
notificationDescription:inNotificationDescription
|
|
boredzo@2439
|
47 |
priority:inPriority
|
|
boredzo@2439
|
48 |
enabled:inEnabled
|
|
boredzo@2439
|
49 |
sticky:inSticky
|
|
ingmarstein@3168
|
50 |
displayPluginName:inDisplay
|
|
ingmarstein@3168
|
51 |
sound:inSound];
|
|
boredzo@1385
|
52 |
}
|
|
boredzo@1385
|
53 |
|
|
boredzo@2501
|
54 |
- (GrowlNotificationTicket *) initWithName:(NSString *)theName {
|
|
evands@2920
|
55 |
return [self initWithName:theName
|
|
evands@2920
|
56 |
humanReadableName:nil
|
|
evands@2923
|
57 |
notificationDescription:nil
|
|
ingmarstein@2943
|
58 |
priority:GrowlPriorityUnset
|
|
evands@2920
|
59 |
enabled:YES
|
|
evands@2920
|
60 |
sticky:NSMixedState
|
|
ingmarstein@3168
|
61 |
displayPluginName:nil
|
|
ingmarstein@3168
|
62 |
sound:nil];
|
|
ingmarstein@1610
|
63 |
}
|
|
ingmarstein@1610
|
64 |
|
|
boredzo@2501
|
65 |
- (GrowlNotificationTicket *) initWithName:(NSString *)inName
|
|
evands@2920
|
66 |
humanReadableName:(NSString *)inHumanReadableName
|
|
evands@2923
|
67 |
notificationDescription:(NSString *)inNotificationDescription
|
|
boredzo@2501
|
68 |
priority:(enum GrowlPriority)inPriority
|
|
boredzo@2501
|
69 |
enabled:(BOOL)inEnabled
|
|
boredzo@2501
|
70 |
sticky:(int)inSticky
|
|
boredzo@2501
|
71 |
displayPluginName:(NSString *)display
|
|
ingmarstein@3168
|
72 |
sound:(NSString *)inSound
|
|
boredzo@2439
|
73 |
{
|
|
evands@3512
|
74 |
if ((self = [self init])) {
|
|
evands@2923
|
75 |
name = [inName retain];
|
|
evands@2923
|
76 |
humanReadableName = [inHumanReadableName retain];
|
|
evands@2923
|
77 |
notificationDescription = [inNotificationDescription retain];
|
|
evands@2923
|
78 |
priority = inPriority;
|
|
evands@2923
|
79 |
enabled = inEnabled;
|
|
evands@2923
|
80 |
sticky = inSticky;
|
|
evands@2923
|
81 |
displayPluginName = [display copy];
|
|
ingmarstein@3168
|
82 |
sound = [inSound retain];
|
|
boredzo@1385
|
83 |
}
|
|
boredzo@1385
|
84 |
return self;
|
|
boredzo@1385
|
85 |
}
|
|
boredzo@1385
|
86 |
|
|
boredzo@2439
|
87 |
- (void) dealloc {
|
|
ingmarstein@2567
|
88 |
[name release];
|
|
evands@2920
|
89 |
[humanReadableName release];
|
|
boredzo@2752
|
90 |
[displayPluginName release];
|
|
evands@2923
|
91 |
[notificationDescription release];
|
|
boredzo@4147
|
92 |
[sound release];
|
|
boredzo@2439
|
93 |
|
|
boredzo@2439
|
94 |
[super dealloc];
|
|
boredzo@2439
|
95 |
}
|
|
boredzo@2439
|
96 |
|
|
boredzo@2439
|
97 |
#pragma mark -
|
|
boredzo@2439
|
98 |
|
|
boredzo@2439
|
99 |
- (NSDictionary *) dictionaryRepresentation {
|
|
boredzo@2439
|
100 |
NSNumber *enabledValue = [[NSNumber alloc] initWithBool:enabled];
|
|
boredzo@2439
|
101 |
NSNumber *stickyValue = [[NSNumber alloc] initWithInt:sticky];
|
|
boredzo@1385
|
102 |
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
ingmarstein@1643
|
103 |
name, @"Name",
|
|
ingmarstein@1643
|
104 |
enabledValue, @"Enabled",
|
|
ingmarstein@1643
|
105 |
stickyValue, @"Sticky",
|
|
boredzo@1385
|
106 |
nil];
|
|
ingmarstein@1643
|
107 |
[enabledValue release];
|
|
ingmarstein@1643
|
108 |
[stickyValue release];
|
|
boredzo@2439
|
109 |
if (priority != GrowlPriorityUnset)
|
|
ingmarstein@2641
|
110 |
setIntegerForKey(dict, @"Priority", priority);
|
|
ingmarstein@2595
|
111 |
if (displayPluginName)
|
|
ingmarstein@2641
|
112 |
setObjectForKey(dict, @"Display", displayPluginName);
|
|
evands@2923
|
113 |
if (notificationDescription)
|
|
evands@2923
|
114 |
setObjectForKey(dict, @"NotificationDescription", notificationDescription);
|
|
evands@2923
|
115 |
if (humanReadableName)
|
|
ingmarstein@2943
|
116 |
setObjectForKey(dict, @"HumanReadableName", humanReadableName);
|
|
ingmarstein@3168
|
117 |
if (sound)
|
|
ingmarstein@3168
|
118 |
setObjectForKey(dict, @"Sound", sound);
|
|
ingmarstein@2943
|
119 |
|
|
boredzo@1385
|
120 |
return dict;
|
|
boredzo@1385
|
121 |
}
|
|
boredzo@1385
|
122 |
|
|
boredzo@2439
|
123 |
- (NSString *) description {
|
|
boredzo@2439
|
124 |
return [NSString stringWithFormat:@"<%@ %p %@>", [self class], self, [[self dictionaryRepresentation] description]];
|
|
boredzo@1385
|
125 |
}
|
|
boredzo@1385
|
126 |
|
|
boredzo@2501
|
127 |
- (BOOL) isEqualToNotification:(GrowlNotificationTicket *) other {
|
|
boredzo@2441
|
128 |
return [[self name] isEqualToString:[other name]];
|
|
boredzo@2441
|
129 |
}
|
|
boredzo@2441
|
130 |
#define GENERIC_EQUALITY_METHOD(other) { \
|
|
boredzo@2501
|
131 |
return ([other isKindOfClass:[GrowlNotificationTicket class]] && [self isEqualToNotification:other]); \
|
|
boredzo@2441
|
132 |
}
|
|
boredzo@2441
|
133 |
//NSObject's way
|
|
boredzo@2441
|
134 |
- (BOOL) isEqualTo:(id) other GENERIC_EQUALITY_METHOD(other)
|
|
boredzo@2441
|
135 |
//Object's way
|
|
boredzo@2441
|
136 |
- (BOOL) isEqual:(id) other GENERIC_EQUALITY_METHOD(other)
|
|
boredzo@2441
|
137 |
#undef GENERIC_EQUALITY_METHOD
|
|
boredzo@2441
|
138 |
|
|
boredzo@1385
|
139 |
#pragma mark -
|
|
boredzo@2439
|
140 |
|
|
ingmarstein@1583
|
141 |
- (NSString *) name {
|
|
boredzo@1385
|
142 |
return [[name retain] autorelease];
|
|
boredzo@1385
|
143 |
}
|
|
boredzo@1385
|
144 |
|
|
evands@2920
|
145 |
- (NSString *) humanReadableName {
|
|
evands@2920
|
146 |
return (humanReadableName ? [[humanReadableName retain] autorelease] : [self name]);
|
|
evands@2920
|
147 |
}
|
|
evands@2920
|
148 |
|
|
evands@2920
|
149 |
- (void) setHumanReadableName:(NSString *)inHumanReadableName {
|
|
evands@2920
|
150 |
if (humanReadableName != inHumanReadableName) {
|
|
evands@2920
|
151 |
[humanReadableName release];
|
|
evands@2920
|
152 |
humanReadableName = [inHumanReadableName retain];
|
|
evands@2920
|
153 |
}
|
|
evands@2920
|
154 |
}
|
|
evands@2920
|
155 |
|
|
evands@2923
|
156 |
- (NSString *) notificationDescription {
|
|
evands@2923
|
157 |
return notificationDescription;
|
|
evands@2923
|
158 |
}
|
|
evands@2923
|
159 |
|
|
evands@2923
|
160 |
- (void) setNotificationDescription:(NSString *)inNotificationDescription {
|
|
evands@2923
|
161 |
if (notificationDescription != inNotificationDescription) {
|
|
evands@2923
|
162 |
[notificationDescription release];
|
|
evands@2923
|
163 |
notificationDescription = [inNotificationDescription retain];
|
|
evands@2923
|
164 |
}
|
|
evands@2923
|
165 |
}
|
|
evands@2923
|
166 |
|
|
boredzo@2439
|
167 |
- (enum GrowlPriority) priority {
|
|
boredzo@1385
|
168 |
return priority;
|
|
boredzo@1385
|
169 |
}
|
|
boredzo@2439
|
170 |
- (void) setPriority:(enum GrowlPriority)newPriority {
|
|
boredzo@1385
|
171 |
priority = newPriority;
|
|
ingmarstein@1722
|
172 |
[ticket synchronize];
|
|
boredzo@1385
|
173 |
}
|
|
boredzo@1385
|
174 |
|
|
boredzo@1385
|
175 |
- (BOOL) enabled {
|
|
boredzo@1385
|
176 |
return enabled;
|
|
boredzo@1385
|
177 |
}
|
|
boredzo@1385
|
178 |
- (void) setEnabled:(BOOL)flag {
|
|
boredzo@1385
|
179 |
enabled = flag;
|
|
ingmarstein@1720
|
180 |
[ticket setUseDefaults:NO];
|
|
ingmarstein@1722
|
181 |
[ticket synchronize];
|
|
boredzo@1385
|
182 |
}
|
|
boredzo@1385
|
183 |
|
|
ingmarstein@1720
|
184 |
- (GrowlApplicationTicket *) ticket {
|
|
ingmarstein@1720
|
185 |
return ticket;
|
|
ingmarstein@1720
|
186 |
}
|
|
boredzo@2439
|
187 |
- (void) setTicket:(GrowlApplicationTicket *)newTicket {
|
|
boredzo@2439
|
188 |
ticket = newTicket;
|
|
ingmarstein@1720
|
189 |
}
|
|
ingmarstein@1720
|
190 |
|
|
ingmarstein@1720
|
191 |
// With sticky, 1 is on, 0 is off, -1 means use what's passed
|
|
ingmarstein@1720
|
192 |
// This corresponds to NSOnState, NSOffState, and NSMixedState
|
|
boredzo@1385
|
193 |
- (int) sticky {
|
|
boredzo@1385
|
194 |
return sticky;
|
|
boredzo@1385
|
195 |
}
|
|
boredzo@1385
|
196 |
- (void) setSticky:(int)value {
|
|
boredzo@1385
|
197 |
sticky = value;
|
|
ingmarstein@1722
|
198 |
[ticket synchronize];
|
|
boredzo@1385
|
199 |
}
|
|
ingmarstein@1583
|
200 |
|
|
boredzo@2441
|
201 |
- (NSString *) displayPluginName {
|
|
boredzo@2441
|
202 |
return displayPluginName;
|
|
boredzo@2441
|
203 |
}
|
|
ingmarstein@2636
|
204 |
- (void) setDisplayPluginName:(NSString *)pluginName {
|
|
boredzo@2441
|
205 |
[displayPluginName release];
|
|
boredzo@2441
|
206 |
displayPluginName = [pluginName copy];
|
|
ingmarstein@2595
|
207 |
displayPlugin = nil;
|
|
boredzo@2441
|
208 |
[ticket synchronize];
|
|
boredzo@2441
|
209 |
}
|
|
boredzo@2441
|
210 |
|
|
ingmarstein@2695
|
211 |
- (GrowlDisplayPlugin *) displayPlugin {
|
|
ingmarstein@2595
|
212 |
if (!displayPlugin && displayPluginName)
|
|
eridius@2773
|
213 |
displayPlugin = (GrowlDisplayPlugin *)[[[GrowlPluginController sharedController] displayPluginDictionaryWithName:displayPluginName author:nil version:nil type:nil] pluginInstance];
|
|
boredzo@2441
|
214 |
return displayPlugin;
|
|
boredzo@2441
|
215 |
}
|
|
boredzo@2441
|
216 |
|
|
ingmarstein@2943
|
217 |
- (NSComparisonResult) humanReadableNameCompare:(GrowlNotificationTicket *)inTicket {
|
|
evands@2920
|
218 |
return [[self humanReadableName] caseInsensitiveCompare:[inTicket humanReadableName]];
|
|
evands@2920
|
219 |
}
|
|
evands@2920
|
220 |
|
|
ingmarstein@3168
|
221 |
- (NSString *) sound {
|
|
ingmarstein@3168
|
222 |
return sound;
|
|
ingmarstein@3168
|
223 |
}
|
|
ingmarstein@3168
|
224 |
- (void) setSound:(NSString *)value {
|
|
ingmarstein@3168
|
225 |
if (value != sound) {
|
|
ingmarstein@3168
|
226 |
[sound release];
|
|
ingmarstein@3168
|
227 |
sound = [value retain];
|
|
ingmarstein@3168
|
228 |
[ticket synchronize];
|
|
ingmarstein@3168
|
229 |
}
|
|
ingmarstein@3168
|
230 |
}
|
|
ingmarstein@3168
|
231 |
|
|
boredzo@1385
|
232 |
@end
|