/*
 * astconfig: Asterisk Configuration Tool
 *
 * Configure Asterisk
 *
 * IAX module support
 *
 * Copyright (C) 2002 Linux Support Services, Inc.
 *
 */

#include <gtk/gtk.h>
#include <asterisk/astconfig.h>
#include <asterisk/config.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "pipe.xpm"
#include "ksmiletris.xpm"	/* Friend */
#include "kdmconfig.xpm"	/* User */
#include "background.xpm"	/* Peer */

static GtkWidget *mainw;
static GtkWidget *elist;

static int visible = 0;

static void build_main(void)
{
	GtkWidget *frame;
	GtkWidget *hbox;
	GtkWidget *vbox;
	GtkWidget *bbox;
	GtkWidget *sbox;
	GtkWidget *backb;

	mainw = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_realize(mainw);
	gtk_window_set_title(GTK_WINDOW(mainw), "AstConfig: IAX Configuration");

	elist = gtk_list_new();
	frame = gtk_frame_new("IAX Entities");
	
	gtk_widget_set_usize(frame, 200, 300);

	/* Silly box for space around list */
	sbox = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(sbox), elist, TRUE, TRUE, 5);
	gtk_container_add(GTK_CONTAINER(frame), sbox);
	gtk_container_set_border_width(GTK_CONTAINER(sbox), 5);


	vbox = gtk_vbox_new(FALSE, 0);
	hbox = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 5);

	backb = gtk_button_new_with_label("Return to main");
	gtk_widget_set_usize(backb, 80, 20);
	
	bbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_end(GTK_BOX(bbox), backb, FALSE, FALSE, 5);

	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5);

	gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);

	gtk_container_add(GTK_CONTAINER(mainw), vbox);
}

	
static int iax_load(void)
{
	struct ast_config *cfg;
	struct ast_variable *var;
	char *ent;
	if (!mainw)
		build_main();
	cfg = ast_load("iax.conf");
	if (cfg) {
		var = ast_variable_browse(cfg, "general");
		while(var) {
			var = var->next;
		}
		ent = ast_category_browse(cfg, NULL);
		while(ent) {
			if (strcasecmp(ent, "general")) {
				printf("Entry: %s\n", ent);
				var = ast_variable_browse(cfg, ent);
			}
			ent = ast_category_browse(cfg, ent);
		}
		ast_destroy(cfg);
	}
	return 0;
}

static void show_main(void)
{
	gtk_widget_show_all(mainw);
	visible = 1;
}

static int iax_launch(void)
{
	if (!mainw) {
		iax_load();
		show_main();
	}
	return 0;
}

static int iax_changes(void)
{
	printf("Changes?!\n");
	return 0;
}

static int iax_needrestart(void)
{
	printf("NeedRestart?!\n");
	return 0;
}

static int iax_savechanges(void)
{
	printf("Save!\n");
	return 0;
}


struct config_module modiax = {
	"Inter Asterisk eXchange (IAX)",
	"Inter-Asterisk eXchange is a powerful VoIP protocol used natively by "
"Asterisk for communicating with other Asterisk PBX's and compatible "
"products such as Gnophone and SNOM Phones.\n\nIAX is more efficient than "
"other RTP based protocols such as H.323 and SIP, and provides features "
"not found in those protocols, such as the ability to transparently "
"interoperate with NAT/PAT and IP Masquerade firewalls, remote dialplan "
"support, internationalization, context specification, authentication.",
	pipe_xpm,
	iax_launch,
	iax_changes,
	iax_needrestart,
	iax_savechanges,
	iax_load
	
};

int mod_init(void)
{
	printf("Initialized IAX module\n");
	module_register(&modiax);
	return 0;
}
