Extras/GrowlMail/GrowlMailPreferencesModule.m
author Peter Hosey <hg@boredzo.org>
Sat Jun 06 21:30:17 2009 -0700 (2009-06-06)
changeset 4209 f8a902d33769
parent 4001 823a48a1b49d
child 4455 a044002973b5
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 //  GrowlMailPreferencesModule.m
    30 //  GrowlMail
    31 //
    32 //  Created by Ingmar Stein on 29.10.04.
    33 //
    34 
    35 #import "GrowlMailPreferencesModule.h"
    36 #import "GrowlMailNotifier.h"
    37 
    38 @interface MailAccount(GrowlMail)
    39 + (NSArray *) remoteMailAccounts;
    40 @end
    41 
    42 @implementation MailAccount(GrowlMail)
    43 + (NSArray *) remoteMailAccounts; {
    44 	NSArray *mailAccounts = [MailAccount mailAccounts];
    45 	NSMutableArray *remoteAccounts = [NSMutableArray arrayWithCapacity:[mailAccounts count]];
    46 	NSEnumerator *enumerator = [mailAccounts objectEnumerator];
    47 	id account;
    48 	Class localAccountClass = [LocalAccount class];
    49 	while ((account = [enumerator nextObject])) {
    50 		if (![account isKindOfClass:localAccountClass])
    51 			[remoteAccounts addObject:account];
    52 	}
    53 
    54 	return remoteAccounts;
    55 }
    56 @end
    57 
    58 @implementation GrowlMailPreferencesModule
    59 - (void) awakeFromNib {
    60 	NSTableColumn *activeColumn = [accountsView tableColumnWithIdentifier:@"active"];
    61 	[[activeColumn dataCell] setImagePosition:NSImageOnly]; // center the checkbox
    62 }
    63 
    64 - (NSString *) preferencesNibName {
    65 	return @"GrowlMailPreferencesPanel";
    66 }
    67 
    68 - (NSView *)preferencesView
    69 {
    70 	if (!view_preferences)
    71 		[NSBundle loadNibNamed:[self preferencesNibName] owner:self];
    72 	return view_preferences;
    73 }
    74 
    75 - (id) viewForPreferenceNamed:(NSString *)aName {
    76 #pragma unused(aName)
    77 	return [self preferencesView];
    78 }
    79 
    80 - (NSString *) titleForIdentifier:(NSString *)aName {
    81 #pragma unused(aName)
    82 	return @"GrowlMail";
    83 }
    84 
    85 - (NSImage *) imageForPreferenceNamed:(NSString *)aName {
    86 	return [NSImage imageNamed:aName];
    87 }
    88 
    89 - (NSSize) minSize {
    90 	return [[self preferencesView] frame].size;
    91 }
    92 
    93 - (BOOL) isResizable {
    94 	return NO;
    95 }
    96 
    97 - (int) numberOfRowsInTableView:(NSTableView *)aTableView {
    98 #pragma unused(aTableView)
    99 	return [[MailAccount remoteMailAccounts] count];
   100 }
   101 
   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]];
   107 	else
   108 		return [account displayName];
   109 }
   110 
   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]];
   115 }
   116 
   117 @end