| 1 |
#import "JVConnectionInspector.h" |
|---|
| 2 |
#import "MVConnectionsController.h" |
|---|
| 3 |
#import "MVKeyChain.h" |
|---|
| 4 |
#import "KAIgnoreRule.h" |
|---|
| 5 |
|
|---|
| 6 |
@implementation MVChatConnection (MVChatConnectionInspection) |
|---|
| 7 |
- (id <JVInspector>) inspector { |
|---|
| 8 |
return [[[JVConnectionInspector alloc] initWithConnection:self] autorelease]; |
|---|
| 9 |
} |
|---|
| 10 |
@end |
|---|
| 11 |
|
|---|
| 12 |
#pragma mark - |
|---|
| 13 |
|
|---|
| 14 |
@implementation JVChatConsolePanel (JVChatConsolePanelInspection) |
|---|
| 15 |
- (id <JVInspector>) inspector { |
|---|
| 16 |
return [[[JVConnectionInspector alloc] initWithConnection:[self connection]] autorelease]; |
|---|
| 17 |
} |
|---|
| 18 |
@end |
|---|
| 19 |
|
|---|
| 20 |
#pragma mark - |
|---|
| 21 |
|
|---|
| 22 |
@implementation JVConnectionInspector |
|---|
| 23 |
- (id) initWithConnection:(MVChatConnection *) connection { |
|---|
| 24 |
if( ( self = [self init] ) ) |
|---|
| 25 |
_connection = [connection retain]; |
|---|
| 26 |
return self; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
- (void) dealloc { |
|---|
| 30 |
[editRooms setDataSource:nil]; |
|---|
| 31 |
[editRooms setDelegate:nil]; |
|---|
| 32 |
|
|---|
| 33 |
[editRules setDataSource:nil]; |
|---|
| 34 |
[editRules setDelegate:nil]; |
|---|
| 35 |
|
|---|
| 36 |
[editRuleRooms setDataSource:nil]; |
|---|
| 37 |
[editRuleRooms setDelegate:nil]; |
|---|
| 38 |
|
|---|
| 39 |
[_connection release]; |
|---|
| 40 |
[_editingRooms release]; |
|---|
| 41 |
_connection = nil; |
|---|
| 42 |
_editingRooms = nil; |
|---|
| 43 |
[super dealloc]; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
#pragma mark - |
|---|
| 47 |
|
|---|
| 48 |
- (NSView *) view { |
|---|
| 49 |
if( ! _nibLoaded ) _nibLoaded = [NSBundle loadNibNamed:@"JVConnectionInspector" owner:self]; |
|---|
| 50 |
return view; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
- (NSSize) minSize { |
|---|
| 54 |
return NSMakeSize( 275., 338. ); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
- (NSString *) title { |
|---|
| 58 |
return [_connection server]; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
- (NSString *) type { |
|---|
| 62 |
return NSLocalizedString( @"Connection", "connection inspector type" ); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
- (void) willLoad { |
|---|
| 66 |
[self buildEncodingMenu]; |
|---|
| 67 |
|
|---|
| 68 |
[tabView removeTabViewItem:[tabView tabViewItemAtIndex:[tabView indexOfTabViewItemWithIdentifier:@"Proxy"]]]; |
|---|
| 69 |
|
|---|
| 70 |
[editAutomatic setState:[[MVConnectionsController defaultController] autoConnectForConnection:_connection]]; |
|---|
| 71 |
[editShowConsoleOnConnect setState:[[MVConnectionsController defaultController] showConsoleOnConnectForConnection:_connection]]; |
|---|
| 72 |
[sslConnection setState:[_connection isSecure]]; |
|---|
| 73 |
[editAddress setObjectValue:[_connection server]]; |
|---|
| 74 |
[editProxy selectItemAtIndex:[editProxy indexOfItemWithTag:[_connection proxyType]]]; |
|---|
| 75 |
[editPort setIntValue:[_connection serverPort]]; |
|---|
| 76 |
[editNickname setObjectValue:[_connection preferredNickname]]; |
|---|
| 77 |
[editAltNicknames setObjectValue:[[_connection alternateNicknames] componentsJoinedByString:@" "]]; |
|---|
| 78 |
[editPassword setObjectValue:[[MVKeyChain defaultKeyChain] internetPasswordForServer:[_connection server] securityDomain:[_connection server] account:[_connection preferredNickname] path:nil port:0 protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]]; |
|---|
| 79 |
[editServerPassword setObjectValue:[[MVKeyChain defaultKeyChain] internetPasswordForServer:[_connection server] securityDomain:[_connection server] account:nil path:nil port:[_connection serverPort] protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]]; |
|---|
| 80 |
[editRealName setObjectValue:[_connection realName]]; |
|---|
| 81 |
[editUsername setObjectValue:[_connection username]]; |
|---|
| 82 |
|
|---|
| 83 |
NSString *commands = [[MVConnectionsController defaultController] connectCommandsForConnection:_connection]; |
|---|
| 84 |
if( commands) [connectCommands setString:commands]; |
|---|
| 85 |
|
|---|
| 86 |
[_editingRooms autorelease]; |
|---|
| 87 |
_editingRooms = [[NSMutableArray arrayWithArray:[[MVConnectionsController defaultController] joinRoomsForConnection:_connection]] retain]; |
|---|
| 88 |
|
|---|
| 89 |
[editRooms reloadData]; |
|---|
| 90 |
|
|---|
| 91 |
NSTableColumn *column = [editRules tableColumnWithIdentifier:@"icon"]; |
|---|
| 92 |
NSImageCell *prototypeCell = [[NSImageCell new] autorelease]; |
|---|
| 93 |
[prototypeCell setImageAlignment:NSImageAlignRight]; |
|---|
| 94 |
[prototypeCell setImageFrameStyle:NSImageFrameNone]; |
|---|
| 95 |
[prototypeCell setImageScaling:NSScaleNone]; |
|---|
| 96 |
[column setDataCell:prototypeCell]; |
|---|
| 97 |
|
|---|
| 98 |
[editRules setTarget:self]; |
|---|
| 99 |
[editRules setDoubleAction:@selector( configureRule: )]; |
|---|
| 100 |
|
|---|
| 101 |
_ignoreRules = [[MVConnectionsController defaultController] ignoreRulesForConnection:_connection]; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
- (BOOL) shouldUnload { |
|---|
| 105 |
[[view window] makeFirstResponder:view]; |
|---|
| 106 |
return YES; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
- (void) didUnload { |
|---|
| 110 |
[[MVConnectionsController defaultController] setJoinRooms:_editingRooms forConnection:_connection]; |
|---|
| 111 |
[[MVConnectionsController defaultController] setConnectCommands:[connectCommands string] forConnection:_connection]; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
#pragma mark - |
|---|
| 115 |
|
|---|
| 116 |
- (void) selectTabWithIdentifier:(NSString *) identifier { |
|---|
| 117 |
[tabView selectTabViewItemWithIdentifier:identifier]; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
#pragma mark - |
|---|
| 121 |
|
|---|
| 122 |
- (void) buildEncodingMenu { |
|---|
| 123 |
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; |
|---|
| 124 |
NSMenuItem *menuItem = nil; |
|---|
| 125 |
unsigned int i = 0; |
|---|
| 126 |
NSStringEncoding defaultEncoding = [_connection encoding]; |
|---|
| 127 |
if( ! encoding ) defaultEncoding = [[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatEncoding"]; |
|---|
| 128 |
|
|---|
| 129 |
const NSStringEncoding *supportedEncodings = [_connection supportedStringEncodings]; |
|---|
| 130 |
|
|---|
| 131 |
for( i = 0; supportedEncodings[i]; i++ ) { |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
menuItem = [[[NSMenuItem alloc] initWithTitle:[NSString localizedNameOfStringEncoding:supportedEncodings[i]] action:@selector( changeEncoding: ) keyEquivalent:@""] autorelease]; |
|---|
| 138 |
if( defaultEncoding == supportedEncodings[i] ) [menuItem setState:NSOnState]; |
|---|
| 139 |
[menuItem setTag:supportedEncodings[i]]; |
|---|
| 140 |
[menuItem setTarget:self]; |
|---|
| 141 |
[menu addItem:menuItem]; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
[encoding setMenu:menu]; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
- (IBAction) changeEncoding:(id) sender { |
|---|
| 148 |
[_connection setEncoding:[sender tag]]; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
#pragma mark - |
|---|
| 152 |
|
|---|
| 153 |
- (IBAction) openNetworkPreferences:(id) sender { |
|---|
| 154 |
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/Network.prefPane"]; |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
- (IBAction) editText:(id) sender { |
|---|
| 158 |
if( sender == editNickname ) { |
|---|
| 159 |
NSString *password = [[MVKeyChain defaultKeyChain] internetPasswordForServer:[editAddress stringValue] securityDomain:[editAddress stringValue] account:[sender stringValue] path:nil port:0 protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]; |
|---|
| 160 |
if( password ) [editPassword setObjectValue:password]; |
|---|
| 161 |
else [editPassword setObjectValue:@""]; |
|---|
| 162 |
[_connection setNickname:[sender stringValue]]; |
|---|
| 163 |
} else if( sender == editAltNicknames ) { |
|---|
| 164 |
[_connection setAlternateNicknames:[[sender stringValue] componentsSeparatedByString:@" "]]; |
|---|
| 165 |
} else if( sender == editPassword ) { |
|---|
| 166 |
[_connection setNicknamePassword:nil]; |
|---|
| 167 |
[[MVKeyChain defaultKeyChain] setInternetPassword:[sender stringValue] forServer:[editAddress stringValue] securityDomain:[editAddress stringValue] account:[editNickname stringValue] path:nil port:0 protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]; |
|---|
| 168 |
} else if( sender == editServerPassword ) { |
|---|
| 169 |
[_connection setPassword:[sender stringValue]]; |
|---|
| 170 |
[[MVKeyChain defaultKeyChain] setInternetPassword:[sender stringValue] forServer:[editAddress stringValue] securityDomain:[editAddress stringValue] account:nil path:nil port:(unsigned short)[editPort intValue] protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]; |
|---|
| 171 |
} else if( sender == editAddress ) { |
|---|
| 172 |
NSString *password = [[MVKeyChain defaultKeyChain] internetPasswordForServer:[sender stringValue] securityDomain:[sender stringValue] account:[editNickname stringValue] path:nil port:0 protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault]; |
|---|
| 173 |
if( password ) [editPassword setObjectValue:password]; |
|---|
| 174 |
else [editPassword setObjectValue:@""]; |
|---|
| 175 |
[_connection setServer:[sender stringValue]]; |
|---|
| 176 |
} else if( sender == editRealName ) { |
|---|
| 177 |
[_connection setRealName:[sender stringValue]]; |
|---|
| 178 |
} else if( sender == editUsername ) { |
|---|
| 179 |
[_connection setUsername:[sender stringValue]]; |
|---|
| 180 |
} else if( sender == editPort ) { |
|---|
| 181 |
[_connection setServerPort:( (unsigned int)[sender intValue] % 65536 )]; |
|---|
| 182 |
} |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
- (void) controlTextDidEndEditing:(NSNotification *) notification { |
|---|
| 186 |
|
|---|
| 187 |
[self editText:[notification object]]; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
- (IBAction) toggleAutoConnect:(id) sender { |
|---|
| 191 |
[[MVConnectionsController defaultController] setAutoConnect:[sender state] forConnection:_connection]; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
- (IBAction) toggleShowConsoleOnConnect:(id) sender { |
|---|
| 195 |
[[MVConnectionsController defaultController] setShowConsoleOnConnect:[sender state] forConnection:_connection]; |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
- (IBAction) toggleSSLConnection:(id) sender { |
|---|
| 199 |
[_connection setSecure:[sender state]]; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
- (IBAction) changeProxy:(id) sender { |
|---|
| 203 |
[_connection setProxyType:[[editProxy selectedItem] tag]]; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
- (IBAction) addRoom:(id) sender { |
|---|
| 207 |
[_editingRooms addObject:@""]; |
|---|
| 208 |
[editRooms noteNumberOfRowsChanged]; |
|---|
| 209 |
[editRooms selectRow:([_editingRooms count] - 1) byExtendingSelection:NO]; |
|---|
| 210 |
[editRooms editColumn:0 row:([_editingRooms count] - 1) withEvent:nil select:NO]; |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
- (IBAction) addRoomToRule:(id) sender { |
|---|
| 214 |
[_editingRuleRooms addObject:@""]; |
|---|
| 215 |
[editRuleRooms noteNumberOfRowsChanged]; |
|---|
| 216 |
[editRuleRooms selectRow:([_editingRuleRooms count] - 1) byExtendingSelection:NO]; |
|---|
| 217 |
[editRuleRooms editColumn:0 row:([_editingRuleRooms count] - 1) withEvent:nil select:NO]; |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
- (IBAction) removeRoom:(id) sender { |
|---|
| 221 |
if( [editRooms selectedRow] == -1 || [editRooms editedRow] != -1 ) return; |
|---|
| 222 |
[_editingRooms removeObjectAtIndex:[editRooms selectedRow]]; |
|---|
| 223 |
[editRooms noteNumberOfRowsChanged]; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
- (IBAction) removeRoomFromRule:(id) sender { |
|---|
| 227 |
if( [editRuleRooms selectedRow] == -1 || [editRuleRooms editedRow] != -1 ) return; |
|---|
| 228 |
[_editingRuleRooms removeObjectAtIndex:[editRuleRooms selectedRow]]; |
|---|
| 229 |
[editRuleRooms noteNumberOfRowsChanged]; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
- (IBAction) removeRule:(id) sender { |
|---|
| 233 |
if( [editRules selectedRow] == -1 || [editRules editedRow] != -1 ) return; |
|---|
| 234 |
[_ignoreRules removeObjectAtIndex:[editRules selectedRow]]; |
|---|
| 235 |
[editRules noteNumberOfRowsChanged]; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
- (IBAction) addRule:(id) sender { |
|---|
| 239 |
[_editingRuleRooms release]; |
|---|
| 240 |
_editingRuleRooms = [[NSMutableArray alloc] init]; |
|---|
| 241 |
|
|---|
| 242 |
[editRuleName setStringValue:@""]; |
|---|
| 243 |
[makeRulePermanent setState:NSOnState]; |
|---|
| 244 |
[ruleUsesSender setState:NSOnState]; |
|---|
| 245 |
[ruleUsesMessage setState:NSOffState]; |
|---|
| 246 |
[ruleUsesRooms setState:NSOffState]; |
|---|
| 247 |
[senderType selectItemAtIndex:0]; |
|---|
| 248 |
[messageType selectItemAtIndex:0]; |
|---|
| 249 |
[editRuleSender setStringValue:@""]; |
|---|
| 250 |
[editRuleMessage setStringValue:@""]; |
|---|
| 251 |
[editRuleRooms reloadData]; |
|---|
| 252 |
|
|---|
| 253 |
_ignoreRuleIsNew = YES; |
|---|
| 254 |
[[NSApplication sharedApplication] beginSheet:ruleSheet modalForWindow:[view window] modalDelegate:self didEndSelector:@selector( ruleSheetDidEnd:returnCode:contextInfo: ) contextInfo:nil]; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
- (IBAction) configureRule:(id) sender { |
|---|
| 258 |
KAIgnoreRule *rule = [_ignoreRules objectAtIndex:[editRules selectedRow]]; |
|---|
| 259 |
|
|---|
| 260 |
[_editingRuleRooms release]; |
|---|
| 261 |
_editingRuleRooms = [[rule rooms] mutableCopy]; |
|---|
| 262 |
|
|---|
| 263 |
NSString *user = [rule user]; |
|---|
| 264 |
NSString *message = [rule message]; |
|---|
| 265 |
BOOL regexUser = NO; |
|---|
| 266 |
BOOL regexMessage = NO; |
|---|
| 267 |
|
|---|
| 268 |
if( user ) { |
|---|
| 269 |
if( [user length] > 2 && [user hasPrefix:@"/"] && [user hasSuffix:@"/"] ) { |
|---|
| 270 |
user = [user substringWithRange:NSMakeRange( 1, [user length] - 2 )]; |
|---|
| 271 |
regexUser = YES; |
|---|
| 272 |
} |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
if( message) { |
|---|
| 276 |
if( [message length] > 2 && [message hasPrefix:@"/"] && [message hasSuffix:@"/"] ) { |
|---|
| 277 |
message = [message substringWithRange:NSMakeRange(1,[message length]-2)]; |
|---|
| 278 |
regexMessage = YES; |
|---|
| 279 |
} |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
[editRuleName setStringValue:[rule friendlyName]]; |
|---|
| 283 |
[makeRulePermanent setState:( [rule isPermanent] ? NSOnState : NSOffState )]; |
|---|
| 284 |
[ruleUsesSender setState:( ! [[rule user] length] ? NSOffState : NSOnState )]; |
|---|
| 285 |
[ruleUsesMessage setState:( ! [[rule message] length] ? NSOffState : NSOnState )]; |
|---|
| 286 |
[ruleUsesRooms setState:( ! [[rule rooms] count] ? NSOffState : NSOnState )]; |
|---|
| 287 |
[senderType selectItemAtIndex:( regexUser ? 1 : 0 )]; |
|---|
| 288 |
[messageType selectItemAtIndex:( regexMessage ? 1 : 0 )]; |
|---|
| 289 |
[editRuleSender setStringValue:( user ? user : @"" )]; |
|---|
| 290 |
[editRuleMessage setStringValue:( message ? message: @"" )]; |
|---|
| 291 |
[editRuleRooms reloadData]; |
|---|
| 292 |
|
|---|
| 293 |
_ignoreRuleIsNew = NO; |
|---|
| 294 |
[[NSApplication sharedApplication] beginSheet:ruleSheet modalForWindow:[view window] modalDelegate:self didEndSelector:@selector( ruleSheetDidEnd:returnCode:contextInfo: ) contextInfo:nil]; |
|---|
| 295 |
|
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
- (IBAction) saveRule:(id) sender { |
|---|
| 299 |
[[NSApplication sharedApplication] endSheet:ruleSheet returnCode:YES]; |
|---|
| 300 |
[ruleSheet orderOut:self]; |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
- (IBAction) discardChangesToRule:(id) sender { |
|---|
| 304 |
[[NSApplication sharedApplication] endSheet:ruleSheet returnCode:NO]; |
|---|
| 305 |
[ruleSheet orderOut:self]; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
- (void) ruleSheetDidEnd:(NSWindow *) sheet returnCode:(int) returnCode contextInfo:(void *) contextInfo { |
|---|
| 309 |
if( returnCode ) { |
|---|
| 310 |
NSString *user = nil; |
|---|
| 311 |
if( [ruleUsesSender state] == NSOnState ) { |
|---|
| 312 |
if( [senderType indexOfSelectedItem] == 0 ) user = [editRuleSender stringValue]; |
|---|
| 313 |
else user = [NSString stringWithFormat:@"/%@/",[editRuleSender stringValue]]; |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
NSString *message = nil; |
|---|
| 317 |
if( [ruleUsesMessage state] == NSOnState ) { |
|---|
| 318 |
if( [messageType indexOfSelectedItem] == 0 ) message = [editRuleMessage stringValue]; |
|---|
| 319 |
else message = [NSString stringWithFormat:@"/%@/",[editRuleMessage stringValue]]; |
|---|
| 320 |
} |
|---|
| 321 |
|
|---|
| 322 |
NSString *friendlyName = [editRuleName stringValue]; |
|---|
| 323 |
if( [friendlyName isEqualToString:@""] ) friendlyName = nil; |
|---|
| 324 |
|
|---|
| 325 |
BOOL isPermanent = ( [makeRulePermanent state] == NSOnState ); |
|---|
| 326 |
|
|---|
| 327 |
if( _ignoreRuleIsNew ) { |
|---|
| 328 |
KAIgnoreRule *rule = [KAIgnoreRule ruleForUser:user message:message inRooms:_editingRuleRooms isPermanent:isPermanent friendlyName:friendlyName]; |
|---|
| 329 |
[_ignoreRules addObject:rule]; |
|---|
| 330 |
[editRules noteNumberOfRowsChanged]; |
|---|
| 331 |
} else { |
|---|
| 332 |
KAIgnoreRule *rule = [_ignoreRules objectAtIndex:[editRules selectedRow]]; |
|---|
| 333 |
[rule setUser:user]; |
|---|
| 334 |
[rule setMessage:message]; |
|---|
| 335 |
[rule setRooms:_editingRuleRooms]; |
|---|
| 336 |
[rule setPermanent:isPermanent]; |
|---|
| 337 |
[rule setFriendlyName:friendlyName]; |
|---|
| 338 |
[editRules reloadData]; |
|---|
| 339 |
} |
|---|
| 340 |
} |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
#pragma mark - |
|---|
| 344 |
|
|---|
| 345 |
- (int) numberOfRowsInTableView:(NSTableView *) tableView { |
|---|
| 346 |
if( tableView == editRooms ) return [_editingRooms count]; |
|---|
| 347 |
else if( tableView == editRules ) return [_ignoreRules count]; |
|---|
| 348 |
else if( tableView == editRuleRooms ) return [_editingRuleRooms count]; |
|---|
| 349 |
else return 0; |
|---|
| 350 |
} |
|---|
| 351 |
|
|---|
| 352 |
- (id) tableView:(NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| 353 |
if( tableView == editRooms ) return [_editingRooms objectAtIndex:row]; |
|---|
| 354 |
else if( tableView == editRules ) { |
|---|
| 355 |
KAIgnoreRule *rule = [_ignoreRules objectAtIndex:row]; |
|---|
| 356 |
if( [[column identifier] isEqualToString:@"icon"] ) { |
|---|
| 357 |
if( [rule user] && [rule message] ) return [NSImage imageNamed:@"privateChatTab"]; |
|---|
| 358 |
else if( [rule user] ) return [NSImage imageNamed:@"person"]; |
|---|
| 359 |
else return [NSImage imageNamed:@"roomTabNewMessage"]; |
|---|
| 360 |
} else { |
|---|
| 361 |
if( ! [rule isPermanent] ) return [[[NSAttributedString alloc] initWithString:[rule friendlyName] attributes:[NSDictionary dictionaryWithObject:[[NSColor blackColor] colorWithAlphaComponent:0.67] forKey:NSForegroundColorAttributeName]] autorelease]; |
|---|
| 362 |
else return [rule friendlyName]; |
|---|
| 363 |
} |
|---|
| 364 |
} else if( tableView == editRuleRooms ) return [_editingRuleRooms objectAtIndex:row]; |
|---|
| 365 |
else return nil; |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
- (void) tableView:(NSTableView *) tableView setObjectValue:(id) object forTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| 369 |
if( tableView == editRooms ) [_editingRooms replaceObjectAtIndex:row withObject:object]; |
|---|
| 370 |
else if( tableView == editRuleRooms ) [_editingRuleRooms replaceObjectAtIndex:row withObject:object]; |
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
- (void) tableViewSelectionDidChange:(NSNotification *) notification { |
|---|
| 374 |
if( [notification object] == editRooms ) { |
|---|
| 375 |
[editRemoveRoom setEnabled:( [editRooms selectedRow] != -1 )]; |
|---|
| 376 |
} else if( [notification object] == editRules ) { |
|---|
| 377 |
[deleteRule setEnabled:( [editRules selectedRow] != -1 )]; |
|---|
| 378 |
[editRule setEnabled:( [editRules selectedRow] != -1 )]; |
|---|
| 379 |
} else if( [notification object] == editRuleRooms ) { |
|---|
| 380 |
[deleteRoomFromRule setEnabled:( [editRuleRooms selectedRow] != -1 )]; |
|---|
| 381 |
} |
|---|
| 382 |
} |
|---|
| 383 |
|
|---|
| 384 |
#pragma mark - |
|---|
| 385 |
|
|---|
| 386 |
- (int) numberOfItemsInComboBox:(NSComboBox *) comboBox { |
|---|
| 387 |
return [[[NSUserDefaults standardUserDefaults] arrayForKey:@"JVChatServers"] count]; |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
- (id) comboBox:(NSComboBox *) comboBox objectValueForItemAtIndex:(int) index { |
|---|
| 391 |
return [[[NSUserDefaults standardUserDefaults] arrayForKey:@"JVChatServers"] objectAtIndex:index]; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
- (unsigned int) comboBox:(NSComboBox *) comboBox indexOfItemWithStringValue:(NSString *) string { |
|---|
| 395 |
return [[[NSUserDefaults standardUserDefaults] arrayForKey:@"JVChatServers"] indexOfObject:string]; |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
- (NSString *) comboBox:(NSComboBox *) comboBox completedString:(NSString *) substring { |
|---|
| 399 |
NSEnumerator *enumerator = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"JVChatServers"] objectEnumerator]; |
|---|
| 400 |
NSString *server = nil; |
|---|
| 401 |
while( ( server = [enumerator nextObject] ) ) |
|---|
| 402 |
if( [server hasPrefix:substring] ) return server; |
|---|
| 403 |
return nil; |
|---|
| 404 |
} |
|---|
| 405 |
@end |
|---|