/*
 * gui.h
 * 
 * Copyright (C) 2006-2007 Josef Kufner <jk@myserver.cz>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#ifndef NETBOARD_GUI_H
#define NETBOARD_GUI_H

#include <gtk/gtk.h>

#include "glade_support.h"
#include "options.h"
#include "message.h"

typedef enum {
	GUI_PAGE_BOARD,
	GUI_PAGE_CHAT,
	GUI_PAGE_STATUS,
	GUI_PAGE_RECORD,
	GUI_PAGE_GAMELOG,
	GUI_PAGE_NETLOG,
	GUI_PAGE_MAX
} GUI_PAGE;

typedef enum {
	GUI_LOG_NONE,
	GUI_LOG_GAME,
	GUI_LOG_NET,
	GUI_LOG_MAX
} GUI_LOG;

typedef enum {
	GUI_ICON_NONE = 0,
	GUI_ICON_TIP,
	GUI_ICON_INFO,
	GUI_ICON_QUESTION,
	GUI_ICON_WARNING,
	GUI_ICON_ERROR,
	GUI_ICON_MAX
} GUI_ICON;

/* option dialog widget */
typedef enum {
	GUI_ODW_T_NONE, GUI_ODW_T_ENTRY, GUI_ODW_T_CHECKBOX, GUI_ODW_T_NUMBER, GUI_ODW_T_COMBO
} GUI_ODW_TYPE;
typedef struct {
	GUI_ODW_TYPE type;
	GtkWidget *widget;
	char opt[OPTION_MAX_OPT_LEN];
} GUI_ODW;
typedef struct {
	char cat[OPTION_MAX_CAT_LEN], mod[OPTION_MAX_MOD_LEN];
	GSList *list;
	GMemChunk *mem_chunk;
	int ok_clicked;
	char notify_target;
} GUI_ODW_LIST;


struct s_gui_page {
	char *option,		/* option to update */
	     *option_tab,	/* option: is tab visible? */
	     *win_title,	/* detached window title */
	     *win_class,	/* detached window class */
	     *menuitem_label,	/* menu item label :) */

	     *widget_name,	/* name of widget to detach */
	     *hide_name,	/* name of widget to hide */
	     *parent_name,	/* name of original parent widget (NULL = same as hide_name) */
	     *notify_icon_name; /* name of notify icon */
	
	GtkWidget *widget,	/* widget to detach */
		  *hide,	/* widget to hide when detached */
		  *window,	/* detached window */
		  *parent,	/* original parent widget */
		  *menuitem,	/* check menu item to update */
		  *notify_icon;	/* notify icon */
};

typedef enum {
	GUI_CHAT_SYS,	/* neutral messages (system, game, connection, ...) */
	GUI_CHAT_IN,	/* incomming messages (from others) */
	GUI_CHAT_OUT,	/* outgoing messages (I sent) */
	GUI_CHAT_TYPE_MAX
} GUI_CHAT_TYPE;

extern struct s_gui_page gui_page[];
extern struct s_gui gui;

extern GtkWidget *main_window;
extern GtkWidget *dialog_connect;
extern GtkWidget *dialog_about;
extern GtkWidget *dialog_game_select;
extern GtkWidget *dialog_option_browser;
extern GtkWidget *dialog_network_profiles;
extern GtkWidget *dialog_send_message;

/* main window */
void gui_update_main_window(void);
GtkWidget *gui_create_main_window(void);
void gui_update_status_tab(void);

/* pages (tabs) */
void gui_update_main_window_tabbar(void);
void gui_switch_main_page(int page);
void gui_page_notify(GUI_PAGE page);
void gui_detach_page(GUI_PAGE page);
void gui_atach_page(GUI_PAGE page);

/* statusbar */
void gui_clean_statusbar(void);
void gui_set_semaphore(int x);
void gui_set_statusbar_clock(int is_visible, int set_icon, gchar *fmt,...);
void gui_set_statusbar_progress(int visible, gdouble fraction, gchar *fmt,...);

/* logs & chat */
void gui_append_to_chat(const char *sender, GUI_CHAT_TYPE type, char *fmt, ...);
void gui_append_to_log(GUI_LOG log_id, char *fmt, ...);
#define gui_append_to_netlog(fmt, args...) gui_append_to_log(GUI_LOG_NET, fmt, ##args)
#define gui_append_to_gamelog(fmt, args...) gui_append_to_log(GUI_LOG_GAME, fmt, ##args)
void gui_erase_logs (void);
void gui_update_expanders(void);

/* dialogs */
void gui_show_dialog_game_select(void);
void gui_show_dialog_connect(void);
void gui_show_error_message_full(GtkWidget *parent, int async, const char *title, const char *fmt, ...);
#define gui_show_error_message(title,fmt,arg...)	gui_show_error_message_full(main_window, 0, title, fmt, ##arg)
#define gui_show_error_message_async(title,fmt,arg...)	gui_show_error_message_full(main_window, 1, title, fmt, ##arg)
int gui_exit_question(void);

/* chat page widgets */
void gui_playerlist_init(void);
void gui_update_playerlist(void);
void gui_role_select(int role_id);
void gui_role_init(GtkListStore *roles_store);

/* options */
void gui_show_option_browser(void);
void gui_update_option_browser(void);
void gui_store_options_with_info(void);
int gui_config_dialog_from_message(MESSAGE * msg, int notify_target);
int gui_config_dialog_from_message_wp(MESSAGE * msg, int notify_target, GtkWidget *parent_window);

/* network profiles */
void gui_show_network_profiles (void);
void gui_update_network_profiles (void);
void gui_show_network_profile_editor(char *id, GtkWidget *parent_window);
void gui_show_network_backend_config(const char *id);

/* dialog send message */
void gui_show_dialog_send_message(void);
void gui_dialog_send_message_get(int *from, int *to, gchar **body);
void gui_dialog_send_message_clear_message(void);
void gui_dialog_send_message_add_message(gchar *text);

/* misc */
void gui_wait_for_callback(void);
void gui_record_init(GtkListStore *record_store);
void gui_show_syncing(int show);

#endif
