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