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

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

VERSION: Updated for 1.1b4.

PSMovieAlertController.[hm]: Set output volume from alert; save and
restore output volume (bug 27).

PSBeepAlert.[hm]: Save and set volume, disabled pending a
synchronous equivalent to NSBeep().

NJRQTMediaPopUpButton.[hm]: Save movieHasAudio (does not include
beeps, pending the above fix, since they don't permit volume
adjustment). savedVolume indicates whether the volume has been saved
but not restored yet; outputVolume stores the set volume (eventually
incorporated into a PSMediaAlert).

PSMediaAlert.[hm]: Stores repetitions and volume information for audio
alerts. New superclass of PSBeepAlert and PSMovieAlert.

PSPreferencesController.m: Fixed bug where hot keys still appeared
even after they couldn't be set - last of bug 29. Add Command-comma
to the list of disallowed equivalents, as it's reserved for
Preferences now (still a bug - it'll show the entire set key
equivalent at the left side of the window when you press
command-comma; ah well.)

Volume [0123].png: Volume-indicating small icons from QuickTime 6.

NJRSoundManager.[hm]: Interface to volume saving, restoring, setting -
necessary because the QuickTime call to SetDefaultOutputVolume sets
the right channel volume only (bug 27).

PSVolumeController.h: Controller for volume popup window (bug 27).
Not your average NSWindowController, but it works. Keyboard control
of volume is still necessary; filed as bug 31.

PSAlarmSetController.[hm]: Added references to sound volume button and
showVolume: action. Added volume setting support (bug 27); mostly
similar interface to calendar, though we need direct calls to
NJRSoundManager to restore sound volume at times. Only enable sound
volume button if selected media file has audio component (and isn't the
system alert sound, which I discussed above). Take advantage of
PSMediaAlert to factor some code in _readAlerts:. Save and restore
volume as part of alerts.

Read Me.rtfd: Updated release notes; fixed some bizarre text
formatting problems; search/replace "* " bullet-space with "*\t"
bullet-tab to improve alignment in release notes.

PSMovieAlert.[hm]: Factored code into PSMediaAlert. Describe output
volume as percentage of maximum.

NJRHotKey.m: Fixed some odd spacing left over from Ecky's code.

PSApplication.m: Restore saved output volume on quit.

English.lproj/MainMenu.nib: Added volume button.

English.lproj/Volume.nib: Volume nib (bug 27).

PSCalendarController.m: Removed casts from a copy/paste error. Fixed
variable names in some code inherited from my TextExtras incremental
search modifications - it's not always a text field now.

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 "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: 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 = [[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, 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 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.