[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];
|
---|
| 33 | [NSException raise: PSAlertCreationException format: @"CanÕt locate media to play as alert."];
|
---|
| 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 | {
|
---|
| 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 |
|
---|
[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];
|
---|
| 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 |
|
---|
[34] | 127 | @end
|
---|