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