| 92 | | - (IBAction) changeServer:(id) sender { |
|---|
| 93 | | if( [[sender selectedItem] tag] ) { |
|---|
| 94 | | [_activeUsers autorelease]; |
|---|
| 95 | | _activeUsers = [[_buddy users] mutableCopyWithZone:nil]; |
|---|
| 96 | | [_activeUsers sortUsingSelector:@selector( compareByNickname: )]; |
|---|
| 97 | | [[nicknames tableColumnWithIdentifier:@"nickname"] setEditable:NO]; |
|---|
| 98 | | [addNickname setEnabled:NO]; |
|---|
| | 91 | - (IBAction) addIdentifier:(id) sender { |
|---|
| | 92 | [_currentRule release]; |
|---|
| | 93 | _currentRule = [[MVChatUserWatchRule allocWithZone:nil] init]; |
|---|
| | 94 | |
|---|
| | 95 | [_editDomains release]; |
|---|
| | 96 | _editDomains = [[NSMutableArray allocWithZone:nil] init]; |
|---|
| | 97 | |
|---|
| | 98 | [identifierDomainsTable reloadData]; |
|---|
| | 99 | |
|---|
| | 100 | [identifierNickname setStringValue:@""]; |
|---|
| | 101 | [identifierRealName setStringValue:@""]; |
|---|
| | 102 | [identifierUsername setStringValue:@""]; |
|---|
| | 103 | [identifierHostname setStringValue:@""]; |
|---|
| | 104 | [identifierDomainsTable setEnabled:NO]; |
|---|
| | 105 | [addDomain setEnabled:NO]; |
|---|
| | 106 | [identifierConnections selectCellWithTag:0]; |
|---|
| | 107 | |
|---|
| | 108 | [identifierOkay setEnabled:NO]; |
|---|
| | 109 | |
|---|
| | 110 | [identifierEditPanel makeFirstResponder:identifierNickname]; |
|---|
| | 111 | |
|---|
| | 112 | _identifierIsNew = YES; |
|---|
| | 113 | [[NSApplication sharedApplication] beginSheet:identifierEditPanel modalForWindow:[view window] modalDelegate:self didEndSelector:@selector( identifierSheetDidEnd:returnCode:contextInfo: ) contextInfo:nil]; |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 116 | - (IBAction) editIdentifier:(id) sender { |
|---|
| | 117 | int index = [identifiersTable selectedRow]; |
|---|
| | 118 | if( index == -1 ) return; |
|---|
| | 119 | |
|---|
| | 120 | [_currentRule release]; |
|---|
| | 121 | _currentRule = [[[_buddy watchRules] objectAtIndex:index] retain]; |
|---|
| | 122 | |
|---|
| | 123 | [_editDomains release]; |
|---|
| | 124 | _editDomains = [[NSMutableArray allocWithZone:nil] init]; |
|---|
| | 125 | if( [[_currentRule applicableServerDomains] count] ) { |
|---|
| | 126 | [_editDomains setArray:[_currentRule applicableServerDomains]]; |
|---|
| | 127 | [identifierDomainsTable setEnabled:YES]; |
|---|
| | 128 | [addDomain setEnabled:YES]; |
|---|
| | 129 | [identifierConnections selectCellWithTag:1]; |
|---|
| 100 | | [_activeUsers autorelease]; |
|---|
| 101 | | _activeUsers = [[NSMutableArray allocWithZone:nil] initWithCapacity:[[_buddy users] count]]; |
|---|
| 102 | | |
|---|
| 103 | | NSEnumerator *enumerator = [[_buddy users] objectEnumerator]; |
|---|
| 104 | | MVChatUser *user = nil; |
|---|
| 105 | | |
|---|
| 106 | | while( ( user = [enumerator nextObject] ) ) |
|---|
| 107 | | if( [[servers titleOfSelectedItem] caseInsensitiveCompare:[user serverAddress]] == NSOrderedSame ) |
|---|
| 108 | | [_activeUsers addObject:user]; |
|---|
| 109 | | |
|---|
| 110 | | [_activeUsers sortUsingSelector:@selector( compareByNickname: )]; |
|---|
| 111 | | |
|---|
| 112 | | [[nicknames tableColumnWithIdentifier:@"nickname"] setEditable:YES]; |
|---|
| 113 | | [addNickname setEnabled:YES]; |
|---|
| 114 | | } |
|---|
| 115 | | |
|---|
| 116 | | [nicknames deselectAll:nil]; |
|---|
| 117 | | [nicknames reloadData]; |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | #pragma mark - |
|---|
| 121 | | |
|---|
| 122 | | - (IBAction) addNickname:(id) sender { |
|---|
| 123 | | [_activeUsers addObject:[NSNull null]]; |
|---|
| 124 | | [nicknames noteNumberOfRowsChanged]; |
|---|
| 125 | | [nicknames selectRow:( [_activeUsers count] - 1 ) byExtendingSelection:NO]; |
|---|
| 126 | | [nicknames editColumn:0 row:( [_activeUsers count] - 1 ) withEvent:nil select:NO]; |
|---|
| 127 | | } |
|---|
| 128 | | |
|---|
| 129 | | - (IBAction) removeNickname:(id) sender { |
|---|
| 130 | | if( [nicknames selectedRow] == -1 || [nicknames editedRow] != -1 ) return; |
|---|
| 131 | | // [_buddy removeUser:[_activeUsers objectAtIndex:[nicknames selectedRow]]]; |
|---|
| 132 | | [_activeUsers removeObjectAtIndex:[nicknames selectedRow]]; |
|---|
| 133 | | [nicknames noteNumberOfRowsChanged]; |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | #pragma mark - |
|---|
| 137 | | |
|---|
| 138 | | - (IBAction) editCard:(id) sender { |
|---|
| 139 | | [_buddy editInAddressBook]; |
|---|
| | 131 | [identifierDomainsTable setEnabled:NO]; |
|---|
| | 132 | [addDomain setEnabled:NO]; |
|---|
| | 133 | [identifierConnections selectCellWithTag:0]; |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | [identifierDomainsTable reloadData]; |
|---|
| | 137 | |
|---|
| | 138 | if( [_currentRule nickname] ) |
|---|
| | 139 | [identifierNickname setStringValue:[_currentRule nickname]]; |
|---|
| | 140 | else [identifierNickname setStringValue:@""]; |
|---|
| | 141 | |
|---|
| | 142 | if( [_currentRule realName] ) |
|---|
| | 143 | [identifierRealName setStringValue:[_currentRule realName]]; |
|---|
| | 144 | else [identifierRealName setStringValue:@""]; |
|---|
| | 145 | |
|---|
| | 146 | if( [_currentRule username] ) |
|---|
| | 147 | [identifierUsername setStringValue:[_currentRule username]]; |
|---|
| | 148 | else [identifierUsername setStringValue:@""]; |
|---|
| | 149 | |
|---|
| | 150 | if( [_currentRule address] ) |
|---|
| | 151 | [identifierHostname setStringValue:[_currentRule address]]; |
|---|
| | 152 | else [identifierHostname setStringValue:@""]; |
|---|
| | 153 | |
|---|
| | 154 | [identifierOkay setEnabled:YES]; |
|---|
| | 155 | |
|---|
| | 156 | [identifierEditPanel makeFirstResponder:identifierNickname]; |
|---|
| | 157 | |
|---|
| | 158 | _identifierIsNew = NO; |
|---|
| | 159 | [[NSApplication sharedApplication] beginSheet:identifierEditPanel modalForWindow:[view window] modalDelegate:self didEndSelector:@selector( identifierSheetDidEnd:returnCode:contextInfo: ) contextInfo:nil]; |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | - (IBAction) removeIdentifier:(id) sender { |
|---|
| | 163 | int index = [identifiersTable selectedRow]; |
|---|
| | 164 | if( index == -1 ) return; |
|---|
| | 165 | |
|---|
| | 166 | MVChatUserWatchRule *rule = [[_buddy watchRules] objectAtIndex:index]; |
|---|
| | 167 | [_buddy removeWatchRule:rule]; |
|---|
| | 168 | |
|---|
| | 169 | [_buddy unregisterWithConnections]; |
|---|
| | 170 | [_buddy registerWithApplicableConnections]; |
|---|
| | 171 | |
|---|
| | 172 | [identifiersTable noteNumberOfRowsChanged]; |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | - (IBAction) discardIdentifierChanges:(id) sender { |
|---|
| | 176 | [[NSApplication sharedApplication] endSheet:identifierEditPanel returnCode:NO]; |
|---|
| | 177 | [identifierEditPanel orderOut:sender]; |
|---|
| | 178 | } |
|---|
| | 179 | |
|---|
| | 180 | - (IBAction) saveIdentifierChanges:(id) sender { |
|---|
| | 181 | [[NSApplication sharedApplication] endSheet:identifierEditPanel returnCode:YES]; |
|---|
| | 182 | [identifierEditPanel orderOut:sender]; |
|---|
| | 183 | } |
|---|
| | 184 | |
|---|
| | 185 | - (void) identifierSheetDidEnd:(NSWindow *) sheet returnCode:(int) returnCode contextInfo:(void *) contextInfo { |
|---|
| | 186 | if( returnCode ) { |
|---|
| | 187 | NSString *string = [identifierNickname stringValue]; |
|---|
| | 188 | [_currentRule setNickname:( [string length] ? string : nil )]; |
|---|
| | 189 | |
|---|
| | 190 | string = [identifierRealName stringValue]; |
|---|
| | 191 | [_currentRule setRealName:( [string length] ? string : nil )]; |
|---|
| | 192 | |
|---|
| | 193 | string = [identifierUsername stringValue]; |
|---|
| | 194 | [_currentRule setUsername:( [string length] ? string : nil )]; |
|---|
| | 195 | |
|---|
| | 196 | string = [identifierHostname stringValue]; |
|---|
| | 197 | [_currentRule setAddress:( [string length] ? string : nil )]; |
|---|
| | 198 | |
|---|
| | 199 | [_currentRule setApplicableServerDomains:( [_editDomains count] && [identifierConnections selectedTag] ? _editDomains : nil )]; |
|---|
| | 200 | |
|---|
| | 201 | if( _identifierIsNew ) |
|---|
| | 202 | [_buddy addWatchRule:_currentRule]; |
|---|
| | 203 | |
|---|
| | 204 | [_buddy unregisterWithConnections]; |
|---|
| | 205 | [_buddy registerWithApplicableConnections]; |
|---|
| | 206 | |
|---|
| | 207 | [identifiersTable reloadData]; |
|---|
| | 208 | } |
|---|
| | 209 | |
|---|
| | 210 | [_currentRule release]; |
|---|
| | 211 | _currentRule = nil; |
|---|
| | 212 | |
|---|
| | 213 | [_editDomains release]; |
|---|
| | 214 | _editDomains = nil; |
|---|
| | 215 | |
|---|
| | 216 | [identifierDomainsTable reloadData]; |
|---|
| | 217 | } |
|---|
| | 218 | |
|---|
| | 219 | - (IBAction) changeConnectionState:(id) sender { |
|---|
| | 220 | BOOL enabled = [identifierConnections selectedTag]; |
|---|
| | 221 | [identifierDomainsTable setEnabled:enabled]; |
|---|
| | 222 | [addDomain setEnabled:enabled]; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | - (void) controlTextDidChange:(NSNotification *) notification { |
|---|
| | 226 | if( [[identifierNickname stringValue] length] || [[identifierRealName stringValue] length] || |
|---|
| | 227 | [[identifierUsername stringValue] length] || [[identifierHostname stringValue] length] ) |
|---|
| | 228 | [identifierOkay setEnabled:YES]; |
|---|
| | 229 | else [identifierOkay setEnabled:NO]; |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | #pragma mark - |
|---|
| | 233 | |
|---|
| | 234 | - (IBAction) addDomain:(id) sender { |
|---|
| | 235 | [_editDomains addObject:@""]; |
|---|
| | 236 | [identifierDomainsTable noteNumberOfRowsChanged]; |
|---|
| | 237 | [identifierDomainsTable selectRow:( [_editDomains count] - 1 ) byExtendingSelection:NO]; |
|---|
| | 238 | [identifierDomainsTable editColumn:0 row:( [_editDomains count] - 1 ) withEvent:nil select:NO]; |
|---|
| | 239 | } |
|---|
| | 240 | |
|---|
| | 241 | - (IBAction) removeDomain:(id) sender { |
|---|
| | 242 | if( [identifierDomainsTable selectedRow] == -1 || [identifierDomainsTable editedRow] != -1 ) return; |
|---|
| | 243 | [_editDomains removeObjectAtIndex:[identifierDomainsTable selectedRow]]; |
|---|
| | 244 | [identifierDomainsTable noteNumberOfRowsChanged]; |
|---|
| | 245 | } |
|---|
| | 246 | |
|---|
| | 247 | #pragma mark - |
|---|
| | 248 | |
|---|
| | 249 | - (IBAction) changeCard:(id) sender { |
|---|
| | 250 | |
|---|
| 177 | | - (int) numberOfRowsInTableView:(NSTableView *) view { |
|---|
| 178 | | return [_activeUsers count]; |
|---|
| 179 | | } |
|---|
| 180 | | |
|---|
| 181 | | - (id) tableView:(NSTableView *) view objectValueForTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| 182 | | if( [[_activeUsers objectAtIndex:row] isMemberOfClass:[NSNull class]] ) return @""; |
|---|
| 183 | | if( [[servers selectedItem] tag] ) |
|---|
| 184 | | return [NSString stringWithFormat:@"%@ (%@)", [[_activeUsers objectAtIndex:row] nickname], [[_activeUsers objectAtIndex:row] serverAddress]]; |
|---|
| 185 | | return [[_activeUsers objectAtIndex:row] nickname]; |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | - (void) tableView:(NSTableView *) view setObjectValue:(id) object forTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| 189 | | if( ! [(NSString *)object length] ) { |
|---|
| 190 | | [_activeUsers removeObjectAtIndex:row]; |
|---|
| 191 | | [nicknames noteNumberOfRowsChanged]; |
|---|
| 192 | | return; |
|---|
| 193 | | } |
|---|
| 194 | | |
|---|
| 195 | | NSString *server = [servers titleOfSelectedItem]; |
|---|
| 196 | | MVChatUser *user = [MVChatUser wildcardUserWithNicknameMask:[NSString stringWithFormat:@"%@@%@", object, server] andHostMask:nil]; |
|---|
| 197 | | |
|---|
| 198 | | if( [[_activeUsers objectAtIndex:row] isMemberOfClass:[NSNull class]] ) { |
|---|
| 199 | | // [_buddy addUser:user]; |
|---|
| 200 | | [_activeUsers replaceObjectAtIndex:row withObject:user]; |
|---|
| 201 | | } else { |
|---|
| 202 | | // [_buddy replaceUser:[_activeUsers objectAtIndex:row] withUser:user]; |
|---|
| 203 | | [_activeUsers replaceObjectAtIndex:row withObject:user]; |
|---|
| 204 | | } |
|---|
| | 290 | - (int) numberOfRowsInTableView:(NSTableView *) tableView { |
|---|
| | 291 | if( [tableView isEqual:identifiersTable] ) |
|---|
| | 292 | return [[_buddy watchRules] count]; |
|---|
| | 293 | if( [tableView isEqual:identifierDomainsTable] ) |
|---|
| | 294 | return [_editDomains count]; |
|---|
| | 295 | return 0; |
|---|
| | 296 | } |
|---|
| | 297 | |
|---|
| | 298 | - (id) tableView:(NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| | 299 | if( [tableView isEqual:identifiersTable] ) { |
|---|
| | 300 | NSMutableString *description = [NSMutableString string]; |
|---|
| | 301 | MVChatUserWatchRule *rule = [[_buddy watchRules] objectAtIndex:row]; |
|---|
| | 302 | unsigned count = 0; |
|---|
| | 303 | |
|---|
| | 304 | NSString *string = [rule nickname]; |
|---|
| | 305 | if( [string length] ) { |
|---|
| | 306 | [description appendString:string]; |
|---|
| | 307 | count++; |
|---|
| | 308 | } |
|---|
| | 309 | |
|---|
| | 310 | string = [rule realName]; |
|---|
| | 311 | if( [string length] ) { |
|---|
| | 312 | if( ! count ) [description appendString:string]; |
|---|
| | 313 | count++; |
|---|
| | 314 | } |
|---|
| | 315 | |
|---|
| | 316 | string = [rule username]; |
|---|
| | 317 | if( [string length] ) { |
|---|
| | 318 | if( ! count ) [description appendString:string]; |
|---|
| | 319 | count++; |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | string = [rule address]; |
|---|
| | 323 | if( [string length] ) { |
|---|
| | 324 | if( ! count ) [description appendString:string]; |
|---|
| | 325 | count++; |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | if( [[rule applicableServerDomains] count] ) |
|---|
| | 329 | count++; |
|---|
| | 330 | |
|---|
| | 331 | count--; // exclude the first rule criterion in the count |
|---|
| | 332 | |
|---|
| | 333 | if( count == 1 ) |
|---|
| | 334 | [description appendFormat:NSLocalizedString( @" (and 1 other criterion)", "one other buddy identifier criterion" ), count]; |
|---|
| | 335 | else if( count > 1 ) |
|---|
| | 336 | [description appendFormat:NSLocalizedString( @" (and %u other criteria)", "count of other buddy identifier criteria" ), count]; |
|---|
| | 337 | |
|---|
| | 338 | return description; |
|---|
| | 339 | } |
|---|
| | 340 | |
|---|
| | 341 | if( [tableView isEqual:identifierDomainsTable] ) |
|---|
| | 342 | return [_editDomains objectAtIndex:row]; |
|---|
| | 343 | |
|---|
| | 344 | return nil; |
|---|
| | 345 | } |
|---|
| | 346 | |
|---|
| | 347 | - (void) tableView:(NSTableView *) tableView setObjectValue:(id) object forTableColumn:(NSTableColumn *) column row:(int) row { |
|---|
| | 348 | if( [tableView isEqual:identifierDomainsTable] ) |
|---|
| | 349 | [_editDomains replaceObjectAtIndex:row withObject:object]; |
|---|