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

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

Fix naming to pacify Clang Analyzer and comply with Cocoa rules.

File size: 4.9 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#import <QuickTime/Movies.h>
15
16@implementation PSMovieAlertController
17
[554]18+ (PSMovieAlertController *)newControllerWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
[34]19{
[554]20 // retained until the alert completes
[53]21 return [[self alloc] initWithAlarm: anAlarm movieAlert: anAlert];
[34]22}
23
[133]24- (void)close;
25{
26 [super close];
27 [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: [alert outputVolume]];
28}
29
[34]30- (void)play;
31{
32 NSTimeInterval delay;
33 if (repetitions == 0) return;
34 if (IsMovieDone((Movie)theMovie) || repetitionsRemaining == repetitions) {
35 if (repetitionsRemaining == 0) {
36 [self close];
37 return;
38 }
39 repetitionsRemaining--;
40 [movieView gotoBeginning: self];
[543]41 [movieView play: self];
[34]42 }
43 delay = (GetMovieDuration((Movie)theMovie) - GetMovieTime((Movie)theMovie, NULL)) / (double)GetMovieTimeScale((Movie)theMovie);
[60]44 // XXX should use a timebase callback for this instead (see NJRQTMediaPopUpButton); also, use QuickTimeÕs built-in loop functionality instead of rolling our own?
[34]45 [self performSelector: @selector(play) withObject: nil afterDelay: delay inModes: [NSArray arrayWithObject: NSDefaultRunLoopMode]];
46}
47
[53]48- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
[34]49{
50 if ([self initWithWindowNibName: @"Movie alert"]) {
[543]51 QTMovie *movie = [anAlert movie];
[34]52 NSWindow *window = [self window]; // connect outlets
[53]53 alarm = anAlarm;
54 alert = anAlert;
[543]55 theMovie = [movie quickTimeMovie];
[34]56 [movieView setMovie: movie];
57 if ([alert hasVideo]) {
58 NSRect screenRect = [[window screen] visibleFrame];
[543]59 NSSize movieSize = [[movie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
[60]60 NSSize minSize = [window minSize];
61 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
[34]62 NSRect frame;
[60]63 screenRect.size.height -= windowFrameHeight;
64 minSize.height -= windowFrameHeight;
[543]65 while (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height) {
66 movieSize.width /= 2;
67 movieSize.height /= 2;
[34]68 }
[60]69 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
70 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
[34]71 [window setContentSize: movieSize];
72 [window center];
73 frame = [window frame];
[45]74 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
[34]75 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
76 [window setFrame: frame display: NO];
77 [window setTitle: [alarm message]];
[53]78 { // XXX workaround for (IMO) ugly appearance of Cocoa utility windows
79 NSView *miniButton = [window standardWindowButton: NSWindowMiniaturizeButton],
80 *zoomButton = [window standardWindowButton: NSWindowZoomButton];
81 // NOTE: this will not work if the window is resizable: when the frame is reset, the standard buttons reappear
82 [miniButton setFrameOrigin: NSMakePoint(-100, -100)];
83 [zoomButton setFrameOrigin: NSMakePoint(-100, -100)];
84 [[miniButton superview] setNeedsDisplay: YES];
85 [[zoomButton superview] setNeedsDisplay: YES];
86 }
[34]87 [[self window] orderFrontRegardless];
88 }
89 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
90 repetitions = [alert repetitions];
91 repetitionsRemaining = repetitions;
[543]92 if ([movie NJR_hasAudio] && [NJRSoundManager volumeIsNotMutedOrInvalid: [alert outputVolume]] && [NJRSoundManager saveDefaultOutputVolume]) {
[133]93 [NJRSoundManager setDefaultOutputVolume: [alert outputVolume]];
94 }
[543]95 if (![movie NJR_isStatic]) [self play]; // if it's an image, don't close the window automatically
[34]96 }
97 return self;
98}
99
100- (void)dealloc;
101{
102 [[NSNotificationCenter defaultCenter] removeObserver: self];
103 [super dealloc];
104}
105
106@end
107
108@implementation PSMovieAlertController (NSWindowNotifications)
109
110- (void)windowWillClose:(NSNotification *)notification;
111{
112 repetitions = 0;
[543]113 [movieView pause: self];
[53]114 [alert completedForAlarm: alarm];
115 [self autorelease];
[34]116 // 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.
117}
118
119@end
Note: See TracBrowser for help on using the repository browser.