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.)
2 Copyright (c) The Growl Project, 2004-2005
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
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.
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.
29 // GrowlMailPreferencesModule.m
32 // Created by Ingmar Stein on 29.10.04.
35 #import "GrowlMailPreferencesModule.h"
36 #import "GrowlMailNotifier.h"
38 @interface MailAccount(GrowlMail)
39 + (NSArray *) remoteMailAccounts;
42 @implementation MailAccount(GrowlMail)
43 + (NSArray *) remoteMailAccounts; {
44 NSArray *mailAccounts = [MailAccount mailAccounts];
45 NSMutableArray *remoteAccounts = [NSMutableArray arrayWithCapacity:[mailAccounts count]];
46 NSEnumerator *enumerator = [mailAccounts objectEnumerator];
48 Class localAccountClass = [LocalAccount class];
49 while ((account = [enumerator nextObject])) {
50 if (![account isKindOfClass:localAccountClass])
51 [remoteAccounts addObject:account];
54 return remoteAccounts;
58 @implementation GrowlMailPreferencesModule
59 - (void) awakeFromNib {
60 NSTableColumn *activeColumn = [accountsView tableColumnWithIdentifier:@"active"];
61 [[activeColumn dataCell] setImagePosition:NSImageOnly]; // center the checkbox
64 - (NSString *) preferencesNibName {
65 return @"GrowlMailPreferencesPanel";
68 - (NSView *)preferencesView
70 if (!view_preferences)
71 [NSBundle loadNibNamed:[self preferencesNibName] owner:self];
72 return view_preferences;
75 - (id) viewForPreferenceNamed:(NSString *)aName {
77 return [self preferencesView];
80 - (NSString *) titleForIdentifier:(NSString *)aName {
85 - (NSImage *) imageForPreferenceNamed:(NSString *)aName {
86 return [NSImage imageNamed:aName];
90 return [[self preferencesView] frame].size;
93 - (BOOL) isResizable {
97 - (int) numberOfRowsInTableView:(NSTableView *)aTableView {
98 #pragma unused(aTableView)
99 return [[MailAccount remoteMailAccounts] count];
102 - (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
103 #pragma unused(aTableView)
104 MailAccount *account = [[MailAccount remoteMailAccounts] objectAtIndex:rowIndex];
105 if ([[aTableColumn identifier] isEqualToString:@"active"])
106 return [NSNumber numberWithBool:[[GrowlMailNotifier sharedNotifier] isAccountEnabled:account]];
108 return [account displayName];
111 - (void) tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
112 #pragma unused(aTableView,aTableColumn)
113 MailAccount *account = [[MailAccount remoteMailAccounts] objectAtIndex:rowIndex];
114 [[GrowlMailNotifier sharedNotifier] setAccount:account enabled:[anObject boolValue]];