source: releases/Pester/1.1a1/Source/PSMovieAlertController.m@ 224

Last change on this file since 224 was 42, checked in by Nicholas Riley, 22 years ago

Fixed another MyCompanyName instance, and documented some known bugs.

File size: 3.5 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 "NSMovie-NJRExtensions.h"
13#import <QuickTime/Movies.h>
14
15// XXX if you specify a truly tiny movie, obey the minimum window size to compensate
16
17@implementation PSMovieAlertController
18
19+ (PSMovieAlertController *)controllerWithAlarm:(PSAlarm *)alarm movieAlert:(PSMovieAlert *)alert;
20{
21 return [[self alloc] initWithAlarm: alarm movieAlert: alert];
22}
23
24- (void)play;
25{
26 NSTimeInterval delay;
27 if (repetitions == 0) return;
28 if (IsMovieDone((Movie)theMovie) || repetitionsRemaining == repetitions) {
29 if (repetitionsRemaining == 0) {
30 [self close];
31 return;
32 }
33 repetitionsRemaining--;
34 [movieView gotoBeginning: self];
35 [movieView start: self];
36 }
37 delay = (GetMovieDuration((Movie)theMovie) - GetMovieTime((Movie)theMovie, NULL)) / (double)GetMovieTimeScale((Movie)theMovie);
38 [self performSelector: @selector(play) withObject: nil afterDelay: delay inModes: [NSArray arrayWithObject: NSDefaultRunLoopMode]];
39}
40
41- (id)initWithAlarm:(PSAlarm *)alarm movieAlert:(PSMovieAlert *)alert;
42{
43 if ([self initWithWindowNibName: @"Movie alert"]) {
44 NSMovie *movie = [alert movie];
45 NSWindow *window = [self window]; // connect outlets
46 [movieView setMovie: movie];
47 theMovie = [movie QTMovie];
48 if ([alert hasVideo]) {
49 NSRect screenRect = [[window screen] visibleFrame];
50 float magnification = 1.0;
51 NSSize movieSize;
52 NSRect frame;
53 screenRect.size.height -= [window frame].size.height - [[window contentView] frame].size.height; // account for height of window frame
54 while (1) {
55 movieSize = [movieView sizeForMagnification: magnification];
56 movieSize.height -= 16; // controller is hidden, but its size is included (documented, ergh)
57 if (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height)
58 magnification /= 2;
59 else
60 break;
61 }
62 [window setContentSize: movieSize];
63 [window center];
64 frame = [window frame];
65 frame.origin.y -= 250; // appear below notifier window
66 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
67 [window setFrame: frame display: NO];
68 [window setTitle: [alarm message]];
69 [[self window] orderFrontRegardless];
70 }
71 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
72 repetitions = [alert repetitions];
73 repetitionsRemaining = repetitions;
74 if (![movie isStatic]) [self play]; // if it's an image, don't close the window automatically
75 }
76 return self;
77}
78
79- (void)dealloc;
80{
81 [[NSNotificationCenter defaultCenter] removeObserver: self];
82 [super dealloc];
83}
84
85@end
86
87@implementation PSMovieAlertController (NSWindowNotifications)
88
89- (void)windowWillClose:(NSNotification *)notification;
90{
91 repetitions = 0;
92 [movieView stop: self];
93 [self release];
94 // 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.
95}
96
97@end
Note: See TracBrowser for help on using the repository browser.