- (void)initChatWindow
{
XfireBuddyListEntry *entry = [[[_xfire buddyList] onlineEntries] objectAtIndex:[buddyListTableView selectedRow]];
chatListEnum = [[chatList openChats] objectEnumerator];
ChatWindowController *chat;
while ((chat = [chatListEnum nextObject]))
{
if ([[chat chatForBuddy] isEqualTo:entry])
{
[[chat windowForChat] makeKeyAndOrderFront:self];
} else
{
ChatWindowController *tempChat = [[ChatWindowController alloc] initWithBuddy:entry];
tempList = [chatList openChats];
[tempList addObject:tempChat];
[tempChat release];
}
}
[chatList mergeListWithChatList:tempList];
}NSLog(@"Before loop");
do {
NSLog(@"Starting while loop.");
if ([[chat chatForBuddy] isEqualTo:entry])
{
NSLog(@"Bringing existing chat forward for buddy: ", [entry displayName]);
[[chat windowForChat] makeKeyAndOrderFront:self];
} else
{
NSLog(@"Creating new chat for buddy: ", [entry displayName]);
ChatWindowController *tempChat = [[ChatWindowController alloc] initWithBuddy:entry];
[tempList addObjectsFromArray:[chatList openChats]];
[tempList addObject:tempChat];
[tempChat release];
}
} while (chat = [chatListEnum nextObject]);
NSLog(@"After Loop");
#import <Cocoa/Cocoa.h>
@interface XFChatList : NSObject {
NSMutableArray *openChats;
}
- (NSMutableArray *)openChats;
- (void)mergeListWithChatList:(NSMutableArray *)aList;
@end
-----------------------------------------------------------------------------------------
#import "XFChatList.h"
@implementation XFChatList
- (id)init
{
if (self = [super init])
{
openChats = [NSMutableArray array];
}
return self;
}
- (void)dealloc
{
NSLog(@"deallocating XFChatList");
[openChats release];
[super dealloc];
}
- (NSMutableArray *)openChats
{
NSLog(@"oc1");
return openChats;
}
- (void)mergeListWithChatList:(NSMutableArray *)aList
{
openChats = aList;
}
@end
#import <Cocoa/Cocoa.h>
#import "Xfire.h"
#import "ChatWindowController.h"
#import "XFChatList.h"
@interface XFController : NSWindowController <XfireDelegate>
{
IBOutlet NSTableView *buddyListTableView;
IBOutlet NSTextField *statusField;
IBOutlet NSTextField *nickField;
IBOutlet NSTextField *passwordField;
IBOutlet NSTextField *usernameField;
IBOutlet NSButton *connectButton;
IBOutlet NSPanel *addBuddy;
IBOutlet NSPanel *loginPanel;
IBOutlet NSWindow *mainWindow;
IBOutlet NSMenuItem *loginItem;
IBOutlet NSMenuItem *logoutItem;
IBOutlet NSTextField *buddyField;
IBOutlet NSTextField *buddyMessage;
BOOL connected;
XFChatList *chatList;
NSMutableArray *tempList;
NSEnumerator *chatListEnum;
Xfire *_xfire;
}
- (IBAction)login:(id)sender;
- (IBAction)logout:(id)sender;
- (IBAction)showLoginPanel:(id)sender;
- (IBAction)hideLoginPanel:(id)sender;
- (IBAction)setStatus:(id)sender;
- (IBAction)setNickName:(id)sender;
- (IBAction)showAddBuddyWindow:(id)sender;
- (IBAction)removeBuddy:(id)sender;
- (void)initChatWindow;
- (void)openChatWindowForBuddy:(XfireBuddyListEntry *)theBuddy;
- (IBAction)addBuddy:(id)sender;
- (IBAction)cancelAddBuddy:(id)sender;
@end