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.)
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.
tick@796
    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
*/
ingmarstein@565
    28
//
ingmarstein@565
    29
//  GrowlMailPreferencesModule.m
ingmarstein@565
    30
//  GrowlMail
ingmarstein@565
    31
//
ingmarstein@565
    32
//  Created by Ingmar Stein on 29.10.04.
ingmarstein@565
    33
//
ingmarstein@565
    34
ingmarstein@565
    35
#import "GrowlMailPreferencesModule.h"
hg@4209
    36
#import "GrowlMailNotifier.h"
ingmarstein@565
    37
ingmarstein@581
    38
@interface MailAccount(GrowlMail)
ingmarstein@1713
    39
+ (NSArray *) remoteMailAccounts;
ingmarstein@581
    40
@end
ingmarstein@581
    41
ingmarstein@581
    42
@implementation MailAccount(GrowlMail)
ingmarstein@1713
    43
+ (NSArray *) remoteMailAccounts; {
ingmarstein@581
    44
	NSArray *mailAccounts = [MailAccount mailAccounts];
ingmarstein@1655
    45
	NSMutableArray *remoteAccounts = [NSMutableArray arrayWithCapacity:[mailAccounts count]];
ingmarstein@581
    46
	NSEnumerator *enumerator = [mailAccounts objectEnumerator];
ingmarstein@581
    47
	id account;
ingmarstein@581
    48
	Class localAccountClass = [LocalAccount class];
ingmarstein@1655
    49
	while ((account = [enumerator nextObject])) {
ingmarstein@2284
    50
		if (![account isKindOfClass:localAccountClass])
ingmarstein@581
    51
			[remoteAccounts addObject:account];
ingmarstein@581
    52
	}
ingmarstein@581
    53
ingmarstein@1141
    54
	return remoteAccounts;
ingmarstein@581
    55
}
ingmarstein@581
    56
@end
ingmarstein@581
    57
ingmarstein@565
    58
@implementation GrowlMailPreferencesModule
ingmarstein@1713
    59
- (void) awakeFromNib {
ingmarstein@581
    60
	NSTableColumn *activeColumn = [accountsView tableColumnWithIdentifier:@"active"];
ingmarstein@1905
    61
	[[activeColumn dataCell] setImagePosition:NSImageOnly]; // center the checkbox
ingmarstein@581
    62
}
ingmarstein@581
    63
ingmarstein@1713
    64
- (NSString *) preferencesNibName {
ingmarstein@1141
    65
	return @"GrowlMailPreferencesPanel";
ingmarstein@565
    66
}
ingmarstein@565
    67
evands@4001
    68
- (NSView *)preferencesView
evands@4001
    69
{
evands@4001
    70
	if (!view_preferences)
evands@4001
    71
		[NSBundle loadNibNamed:[self preferencesNibName] owner:self];
evands@4001
    72
	return view_preferences;
evands@4001
    73
}
evands@4001
    74
ingmarstein@1713
    75
- (id) viewForPreferenceNamed:(NSString *)aName {
ingmarstein@1865
    76
#pragma unused(aName)
evands@4001
    77
	return [self preferencesView];
ingmarstein@565
    78
}
ingmarstein@565
    79
ingmarstein@1713
    80
- (NSString *) titleForIdentifier:(NSString *)aName {
ingmarstein@1865
    81
#pragma unused(aName)
ingmarstein@1141
    82
	return @"GrowlMail";
ingmarstein@565
    83
}
ingmarstein@565
    84
ingmarstein@1713
    85
- (NSImage *) imageForPreferenceNamed:(NSString *)aName {
ingmarstein@2284
    86
	return [NSImage imageNamed:aName];
ingmarstein@565
    87
}
ingmarstein@565
    88
ingmarstein@1713
    89
- (NSSize) minSize {
evands@4001
    90
	return [[self preferencesView] frame].size;
evands@4001
    91
}
evands@4001
    92
evands@4001
    93
- (BOOL) isResizable {
evands@4001
    94
	return NO;
ingmarstein@565
    95
}
ingmarstein@565
    96
ingmarstein@1713
    97
- (int) numberOfRowsInTableView:(NSTableView *)aTableView {
ingmarstein@1865
    98
#pragma unused(aTableView)
ingmarstein@1141
    99
	return [[MailAccount remoteMailAccounts] count];
ingmarstein@581
   100
}
ingmarstein@581
   101
ingmarstein@1713
   102
- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
ingmarstein@1865
   103
#pragma unused(aTableView)
ingmarstein@581
   104
	MailAccount *account = [[MailAccount remoteMailAccounts] objectAtIndex:rowIndex];
ingmarstein@2284
   105
	if ([[aTableColumn identifier] isEqualToString:@"active"])
hg@4209
   106
		return [NSNumber numberWithBool:[[GrowlMailNotifier sharedNotifier] isAccountEnabled:account]];
ingmarstein@2284
   107
	else
ingmarstein@1141
   108
		return [account displayName];
ingmarstein@581
   109
}
ingmarstein@581
   110
ingmarstein@1713
   111
- (void) tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
ingmarstein@2284
   112
#pragma unused(aTableView,aTableColumn)
ingmarstein@581
   113
	MailAccount *account = [[MailAccount remoteMailAccounts] objectAtIndex:rowIndex];
hg@4209
   114
	[[GrowlMailNotifier sharedNotifier] setAccount:account enabled:[anObject boolValue]];
ingmarstein@581
   115
}
ingmarstein@581
   116
ingmarstein@565
   117
@end