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

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

Remove last bits of QuickTime usage.

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 [[NSNotificationCenter defaultCenter] removeObserver: self
38 name: QTMovieRateDidChangeNotification
39 object: [movieView movie]];
40
41 [self close];
42 return;
43 }
44 repetitionsRemaining--;
45 [movieView gotoBeginning: self];
46 [movieView play: self];
47}
48
49- (void)play;
50{
51 repetitionsRemaining = repetitions - 1;
52
53 [[NSNotificationCenter defaultCenter] addObserver: self
54 selector: @selector(_movieRateDidChange:)
55 name: QTMovieRateDidChangeNotification
56 object: [movieView movie]];
57 [movieView play: self];
58}
59
60- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
61{
62 if ([self initWithWindowNibName: @"Movie alert"]) {
63 QTMovie *movie = [anAlert movie];
64 NSWindow *window = [self window]; // connect outlets
65 alarm = anAlarm;
66 alert = anAlert;
67 [movieView setMovie: movie];
68 if ([alert hasVideo]) {
69 NSRect screenRect = [[window screen] visibleFrame];
70 NSSize movieSize = [[movie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
71 NSSize minSize = [window minSize];
72 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
73 NSRect frame;
74 screenRect.size.height -= windowFrameHeight;
75 minSize.height -= windowFrameHeight;
76 while (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height) {
77 movieSize.width /= 2;
78 movieSize.height /= 2;
79 }
80 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
81 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
82 [window setContentSize: movieSize];
83 [window center];
84 frame = [window frame];
85 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
86 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
87 [window setFrame: frame display: NO];
88 [window setTitle: [alarm message]];
89 { // XXX workaround for (IMO) ugly appearance of Cocoa utility windows
90 NSView *miniButton = [window standardWindowButton: NSWindowMiniaturizeButton],
91 *zoomButton = [window standardWindowButton: NSWindowZoomButton];
92 // NOTE: this will not work if the window is resizable: when the frame is reset, the standard buttons reappear
93 [miniButton setFrameOrigin: NSMakePoint(-100, -100)];
94 [zoomButton setFrameOrigin: NSMakePoint(-100, -100)];
95 [[miniButton superview] setNeedsDisplay: YES];
96 [[zoomButton superview] setNeedsDisplay: YES];
97 }
98 [[self window] orderFrontRegardless];
99 }
100 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
101 repetitions = [alert repetitions];
102 if ([movie NJR_hasAudio] && [NJRSoundManager volumeIsNotMutedOrInvalid: [alert outputVolume]] && [NJRSoundManager saveDefaultOutputVolume]) {
103 [NJRSoundManager setDefaultOutputVolume: [alert outputVolume]];
104 }
105 if (![movie NJR_isStatic]) [self play]; // if it's an image, don't close the window automatically
106 }
107 return self;
108}
109
110- (void)dealloc;
111{
112 [[NSNotificationCenter defaultCenter] removeObserver: self];
113 [super dealloc];
114}
115
116@end
117
118@implementation PSMovieAlertController (NSWindowNotifications)
119
120- (void)windowWillClose:(NSNotification *)notification;
121{
122 repetitions = 0;
123 [movieView pause: self];
124 [alert completedForAlarm: alarm];
125 [self autorelease];
126 // 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.
127}
128
129@end
Note: See TracBrowser for help on using the repository browser.