1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#import <AppKit/AppKitDefines.h>
#import <AppKit/NSSound.h>
#import "AlarmBackend.h"
#import "Alarm.h"
@interface SoundBackend : AlarmBackend
{
NSSound *sound;
}
@end
static NSString *logKey = @"SoundBackend";
static NSMutableArray *sounds;
@implementation SoundBackend
+ (void)initialize
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *path, *file;
NSArray *paths, *files;
NSEnumerator *enumerator, *fenum;
if ([SoundBackend class] == self) {
NSDebugLLog(logKey, @"SoundBackend initialize");
sounds = [[NSMutableArray alloc] initWithCapacity:8];
paths = NSStandardLibraryPaths();
enumerator = [paths objectEnumerator];
while ((path = [enumerator nextObject])) {
path = [path stringByAppendingPathComponent:@"/Sounds/"];
files = [fm directoryContentsAtPath:path];
if (files) {
fenum = [files objectEnumerator];
while ((file = [fenum nextObject])) {
if ([NSSound soundNamed:[file stringByDeletingPathExtension]]) {
[sounds addObject:[file stringByDeletingPathExtension]];
NSDebugLLog(logKey, @"Loaded sound %@", file);
} else {
NSDebugLLog(logKey, @"Failed loading sound %@", file);
}
}
}
}
}
}
+ (NSString *)backendName
{
return @"Sound notification";
}
- (enum icalproperty_action)backendType
{
return ICAL_ACTION_AUDIO;
}
- (id)init
{
self = [super init];
if (self) {
sound = [NSSound soundNamed:@"Basso"];
if (!sound) {
NSDebugLLog(logKey, @"Could not find Basso default sound, SoundBackend disabled");
[self release];
self = nil;
}
}
return self;
}
- (void)display:(Alarm *)alarm
{
[sound play];
}
@end
|