#import <ObjFW/ObjFW.h>
#import <ObjXMPP/ObjXMPP.h>

#import "JubGtkUI.h"
#import "JubConfig.h"
#import "JubChatClient.h"

@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
{
	JubChatClient *client;
	id<JubUI> ui;
}
@end

OF_APPLICATION_DELEGATE(AppDelegate)

@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
	JubConfig *config = [[[JubConfig alloc] initWithFile: @"config.xml"]
	    autorelease];

	client = [[JubChatClient alloc] initWithConfig: config];

	ui = [[JubGtkUI alloc] initWithClient: client];

	client.ui = ui;
	[client.connection addDelegate: self];

	[ui startUIThread];
}

-  (void)connection: (XMPPConnection*)conn
  didReceiveElement: (OFXMLElement*)element
{
	of_log(@"In:  %@", element);
}

- (void)connection: (XMPPConnection*)conn
    didSendElement: (OFXMLElement*)element
{
	of_log(@"Out: %@", element);
}

-  (void)connection: (XMPPConnection*)connection_
  didThrowException: (id)e
{
	@throw e;
}
@end
