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

// Function to create universal vbox
void singlebody_control_widget_vbox()
{
	log_vbox = gtk_vbox_new (FALSE, 0);
}

// Function to create username entry
void singlebody_control_widget_loggin_username()
{
	log_username = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (log_username), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (log_username), LANG_ENTER_NAME);
	g_signal_connect (log_username, "activate", G_CALLBACK (singlebody_control_registration_shown), NULL);
	gtk_editable_select_region (GTK_EDITABLE (log_username), 0, GTK_ENTRY (log_username)->text_length);
}

// Function to create password entry
void singlebody_control_widget_loggin_password()
{
	log_password = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (log_password), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (log_password), LANG_ENTER_PASSWORD);
	gtk_entry_set_visibility(GTK_ENTRY (log_password), FALSE);
	g_signal_connect (log_password, "activate", G_CALLBACK (signal_send_loggin), NULL);
	gtk_editable_select_region (GTK_EDITABLE (log_password), 0, GTK_ENTRY (log_password)->text_length);
}

// Function to create loggin label
void singlebody_control_widget_loggin_label()
{
	log_label = gtk_label_new (LANG_LABEL_LOGIN);
	gtk_label_set_justify(GTK_LABEL (log_label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL (log_label), FALSE);
	gtk_label_set_selectable(GTK_LABEL (log_label), FALSE);    
	gtk_label_set_single_line_mode(GTK_LABEL (log_label), TRUE); 
}

// Function to create registartion entry 1
void singlebody_control_widget_registration_entry1()
{
	reg_entry1 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry1), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry1), LANG_NAME);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry1), 0, GTK_ENTRY (reg_entry1)->text_length);
}

// Function to create registartion entry 2
void singlebody_control_widget_registration_entry2()
{
	reg_entry2 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry2), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry2), LANG_SURNAME);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry2), 0, GTK_ENTRY (reg_entry2)->text_length);
}

// Function to create registartion entry 3
void singlebody_control_widget_registration_entry3()
{
	reg_entry3 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry3), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry3), LANG_NICKNAME2);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry3), 0, GTK_ENTRY (reg_entry3)->text_length);
}

// Function to create registartion entry 8
void singlebody_control_widget_registration_entry8()
{
	reg_entry8 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry8), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry8), LANG_PASSWORD);
	gtk_entry_set_visibility(GTK_ENTRY (reg_entry8), FALSE);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry8), 0, GTK_ENTRY (reg_entry8)->text_length);
}

// Function to create registartion entry 4
void singlebody_control_widget_registration_entry4()
{
	reg_entry4 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry4), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry4), LANG_CITY);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry4), 0, GTK_ENTRY (reg_entry4)->text_length);
}

// Function to create registartion entry 5
void singlebody_control_widget_registration_entry5()
{
	reg_entry5 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry5), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry5), LANG_COUNTRY);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry5), 0, GTK_ENTRY (reg_entry5)->text_length);
}

// Function to create registartion entry 6
void singlebody_control_widget_registration_entry6()
{
	reg_entry6 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry6), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry6), LANG_AGE);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry6), 0, GTK_ENTRY (reg_entry6)->text_length);
}

// Function to create registartion entry 7
void singlebody_control_widget_registration_entry7()
{
	reg_entry7 = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_entry7), DATA_ONE_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_entry7), LANG_GENDER);
	gtk_editable_select_region (GTK_EDITABLE (reg_entry7), 0, GTK_ENTRY (reg_entry7)->text_length);
}

// Function to create registartion entry for image
void singlebody_control_widget_registration_image()
{
	reg_image = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY (reg_image), AVATAR_SIZE);
	gtk_entry_set_text (GTK_ENTRY (reg_image), LANG_GRAVATAR);
	gtk_editable_select_region (GTK_EDITABLE (reg_image), 0, GTK_ENTRY (reg_image)->text_length);
	g_signal_connect (G_OBJECT(reg_image), "activate", G_CALLBACK (signal_send_registration), NULL);
}

// Function to create registartion separator
void singlebody_control_widget_registration_separator()
{
	reg_separator = gtk_hseparator_new ();
	gtk_widget_set_size_request (reg_separator, 400, 5);
}

