Extras/GrowlMail/GrowlMail.m
author Peter Hosey <hg@boredzo.org>
Sat Jun 06 21:30:17 2009 -0700 (2009-06-06)
changeset 4209 f8a902d33769
parent 4178 9ea7cd00514b
child 4277 61dc661bdb56
permissions -rw-r--r--
Refactored GrowlMail to have a separate singleton notifier object, in order to make the mail-bundle class less dependent on being a singleton. (Assumptions are bad, especially when you're working with private/undocumented APIs.)
     1 /*
     2  Copyright (c) The Growl Project, 2004-2005
     3  All rights reserved.
     4 
     5  Redistribution and use in source and binary forms, with or without modification,
     6  are permitted provided that the following conditions are met:
     7 
     8  1. Redistributions of source code must retain the above copyright
     9  notice, this list of conditions and the following disclaimer.
    10  2. Redistributions in binary form must reproduce the above copyright
    11  notice, this list of conditions and the following disclaimer in the
    12  documentation and/or other materials provided with the distribution.
    13  3. Neither the name of Growl nor the names of its contributors
    14  may be used to endorse or promote products derived from this software
    15  without specific prior written permission.
    16 
    17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    21  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    22  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    24  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    25  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    26  OF THE POSSIBILITY OF SUCH DAMAGE.
    27 */
    28 //
    29 //  GrowlMail.m
    30 //  GrowlMail
    31 //
    32 //  Created by Adam Iser on Mon Jul 26 2004.
    33 //  Copyright (c) 2004-2005 The Growl Project. All rights reserved.
    34 //
    35 
    36 #import "GrowlMail.h"
    37 
    38 #import "GrowlMailNotifier.h"
    39 
    40 NSBundle *GMGetGrowlMailBundle(void) {
    41 	return [NSBundle bundleForClass:[GrowlMail class]];
    42 }
    43 
    44 @implementation GrowlMail
    45 
    46 #pragma mark Boring bookkeeping stuff
    47 
    48 + (void) initialize {
    49 	[super initialize];
    50 
    51 	// this image is leaked
    52 	NSImage *image = [[NSImage alloc] initByReferencingFile:[GMGetGrowlMailBundle() pathForImageResource:@"GrowlMail"]];
    53 	[image setName:@"GrowlMail"];
    54 
    55 	[GrowlMail registerBundle];
    56 
    57 	NSLog(@"Loaded GrowlMail %@", [GMGetGrowlMailBundle() objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]);
    58 }
    59 
    60 + (BOOL) hasPreferencesPanel {
    61 	return YES;
    62 }
    63 
    64 + (NSString *) preferencesOwnerClassName {
    65 	return @"GrowlMailPreferencesModule";
    66 }
    67 
    68 + (NSString *) preferencesPanelName {
    69 	return @"GrowlMail";
    70 }
    71 
    72 - (id) init {
    73 	if ((self = [super init])) {
    74 		NSString *privateFrameworksPath = [GMGetGrowlMailBundle() privateFrameworksPath];
    75 		NSString *growlBundlePath = [privateFrameworksPath stringByAppendingPathComponent:@"Growl.framework"];
    76 
    77 		NSBundle *growlBundle = [NSBundle bundleWithPath:growlBundlePath];
    78 		if (growlBundle) {
    79 			if ([growlBundle load]) {
    80 				if ([GrowlApplicationBridge respondsToSelector:@selector(frameworkInfoDictionary)]) {
    81 					//Create or obtain our singleton notifier instance.
    82 					notifier = [[GrowlMailNotifier alloc] init];
    83 					if (!notifier)
    84 						NSLog(@"Could not initialize GrowlMail notifier object");
    85 
    86 					NSDictionary *infoDictionary = [GrowlApplicationBridge frameworkInfoDictionary];
    87 					NSLog(@"Using Growl.framework %@ (%@)",
    88 						  [infoDictionary objectForKey:@"CFBundleShortVersionString"],
    89 						  [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]);
    90 				} else {
    91 					NSLog(@"Using a version of Growl.framework older than 1.1. One of the other installed Mail plugins should be updated to Growl.framework 1.1 or later.");
    92 				}
    93 			}
    94 		} else {
    95 			NSLog(@"Could not load Growl.framework, GrowlMail disabled");
    96 		}
    97 	}
    98 
    99 	return self;
   100 }
   101 
   102 - (void) dealloc {
   103 	[notifier release];
   104 
   105 	[super dealloc];
   106 }
   107 
   108 @end