| | 147 | } |
|---|
| | 148 | |
|---|
| | 149 | |
|---|
| | 150 | |
|---|
| | 151 | #pragma mark - |
|---|
| | 152 | |
|---|
| | 153 | - (void)_selectTab:(NSString *)identifier { |
|---|
| | 154 | NSTabViewItem *item; |
|---|
| | 155 | |
|---|
| | 156 | item = [_preferencesTabView tabViewItemWithIdentifier:identifier]; |
|---|
| | 157 | |
|---|
| | 158 | if(item) { |
|---|
| | 159 | [self _selectTabViewItem:item]; |
|---|
| | 160 | |
|---|
| | 161 | [[[self window] toolbar] setSelectedItemIdentifier:identifier]; |
|---|
| | 162 | } |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | |
|---|
| | 166 | |
|---|
| | 167 | - (void)_selectTabViewItem:(NSTabViewItem *)item { |
|---|
| | 168 | NSBox *box; |
|---|
| | 169 | NSRect rect; |
|---|
| | 170 | |
|---|
| | 171 | if(_selectedTabViewItem != item) { |
|---|
| | 172 | if([[_selectedTabViewItem identifier] isEqualToString:@"Bookmarks"]) |
|---|
| | 173 | [self _unselectBookmark]; |
|---|
| | 174 | |
|---|
| | 175 | box = [[[item view] subviews] objectAtIndex:0]; |
|---|
| | 176 | rect = [[self window] frameRectForContentRect:[box frame]]; |
|---|
| | 177 | rect.origin = [[self window] frame].origin; |
|---|
| | 178 | rect.origin.y -= rect.size.height - [[self window] frame].size.height; |
|---|
| | 179 | |
|---|
| | 180 | [box setFrameOrigin:NSMakePoint(10000.0, 0.0)]; |
|---|
| | 181 | [box setNeedsDisplay:YES]; |
|---|
| | 182 | |
|---|
| | 183 | [_preferencesTabView selectTabViewItem:item]; |
|---|
| | 184 | [[self window] setFrame:rect display:YES animate:YES]; |
|---|
| | 185 | |
|---|
| | 186 | [box setFrameOrigin:NSZeroPoint]; |
|---|
| | 187 | [box setNeedsDisplay:YES]; |
|---|
| | 188 | |
|---|
| | 189 | [[self window] setTitle:[item label]]; |
|---|
| | 190 | |
|---|
| | 191 | _selectedTabViewItem = item; |
|---|
| | 192 | } |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | |
|---|
| | 196 | |
|---|
| | 197 | #pragma mark - |
|---|
| | 198 | |
|---|
| | 199 | - (void)_loadSettings { |
|---|
| | 200 | NSEnumerator *enumerator; |
|---|
| | 201 | NSDictionary *event; |
|---|
| | 202 | NSMenuItem *menuItem; |
|---|
| | 203 | BOOL on; |
|---|
| | 204 | |
|---|
| | 205 | // --- general |
|---|
| | 206 | [_nickTextField setStringValue:[WCSettings objectForKey:WCNick]]; |
|---|
| | 207 | [_statusTextField setStringValue:[WCSettings objectForKey:WCStatus]]; |
|---|
| | 208 | [_iconImageView setImage:[NSImage imageWithData: |
|---|
| | 209 | [NSData dataWithBase64EncodedString:[WCSettings objectForKey:WCCustomIcon]]]]; |
|---|
| | 210 | |
|---|
| | 211 | [_showConnectAtStartupButton setState:[WCSettings boolForKey:WCShowConnectAtStartup]]; |
|---|
| | 212 | [_showDockAtStartupButton setState:[WCSettings boolForKey:WCShowDockAtStartup]]; |
|---|
| | 213 | [_showTrackersAtStartupButton setState:[WCSettings boolForKey:WCShowTrackersAtStartup]]; |
|---|
| | 214 | |
|---|
| | 215 | [_autoHideOnSwitchButton setState:[WCSettings boolForKey:WCAutoHideOnSwitch]]; |
|---|
| | 216 | [_confirmDisconnectButton setState:[WCSettings boolForKey:WCConfirmDisconnect]]; |
|---|
| | 217 | |
|---|
| | 218 | // --- appearance/chat |
|---|
| | 219 | [_chatTextColorWell setColor:[WCSettings objectForKey:WCChatTextColor]]; |
|---|
| | 220 | [_chatBackgroundColorWell setColor:[WCSettings objectForKey:WCChatBackgroundColor]]; |
|---|
| | 221 | [_chatURLsColorWell setColor:[WCSettings objectForKey:WCChatURLsColor]]; |
|---|
| | 222 | [_chatEventsColorWell setColor:[WCSettings objectForKey:WCChatEventsColor]]; |
|---|
| | 223 | [_chatFontTextField setStringValue:[[WCSettings objectForKey:WCChatFont] displayNameWithSize]]; |
|---|
| | 224 | [_chatUserListFontTextField setStringValue:[[WCSettings objectForKey:WCChatUserListFont] displayNameWithSize]]; |
|---|
| | 225 | [_chatUserListIconSizeMatrix selectCellWithTag:[WCSettings intForKey:WCChatUserListIconSize]]; |
|---|
| | 226 | [_chatUserListAlternateRowsButton setState:[WCSettings boolForKey:WCChatUserListAlternateRows]]; |
|---|
| | 227 | |
|---|
| | 228 | // --- appearance/messages |
|---|
| | 229 | [_messagesTextColorWell setColor:[WCSettings objectForKey:WCMessagesTextColor]]; |
|---|
| | 230 | [_messagesBackgroundColorWell setColor:[WCSettings objectForKey:WCMessagesBackgroundColor]]; |
|---|
| | 231 | [_messagesFontTextField setStringValue:[[WCSettings objectForKey:WCMessagesFont] displayNameWithSize]]; |
|---|
| | 232 | [_messagesListFontTextField setStringValue:[[WCSettings objectForKey:WCMessagesListFont] displayNameWithSize]]; |
|---|
| | 233 | [_messagesListAlternateRowsButton setState:[WCSettings boolForKey:WCMessagesListAlternateRows]]; |
|---|
| | 234 | |
|---|
| | 235 | // --- appearance/news |
|---|
| | 236 | [_newsTextColorWell setColor:[WCSettings objectForKey:WCNewsTextColor]]; |
|---|
| | 237 | [_newsTitlesColorWell setColor:[WCSettings objectForKey:WCNewsTitlesColor]]; |
|---|
| | 238 | [_newsBackgroundColorWell setColor:[WCSettings objectForKey:WCNewsBackgroundColor]]; |
|---|
| | 239 | [_newsFontTextField setStringValue:[[WCSettings objectForKey:WCNewsFont] displayNameWithSize]]; |
|---|
| | 240 | |
|---|
| | 241 | // --- appearance/files |
|---|
| | 242 | [_filesFontTextField setStringValue:[[WCSettings objectForKey:WCFilesFont] displayNameWithSize]]; |
|---|
| | 243 | [_filesAlternateRowsButton setState:[WCSettings boolForKey:WCFilesAlternateRows]]; |
|---|
| | 244 | |
|---|
| | 245 | // --- appearance/preview |
|---|
| | 246 | [_previewTextColorWell setColor:[WCSettings objectForKey:WCPreviewTextColor]]; |
|---|
| | 247 | [_previewBackgroundColorWell setColor:[WCSettings objectForKey:WCPreviewBackgroundColor]]; |
|---|
| | 248 | [_previewFontTextField setStringValue:[[WCSettings objectForKey:WCPreviewFont] displayNameWithSize]]; |
|---|
| | 249 | |
|---|
| | 250 | // --- bookmarks |
|---|
| | 251 | [self _selectBookmark]; |
|---|
| | 252 | |
|---|
| | 253 | // --- chat |
|---|
| | 254 | [_chatStyleMatrix selectCellWithTag:[WCSettings intForKey:WCChatStyle]]; |
|---|
| | 255 | [_historyScrollbackButton setState:[WCSettings boolForKey:WCHistoryScrollback]]; |
|---|
| | 256 | [_historyScrollbackModifierPopUpButton selectItemWithTag: |
|---|
| | 257 | [WCSettings intForKey:WCHistoryScrollbackModifier]]; |
|---|
| | 258 | [_tabCompleteNicksButton setState:[WCSettings boolForKey:WCTabCompleteNicks]]; |
|---|
| | 259 | [_tabCompleteNicksTextField setStringValue:[WCSettings objectForKey:WCTabCompleteNicksString]]; |
|---|
| | 260 | [_timestampChatButton setState:[WCSettings boolForKey:WCTimestampChat]]; |
|---|
| | 261 | [_timestampChatIntervalTextField setStringValue:[NSSWF:@"%.0f", |
|---|
| | 262 | [WCSettings doubleForKey:WCTimestampChatInterval] / 60.0]]; |
|---|
| | 263 | [_timestampEveryLineButton setState:[WCSettings boolForKey:WCTimestampEveryLine]]; |
|---|
| | 264 | [_timestampEveryLineColorWell setColor:[WCSettings objectForKey:WCTimestampEveryLineColor]]; |
|---|
| | 265 | |
|---|
| | 266 | // --- events |
|---|
| | 267 | enumerator = [[WCSettings objectForKey:WCEvents] objectEnumerator]; |
|---|
| | 268 | |
|---|
| | 269 | while((event = [enumerator nextObject])) { |
|---|
| | 270 | menuItem = [_eventsPopUpButton itemWithTag:[event intForKey:WCEventsEvent]]; |
|---|
| | 271 | on = [event boolForKey:WCEventsPlaySound] || |
|---|
| | 272 | [event boolForKey:WCEventsBounceInDock] || |
|---|
| | 273 | [event boolForKey:WCEventsPostInChat]; |
|---|
| | 274 | [menuItem setImage:[NSImage imageNamed:on ? @"EventOn" : @"EventOff"]]; |
|---|
| | 275 | } |
|---|
| | 276 | |
|---|
| | 277 | [self _updateEvents]; |
|---|
| | 278 | |
|---|
| | 279 | // --- files |
|---|
| | 280 | [_downloadFolderTextField setStringValue:[[WCSettings objectForKey:WCDownloadFolder] stringByAbbreviatingWithTildeInPath]]; |
|---|
| | 281 | [_openFoldersInNewWindowsButton setState:[WCSettings boolForKey:WCOpenFoldersInNewWindows]]; |
|---|
| | 282 | [_queueTransfersButton setState:[WCSettings boolForKey:WCQueueTransfers]]; |
|---|
| | 283 | [_encryptTransfersButton setState:[WCSettings boolForKey:WCEncryptTransfers]]; |
|---|
| | 284 | [_showTransfersProgressBarButton setState:[WCSettings boolForKey:WCShowTransfersProgressBar]]; |
|---|
| | 285 | [_removeTransfersButton setState:[WCSettings boolForKey:WCRemoveTransfers]]; |
|---|
| | 286 | |
|---|
| | 287 | [_bookmarksTableView reloadData]; |
|---|
| | 288 | [_ignoresTableView reloadData]; |
|---|
| | 289 | |
|---|
| | 290 | [self _validate]; |
|---|
| | 291 | } |
|---|
| | 292 | |
|---|
| | 293 | |
|---|
| | 294 | |
|---|
| | 295 | - (void)_saveSettings { |
|---|
| | 296 | // --- general |
|---|
| | 297 | if(![[_nickTextField stringValue] isEqualToString:[WCSettings objectForKey:WCNick]]) { |
|---|
| | 298 | [WCSettings setObject:[_nickTextField stringValue] forKey:WCNick]; |
|---|
| | 299 | [[NSNotificationCenter defaultCenter] postNotificationName:WCNickDidChange object:NULL]; |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | if(![[_statusTextField stringValue] isEqualToString:[WCSettings objectForKey:WCStatus]]) { |
|---|
| | 303 | [WCSettings setObject:[_statusTextField stringValue] forKey:WCStatus]; |
|---|
| | 304 | [[NSNotificationCenter defaultCenter] postNotificationName:WCStatusDidChange object:NULL]; |
|---|
| | 305 | } |
|---|
| | 306 | |
|---|
| | 307 | [WCSettings setBool:[_showConnectAtStartupButton state] forKey:WCShowConnectAtStartup]; |
|---|
| | 308 | [WCSettings setBool:[_showDockAtStartupButton state] forKey:WCShowDockAtStartup]; |
|---|
| | 309 | [WCSettings setBool:[_showTrackersAtStartupButton state] forKey:WCShowTrackersAtStartup]; |
|---|
| | 310 | |
|---|
| | 311 | [WCSettings setBool:[_autoHideOnSwitchButton state] forKey:WCAutoHideOnSwitch]; |
|---|
| | 312 | [WCSettings setBool:[_confirmDisconnectButton state] forKey:WCConfirmDisconnect]; |
|---|
| | 313 | |
|---|
| | 314 | // --- appearance/chat |
|---|
| | 315 | [WCSettings setObject:[_chatTextColorWell color] forKey:WCChatTextColor]; |
|---|
| | 316 | [WCSettings setObject:[_chatBackgroundColorWell color] forKey:WCChatBackgroundColor]; |
|---|
| | 317 | [WCSettings setObject:[_chatURLsColorWell color] forKey:WCChatURLsColor]; |
|---|
| | 318 | [WCSettings setObject:[_chatEventsColorWell color] forKey:WCChatEventsColor]; |
|---|
| | 319 | [WCSettings setInt:[[_chatUserListIconSizeMatrix selectedCell] tag] forKey:WCChatUserListIconSize]; |
|---|
| | 320 | [WCSettings setBool:[_chatUserListAlternateRowsButton state] forKey:WCChatUserListAlternateRows]; |
|---|
| | 321 | |
|---|
| | 322 | // --- appearance/messages |
|---|
| | 323 | [WCSettings setObject:[_messagesTextColorWell color] forKey:WCMessagesTextColor]; |
|---|
| | 324 | [WCSettings setObject:[_messagesBackgroundColorWell color] forKey:WCMessagesBackgroundColor]; |
|---|
| | 325 | [WCSettings setBool:[_messagesListAlternateRowsButton state] forKey:WCMessagesListAlternateRows]; |
|---|
| | 326 | |
|---|
| | 327 | // --- appearance/news |
|---|
| | 328 | [WCSettings setObject:[_newsTextColorWell color] forKey:WCNewsTextColor]; |
|---|
| | 329 | [WCSettings setObject:[_newsTitlesColorWell color] forKey:WCNewsTitlesColor]; |
|---|
| | 330 | [WCSettings setObject:[_newsBackgroundColorWell color] forKey:WCNewsBackgroundColor]; |
|---|
| | 331 | |
|---|
| | 332 | // --- appearance/files |
|---|
| | 333 | [WCSettings setBool:[_filesAlternateRowsButton state] forKey:WCFilesAlternateRows]; |
|---|
| | 334 | |
|---|
| | 335 | // --- appearance/preview |
|---|
| | 336 | [WCSettings setObject:[_previewTextColorWell color] forKey:WCPreviewTextColor]; |
|---|
| | 337 | [WCSettings setObject:[_previewBackgroundColorWell color] forKey:WCPreviewBackgroundColor]; |
|---|
| | 338 | |
|---|
| | 339 | // --- bookmarks |
|---|
| | 340 | [self _unselectBookmark]; |
|---|
| | 341 | |
|---|
| | 342 | // --- chat |
|---|
| | 343 | [WCSettings setInt:[[_chatStyleMatrix selectedCell] tag] forKey:WCChatStyle]; |
|---|
| | 344 | [WCSettings setBool:[_historyScrollbackButton state] forKey:WCHistoryScrollback]; |
|---|
| | 345 | [WCSettings setInt:[[_historyScrollbackModifierPopUpButton selectedItem] tag] |
|---|
| | 346 | forKey:WCHistoryScrollbackModifier]; |
|---|
| | 347 | [WCSettings setBool:[_tabCompleteNicksButton state] forKey:WCTabCompleteNicks]; |
|---|
| | 348 | [WCSettings setObject:[_tabCompleteNicksTextField stringValue] forKey:WCTabCompleteNicksString]; |
|---|
| | 349 | [WCSettings setBool:[_timestampChatButton state] forKey:WCTimestampChat]; |
|---|
| | 350 | [WCSettings setInt:[_timestampChatIntervalTextField intValue] * 60 forKey:WCTimestampChatInterval]; |
|---|
| | 351 | [WCSettings setBool:[_timestampEveryLineButton state] forKey:WCTimestampEveryLine]; |
|---|
| | 352 | [WCSettings setObject:[_timestampEveryLineColorWell color] forKey:WCTimestampEveryLineColor]; |
|---|
| | 353 | |
|---|
| | 354 | // --- events |
|---|
| | 355 | [self _updateEvents]; |
|---|
| | 356 | |
|---|
| | 357 | // --- files |
|---|
| | 358 | [WCSettings setObject:[_downloadFolderTextField stringValue] forKey:WCDownloadFolder]; |
|---|
| | 359 | [WCSettings setBool:[_openFoldersInNewWindowsButton state] forKey:WCOpenFoldersInNewWindows]; |
|---|
| | 360 | [WCSettings setBool:[_queueTransfersButton state] forKey:WCQueueTransfers]; |
|---|
| | 361 | [WCSettings setBool:[_encryptTransfersButton state] forKey:WCEncryptTransfers]; |
|---|
| | 362 | [WCSettings setBool:[_showTransfersProgressBarButton state] forKey:WCShowTransfersProgressBar]; |
|---|
| | 363 | [WCSettings setBool:[_removeTransfersButton state] forKey:WCRemoveTransfers]; |
|---|
| | 364 | |
|---|
| | 365 | [[NSNotificationCenter defaultCenter] postNotificationName:WCPreferencesDidChange object:self]; |
|---|
| | 366 | } |
|---|
| | 367 | |
|---|
| | 368 | |
|---|
| | 369 | |
|---|
| | 370 | - (void)_selectBookmark { |
|---|
| | 371 | NSDictionary *bookmark; |
|---|
| | 372 | int row; |
|---|
| | 373 | |
|---|
| | 374 | row = [_bookmarksTableView selectedRow]; |
|---|
| | 375 | |
|---|
| | 376 | if(row >= 0) { |
|---|
| | 377 | bookmark = [WCSettings bookmarkAtIndex:row]; |
|---|
| | 378 | |
|---|
| | 379 | [_bookmarksNameTextField setEnabled:YES]; |
|---|
| | 380 | [_bookmarksAddressTextField setEnabled:YES]; |
|---|
| | 381 | [_bookmarksLoginTextField setEnabled:YES]; |
|---|
| | 382 | [_bookmarksPasswordTextField setEnabled:YES]; |
|---|
| | 383 | [_bookmarksNickTextField setEnabled:YES]; |
|---|
| | 384 | [_bookmarksStatusTextField setEnabled:YES]; |
|---|
| | 385 | |
|---|
| | 386 | [_bookmarksNameTextField setStringValue:[bookmark objectForKey:WCBookmarksName]]; |
|---|
| | 387 | [_bookmarksAddressTextField setStringValue:[bookmark objectForKey:WCBookmarksAddress]]; |
|---|
| | 388 | [_bookmarksLoginTextField setStringValue:[bookmark objectForKey:WCBookmarksLogin]]; |
|---|
| | 389 | |
|---|
| | 390 | if([[[WCKeychain keychain] passwordForBookmark:bookmark] length] > 0) |
|---|
| | 391 | [_bookmarksPasswordTextField setStringValue:WCBookmarksPasswordMagic]; |
|---|
| | 392 | else |
|---|
| | 393 | [_bookmarksPasswordTextField setStringValue:@""]; |
|---|
| | 394 | |
|---|
| | 395 | [_bookmarksNickTextField setStringValue:[bookmark objectForKey:WCBookmarksNick]]; |
|---|
| | 396 | [_bookmarksStatusTextField setStringValue:[bookmark objectForKey:WCBookmarksStatus]]; |
|---|
| | 397 | } else { |
|---|
| | 398 | [_bookmarksNameTextField setEnabled:NO]; |
|---|
| | 399 | [_bookmarksAddressTextField setEnabled:NO]; |
|---|
| | 400 | [_bookmarksLoginTextField setEnabled:NO]; |
|---|
| | 401 | [_bookmarksPasswordTextField setEnabled:NO]; |
|---|
| | 402 | [_bookmarksNickTextField setEnabled:NO]; |
|---|
| | 403 | [_bookmarksStatusTextField setEnabled:NO]; |
|---|
| | 404 | |
|---|
| | 405 | [_bookmarksNameTextField setStringValue:@""]; |
|---|
| | 406 | [_bookmarksAddressTextField setStringValue:@""]; |
|---|
| | 407 | [_bookmarksLoginTextField setStringValue:@""]; |
|---|
| | 408 | [_bookmarksPasswordTextField setStringValue:@""]; |
|---|
| | 409 | [_bookmarksNickTextField setStringValue:@""]; |
|---|
| | 410 | [_bookmarksStatusTextField setStringValue:@""]; |
|---|
| | 411 | } |
|---|
| | 412 | } |
|---|
| | 413 | |
|---|
| | 414 | |
|---|
| | 415 | |
|---|
| | 416 | - (void)_unselectBookmark { |
|---|
| | 417 | NSMutableDictionary *bookmark; |
|---|
| | 418 | NSString *password; |
|---|
| | 419 | int row; |
|---|
| | 420 | |
|---|
| | 421 | row = [_bookmarksTableView selectedRow]; |
|---|
| | 422 | |
|---|
| | 423 | if(row < 0) |
|---|
| | 424 | return; |
|---|
| | 425 | |
|---|
| | 426 | bookmark = [[WCSettings bookmarkAtIndex:row] mutableCopy]; |
|---|
| | 427 | [bookmark setObject:[_bookmarksNameTextField stringValue] forKey:WCBookmarksName]; |
|---|
| | 428 | [bookmark setObject:[_bookmarksAddressTextField stringValue] forKey:WCBookmarksAddress]; |
|---|
| | 429 | [bookmark setObject:[_bookmarksLoginTextField stringValue] forKey:WCBookmarksLogin]; |
|---|
| | 430 | [bookmark setObject:[_bookmarksNickTextField stringValue] forKey:WCBookmarksNick]; |
|---|
| | 431 | [bookmark setObject:[_bookmarksStatusTextField stringValue] forKey:WCBookmarksStatus]; |
|---|
| | 432 | [WCSettings setBookmark:bookmark atIndex:row]; |
|---|
| | 433 | [bookmark release]; |
|---|
| | 434 | |
|---|
| | 435 | password = [_bookmarksPasswordTextField stringValue]; |
|---|
| | 436 | |
|---|
| | 437 | if(![password isEqualToString:WCBookmarksPasswordMagic]) { |
|---|
| | 438 | if([password length] > 0) |
|---|
| | 439 | [[WCKeychain keychain] setPassword:password forBookmark:bookmark]; |
|---|
| | 440 | else |
|---|
| | 441 | [[WCKeychain keychain] deletePasswordForBookmark:bookmark]; |
|---|
| | 442 | } |
|---|
| | 443 | } |
|---|
| | 444 | |
|---|
| | 445 | |
|---|
| | 446 | |
|---|
| | 447 | - (void)_updateEvents { |
|---|
| | 448 | NSMutableDictionary *newEvent; |
|---|
| | 449 | NSDictionary *event; |
|---|
| | 450 | int tag; |
|---|
| | 451 | BOOL on; |
|---|
| | 452 | |
|---|
| | 453 | if(_selectedEvent > 0) { |
|---|
| | 454 | newEvent = [[WCSettings eventForTag:_selectedEvent] mutableCopy]; |
|---|
| | 455 | [newEvent setInt:_selectedEvent forKey:WCEventsEvent]; |
|---|
| | 456 | [newEvent setBool:[_playSoundButton state] forKey:WCEventsPlaySound]; |
|---|
| | 457 | [newEvent setObject:[_soundsPopUpButton titleOfSelectedItem] forKey:WCEventsSound]; |
|---|
| | 458 | [newEvent setBool:[_bounceInDockButton state] forKey:WCEventsBounceInDock]; |
|---|
| | 459 | [newEvent setBool:[_postInChatButton state] forKey:WCEventsPostInChat]; |
|---|
| | 460 | [WCSettings setEvent:newEvent forTag:_selectedEvent]; |
|---|
| | 461 | [newEvent release]; |
|---|
| | 462 | } |
|---|
| | 463 | |
|---|
| | 464 | tag = [_eventsPopUpButton tagOfSelectedItem]; |
|---|
| | 465 | event = [WCSettings eventForTag:tag]; |
|---|
| | 466 | [_playSoundButton setState:[event boolForKey:WCEventsPlaySound]]; |
|---|
| | 467 | |
|---|
| | 468 | if([(NSString *) [event objectForKey:WCEventsSound] length] > 0) |
|---|
| | 469 | [_soundsPopUpButton selectItemWithTitle:[event objectForKey:WCEventsSound]]; |
|---|
| | 470 | |
|---|
| | 471 | [_bounceInDockButton setState:[event boolForKey:WCEventsBounceInDock]]; |
|---|
| | 472 | [_postInChatButton setState:[event boolForKey:WCEventsPostInChat]]; |
|---|
| | 473 | |
|---|
| | 474 | on = (tag == WCEventsUserJoined || tag == WCEventsUserChangedNick || tag == WCEventsUserLeft); |
|---|
| | 475 | [_postInChatButton setEnabled:on]; |
|---|
| | 476 | |
|---|
| | 477 | [self _touchEvents]; |
|---|
| | 478 | |
|---|
| | 479 | _selectedEvent = tag; |
|---|
| | 480 | } |
|---|
| | 481 | |
|---|
| | 482 | |
|---|
| | 483 | |
|---|
| | 484 | - (void)_touchEvents { |
|---|
| | 485 | BOOL on; |
|---|
| | 486 | |
|---|
| | 487 | on = [_playSoundButton state] || [_bounceInDockButton state] || [_postInChatButton state]; |
|---|
| | 488 | [[_eventsPopUpButton selectedItem] setImage:[NSImage imageNamed:on ? @"EventOn" : @"EventOff"]]; |
|---|
| | 489 | |
|---|
| | 490 | [_soundsPopUpButton setEnabled:[_playSoundButton state]]; |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | |
|---|
| | 494 | |
|---|
| | 495 | #pragma mark - |
|---|
| | 496 | |
|---|
| | 497 | - (void)_setIcon:(NSImage *)icon { |
|---|
| | 498 | NSBitmapImageRep *imageRep; |
|---|
| | 499 | NSImage *image; |
|---|
| | 500 | NSData *data; |
|---|
| | 501 | NSSize iconSize, size; |
|---|
| | 502 | |
|---|
| | 503 | iconSize = size = [icon size]; |
|---|
| | 504 | |
|---|
| | 505 | if(iconSize.width > 32.0 || iconSize.height > 32.0) { |
|---|
| | 506 | if(iconSize.width > 32.0 && iconSize.height <= 32.0) |
|---|
| | 507 | size = NSMakeSize(32.0, iconSize.height); |
|---|
| | 508 | else if(iconSize.width <= 32.0 && iconSize.height > 32.0) |
|---|
| | 509 | size = NSMakeSize(iconSize.height, 32.0); |
|---|
| | 510 | else if(iconSize.width > iconSize.height) |
|---|
| | 511 | size = NSMakeSize(32.0, 32.0 * (iconSize.width / iconSize.height)); |
|---|
| | 512 | else if(iconSize.width < iconSize.height) |
|---|
| | 513 | size = NSMakeSize(32.0 * (iconSize.width / iconSize.height), 32.0); |
|---|
| | 514 | else |
|---|
| | 515 | size = NSMakeSize(32.0, 32.0); |
|---|
| | 516 | |
|---|
| | 517 | [icon setScalesWhenResized:YES]; |
|---|
| | 518 | [icon setSize:size]; |
|---|
| | 519 | } |
|---|
| | 520 | |
|---|
| | 521 | if(NSEqualSizes(iconSize, size)) { |
|---|
| | 522 | image = icon; |
|---|
| | 523 | } else { |
|---|
| | 524 | image = [[NSImage alloc] initWithSize:size]; |
|---|
| | 525 | [image lockFocus]; |
|---|
| | 526 | [icon drawAtPoint:NSZeroPoint |
|---|
| | 527 | fromRect:NSMakeRect(0.0, 0.0, size.width, size.height) |
|---|
| | 528 | operation:NSCompositeCopy |
|---|
| | 529 | fraction:1.0]; |
|---|
| | 530 | [image unlockFocus]; |
|---|
| | 531 | |
|---|
| | 532 | [_iconImageView setImage:image]; |
|---|
| | 533 | [image release]; |
|---|
| | 534 | } |
|---|
| | 535 | |
|---|
| | 536 | imageRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]]; |
|---|
| | 537 | data = [imageRep representationUsingType:NSPNGFileType properties:NULL]; |
|---|
| | 538 | |
|---|
| | 539 | [WCSettings setObject:[data base64EncodedString] forKey:WCCustomIcon]; |
|---|
| | 540 | [[NSNotificationCenter defaultCenter] postNotificationName:WCIconDidChange object:NULL]; |
|---|
| | 541 | } |
|---|
| | 542 | |
|---|
| | 543 | @end |
|---|
| | 544 | |
|---|
| | 545 | |
|---|
| | 546 | @implementation WCPreferences |
|---|
| | 547 | |
|---|
| | 548 | + (WCPreferences *)preferences { |
|---|
| | 549 | static id sharedPreferences; |
|---|
| | 550 | |
|---|
| | 551 | if(!sharedPreferences) |
|---|
| | 552 | sharedPreferences = [[self alloc] init]; |
|---|
| | 553 | |
|---|
| | 554 | return sharedPreferences; |
|---|
| | 555 | } |
|---|
| | 556 | |
|---|
| | 557 | |
|---|
| | 558 | |
|---|
| | 559 | - (id)init { |
|---|
| | 560 | self = [super initWithWindowNibName:@"Preferences"]; |
|---|
| | 561 | |
|---|
| | 562 | [self window]; |
|---|
| | 563 | |
|---|
| | 564 | [[NSNotificationCenter defaultCenter] |
|---|
| | 565 | addObserver:self |
|---|
| | 566 | selector:@selector(bookmarksDidChange:) |
|---|
| | 567 | name:WCBookmarksDidChange]; |
|---|
| | 568 | |
|---|
| | 569 | return self; |
|---|
| | 570 | } |
|---|
| | 571 | |
|---|
| | 572 | |
|---|
| | 573 | |
|---|
| | 574 | #pragma mark - |
|---|
| | 575 | |
|---|
| | 576 | - (void)windowDidLoad { |
|---|
| | 577 | NSEnumerator *enumerator; |
|---|
| | 578 | NSArray *sounds; |
|---|
| | 579 | NSString *path; |
|---|
| | 580 | WIColorCell *colorCell; |
|---|
| | 581 | |
|---|
| | 582 | colorCell = [[WIColorCell alloc] init]; |
|---|
| | 583 | [colorCell setEditable:YES]; |
|---|
| | 584 | [colorCell setTarget:self]; |
|---|
| | 585 | [colorCell setAction: @selector(showColorPanel:)]; |
|---|
| | 586 | [_highlightsColorTableColumn setDataCell:colorCell]; |
|---|
| | 587 | [colorCell release]; |
|---|
| | 588 | |
|---|
| | 589 | [_bookmarksTableView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
|---|
| | 590 | [_highlightsTableView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
|---|
| | 591 | [_ignoresTableView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
|---|
| | 592 | |
|---|
| | 593 | [_bookmarksTableView registerForDraggedTypes:[NSArray arrayWithObject:WCBookmarkPboardType]]; |
|---|
| | 594 | [_highlightsTableView registerForDraggedTypes:[NSArray arrayWithObject:WCIgnorePboardType]]; |
|---|
| | 595 | [_ignoresTableView registerForDraggedTypes:[NSArray arrayWithObject:WCIgnorePboardType]]; |
|---|
| | 596 | |
|---|
| | 597 | sounds = [[NSFileManager defaultManager] libraryResourcesForTypes:[NSSound soundUnfilteredFileTypes] |
|---|
| | 598 | inDirectory:@"Sounds"]; |
|---|
| | 599 | enumerator = [sounds objectEnumerator]; |
|---|
| | 600 | |
|---|
| | 601 | [_soundsPopUpButton removeAllItems]; |
|---|
| | 602 | |
|---|
| | 603 | while((path = [enumerator nextObject])) |
|---|
| | 604 | [_soundsPopUpButton addItemWithTitle:[[path lastPathComponent] stringByDeletingPathExtension]]; |
|---|
| | 605 | |
|---|
| | 606 | [[self window] setToolbar:[self _toolbar]]; |
|---|
| | 607 | [[self window] center]; |
|---|
| | 608 | |
|---|
| | 609 | [self _loadSettings]; |
|---|
| | 610 | [self _selectTab:@"General"]; |
|---|
| | 611 | } |
|---|
| | 612 | |
|---|
| | 613 | |
|---|
| | 614 | |
|---|
| | 615 | - (void)windowWillClose:(NSNotification *)notification { |
|---|
| | 616 | [self _saveSettings]; |
|---|