/*************************************************************************************************************
* This file contains Control SingleBodies systems
* 2012/10 by Dlxko
* Version 4.0
**************************************************************************************************************/
#include "ControlSingleBodies.h"

// Function to delete all widgets before refreshing another ones
void additional_function_control_single_bodies_delete_oldies()
{
	// If loggin is shown
	if(singlebody_loggin_shown)
	{
		gtk_widget_destroy(log_label);
		gtk_widget_destroy(log_password);
		gtk_widget_destroy(log_username);
		gtk_widget_destroy(log_vbox);
		singlebody_loggin_shown = false;
	}
	// If registration is shown
	else if (singlebody_registration_shown)
	{
		gtk_widget_destroy(reg_button);
		gtk_widget_destroy(reg_label);
		gtk_widget_destroy(reg_separator);
		gtk_widget_destroy(reg_image);
		gtk_widget_destroy(reg_entry7);
		gtk_widget_destroy(reg_entry6);
		gtk_widget_destroy(reg_entry5);
		gtk_widget_destroy(reg_entry4);
		gtk_widget_destroy(reg_entry3);
		gtk_widget_destroy(reg_entry2);
		gtk_widget_destroy(reg_entry1);
		gtk_widget_destroy(log_vbox);
		singlebody_registration_shown = false;
	}
}

// Function to create new widgets
void additional_function_control_single_bodies_create_freshes(int function_type)
{
	// For loggin window
	if(function_type == 1)
	{
		singlebody_control_widget_vbox();
		singlebody_control_widget_loggin_username();
		singlebody_control_widget_loggin_password();
		singlebody_control_widget_loggin_label();
	}
	// For registration window
	else if(function_type == 2)
	{
		singlebody_control_widget_vbox();
		singlebody_control_widget_registration_entry1();
		singlebody_control_widget_registration_entry2();
		singlebody_control_widget_registration_entry3();
		singlebody_control_widget_registration_entry8();
		singlebody_control_widget_registration_entry4();
		singlebody_control_widget_registration_entry5();
		singlebody_control_widget_registration_entry6();
		singlebody_control_widget_registration_entry7();
		singlebody_control_widget_registration_image();
		singlebody_control_widget_registration_separator();
		singlebody_control_widget_registration_label();
		singlebody_control_widget_registration_button();
	}
	// For buddylist
	else if(function_type == 3)
	{
		singlebody_control_widget_vbox();
		singlebody_control_widget_buddylist_create();
	}
}

// Function to composite design
void additional_function_control_single_bodies_do_design(int function_type)
{
	// For loggin
	if(function_type == 1)
	{
		gtk_window_resize (GTK_WINDOW (log_window), 300, 80);
		gtk_container_add (GTK_CONTAINER (log_window), log_vbox);
		gtk_box_pack_start (GTK_BOX (log_vbox), log_username, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), log_password, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), log_label, FALSE, TRUE, 5);
		gtk_widget_show_all(log_window);
	}
	// For registration
	else if(function_type == 2)
	{
		gtk_window_resize (GTK_WINDOW (log_window), 400, 340);
		gtk_container_add (GTK_CONTAINER (log_window), log_vbox);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry1, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry2, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry3, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry8, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry4, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry5, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry6, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_entry7, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_image, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_separator, FALSE, TRUE, 5);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_label, FALSE, TRUE, 5);
		gtk_box_pack_start (GTK_BOX (log_vbox), reg_button, FALSE, TRUE, 5);
		gtk_widget_show_all(log_window);
	}
	// For buddylist
	else if(function_type == 3)
	{
		// Pack them into container
		gtk_window_set_title(GTK_WINDOW(log_window), LANG_CONTACTS);
		gtk_window_set_opacity(GTK_WINDOW(log_window), 1);
        gtk_window_resize(GTK_WINDOW(log_window), 130, 400);

		gtk_container_add (GTK_CONTAINER (log_window), log_vbox);
		gtk_box_pack_start(GTK_BOX(log_vbox), buddy_toolbar, FALSE, FALSE, 0);
		gtk_box_pack_start(GTK_BOX(log_vbox), buddy_scroll, TRUE, TRUE, 0);
		gtk_container_add(GTK_CONTAINER(buddy_scroll), buddy_treeView);
		gtk_widget_show_all(log_window);
	}
}

// Function to update handlers
void  additional_function_control_single_bodies_update_handlers(int function_type)
{
	// For loggin
	if(function_type == 1)
	{
		singlebody_loggin_shown = true;
		singlebody_registration_shown = false;
		singlebody_buddylist_shown = false;
	}
	// For registration view
	else if(function_type == 2)
	{
		singlebody_loggin_shown = false;
		singlebody_registration_shown = true;
		singlebody_buddylist_shown = false;
	}
	// For buddylist
	else if(function_type == 3)
	{
		singlebody_loggin_shown = false;
		singlebody_registration_shown = false;
		singlebody_buddylist_shown = true;
	}
}

// Function to process scripts
void additional_function_control_single_bodies_process_scripts(int function_type)
{
	additional_function_control_single_bodies_delete_oldies();
	additional_function_control_single_bodies_create_freshes(function_type);
	additional_function_control_single_bodies_do_design(function_type);
	additional_function_control_single_bodies_update_handlers(function_type);
}

// Function to show loggin
void singlebody_control_loggin_shown()
{
	// If already shown return
	if(singlebody_loggin_shown)
		return;

	// Process script
	additional_function_control_single_bodies_process_scripts(1);
}

void singlebody_control_registration_shown()
{
	// If already shown return
	if(singlebody_registration_shown)
		return;

	// Process script
	additional_function_control_single_bodies_process_scripts(2);
}

// Function to show info or conversarion
void singlebody_control_buddylist_shown()
{
	// If already shown return
	if(singlebody_buddylist_shown)
		return;

	// Process script
	additional_function_control_single_bodies_process_scripts(3);
}