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
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
36 if (repetitions == 0 || repetitionsRemaining == 0) {
37 [[NSNotificationCenter defaultCenter] removeObserver: self
38 name: QTMovieRateDidChangeNotification
39 object: [movieView movie]];
40
41 [self close];
42 return;
[34]43 }
[569]44 repetitionsRemaining--;
45 [movieView gotoBeginning: self];
46 [movieView play: self];
[34]47}
48
[569]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
[53]60- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
[34]61{
62 if ([self initWithWindowNibName: @"Movie alert"]) {
[543]63 QTMovie *movie = [anAlert movie];
[34]64 NSWindow *window = [self window]; // connect outlets
[53]65 alarm = anAlarm;
66 alert = anAlert;
[34]67 [movieView setMovie: movie];
68 if ([alert hasVideo]) {
69 NSRect screenRect = [[window screen] visibleFrame];
[543]70 NSSize movieSize = [[movie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
[60]71 NSSize minSize = [window minSize];
72 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
[34]73 NSRect frame;
[60]74 screenRect.size.height -= windowFrameHeight;
75 minSize.height -= windowFrameHeight;
[543]76 while (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height) {
77 movieSize.width /= 2;
78 movieSize.height /= 2;
[34]79 }
[60]80 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
81 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
[34]82 [window setContentSize: movieSize];
83 [window center];
84 frame = [window frame];
[45]85 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
[34]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]];
[53]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 }
[34]98 [[self window] orderFrontRegardless];
99 }
100 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
101 repetitions = [alert repetitions];
[543]102 if ([movie NJR_hasAudio] && [NJRSoundManager volumeIsNotMutedOrInvalid: [alert outputVolume]] && [NJRSoundManager saveDefaultOutputVolume]) {
[133]103 [NJRSoundManager setDefaultOutputVolume: [alert outputVolume]];
104 }
[543]105 if (![movie NJR_isStatic]) [self play]; // if it's an image, don't close the window automatically
[34]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;
[543]123 [movieView pause: self];
[53]124 [alert completedForAlarm: alarm];
125 [self autorelease];
[34]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.