2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIAccountController.h"
18 #import "AIContactAccountsPane.h"
19 #import "AIContactController.h"
20 #import <AIUtilities/AIAlternatingRowTableView.h>
21 #import <AIUtilities/AIMenuAdditions.h>
22 #import <AIUtilities/AIPopUpButtonAdditions.h>
23 #import <Adium/AIAccount.h>
24 #import <Adium/AIListContact.h>
25 #import <Adium/AIListObject.h>
26 #import <Adium/AIListGroup.h>
27 #import <Adium/AILocalizationTextField.h>
28 #import <Adium/AIMetaContact.h>
30 @interface AIContactAccountsPane (PRIVATE)
31 - (void)updateAccountList;
32 - (void)updateGroupList;
36 * @class AIContactAccountsPane
37 * @brief Accounts pane in the contact info window
39 * Provides a list of what accounts list a contact and in what group.
41 @implementation AIContactAccountsPane
43 //Preference pane properties
47 - (CONTACT_INFO_CATEGORY)contactInfoCategory{
48 return(AIInfo_Accounts);
54 - (NSString *)nibName{
55 return(@"ContactAccounts");
59 * @brief Configure the preference view
63 [label_listedOnTheFollowingOfYourAccounts setLocalizedString:AILocalizedString(@"Listed on the following of your accounts:",nil)];
65 //Configure Table view
66 [tableView_accounts setDrawsAlternatingRows:YES];
67 [tableView_accounts setAcceptsFirstMouse:YES];
68 [[[tableView_accounts tableColumnWithIdentifier:@"account"] headerCell] setTitle:AILocalizedString(@"On Account",nil)];
69 [[[tableView_accounts tableColumnWithIdentifier:@"group"] headerCell] setTitle:AILocalizedString(@"In Group",nil)];
71 //Observe contact list changes
72 [[adium notificationCenter] addObserver:self
73 selector:@selector(updateGroupList)
74 name:Contact_ListChanged
76 [self updateGroupList];
78 //Observe account changes
79 [[adium notificationCenter] addObserver:self
80 selector:@selector(updateAccountList)
81 name:Account_ListChanged
83 [self updateAccountList];
87 * @brief Preference view is closing
91 [accounts release]; accounts = nil;
92 [listObject release]; listObject = nil;
93 [[adium notificationCenter] removeObserver:self];
97 * @brief Configure the pane for a list object
99 - (void)configureForListObject:(AIListObject *)inObject
102 [listObject release];
103 listObject = [inObject retain];
105 //Rebuild our account list
106 [self updateAccountList];
110 * @brief Update our list of accounts
112 - (void)updateAccountList
114 //Get the new accounts
117 if ([listObject isKindOfClass:[AIMetaContact class]]){
118 NSEnumerator *enumerator;
119 NSString *serviceClass;
121 accounts = [[NSMutableArray alloc] init];
122 enumerator = [[(AIMetaContact *)listObject dictionaryOfServiceClassesAndListContacts] keyEnumerator];
123 while (serviceClass = [enumerator nextObject]){
124 [(NSMutableArray *)accounts addObjectsFromArray:[[adium accountController] accountsWithServiceClass:serviceClass]];
128 accounts = [[[adium accountController] accountsWithServiceClassOfService:[listObject service]] retain];
132 [tableView_accounts reloadData];
136 * @brief Update our list of groups
138 - (void)updateGroupList
141 NSMenu *groupMenu = [[adium contactController] menuOfAllGroupsInGroup:nil withTarget:self];
142 NSMenuItem *unlistedItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"(Not Listed)",nil)
144 action:@selector(selectGroup:)
145 keyEquivalent:@""] autorelease];
146 [groupMenu insertItem:[NSMenuItem separatorItem] atIndex:0];
147 [groupMenu insertItem:unlistedItem atIndex:0];
149 [[[tableView_accounts tableColumnWithIdentifier:@"group"] dataCell] setMenu:groupMenu];
152 [tableView_accounts reloadData];
156 //Table View Data Sources ----------------------------------------------------------------------------------------------
157 #pragma mark TableView Data Sources
159 * @brief Number of table view rows
161 - (int)numberOfRowsInTableView:(NSTableView *)tableView
163 return([accounts count]);
167 * @brief Table view object value
169 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
171 NSString *identifier = [tableColumn identifier];
172 AIAccount *account = [accounts objectAtIndex:row];
174 if([identifier isEqualToString:@"account"]){
175 NSString *accountFormattedUID = [account formattedUID];
177 if([account integerStatusObjectForKey:@"Online"]){
178 return(accountFormattedUID);
181 //Gray the names of offline accounts
182 NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSColor grayColor] forKey:NSForegroundColorAttributeName];
183 NSAttributedString *string = [[NSAttributedString alloc] initWithString:accountFormattedUID attributes:attributes];
184 return([string autorelease]);
193 * @brief Table view will display a cell
195 - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(int)row
197 NSString *identifier = [tableColumn identifier];
199 AIListContact *exactContact;
202 account = [accounts objectAtIndex:row];
203 if ([listObject isKindOfClass:[AIMetaContact class]]){
204 //If we're dealing with a metaContact, make sure it's the topmost one
205 exactContact = (AIListContact *)[[adium contactController] parentContactForListObject:listObject];
208 //Retrieve an AIListContact on this account
209 exactContact = [[adium contactController] existingContactWithService:[listObject service]
211 UID:[listObject UID]];
214 accountOnline = [account online];
216 //Disable cells for offline accounts
217 [cell setEnabled:accountOnline];
219 //Select active group
220 if([identifier isEqualToString:@"group"]){
224 if(group = [[adium contactController] remoteGroupForContact:exactContact]){
225 [cell selectItemWithRepresentedObject:group];
227 [cell selectItemAtIndex:0];
230 [cell setTitle:AILocalizedString(@"(Unavailable)",nil)];
237 * @brief Empty. This method is the target of our menus, and needed for menu validation.
239 - (void)selectGroup:(id)sender {};
242 * @brief Table view set object value
244 - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(int)row
246 NSString *identifier = [tableColumn identifier];
247 AIAccount *account = [accounts objectAtIndex:row];
248 AIListContact *exactContact;
250 if([identifier isEqualToString:@"group"]){
251 NSMenu *menu = [[tableColumn dataCell] menu];
252 int menuIndex = [object intValue];
254 if(menuIndex >= 0 && menuIndex < [menu numberOfItems]){
255 AIListGroup *group = [[menu itemAtIndex:menuIndex] representedObject];
257 if ([listObject isKindOfClass:[AIMetaContact class]]){
258 //If we're dealing with a metaContact, make sure it's the topmost one
259 exactContact = (AIListContact *)[[adium contactController] parentContactForListObject:listObject];
262 //Retrieve an AIListContact on this account
263 exactContact = [[adium contactController] existingContactWithService:[listObject service]
265 UID:[listObject UID]];
269 if (group != [exactContact containingObject]){
271 if (exactContact && ([exactContact containingObject] ||
272 [exactContact isKindOfClass:[AIMetaContact class]])){
274 [[adium contactController] moveContact:exactContact toGroup:group];
279 exactContact = [[adium contactController] contactWithService:[listObject service]
281 UID:[listObject UID]];
284 [[adium contactController] addContacts:[NSArray arrayWithObject:exactContact]
290 //User selected not listed, so we'll remove that contact
291 [[adium contactController] removeListObjects:[NSArray arrayWithObject:exactContact]];