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

Last change on this file since 36 was 34, checked in by Nicholas Riley, 21 years ago

Changes for Pester 1.1d1.

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