#import <ObjXMPP/ObjXMPP.h>
#include <gtk/gtk.h>

#import "JubGtkUI.h"
#import "JubGtkChatUI.h"
#import "JubGtkRosterUI.h"

void on_roster_window_destroy(GObject *object, gpointer user_data)
{
	gtk_main_quit();
}

@implementation JubGtkUI
- initWithClient: (JubChatClient*)client;
{
	self = [super init];

	@try {
		int *argc;
		char ***argv;

		[[OFApplication sharedApplication] getArgumentCount: &argc
						  andArgumentValues: &argv];

		gtk_init(argc, argv);

		_rosterUI = [[JubGtkRosterUI alloc]
		    initWithClient: client];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_rosterUI release];

	[super dealloc];
}

- (void)startUIThread
{
	[[OFThread threadWithBlock: ^(void){
		gtk_main();
		[OFApplication terminate];

		return nil;
	}] start];
}

- (Class)chatUIClass
{
	return [JubGtkChatUI class];
}

-      (void)client: (JubChatClient*)client
  didChangePresence: (XMPPPresence*)presence
{
	[_rosterUI   client: client
	  didChangePresence: presence];
}
@end
