#include "gtkicq.h"
#include "pixmaps.h" /* Added so we can have status pixmaps beside the actual menu item in the Status Menu */

GtkWidget *main_menu( struct sokandlb *data )
{
	GtkWidget *menubar, *menubar_options, *menubar_status, *menubar_help;
	GtkWidget *menu, *menuitem_search, *menuitem_history, *menuitem_options,
	          *menuitem, *menuitem_quit;
	GtkWidget *menuitem_online, *menuitem_away, *menuitem_na, *menuitem_ffc,
	          *menuitem_occ, *menuitem_dnd, *menuitem_inv, *menuitem_offline;
	GtkWidget *menuitem_about;

	GtkWidget *pixmap, *item, *itembox, *itemlabel;

#ifdef TRACE_FUNCTION
	printf( "main_menu\n" );
#endif

	/* ICQ Menu */

	menubar = gtk_menu_bar_new();
	menubar_options = gtk_menu_item_new_with_label( "ICQ" );

	menu = gtk_menu_new();
	menuitem_search = gtk_menu_item_new_with_label( "Add Contact" );
	menuitem_history = gtk_menu_item_new_with_label( "Connection History" );
	menuitem_options = gtk_menu_item_new_with_label( "Options" );
	menuitem = gtk_menu_item_new();
	menuitem_quit = gtk_menu_item_new_with_label( "Quit" );
	menuitem = gtk_menu_item_new();
	gtk_menu_item_set_submenu( GTK_MENU_ITEM( menubar_options ), menu );
	gtk_menu_bar_append( GTK_MENU_BAR( menubar ), menubar_options );
	gtk_menu_append( GTK_MENU( menu ), menuitem_search );
	gtk_menu_append( GTK_MENU( menu ), menuitem_history );
	gtk_menu_append( GTK_MENU( menu ), menuitem_options );
	gtk_menu_append( GTK_MENU( menu ), menuitem );
	gtk_menu_append( GTK_MENU( menu ), menuitem_quit );
	gtk_widget_show( menuitem_search );
	gtk_widget_show( menuitem_history );
	gtk_widget_show( menuitem );
	gtk_widget_show( menuitem );
	gtk_widget_show( menuitem_options );
	gtk_widget_show( menubar_options );
	gtk_widget_show( menuitem_quit );

	/* Status Menu */

	menu = gtk_menu_new();
	menubar_status = gtk_menu_item_new_with_label( "Status" );

	/* Online Menu Selection */

	menuitem_online = gtk_menu_item_new();
	itemlabel = gtk_label_new( "  Online" );
	itembox = gtk_hbox_new( FALSE, 0 );
	pixmap = gtk_pixmap_new( icon_online_pixmap, icon_online_bitmap );
	gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
	gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_online ), itembox );
        gtk_widget_show( itembox );

	/* Away Menu Selection */

	menuitem_away = gtk_menu_item_new();
        itemlabel = gtk_label_new( "   Away" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_away_pixmap, icon_away_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_away ), itembox );
        gtk_widget_show( itembox );

	/* Not Available (NA) Menu Selection */

	menuitem_na = gtk_menu_item_new();
	itemlabel = gtk_label_new( "  Not Available" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_na_pixmap, icon_na_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_na ), itembox );
        gtk_widget_show( itembox );

	/* Free for Chat (FFC) Menu Selection */

	menuitem_ffc = gtk_menu_item_new();
        itemlabel = gtk_label_new( "  Free for Chat" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_ffc_pixmap, icon_ffc_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_ffc ), itembox );
        gtk_widget_show( itembox );

	/* Occupied (OCC) Menu Selection */

	menuitem_occ = gtk_menu_item_new();
        itemlabel = gtk_label_new( "  Occupied" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_occ_pixmap, icon_occ_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_occ ), itembox );
        gtk_widget_show( itembox );

	/* Do Not Disturb (DND) ...or I will "89" you off the internet because you're using MS-Windows Menu Selection */

	menuitem_dnd = gtk_menu_item_new();
        itemlabel = gtk_label_new( "  Do Not Disturb" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_dnd_pixmap, icon_dnd_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_dnd ), itembox );
        gtk_widget_show( itembox );

	/* Invisible (inv) Menu Selection */

	menuitem_inv = gtk_menu_item_new();
        itemlabel = gtk_label_new( "   Invisible" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_inv_pixmap, icon_inv_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_inv ), itembox );
        gtk_widget_show( itembox );

	/* Section Break in Status Menu */

	menuitem = gtk_menu_item_new();

	/* Offline Menu Selection */

	menuitem_offline = gtk_menu_item_new();
        itemlabel = gtk_label_new( "  Offline" );
        itembox = gtk_hbox_new( FALSE, 0 );
        pixmap = gtk_pixmap_new( icon_offline_pixmap, icon_offline_bitmap );
        gtk_box_pack_start( GTK_BOX( itembox ), pixmap, FALSE, FALSE, 0 );
        gtk_widget_show( pixmap );
        gtk_box_pack_start( GTK_BOX( itembox ), itemlabel, FALSE, FALSE, 0 );
        gtk_widget_show( itemlabel );
        gtk_container_add( GTK_CONTAINER( menuitem_offline ), itembox );
        gtk_widget_show( itembox );

	gtk_menu_item_set_submenu( GTK_MENU_ITEM( menubar_status ), menu );
	gtk_menu_bar_append( GTK_MENU_BAR( menubar ), menubar_status );
	gtk_menu_append( GTK_MENU( menu ), menuitem_online );
	gtk_menu_append( GTK_MENU( menu ), menuitem_away );
	gtk_menu_append( GTK_MENU( menu ), menuitem_na );
	gtk_menu_append( GTK_MENU( menu ), menuitem_ffc );
	gtk_menu_append( GTK_MENU( menu ), menuitem_occ );
	gtk_menu_append( GTK_MENU( menu ), menuitem_dnd );
	gtk_menu_append( GTK_MENU( menu ), menuitem_inv );
	gtk_menu_append( GTK_MENU( menu ), menuitem );
	gtk_menu_append( GTK_MENU( menu ), menuitem_offline );

	gtk_widget_show( menuitem_online );
	gtk_widget_show( menuitem_away );
	gtk_widget_show( menuitem_na );
	gtk_widget_show( menuitem_ffc );
	gtk_widget_show( menuitem_occ );
	gtk_widget_show( menuitem_dnd );
	gtk_widget_show( menuitem_inv );
	gtk_widget_show( menuitem );
	gtk_widget_show( menuitem_offline );
	gtk_widget_show( menubar_status );

	/* Help Menu */

	menu = gtk_menu_new();
        menubar_help = gtk_menu_item_new_with_label( "Help" );

	menuitem_about = gtk_menu_item_new_with_label( "About..." );

	gtk_menu_item_set_submenu( GTK_MENU_ITEM( menubar_help ), menu );
	gtk_menu_item_right_justify( GTK_MENU_ITEM ( menubar_help ) );
        gtk_menu_bar_append( GTK_MENU_BAR( menubar ), menubar_help );
        gtk_menu_append( GTK_MENU( menu ), menuitem_about );

        gtk_widget_show( menubar_help );
	gtk_widget_show( menuitem_about );

	/* Signal Calls */

	gtk_signal_connect_object( GTK_OBJECT( menuitem_search ), "activate",
	                           GTK_SIGNAL_FUNC( search_window ), (gpointer)data );
	
	gtk_signal_connect_object( GTK_OBJECT( menuitem_quit ), "activate",
	                           GTK_SIGNAL_FUNC( icq_quit_object ), (gpointer)data );

	gtk_signal_connect( GTK_OBJECT( menuitem_online ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_online ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_offline ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_offline ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_away ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_away ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_na ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_na ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_inv ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_invisible ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_dnd ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_dnd ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_occ ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_occ ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_ffc ), "activate",
	                    GTK_SIGNAL_FUNC( icq_set_status_ffc ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_options ), "activate",
	                    GTK_SIGNAL_FUNC( configure_window ), data );
	gtk_signal_connect( GTK_OBJECT( menuitem_history ), "activate",
	                    GTK_SIGNAL_FUNC( toggle_log_window ), NULL );

	gtk_signal_connect( GTK_OBJECT( menuitem_about ), "activate",
                            GTK_SIGNAL_FUNC( create_about_window ), NULL );

	return menubar;
}
