source: trunk/Cocoa/Pester/Source/PSMovieAlertController.m@ 620

Last change on this file since 620 was 570, checked in by Nicholas Riley, 15 years ago

PSMovieAlertController.m: don't trigger _movieRateDidChange: on early termination.

File size: 4.8 KB
Line 
1//
2// PSMovieAlertController.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlarmAlertController.h"
10#import "PSMovieAlertController.h"
11#import "PSMovieAlert.h"
12#import "QTMovie-NJRExtensions.h"
13#import "NJRSoundManager.h"
14
15@implementation PSMovieAlertController
16
17+ (PSMovieAlertController *)newControllerWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
18{
19 // retained until the alert completes
20 return [[self alloc] initWithAlarm: anAlarm movieAlert: anAlert];
21}
22
23- (void)close;
24{
25 [super close];
26 [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: [alert outputVolume]];
27}
28
29- (void)_movieRateDidChange:(NSNotification *)notification;
30{
31 float newRate = [[[notification userInfo] objectForKey: QTMovieRateDidChangeNotificationParameter]
32 floatValue];
33 if (newRate != 0)
34 return;
35
36 if (repetitions == 0 || repetitionsRemaining == 0) {
37 [self close];
38 return;
39 }
40 repetitionsRemaining--;
41 [movieView gotoBeginning: self];
42 [movieView play: self];
43}
44
45- (void)play;
46{
47 repetitionsRemaining = repetitions - 1;
48
49 [[NSNotificationCenter defaultCenter] addObserver: self
50 selector: @selector(_movieRateDidChange:)
51 name: QTMovieRateDidChangeNotification
52 object: [movieView movie]];
53 [movieView play: self];
54}
55
56- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
57{
58 if ([self initWithWindowNibName: @"Movie alert"]) {
59 QTMovie *movie = [anAlert movie];
60 NSWindow *window = [self window]; // connect outlets
61 alarm = anAlarm;
62 alert = anAlert;
63 [movieView setMovie: movie];
64 if ([alert hasVideo]) {
65 NSRect screenRect = [[window screen] visibleFrame];
66 NSSize movieSize = [[movie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
67 NSSize minSize = [window minSize];
68 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
69 NSRect frame;
70 screenRect.size.height -= windowFrameHeight;
71 minSize.height -= windowFrameHeight;
72 while (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height) {
73 movieSize.width /= 2;
74 movieSize.height /= 2;
75 }
76 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
77 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
78 [window setContentSize: movieSize];
79 [window center];
80 frame = [window frame];
81 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
82 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
83 [window setFrame: frame display: NO];
84 [window setTitle: [alarm message]];
85 { // XXX workaround for (IMO) ugly appearance of Cocoa utility windows
86 NSView *miniButton = [window standardWindowButton: NSWindowMiniaturizeButton],
87 *zoomButton = [window standardWindowButton: NSWindowZoomButton];
88 // NOTE: this will not work if the window is resizable: when the frame is reset, the standard buttons reappear
89 [miniButton setFrameOrigin: NSMakePoint(-100, -100)];
90 [zoomButton setFrameOrigin: NSMakePoint(-100, -100)];
91 [[miniButton superview] setNeedsDisplay: YES];
92 [[zoomButton superview] setNeedsDisplay: YES];
93 }
94 [[self window] orderFrontRegardless];
95 }
96 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
97 repetitions = [alert repetitions];
98 if ([movie NJR_hasAudio] && [NJRSoundManager volumeIsNotMutedOrInvalid: [alert outputVolume]] && [NJRSoundManager saveDefaultOutputVolume]) {
99 [NJRSoundManager setDefaultOutputVolume: [alert outputVolume]];
100 }
101 if (![movie NJR_isStatic]) [self play]; // if it's an image, don't close the window automatically
102 }
103 return self;
104}
105
106- (void)dealloc;
107{
108 [[NSNotificationCenter defaultCenter] removeObserver: self];
109 [super dealloc];
110}
111
112@end
113
114@implementation PSMovieAlertController (NSWindowNotifications)
115
116- (void)windowWillClose:(NSNotification *)notification;
117{
118 repetitions = 0;
119 [[NSNotificationCenter defaultCenter] removeObserver: self
120 name: QTMovieRateDidChangeNotification
121 object: [movieView movie]];
122 [movieView pause: self];
123 [alert completedForAlarm: alarm];
124 [self autorelease];
125 // note: there may still be a retained copy of this object until the runloop timer has let go of us at the end of the current movie playback cycle; donÕt worry about it.
126}
127
128@end
Note: See TracBrowser for help on using the repository browser.