/*************************************************************************************************************
* This file contains creating and functionality of info system
* 2012/8 by Dlxko
* Version 3.0
**************************************************************************************************************/
#include "Infos.h"

// Widgets
static GtkWidget *info_window;
static GtkWidget *info_vbox;

// Function to apply server for info
void function_info_request(GtkWidget *unused_button, gint input_buddy_number)
{
	// Check buddy nuber
	if( (input_buddy_number == 0) || (input_buddy_number < 0) || (input_buddy_number > MAX_BUDDIES))
		return;

	// Count lenght
	sending_text_len = LENGHT_SIZE + DATA_ONE_SIZE + OPCODE_SIZE;
	sprintf_s(sending_text_len_char, LENGHT_SIZE, "%d", sending_text_len);

	// Update text for server with "DX_OPCODE_INF" and name datas
	memset(sending_text,0,BUF_SIZE);
	memcpy(sending_text, sending_text_len_char, LENGHT_SIZE);
	memcpy(&sending_text[LENGHT_SIZE], DX_OPCODE_INF, OPCODE_SIZE);
	memcpy(&sending_text[LENGHT_SIZE+OPCODE_SIZE], buddy[input_buddy_number].nick_name, strlen(buddy[input_buddy_number].nick_name));

	// Send socket
	function_send_data(sending_text, sending_text_len);
	return;
}

// Function to show hidden info window
void function_show_info_window()
{
	// Show it if hidden
	if (!gtk_widget_get_visible(info_window))
		gtk_widget_show_all(info_window);
}

// Function to create info window
void create_info_window()
{
	// New window, parameters, title, closing
	info_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request (GTK_WIDGET (info_window), 200, 300);
	gtk_window_set_title (GTK_WINDOW (info_window), LANG_INFOS_WINDOW_TITLE);
	gtk_widget_hide_on_delete(info_window);
	gtk_window_set_icon(GTK_WINDOW(info_window), default_icon);
	g_signal_connect_swapped (info_window, "delete-event", G_CALLBACK (signal_close_info), info_window);

	// Create new box and container and show
	info_vbox = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (info_window), info_vbox);

	// Create label
	info_label = gtk_label_new(LANG_CANT_LOAD_INFOS);
	gtk_box_pack_start (GTK_BOX (info_vbox), info_label, FALSE, TRUE, 5);
}