// Function to create registartion label
void singlebody_control_widget_registration_label()
{
	reg_label = gtk_label_new (LANG_REGISTER);
	gtk_label_set_justify(GTK_LABEL (reg_label), GTK_JUSTIFY_CENTER);
	gtk_label_set_line_wrap(GTK_LABEL (reg_label), FALSE);
	gtk_label_set_selectable(GTK_LABEL (reg_label), FALSE);    
	gtk_label_set_single_line_mode(GTK_LABEL (reg_label), TRUE); 
}

// Function to create registartion button
void singlebody_control_widget_registration_button()
{
	reg_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
	g_signal_connect (G_OBJECT(reg_button), "clicked", G_CALLBACK (signal_send_registration), NULL);
}

// Function to create buddylist
void singlebody_control_widget_buddylist_create()
{
	// Create scroll, set options, and pack into vbox
	buddy_scroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(buddy_scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

	// Create tree view
	buddy_tree_view = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING);

	// Create shortable list
	buddy_sortable_model = GTK_TREE_SORTABLE(buddy_tree_view);
	gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(buddy_sortable_model), STATUS_H_COLUM, function_compare_rows, GINT_TO_POINTER(STATUS_H_COLUM), NULL);
	gtk_tree_sortable_set_sort_column_id(buddy_sortable_model, STATUS_H_COLUM, GTK_SORT_DESCENDING);

	// Create buddy treeView and renderer
	buddy_treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(buddy_tree_view));

	// Create new avatar colum and renderer
	buddy_renderer = gtk_cell_renderer_pixbuf_new();
	buddy_column = gtk_tree_view_column_new_with_attributes(LANG_STATUS, buddy_renderer, "pixbuf", STATUS_COLUM, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW (buddy_treeView), buddy_column);

	// Create new nickname colum and renderer
	buddy_renderer = gtk_cell_renderer_text_new();
	buddy_column = gtk_tree_view_column_new_with_attributes(LANG_NICKNAME, buddy_renderer, "text", NICK_COLUM, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW (buddy_treeView), buddy_column);

	// Create new avatar colum and renderer
	buddy_renderer = gtk_cell_renderer_pixbuf_new();
	buddy_column = gtk_tree_view_column_new_with_attributes(LANG_AVATAR, buddy_renderer, "pixbuf", AVATAR_COLUM, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW (buddy_treeView), buddy_column);
	buddy_renderer = gtk_cell_renderer_text_new();

	// Create new colum status
	buddy_renderer = gtk_cell_renderer_text_new();
	buddy_column = gtk_tree_view_column_new_with_attributes("a", buddy_renderer, "text", STATUS_H_COLUM, NULL);
	gtk_tree_view_column_set_visible(buddy_column, FALSE);
	gtk_tree_view_append_column(GTK_TREE_VIEW (buddy_treeView), buddy_column);

	// Create toolbar
	buddy_toolbar = gtk_toolbar_new();
	gtk_toolbar_set_icon_size(GTK_TOOLBAR(buddy_toolbar), GTK_ICON_SIZE_MENU);
	gtk_toolbar_set_style(GTK_TOOLBAR(buddy_toolbar), GTK_TOOLBAR_ICONS);
	gtk_container_set_border_width(GTK_CONTAINER(buddy_toolbar), 0);

	// Create buttons
	buddy_addremo = gtk_tool_button_new_from_stock(GTK_STOCK_ADD);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_addremo, -1);
	buddy_showhide = gtk_tool_button_new_from_stock(GTK_STOCK_CLEAR);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_showhide, -1);
	buddy_events = gtk_tool_button_new_from_stock(GTK_STOCK_INDENT);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_events, -1);
	buddy_disturb = gtk_tool_button_new_from_stock(GTK_STOCK_NO);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_disturb, -1);
	
	// Create selection
	buddy_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(buddy_treeView));

	// Handle signals
	g_signal_connect(buddy_treeView, "row-activated", (GCallback) signal_list_row_activated, NULL);
	g_signal_connect(G_OBJECT(buddy_addremo), "clicked", G_CALLBACK(signal_create_buddy_adder), NULL);
	g_signal_connect(G_OBJECT(buddy_showhide), "clicked", G_CALLBACK(function_buddy_hide), NULL);
	g_signal_connect(G_OBJECT(buddy_disturb), "clicked", G_CALLBACK(function_dont_disturb), NULL);
	g_signal_connect (G_OBJECT(buddy_events), "clicked", G_CALLBACK (signal_show_requests), NULL);
}