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

#import "JubGtkUI.h"

@interface AppDelegate: OFObject
    <OFApplicationDelegate, XMPPConnectionDelegate>
{
	XMPPConnection *connection;
	XMPPRoster *roster;
	id<JubUI> ui;
}
@end

OF_APPLICATION_DELEGATE(AppDelegate)

@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
	ui = [[JubGtkUI alloc] init];

	connection = [[XMPPConnection alloc] init];
	[connection addDelegate: self];

	connection.domain = @"localhost";
	connection.username = @"alice";
	connection.password = @"test";

	[connection connect];
	[connection handleConnection];

	roster = [[XMPPRoster alloc] initWithConnection: connection];
	[roster addDelegate: [ui rosterDelegate]];

	[ui startUIThread];
}

- (void)connection: (XMPPConnection*)conn_
     wasBoundToJID: (XMPPJID*)jid
{
	of_log(@"Bound to JID: %@", [jid fullJID]);

	[roster requestRoster];
}

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

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