source: releases/Pester/1.1a5/Source/PSMovieAlert.m@ 102

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

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

File size: 3.5 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 movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: path] byReference: YES];
38 if (movie == nil) {
39 [self release];
40 self = nil;
41 } else {
42 hasAudio = [movie hasAudio];
43 hasVideo = [movie hasVideo];
44
45 if (!hasAudio && !hasVideo) {
46 [self release]; self = nil;
47 }
48 }
49 }
50
51 return self;
52}
53
54- (BOOL)hasVideo;
55{
56 return hasVideo;
57}
58
59- (BOOL)requiresPesterFrontmost;
60{
61 return hasVideo;
62}
63
64- (NSMovie *)movie;
65{
66 return movie;
67}
68
69- (BDAlias *)movieFileAlias;
70{
71 return alias;
72}
73
74- (unsigned short)repetitions;
75{
76 return repetitions;
77}
78
79- (void)dealloc;
80{
81 [alias release];
82 [movie release];
83 [super dealloc];
84}
85
86- (NSString *)description;
87{
88 return [NSString stringWithFormat: @"PSMovieAlert (%@%@): %@, repeats %hu times", hasAudio ? @"A" : @"", hasVideo ? @"V" : @"", [alias fullPath], repetitions];
89}
90
91- (void)triggerForAlarm:(PSAlarm *)alarm;
92{
93 [PSMovieAlertController controllerWithAlarm: alarm movieAlert: self];
94}
95
96- (NSAttributedString *)actionDescription;
97{
98 BOOL isStatic = [movie isStatic];
99 NSMutableAttributedString *string = [[(isStatic ? @"Show " : @"Play ") small] mutableCopy];
100 NSString *kindString = nil, *name = [alias displayNameWithKindString: &kindString];
101 if (name == nil) name = @"ÇcanÕt locate media fileÈ";
102 else [string appendAttributedString: [[NSString stringWithFormat: @"%@ ", kindString] small]];
103 [string appendAttributedString: [name underlined]];
104 if (repetitions > 1 && !isStatic) {
105 [string appendAttributedString: [[NSString stringWithFormat: @" %hu times", repetitions] small]];
106 }
107 return [string autorelease];
108}
109
110#pragma mark property list serialization (Pester 1.1)
111
112- (NSDictionary *)propertyListRepresentation;
113{
114 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
115 [plAlert setObject: [NSNumber numberWithUnsignedShort: repetitions] forKey: PLAlertRepetitions];
116 [plAlert setObject: [alias aliasData] forKey: PLAlertAlias];
117 return [plAlert autorelease];
118}
119
120- (id)initWithPropertyList:(NSDictionary *)dict;
121{
122 return [self initWithMovieFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]
123 repetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]];
124}
125
126@end
Note: See TracBrowser for help on using the repository browser.