CFRelease the duration preference value if we get one. Found by the clang static analyzer.
2 // GrowlMusicVideoWindowController.m
5 // Created by Jorge Salvador Caffarena on 09/09/04.
6 // Copyright 2004 Jorge Salvador Caffarena. All rights reserved.
9 #import "GrowlMusicVideoWindowController.h"
10 #import "GrowlFadingWindowTransition.h"
11 #import "GrowlMusicVideoWindowView.h"
12 #import "GrowlMusicVideoPrefs.h"
13 #import "NSWindow+Transforms.h"
14 #import "GrowlSlidingWindowTransition.h"
15 #import "GrowlWipeWindowTransition.h"
16 #include "CFDictionaryAdditions.h"
17 #import "GrowlApplicationNotification.h"
19 @implementation GrowlMusicVideoWindowController
22 int sizePref = MUSICVIDEO_SIZE_NORMAL;
25 READ_GROWL_PREF_INT(MUSICVIDEO_SCREEN_PREF, GrowlMusicVideoPrefDomain, &screenNumber);
26 NSArray *screens = [NSScreen screens];
27 unsigned screensCount = [screens count];
29 [self setScreen:((screensCount >= (screenNumber + 1)) ? [screens objectAtIndex:screenNumber] : [screens objectAtIndex:0])];
33 NSRect screen = [[self screen] frame];
34 READ_GROWL_PREF_INT(MUSICVIDEO_SIZE_PREF, GrowlMusicVideoPrefDomain, &sizePref);
35 sizeRect.origin = screen.origin;
36 sizeRect.size.width = screen.size.width;
37 if (sizePref == MUSICVIDEO_SIZE_HUGE)
38 sizeRect.size.height = 192.0f;
40 sizeRect.size.height = 96.0f;
41 frameHeight = sizeRect.size.height;
43 READ_GROWL_PREF_INT(MUSICVIDEO_SIZE_PREF, GrowlMusicVideoPrefDomain, &sizePref);
44 NSPanel *panel = [[NSPanel alloc] initWithContentRect:sizeRect
45 styleMask:NSBorderlessWindowMask
46 backing:NSBackingStoreBuffered
48 NSRect panelFrame = [panel frame];
49 [panel setBecomesKeyOnlyIfNeeded:YES];
50 [panel setHidesOnDeactivate:NO];
51 [panel setBackgroundColor:[NSColor clearColor]];
52 [panel setLevel:NSStatusWindowLevel];
53 [panel setIgnoresMouseEvents:YES];
54 [panel setSticky:YES];
56 [panel setHasShadow:NO];
57 [panel setCanHide:NO];
58 [panel setOneShot:YES];
59 [panel useOptimizedDrawing:YES];
60 [panel setDelegate:self];
62 GrowlMusicVideoWindowView *view = [[GrowlMusicVideoWindowView alloc] initWithFrame:panelFrame];
64 [view setTarget:self];
65 [view setAction:@selector(notificationClicked:)]; // Not used for now
67 [panel setContentView:view]; // retains subview
70 [panel setFrameTopLeftPoint:screen.origin];
72 // call super so everything else is set up...
73 if ((self = [super initWithWindow:panel])) {
74 CFNumberRef prefsDuration = NULL;
75 READ_GROWL_PREF_VALUE(MUSICVIDEO_DURATION_PREF, GrowlMusicVideoPrefDomain, CFNumberRef, &prefsDuration);
76 [self setDisplayDuration:(prefsDuration ?
77 [(NSNumber *)prefsDuration doubleValue] :
78 GrowlMusicVideoDurationPrefDefault)];
79 if (prefsDuration) CFRelease(prefsDuration);
81 //The default duration for transitions is far too long for the music video effect.
82 [self setTransitionDuration:0.3];
84 MusicVideoEffectType effect = MUSICVIDEO_EFFECT_SLIDE;
85 READ_GROWL_PREF_INT(MUSICVIDEO_EFFECT_PREF, GrowlMusicVideoPrefDomain, &effect);
88 case MUSICVIDEO_EFFECT_SLIDE:
91 GrowlSlidingWindowTransition *slider = [[GrowlSlidingWindowTransition alloc] initWithWindow:panel];
92 [slider setFromOrigin:NSMakePoint(NSMinX(screen),NSMinY(screen)-frameHeight) toOrigin:NSMakePoint(NSMinX(screen),NSMinY(screen))];
93 [self setStartPercentage:0 endPercentage:100 forTransition:slider];
94 [slider setAutoReverses:YES];
95 [self addTransition:slider];
99 case MUSICVIDEO_EFFECT_FADING:
101 GrowlFadingWindowTransition *fader = [[GrowlFadingWindowTransition alloc] initWithWindow:panel];
102 [self addTransition:fader];
103 [self setStartPercentage:0 endPercentage:100 forTransition:fader];
104 [fader setAutoReverses:YES];
107 // I am adding in a sliding transition from screen,screen to screen,screen to make sure the window is properly positioned during the animation - swr
108 GrowlSlidingWindowTransition *slider = [[GrowlSlidingWindowTransition alloc] initWithWindow:panel];
109 [slider setFromOrigin:NSMakePoint(NSMinX(screen),NSMinY(screen)) toOrigin:NSMakePoint(NSMinX(screen),NSMinY(screen))];
110 [self setStartPercentage:0 endPercentage:100 forTransition:slider];
111 [slider setAutoReverses:YES];
112 [self addTransition:slider];
116 case MUSICVIDEO_EFFECT_WIPE:
118 NSLog(@"Wipe not implemented");
120 //[panel setFrameOrigin:NSMakePoint( 0, 0)];
121 //GrowlWipeWindowTransition *wiper = [[GrowlWipeWindowTransition alloc] initWithWindow:panel];
122 // save for scale effect [wiper setFromOrigin:NSMakePoint(0,0) toOrigin:NSMakePoint(NSMaxX(screen), frameHeight)];
123 //[wiper setFromOrigin:NSMakePoint(NSMaxX(screen), 0) toOrigin:NSMakePoint(NSMaxX(screen), frameHeight)];
124 //[self setStartPercentage:0 endPercentage:100 forTransition:wiper];
125 //[wiper setAutoReverses:YES];
126 //[self addTransition:wiper];
139 - (void) setNotification: (GrowlApplicationNotification *) theNotification {
140 [super setNotification:theNotification];
141 if (!theNotification)
144 NSDictionary *noteDict = [notification dictionaryRepresentation];
145 NSString *title = [notification title];
146 NSString *text = [notification notificationDescription];
147 NSImage *icon = getObjectForKey(noteDict, GROWL_NOTIFICATION_ICON);
148 int prio = getIntegerForKey(noteDict, GROWL_NOTIFICATION_PRIORITY);
150 NSPanel *panel = (NSPanel *)[self window];
151 GrowlMusicVideoWindowView *view = [panel contentView];
152 [view setPriority:prio];
153 [view setTitle:title];