/*************************************************************************************************************
* This file contains main header file
* 2012/8 by Dlxko
* Version 3.0
**************************************************************************************************************/

// Main includes
#include <stdio.h>
#include <iostream>

// Gtk includes
#include <gtk/gtk.h>
#include <glib.h>

// Winsock include
#include "winsock2.h"

// Main includes
#include "../Languages/English.h"
#include "../Sourcefiles/Config.h"

// System includes
#include <time.h>
#include <tchar.h>
#include <urlmon.h>
#include <curl.h>
#include <sys/stat.h>

// Pragmas
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "Ws2_32.lib")

/* Widgets external definitions */
//Registration window
extern GtkWidget *reg_entry1; // Name
extern GtkWidget *reg_entry2; // Surname
extern GtkWidget *reg_entry3; // Nickname
extern GtkWidget *reg_entry4; // Location
extern GtkWidget *reg_entry5; // State
extern GtkWidget *reg_entry6; // Age
extern GtkWidget *reg_entry7; // Gender
extern GtkWidget *reg_entry8; // Password
extern GtkWidget *reg_separator; // Separator
extern GtkWidget *reg_button; // Button
extern GtkWidget *reg_label; // Label
extern GtkWidget *reg_image; // Gravatar

// Loggin window
extern GtkWidget *log_window;
extern GtkWidget *log_vbox;
extern GtkWidget *log_username;
extern GtkWidget *log_password;
extern GtkWidget *log_label;

// Buddy window
extern GtkWidget *buddy_window;
extern GtkTreeSortable  *buddy_sortable_model;
extern GtkListStore *buddy_tree_view;
extern GtkWidget *buddy_toolbar;
extern GtkToolItem *buddy_events;

// Request window
extern GtkWidget *requests_window;
extern GtkWidget *requests_vbox;

// Add friend widgets
extern GtkWidget *new_friend_window;
extern GtkWidget *new_friend_label;

// Info
extern GtkWidget *info_label;

// History
extern GtkWidget *history_window;
extern GtkWidget *history_window_view;
extern GtkTextBuffer *history_buffer;
extern GtkWidget *history_view;
extern GtkWidget *history_label;

/* Project functions declarations */
// Dialogs
extern void function_show_error(char input_message[DIALOG_BUFFER_SIZE]);
extern void function_show_warning(char input_message[DIALOG_BUFFER_SIZE]);
extern void function_show_warning_ftp(char input_message[DIALOG_BUFFER_SIZE], int fx_type);
extern void create_dialog_window();

// Functions
extern void function_midcopy ( char* input, char* output, int start_pos, int stop_pos);
extern int function_convert_packet_lenght(char function_char_lenght[LENGHT_SIZE+1]);
extern int function_get_buddy_number(char nick_name[10]);
extern void function_send_data (char *buffer, int size );

// Time
extern std::string function_get_std_time();

//Connect
extern SOCKET dxconnect();

// History
extern void function_show_history_window(GtkWidget *unused_button, gint input_buddy_number);
extern void create_history_window();
extern void create_history_view_window();

// Infos
extern void function_info_request(GtkWidget *unused_button, gint input_buddy_number);
extern void function_show_info_window();
extern void create_info_window();

// Buddyactions
extern bool function_make_offline(char nick_name[10]);
extern int function_make_online(char nick_name[10]);
extern void function_buddy_hide();

// Adder
extern void signal_create_buddy_adder();

// Requests
extern void crate_requests();
extern void signal_show_requests();
extern void signal_requests_ok(GtkWidget *button, gint event_id);
extern void signal_requests_shut(GtkWidget *button, gint event_id);

// BuddyList
extern void create_buddylist();

// Channel
extern bool create_channel();

// Chat
extern void create_buddy_chat(int input_buddy_number);
extern void function_create_chat(gint buddy_number);

// Loggining
extern void create_loggin();

// Logoff
extern void signal_close_history_view(GtkWidget *history_view);
extern void signal_close_history(GtkWidget *history);
extern void signal_close_info(GtkWidget *info);
extern void signal_close_chat(GtkWidget *chat);
extern void signal_loggin_go_offline();
extern void signal_go_offline();
extern void signal_close_requests();
extern void function_exit_client(int code);

// Pixmaps
extern bool create_pixmaps();
extern void function_get_smile(GtkTextBuffer *buffer);

// Registration
extern void create_registration();

// Sendaction
extern void signal_send_message(GtkWidget *entry, gint buddy_numb);

// Statusbar
extern void function_update_statusbar(GtkTextBuffer *input_textview_buffer, GtkStatusbar  *input_statusbar_widget);

// FTPUpload
extern void signal_ftp_upload(GtkWidget *unused_button, gint input_buddy_number);

//FTPDownload
extern void function_ftp_download(char function_remote_addr[FILE_PATH_SIZE], char function_file_name[FILE_NAME_SIZE], int function_buddy_number, GtkTextIter function_end_iter, char function_msg_number[MSG_NUMB_SIZE]);

// FxPacket
extern void function_process_packet(char fx_data_packet[BUF_SIZE], int fx_packet_size);

/* Extern variables definitions */
//Extern socket variables
extern SOCKET s;

// Pixbuf variables
extern GdkPixbuf *px_received;
extern GdkPixbuf *px_sending;
extern GdkPixbuf *px_send;
extern GdkPixbuf *px_failed;
extern GdkPixbuf *px_receiving;

// Default window icon
extern GdkPixbuf *default_icon;

// Default avatar image
extern GdkPixbuf *default_buddy_pixbuf;

// Saved my name
extern char my_name[DATA_ONE_SIZE+1];

// Sending text buffers
extern char sending_text[BUF_SIZE];
extern int  sending_text_len;
extern char sending_text_len_char[LENGHT_SIZE+1];

// Entry text
extern const gchar *entry_text;

// Dialog text
extern char dialog_text[DIALOG_BUFFER_SIZE];

// Main
extern int current_buddy;
extern int activated_events;
extern bool active_ftp_upload;
extern bool active_ftp_download;

/* Project structures definitions */
// Buddy structure
struct _buddy
{
	bool          buddy_chat;
	bool          online;
	bool          listed;
	bool          deleted;

	int           who_sender;
	char		  nick_name[DATA_ONE_SIZE+1];

	GtkWidget     *text_view;
	GtkWidget     *statusbar;
	GtkWidget     *window;
	GtkWidget     *scroll;
	GtkWidget     *entry;
	GtkWidget     *vbox;

	gint          tmp_pos;
	GtkTextBuffer *buffer;

	GtkTreeIter   *tree_iter;

	GtkWidget     *toolbar;
	GtkToolItem   *menu_transfer;
	GtkToolItem   *menu_buddy_info;
	GtkToolItem   *menu_buddy_history;
};

// Message structure
struct _messages
{
	int chat;
	bool waiting;
	gint char_count;
};

// Event requests structure
struct _req_events
{
	char       id[REQUESTS_ID_CHAR_SIZE];
	int        id_integer;
	bool       active;
	char       nick_name[DATA_ONE_SIZE+1];
	GtkWidget  *vbox;
	GtkWidget  *hbox;
	GtkWidget  *label;
	GtkWidget  *ok_button;
	GtkWidget  *shut_button;
};

// Threeshort enum
enum
{
	PIXBUF_COL,
	TEXT_COL,
	TEXT_COL2
};

// Structure variables
extern _buddy		buddy[MAX_BUDDIES];
extern _messages	messages[MAX_MESSAGES];
extern _req_events  req_events[MAX_REQUESTS];