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

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

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

@implementation JubGtkUI
- initWithConnection: (XMPPConnection*)connection
{
	self = [super init];

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

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

		gtk_init(argc, argv);

		rosterUI = [[JubGtkRosterUI alloc]
		    initWithConnection: connection];
	} @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];
}

- (id<XMPPRosterDelegate>)rosterDelegate
{
	return rosterUI;
}
@end
