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

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

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

File size: 4.8 KB
RevLine 
[34]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"
[543]12#import "QTMovie-NJRExtensions.h"
[133]13#import "NJRSoundManager.h"
[34]14
15@implementation PSMovieAlertController
16
[554]17+ (PSMovieAlertController *)newControllerWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
[34]18{
[554]19 // retained until the alert completes
[53]20 return [[self alloc] initWithAlarm: anAlarm movieAlert: anAlert];
[34]21}
22
[133]23- (void)close;
24{
25 [super close];
26 [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: [alert outputVolume]];
27}
28
[569]29- (void)_movieRateDidChange:(NSNotification *)notification;
[34]30{
[569]31 float newRate = [[[notification userInfo] objectForKey: QTMovieRateDidChangeNotificationParameter]
32 floatValue];
33 if (newRate != 0)
34 return;
35
[570]36 if (repetitions == 0 || repetitionsRemaining == 0) {
[569]37 [self close];
38 return;
[34]39 }
[569]40 repetitionsRemaining--;
41 [movieView gotoBeginning: self];
42 [movieView play: self];
[34]43}
44
[569]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
[53]56- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
[34]57{
58 if ([self initWithWindowNibName: @"Movie alert"]) {
[543]59 QTMovie *movie = [anAlert movie];
[34]60 NSWindow *window = [self window]; // connect outlets
[53]61 alarm = anAlarm;
62 alert = anAlert;
[34]63 [movieView setMovie: movie];
64 if ([alert hasVideo]) {
65 NSRect screenRect = [[window screen] visibleFrame];
[543]66 NSSize movieSize = [[movie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
[60]67 NSSize minSize = [window minSize];
68 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
[34]69 NSRect frame;
[60]70 screenRect.size.height -= windowFrameHeight;
71 minSize.height -= windowFrameHeight;
[543]72 while (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height) {
73 movieSize.width /= 2;
74 movieSize.height /= 2;
[34]75 }
[60]76 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
77 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
[34]78 [window setContentSize: movieSize];
79 [window center];
80 frame = [window frame];
[45]81 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
[34]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]];
[53]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 }
[34]94 [[self window] orderFrontRegardless];
95 }
96 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
97 repetitions = [alert repetitions];
[543]98 if ([movie NJR_hasAudio] && [NJRSoundManager volumeIsNotMutedOrInvalid: [alert outputVolume]] && [NJRSoundManager saveDefaultOutputVolume]) {
[133]99 [NJRSoundManager setDefaultOutputVolume: [alert outputVolume]];
100 }
[543]101 if (![movie NJR_isStatic]) [self play]; // if it's an image, don't close the window automatically
[34]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;
[570]119 [[NSNotificationCenter defaultCenter] removeObserver: self
120 name: QTMovieRateDidChangeNotification
121 object: [movieView movie]];
[543]122 [movieView pause: self];
[53]123 [alert completedForAlarm: alarm];
124 [self autorelease];
[34]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.