Release the sound object. This was a leak that the clang static analyzer found, IIRC.
2 // GrowlNotificationTicket.m
5 // Created by Karl Adam on 01.10.05.
6 // Copyright 2005-2006 matrixPointer. All rights reserved.
9 #import "GrowlNotificationTicket.h"
10 #import "GrowlApplicationTicket.h"
11 #import "GrowlPluginController.h"
12 #import "GrowlDisplayPlugin.h"
13 #include "CFDictionaryAdditions.h"
14 #include "CFMutableDictionaryAdditions.h"
16 @implementation GrowlNotificationTicket
18 + (GrowlNotificationTicket *) notificationWithName:(NSString *)theName {
19 return [[[GrowlNotificationTicket alloc] initWithName:theName] autorelease];
22 + (GrowlNotificationTicket *) notificationWithDictionary:(NSDictionary *)dict {
23 return [[[GrowlNotificationTicket alloc] initWithDictionary:dict] autorelease];
26 - (GrowlNotificationTicket *) initWithDictionary:(NSDictionary *)dict {
27 NSString *inName = getObjectForKey(dict, @"Name");
29 NSString *inHumanReadableName = getObjectForKey(dict, @"HumanReadableName");
31 NSString *inNotificationDescription = getObjectForKey(dict, @"NotificationDescription");
33 id value = getObjectForKey(dict, @"Priority");
34 enum GrowlPriority inPriority = value ? [value intValue] : GrowlPriorityUnset;
36 BOOL inEnabled = getBooleanForKey(dict, @"Enabled");
38 int inSticky = getIntegerForKey(dict, @"Sticky");
39 inSticky = (inSticky >= 0 ? (inSticky > 0 ? NSOnState : NSOffState) : NSMixedState);
41 NSString *inDisplay = [dict objectForKey:@"Display"];
42 NSString *inSound = [dict objectForKey:@"Sound"];
44 return [self initWithName:inName
45 humanReadableName:inHumanReadableName
46 notificationDescription:inNotificationDescription
50 displayPluginName:inDisplay
54 - (GrowlNotificationTicket *) initWithName:(NSString *)theName {
55 return [self initWithName:theName
57 notificationDescription:nil
58 priority:GrowlPriorityUnset
65 - (GrowlNotificationTicket *) initWithName:(NSString *)inName
66 humanReadableName:(NSString *)inHumanReadableName
67 notificationDescription:(NSString *)inNotificationDescription
68 priority:(enum GrowlPriority)inPriority
69 enabled:(BOOL)inEnabled
71 displayPluginName:(NSString *)display
72 sound:(NSString *)inSound
74 if ((self = [self init])) {
75 name = [inName retain];
76 humanReadableName = [inHumanReadableName retain];
77 notificationDescription = [inNotificationDescription retain];
78 priority = inPriority;
81 displayPluginName = [display copy];
82 sound = [inSound retain];
89 [humanReadableName release];
90 [displayPluginName release];
91 [notificationDescription release];
99 - (NSDictionary *) dictionaryRepresentation {
100 NSNumber *enabledValue = [[NSNumber alloc] initWithBool:enabled];
101 NSNumber *stickyValue = [[NSNumber alloc] initWithInt:sticky];
102 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
104 enabledValue, @"Enabled",
105 stickyValue, @"Sticky",
107 [enabledValue release];
108 [stickyValue release];
109 if (priority != GrowlPriorityUnset)
110 setIntegerForKey(dict, @"Priority", priority);
111 if (displayPluginName)
112 setObjectForKey(dict, @"Display", displayPluginName);
113 if (notificationDescription)
114 setObjectForKey(dict, @"NotificationDescription", notificationDescription);
115 if (humanReadableName)
116 setObjectForKey(dict, @"HumanReadableName", humanReadableName);
118 setObjectForKey(dict, @"Sound", sound);
123 - (NSString *) description {
124 return [NSString stringWithFormat:@"<%@ %p %@>", [self class], self, [[self dictionaryRepresentation] description]];
127 - (BOOL) isEqualToNotification:(GrowlNotificationTicket *) other {
128 return [[self name] isEqualToString:[other name]];
130 #define GENERIC_EQUALITY_METHOD(other) { \
131 return ([other isKindOfClass:[GrowlNotificationTicket class]] && [self isEqualToNotification:other]); \
134 - (BOOL) isEqualTo:(id) other GENERIC_EQUALITY_METHOD(other)
136 - (BOOL) isEqual:(id) other GENERIC_EQUALITY_METHOD(other)
137 #undef GENERIC_EQUALITY_METHOD
141 - (NSString *) name {
142 return [[name retain] autorelease];
145 - (NSString *) humanReadableName {
146 return (humanReadableName ? [[humanReadableName retain] autorelease] : [self name]);
149 - (void) setHumanReadableName:(NSString *)inHumanReadableName {
150 if (humanReadableName != inHumanReadableName) {
151 [humanReadableName release];
152 humanReadableName = [inHumanReadableName retain];
156 - (NSString *) notificationDescription {
157 return notificationDescription;
160 - (void) setNotificationDescription:(NSString *)inNotificationDescription {
161 if (notificationDescription != inNotificationDescription) {
162 [notificationDescription release];
163 notificationDescription = [inNotificationDescription retain];
167 - (enum GrowlPriority) priority {
170 - (void) setPriority:(enum GrowlPriority)newPriority {
171 priority = newPriority;
172 [ticket synchronize];
178 - (void) setEnabled:(BOOL)flag {
180 [ticket setUseDefaults:NO];
181 [ticket synchronize];
184 - (GrowlApplicationTicket *) ticket {
187 - (void) setTicket:(GrowlApplicationTicket *)newTicket {
191 // With sticky, 1 is on, 0 is off, -1 means use what's passed
192 // This corresponds to NSOnState, NSOffState, and NSMixedState
196 - (void) setSticky:(int)value {
198 [ticket synchronize];
201 - (NSString *) displayPluginName {
202 return displayPluginName;
204 - (void) setDisplayPluginName:(NSString *)pluginName {
205 [displayPluginName release];
206 displayPluginName = [pluginName copy];
208 [ticket synchronize];
211 - (GrowlDisplayPlugin *) displayPlugin {
212 if (!displayPlugin && displayPluginName)
213 displayPlugin = (GrowlDisplayPlugin *)[[[GrowlPluginController sharedController] displayPluginDictionaryWithName:displayPluginName author:nil version:nil type:nil] pluginInstance];
214 return displayPlugin;
217 - (NSComparisonResult) humanReadableNameCompare:(GrowlNotificationTicket *)inTicket {
218 return [[self humanReadableName] caseInsensitiveCompare:[inTicket humanReadableName]];
221 - (NSString *) sound {
224 - (void) setSound:(NSString *)value {
225 if (value != sound) {
227 sound = [value retain];
228 [ticket synchronize];