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

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

Minimally convert media playback to QTKit. Some direct QuickTime access still needs migrating.

File size: 4.2 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 "QTMovie-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: NSLocalizedString(@"Can't locate media to play as alert.", "Exception message on PSMovieAlert initialization when alias doesn't resolve")];
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 = [[QTMovie alloc] initWithFile: path error: NULL];
39 if (movie == nil) {
40 [self release];
41 self = nil;
42 } else {
43 hasAudio = [movie NJR_hasAudio];
44 hasVideo = [movie NJR_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- (QTMovie *)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, hasAudio && outputVolume != kNoVolume ? [NSString stringWithFormat: @" at %.0f%% volume", outputVolume * 100] : @""];
90}
91
92- (void)triggerForAlarm:(PSAlarm *)alarm;
93{
94 [PSMovieAlertController controllerWithAlarm: alarm movieAlert: self];
95}
96
97- (NSAttributedString *)actionDescription;
98{
99 BOOL isStatic = [movie NJR_isStatic];
100 NSMutableAttributedString *string = [[(isStatic ? @"Show " : @"Play ") small] mutableCopy];
101 NSString *kindString = nil, *name = [alias displayNameWithKindString: &kindString];
102 if (name == nil) name = NSLocalizedString(@"<<can't locate media file>>", "Movie alert description surrogate for media display name when alias doesn't resolve");
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 if (hasAudio && outputVolume != kNoVolume) {
109 [string appendAttributedString: [[NSString stringWithFormat: @" at %.0f%% volume", outputVolume * 100] small]];
110 }
111 return [string autorelease];
112}
113
114#pragma mark property list serialization (Pester 1.1)
115
116- (NSDictionary *)propertyListRepresentation;
117{
118 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
119 [plAlert setObject: [NSNumber numberWithUnsignedShort: repetitions] forKey: PLAlertRepetitions];
120 [plAlert setObject: [alias aliasData] forKey: PLAlertAlias];
121 return [plAlert autorelease];
122}
123
124- (id)initWithPropertyList:(NSDictionary *)dict;
125{
126 if ( (self = [super initWithPropertyList: dict]) != nil)
127 [self initWithMovieFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]
128 repetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]];
129 return self;
130}
131
132@end
Note: See TracBrowser for help on using the repository browser.