source: trunk/Cocoa/Pester/Source/PSMediaAlert.m@ 547

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

Don't keep QTMovies around (and corresponding files open) for pending alarms; we could run out of file handles this way.

File size: 1.8 KB
RevLine 
[133]1//
2// PSMediaAlert.m
3// Pester
4//
5// Created by Nicholas Riley on Tue Apr 08 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "PSMediaAlert.h"
10#import "NSDictionary-NJRExtensions.h"
11#import "NJRSoundManager.h"
12
13// property list keys
14static NSString * const PLAlertRepetitions = @"times"; // NSString
15static NSString * const PLAlertOutputVolume = @"volume"; // NSNumber
16
[544]17const float PSMediaAlertNoVolume = 0;
[543]18
[133]19@implementation PSMediaAlert
20
21#pragma mark initialize-release
22
23- (id)initWithRepetitions:(unsigned short)numReps;
24{
25 if ( (self = [super init]) != nil) {
[364]26 // XXX not DRY, but can't think of a more sensible way
27 if (numReps < 1)
28 numReps = 1;
29 else if (numReps > 99)
30 numReps = 99;
31 repetitions = numReps;
[133]32 }
33 return self;
34}
35
36#pragma mark accessing
37
38- (unsigned short)repetitions;
39{
40 return repetitions;
41}
42
43- (float)outputVolume;
44{
45 return outputVolume;
46}
47
48- (void)setOutputVolume:(float)volume;
49{
50 if ([NJRSoundManager volumeIsNotMutedOrInvalid: volume])
51 outputVolume = volume;
52 else
[543]53 outputVolume = PSMediaAlertNoVolume;
[133]54}
55
56#pragma mark property list serialization (Pester 1.1)
57
58- (NSDictionary *)propertyListRepresentation;
59{
60 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
61 [plAlert setObject: [NSNumber numberWithUnsignedShort: repetitions] forKey: PLAlertRepetitions];
[543]62 if (outputVolume != PSMediaAlertNoVolume) {
[133]63 [plAlert setObject: [NSNumber numberWithFloat: outputVolume] forKey: PLAlertOutputVolume];
64 }
65 return [plAlert autorelease];
66}
67
68- (id)initWithPropertyList:(NSDictionary *)dict;
69{
70 if ( (self = [self initWithRepetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]]) != nil) {
71 [self setOutputVolume: [[dict objectForKey: PLAlertOutputVolume] floatValue]];
72 }
73 return self;
74}
75
76@end
Note: See TracBrowser for help on using the repository browser.