source: trunk/Cocoa/Pester/Source/PSMovieAlert.m@ 67

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

PSScriptAlert.m: Removed reference to NDAppleScriptObject.

PSMovieAlertController.[hm]: Added minimum sizing.

NJRCenteringMovieView.[hm]: Support for centering movie inside its
frame if the frame is too large for the movie; sizes movie
proportionally if necessary (not used in Pester).

NSImage-NJRExtensions.[hm]: Fixed copyright.

Read Me.rtfd: Updated with bug fixes.

PSMovieAlert.m: Note bug in NSMovieView, currently doesn't affect us.

NJRQTMediaPopUpButton.m: Work around background processor use bug when
NSMovieView has movie set but not playing.

NJRVoicePopUpButton.m: Removed obsolete comment.

PSApplication.m: Only show alarm set window on rapp if alerts aren't
expiring.

PSAlarms.[hm]: Added -alarmsExpiring for support of conditional
rapp window open feature in PSApplication.

PSAlarmSetController.m: Stop window update timer and movie playback on
hide, restart timer on activate - fixes background processor usage.

File size: 3.6 KB
Line 
1//
2// PSMovieAlert.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 <QuickTime/Movies.h>
10#import "PSMovieAlert.h"
11#import "PSMovieAlertController.h"
12#import "NSDictionary-NJRExtensions.h"
13#import "NSMovie-NJRExtensions.h"
14#import "BDAlias.h"
15
16// property list keys
17static NSString * const PLAlertRepetitions = @"times"; // NSString
18static NSString * const PLAlertAlias = @"alias"; // NSData
19
20@implementation PSMovieAlert
21
22+ (PSMovieAlert *)alertWithMovieFileAlias:(BDAlias *)anAlias repetitions:(unsigned short)numReps;
23{
24 return [[[self alloc] initWithMovieFileAlias: anAlias repetitions: numReps] autorelease];
25}
26
27- (id)initWithMovieFileAlias:(BDAlias *)anAlias repetitions:(unsigned int) numReps;
28{
29 if ( (self = [super init]) != nil) {
30 NSString *path = [anAlias fullPath];
31 if (path == nil) {
32 [self release];
33 [NSException raise: PSAlertCreationException format: @"CanÕt locate media to play as alert."];
34 }
35 alias = [anAlias retain];
36 repetitions = numReps;
37 // XXX if we support remote movie URLs, need to call EnterMovies() ourselves at least in Jaguar (_MacTech_ December 2002, p. 64); also should do async movie loading (p. 73Ð74).
38 movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: path] byReference: YES];
39 if (movie == nil) {
40 [self release];
41 self = nil;
42 } else {
43 hasAudio = [movie hasAudio];
44 hasVideo = [movie hasVideo];
45
46 if (!hasAudio && !hasVideo) {
47 [self release]; self = nil;
48 }
49 }
50 }
51
52 return self;
53}
54
55- (BOOL)hasVideo;
56{
57 return hasVideo;
58}
59
60- (BOOL)requiresPesterFrontmost;
61{
62 return hasVideo;
63}
64
65- (NSMovie *)movie;
66{
67 return movie;
68}
69
70- (BDAlias *)movieFileAlias;
71{
72 return alias;
73}
74
75- (unsigned short)repetitions;
76{
77 return repetitions;
78}
79
80- (void)dealloc;
81{
82 [alias release];
83 [movie release];
84 [super dealloc];
85}
86
87- (NSString *)description;
88{
89 return [NSString stringWithFormat: @"PSMovieAlert (%@%@): %@, repeats %hu times", hasAudio ? @"A" : @"", hasVideo ? @"V" : @"", [alias fullPath], repetitions];
90}
91
92- (void)triggerForAlarm:(PSAlarm *)alarm;
93{
94 [PSMovieAlertController controllerWithAlarm: alarm movieAlert: self];
95}
96
97- (NSAttributedString *)actionDescription;
98{
99 BOOL isStatic = [movie isStatic];
100 NSMutableAttributedString *string = [[(isStatic ? @"Show " : @"Play ") small] mutableCopy];
101 NSString *kindString = nil, *name = [alias displayNameWithKindString: &kindString];
102 if (name == nil) name = @"ÇcanÕt locate media fileÈ";
103 else [string appendAttributedString: [[NSString stringWithFormat: @"%@ ", kindString] small]];
104 [string appendAttributedString: [name underlined]];
105 if (repetitions > 1 && !isStatic) {
106 [string appendAttributedString: [[NSString stringWithFormat: @" %hu times", repetitions] small]];
107 }
108 return [string autorelease];
109}
110
111#pragma mark property list serialization (Pester 1.1)
112
113- (NSDictionary *)propertyListRepresentation;
114{
115 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
116 [plAlert setObject: [NSNumber numberWithUnsignedShort: repetitions] forKey: PLAlertRepetitions];
117 [plAlert setObject: [alias aliasData] forKey: PLAlertAlias];
118 return [plAlert autorelease];
119}
120
121- (id)initWithPropertyList:(NSDictionary *)dict;
122{
123 return [self initWithMovieFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]
124 repetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]];
125}
126
127@end
Note: See TracBrowser for help on using the repository browser.