[34] | 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"
|
---|
[53] | 12 | #import "NSDictionary-NJRExtensions.h"
|
---|
[34] | 13 | #import "NSMovie-NJRExtensions.h"
|
---|
[53] | 14 | #import "BDAlias.h"
|
---|
[34] | 15 |
|
---|
[53] | 16 | // property list keys
|
---|
| 17 | static NSString * const PLAlertRepetitions = @"times"; // NSString
|
---|
| 18 | static NSString * const PLAlertAlias = @"alias"; // NSData
|
---|
| 19 |
|
---|
[34] | 20 | @implementation PSMovieAlert
|
---|
| 21 |
|
---|
| 22 | + (PSMovieAlert *)alertWithMovieFileAlias:(BDAlias *)anAlias repetitions:(unsigned short)numReps;
|
---|
| 23 | {
|
---|
[53] | 24 | return [[[self alloc] initWithMovieFileAlias: anAlias repetitions: numReps] autorelease];
|
---|
[34] | 25 | }
|
---|
| 26 |
|
---|
[53] | 27 | - (id)initWithMovieFileAlias:(BDAlias *)anAlias repetitions:(unsigned int) numReps;
|
---|
[34] | 28 | {
|
---|
| 29 | if ( (self = [super init]) != nil) {
|
---|
[53] | 30 | NSString *path = [anAlias fullPath];
|
---|
| 31 | if (path == nil) {
|
---|
| 32 | [self release];
|
---|
[103] | 33 | [NSException raise: PSAlertCreationException format: NSLocalizedString(@"Can't locate media to play as alert.", "Exception message on PSMovieAlert initialization when alias doesn't resolve")];
|
---|
[53] | 34 | }
|
---|
[34] | 35 | alias = [anAlias retain];
|
---|
| 36 | repetitions = numReps;
|
---|
[60] | 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).
|
---|
[53] | 38 | movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: path] byReference: YES];
|
---|
[34] | 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 |
|
---|
[53] | 60 | - (BOOL)requiresPesterFrontmost;
|
---|
| 61 | {
|
---|
| 62 | return hasVideo;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[34] | 65 | - (NSMovie *)movie;
|
---|
| 66 | {
|
---|
| 67 | return movie;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[53] | 70 | - (BDAlias *)movieFileAlias;
|
---|
| 71 | {
|
---|
| 72 | return alias;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[34] | 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 | {
|
---|
[133] | 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] : @""];
|
---|
[34] | 90 | }
|
---|
| 91 |
|
---|
| 92 | - (void)triggerForAlarm:(PSAlarm *)alarm;
|
---|
| 93 | {
|
---|
| 94 | [PSMovieAlertController controllerWithAlarm: alarm movieAlert: self];
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[53] | 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];
|
---|
[103] | 102 | if (name == nil) name = NSLocalizedString(@"<<can't locate media file>>", "Movie alert description surrogate for media display name when alias doesn't resolve");
|
---|
[53] | 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 | }
|
---|
[133] | 108 | if (hasAudio && outputVolume != kNoVolume) {
|
---|
| 109 | [string appendAttributedString: [[NSString stringWithFormat: @" at %.0f%% volume", outputVolume * 100] small]];
|
---|
| 110 | }
|
---|
[53] | 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 | {
|
---|
[133] | 126 | if ( (self = [super initWithPropertyList: dict]) != nil)
|
---|
| 127 | [self initWithMovieFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]
|
---|
| 128 | repetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]];
|
---|
| 129 | return self;
|
---|
[53] | 130 | }
|
---|
| 131 |
|
---|
[34] | 132 | @end
|
---|