Plugins/Displays/Speech/GrowlSpeechDisplay.m
author Rudy Richter
Sat Aug 01 20:43:39 2009 -0400 (2009-08-01)
changeset 4259 0e9b6b0b1e25
parent 3280 b9c833c157ce
child 4477 49d5f4f052c8
permissions -rw-r--r--
Plugins: clang warnings
     1 //
     2 //  GrowlSpeechDisplay.m
     3 //  Display Plugins
     4 //
     5 //  Created by Ingmar Stein on 15.11.04.
     6 //  Copyright 2004-2006 The Growl Project. All rights reserved.
     7 //
     8 
     9 #import "GrowlSpeechDisplay.h"
    10 #import "GrowlSpeechPrefs.h"
    11 #import "GrowlSpeechDefines.h"
    12 #import "GrowlPathUtilities.h"
    13 #import "GrowlDefinesInternal.h"
    14 #import "GrowlApplicationNotification.h"
    15 #include "CFDictionaryAdditions.h"
    16 
    17 @implementation GrowlSpeechDisplay
    18 
    19 - (void) dealloc {
    20 	[preferencePane release];
    21 	[super dealloc];
    22 }
    23 
    24 - (NSPreferencePane *) preferencePane {
    25 	if (!preferencePane)
    26 		preferencePane = [[GrowlSpeechPrefs alloc] initWithBundle:[NSBundle bundleWithIdentifier:@"com.growl.Speech"]];
    27 	return preferencePane;
    28 }
    29 
    30 - (void) displayNotification:(GrowlApplicationNotification *)notification {
    31 	NSString *voice = nil;
    32 	READ_GROWL_PREF_VALUE(GrowlSpeechVoicePref, GrowlSpeechPrefDomain, NSString *, &voice);
    33 	if (voice) {
    34 		CFMakeCollectable(voice);
    35 		[voice autorelease];
    36 	} else {
    37 		voice = [NSSpeechSynthesizer defaultVoice];
    38 	}
    39 	
    40 	NSString *desc = [notification notificationDescription];
    41 
    42 	NSSpeechSynthesizer *syn = [[NSSpeechSynthesizer alloc] initWithVoice:voice];
    43 	[syn startSpeakingString:desc];
    44 
    45 	NSDictionary *noteDict = [notification dictionaryRepresentation];
    46 	if (getBooleanForKey(noteDict, GROWL_SCREENSHOT_MODE)) {
    47 		NSString *path = [[[GrowlPathUtilities screenshotsDirectory] stringByAppendingPathComponent:[GrowlPathUtilities nextScreenshotName]] stringByAppendingPathExtension:@"aiff"];
    48 		NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
    49 		[syn startSpeakingString:desc toURL:url];
    50 		[url release];
    51 	}
    52 
    53 	[syn autorelease];
    54 
    55 	id clickContext = getObjectForKey(noteDict, GROWL_NOTIFICATION_CLICK_CONTEXT);
    56 	if (clickContext) {
    57 		NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
    58 			getObjectForKey(noteDict, @"ClickHandlerEnabled"), @"ClickHandlerEnabled",
    59 			clickContext,                                      GROWL_KEY_CLICKED_CONTEXT,
    60 			getObjectForKey(noteDict, GROWL_APP_PID),          GROWL_APP_PID,
    61 			nil];
    62 		[[NSNotificationCenter defaultCenter] postNotificationName:GROWL_NOTIFICATION_TIMED_OUT
    63 															object:[notification applicationName]
    64 														  userInfo:userInfo];
    65 		[userInfo release];
    66 	}
    67 }
    68 
    69 - (BOOL)requiresPositioning {
    70 	return NO;
    71 }
    72 
    73 @end