CFRelease the duration preference value if we get one. Found by the clang static analyzer.
2 // GrowlNanoWindowController.m
5 // Created by Rudy Richter on 12/12/2005.
6 // Copyright 2005-2006, The Growl Project. All rights reserved.
10 #import "GrowlNanoWindowController.h"
11 #import "GrowlNanoWindowView.h"
12 #import "GrowlNanoPrefs.h"
13 #import "NSWindow+Transforms.h"
14 #import "GrowlSlidingWindowTransition.h"
15 #import "GrowlWipeWindowTransition.h"
16 #import "GrowlFadingWindowTransition.h"
18 #import "GrowlApplicationNotification.h"
19 #include "CFDictionaryAdditions.h"
21 @implementation GrowlNanoWindowController
24 int sizePref = Nano_SIZE_NORMAL;
27 CFNumberRef prefsDuration = NULL;
28 READ_GROWL_PREF_VALUE(Nano_DURATION_PREF, GrowlNanoPrefDomain, CFNumberRef, &prefsDuration);
29 [self setDisplayDuration:(prefsDuration ?
30 [(NSNumber *)prefsDuration doubleValue] :
31 GrowlNanoDurationPrefDefault)];
32 if (prefsDuration) CFRelease(prefsDuration);
35 READ_GROWL_PREF_INT(Nano_SCREEN_PREF, GrowlNanoPrefDomain, &screenNumber);
36 NSArray *screens = [NSScreen screens];
37 unsigned int screensCount = [screens count];
39 [self setScreen:((screensCount >= (screenNumber + 1)) ? [screens objectAtIndex:screenNumber] : [screens objectAtIndex:0])];
43 NSRect screen = [[self screen] frame];
44 READ_GROWL_PREF_INT(Nano_SIZE_PREF, GrowlNanoPrefDomain, &sizePref);
45 sizeRect.origin = screen.origin;
46 if (sizePref == Nano_SIZE_HUGE) {
47 sizeRect.size.height = 50.0f;
48 sizeRect.size.width = 270.0f;
50 sizeRect.size.height = 25.0f;
51 sizeRect.size.width = 185.0f;
53 frameHeight = sizeRect.size.height;
55 READ_GROWL_PREF_INT(Nano_SIZE_PREF, GrowlNanoPrefDomain, &sizePref);
56 NSPanel *panel = [[NSPanel alloc] initWithContentRect:sizeRect
57 styleMask:NSBorderlessWindowMask
58 backing:NSBackingStoreBuffered
60 NSRect panelFrame = [panel frame];
61 [panel setBecomesKeyOnlyIfNeeded:YES];
62 [panel setHidesOnDeactivate:NO];
63 [panel setBackgroundColor:[NSColor clearColor]];
64 [panel setLevel:NSFloatingWindowLevel];
65 [panel setIgnoresMouseEvents:YES];
66 [panel setSticky:YES];
68 [panel setHasShadow:NO];
69 [panel setCanHide:NO];
70 [panel setOneShot:YES];
71 [panel useOptimizedDrawing:YES];
72 [panel setDelegate:self];
74 GrowlNanoWindowView *view = [[GrowlNanoWindowView alloc] initWithFrame:panelFrame];
76 [view setTarget:self];
77 [view setAction:@selector(notificationClicked:)]; // Not used for now
79 [panel setContentView:view]; // retains subview
82 float xPosition = NSMaxX(screen) - (NSMaxX(screen) / 4);
83 float yPosition = NSMaxY(screen);
84 if([NSMenu menuBarVisible])
85 yPosition-=[NSMenuView menuBarHeight];
87 [panel setFrameOrigin:NSMakePoint(xPosition, yPosition)];
89 // call super so everything else is set up...
90 if ((self = [super initWithWindow:panel])) {
91 NanoEffectType effect = Nano_EFFECT_SLIDE;
92 READ_GROWL_PREF_INT(Nano_EFFECT_PREF, GrowlNanoPrefDomain, &effect);
95 case Nano_EFFECT_SLIDE:
98 GrowlSlidingWindowTransition *slider = [[GrowlSlidingWindowTransition alloc] initWithWindow:panel];
99 [slider setFromOrigin:NSMakePoint(xPosition, yPosition) toOrigin:NSMakePoint(xPosition, yPosition - frameHeight)];
100 [slider setAutoReverses:YES];
101 [self addTransition:slider];
102 [self setStartPercentage:0 endPercentage:100 forTransition:slider];
108 case Nano_EFFECT_WIPE:
111 [panel setFrameOrigin:NSMakePoint(xPosition, NSMaxY(screen))];
112 GrowlWipeWindowTransition *wiper = [[GrowlWipeWindowTransition alloc] initWithWindow:panel];
113 [wiper setFromOrigin:NSMakePoint(xPosition, yPosition) toOrigin:NSMakePoint(xPosition, yPosition - frameHeight)];
114 [wiper setAutoReverses:YES];
115 [self addTransition:wiper];
116 [self setStartPercentage:0 endPercentage:100 forTransition:wiper];
120 NSLog(@"Wipe not implemented");
123 case Nano_EFFECT_FADE:
125 [panel setAlphaValue:0.0];
126 [panel setFrameOrigin:NSMakePoint(xPosition, yPosition - frameHeight)];
128 GrowlFadingWindowTransition *fader = [[GrowlFadingWindowTransition alloc] initWithWindow:panel];
129 [self addTransition:fader];
130 [self setStartPercentage:0 endPercentage:100 forTransition:fader];
131 [fader setAutoReverses:YES];
143 - (void) setNotification: (GrowlApplicationNotification *) theNotification {
144 [super setNotification:theNotification];
145 if (!theNotification)
148 NSDictionary *noteDict = [notification dictionaryRepresentation];
149 NSString *title = [notification title];
150 NSString *text = [notification notificationDescription];
151 NSImage *icon = getObjectForKey(noteDict, GROWL_NOTIFICATION_ICON);
152 int prio = getIntegerForKey(noteDict, GROWL_NOTIFICATION_PRIORITY);
154 NSPanel *panel = (NSPanel *)[self window];
155 GrowlNanoWindowView *view = [panel contentView];
156 [view setPriority:prio];
157 [view setTitle:title];