/*************************************************************************************************************
* This file contains send disturb status action
* 2012/10 by Dlxko
* Version 4.0
**************************************************************************************************************/
#include "Disturb.h"

// Local static variables
static GtkToolItem *buddy_online;

// Function to send message
void function_do_disturb()
{
	// Count lenght of whole packet
	sending_text_len = LENGHT_SIZE + OPCODE_SIZE;
	memset(sending_text_len_char, 0, LENGHT_SIZE);
	sprintf_s(sending_text_len_char, LENGHT_SIZE, "%d", sending_text_len);

	// Update text for server with "DX_OPCODE_ONL" containing name and password datas
	memset(sending_text,0,BUF_SIZE);
	memcpy(sending_text, sending_text_len_char, LENGHT_SIZE);
	memcpy(&sending_text[LENGHT_SIZE], DX_OPCODE_ONL, OPCODE_SIZE);

	// Send packet to socket
	function_send_data(sending_text, sending_text_len);

	// Change pic
	gtk_container_remove(GTK_CONTAINER(buddy_toolbar), GTK_WIDGET (buddy_online));
	buddy_disturb = gtk_tool_button_new_from_stock(GTK_STOCK_NO);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_disturb, -1);
	g_signal_connect(G_OBJECT(buddy_disturb), "clicked", G_CALLBACK(function_dont_disturb), NULL);
	gtk_widget_show_all(buddy_toolbar);
}

// Function to send message
void function_dont_disturb()
{
	// Count lenght of whole packet
	sending_text_len = LENGHT_SIZE + OPCODE_SIZE;
	memset(sending_text_len_char, 0, LENGHT_SIZE);
	sprintf_s(sending_text_len_char, LENGHT_SIZE, "%d", sending_text_len);

	// Update text for server with "DX_OPCODE_DIS" containing name and password datas
	memset(sending_text,0,BUF_SIZE);
	memcpy(sending_text, sending_text_len_char, LENGHT_SIZE);
	memcpy(&sending_text[LENGHT_SIZE], DX_OPCODE_DIS, OPCODE_SIZE);

	// Send packet to socket
	function_send_data(sending_text, sending_text_len);

	// Change pic
	gtk_container_remove(GTK_CONTAINER(buddy_toolbar), GTK_WIDGET(buddy_disturb));
	buddy_online = gtk_tool_button_new_from_stock(GTK_STOCK_YES);
	gtk_toolbar_insert(GTK_TOOLBAR(buddy_toolbar), buddy_online, -1);
	g_signal_connect(G_OBJECT(buddy_online), "clicked", G_CALLBACK(function_do_disturb), NULL);
	gtk_widget_show_all(buddy_toolbar);
}