# -*- Perl -*-
#
# X-Rust Menu Definitions and Subroutines
#
# $Id: xrust_menu.pl,v 1.1.1.1 2000/05/03 19:54:39 wright Exp $

use strict;
use vars qw(%COLORS %FILTER $globals %CONFIGURE @caller_queues %FONTS);

sub create_main_menu_bar {
    #
    # Abstract: Create (and return the object) for the main menu bar.
    #

    my $MW = shift;
    my $radial;

    my($each);

    my $menu_bar = $MW->Frame(-relief => 'raised', -bd => 2);

    # -----------------------------------------------------------------

    my $menu_bar_file = $menu_bar->Menubutton(
					      -text       => 'File',
					      -underline  => 0
					      );

    my $menu_bar_file_menu = $menu_bar_file->Menu(-tearoff => 0);
    $menu_bar_file->configure(-menu => $menu_bar_file_menu,
			      -font => $FONTS{'MENU_FONT'});
    push(@{$COLORS{'Menu'}->{'widgets'}}, $menu_bar_file); 

    $menu_bar_file->command( 
			    -label      => 'Rescan Tickets',
			    -underline  => 0,
			    -command    => \&do_query,
			    -font       => $FONTS{'MENU_FONT'}
			    );

    $menu_bar_file->separator;
    
    $menu_bar_file->command(
			    -label     => 'Exit All',
			    -underline => 0,
			    -command   => \&exit_gui,
			    -font      => $FONTS{'MENU_FONT'}
			   );

    # -----------------------------------------------------------------

    my $menu_bar_filter = $menu_bar->Menubutton(
						-text => 'Filter',
						-underline => 0
					       );

    my $menu_bar_filter_menu = $menu_bar_filter->Menu(-tearoff => 0);
    $menu_bar_filter->configure(-menu => $menu_bar_filter_menu,
				-font => $FONTS{'MENU_FONT'});
    

    my $full_d;
    foreach $each ("normal", "date") {
	$full_d = "Display Normal" if ($each eq "normal");
	$full_d = "Display Date" if ($each eq "date");
	$menu_bar_filter->radiobutton(
				      -label => "$full_d",
				      -variable => \$CONFIGURE{'format_type'},
				      -command => \&redraw_query,
				      -value    => $each,
				      -font => $FONTS{'MENU_FONT'}
				      );
    }

    $menu_bar_filter->separator;

    $menu_bar_filter->command(-underline => 0,
			      -label => 'User',
			      -command => [\&specify_func, 0, 0, "USER"],
			      -font    => $FONTS{'MENU_FONT'}			  
			      );	


    $menu_bar_filter->command(-underline => 0,
			      -label => 'Owner',
			      -command => [\&specify_func, 0, 0, "OWNER"],
			      -font    => $FONTS{'MENU_FONT'}			  
			      );	

    # ***** Queue *****

    $menu_bar_filter->cascade(-underline => 0,
			      -label => 'Queue'
			      );

    my $queue_qm = $menu_bar_filter->cget(-menu);
    my $menu_bar_filter_queue = $queue_qm->Menu(-tearoff => 0);
    push(@{$COLORS{'Menu'}->{'widgets'}}, $menu_bar_filter_queue); 
    push(@{$COLORS{'Menu'}->{'widgets'}}, $queue_qm); 
			   
    $menu_bar_filter->entryconfigure('Queue',-menu => $menu_bar_filter_queue,
				     -font => $FONTS{'MENU_FONT'});

    $menu_bar_filter_queue->radiobutton(
					-label     => "all",
					-variable => \$FILTER{'queue_name'},
					-value    => "all"
				       );


	    
    my $count = 0;
    foreach $each (split(':',$globals->{"alias_name"})) {
	if ($caller_queues[$count]) {
	    $menu_bar_filter_queue->radiobutton(
						-label     => "$each",
						-variable => \$FILTER{'queue_name'},
						-value    => $each
					       );
	}
	$count++;
    }

    # ***** Status *****

    $menu_bar_filter->cascade(-underline => 0,
			      -label => 'Status'
			      );

    my $status_qm = $menu_bar_filter->cget(-menu);
    my $menu_bar_filter_status = $status_qm->Menu(-tearoff => 0);

    $menu_bar_filter->entryconfigure('Status',-menu => $menu_bar_filter_status,
				     -font => $FONTS{'MENU_FONT'});
    
    foreach $each ("all",split(':',$globals->{"valid_status"})) {
	$menu_bar_filter_status->radiobutton(
					     -label     => "$each",
					     -variable => \$FILTER{'status'},
					     -value    => $each
					    );
    }


    # ***** Priority *****

    $menu_bar_filter->cascade(-underline => 0,
			      -label => 'Priority'
			      );

    my $priority_qm = $menu_bar_filter->cget(-menu);
    my $menu_bar_filter_priority = $priority_qm->Menu(-tearoff => 0);

    $menu_bar_filter->entryconfigure('Priority',-menu => $menu_bar_filter_priority,
				     -font => $FONTS{'MENU_FONT'});
    
    foreach $each ("all","high","normal","low") {
	$radial = $menu_bar_filter_priority->radiobutton(
							 -label     => "$each",
							 -variable => \$FILTER{'priority'},
							 -value    => $each
							 );
    }

    # ***** Queue Type *****

    $menu_bar_filter->cascade(-underline => 0,
			      -label => 'Queue Type'
			      );

    my $type_qm = $menu_bar_filter->cget(-menu);
    my $menu_bar_filter_type = $type_qm->Menu(-tearoff => 0);

    $menu_bar_filter->entryconfigure('Queue Type',-menu => $menu_bar_filter_type,
				     -font => $FONTS{'MENU_FONT'});
 
    foreach $each ("active","resolved","archived") {
	$menu_bar_filter_type->radiobutton(
					   -label     => "$each",
					   -variable => \$FILTER{'type'},
					   -value    => $each
					   );
    }

    # ***** Category *****
    $menu_bar_filter->cascade(-underline => 0,
			      -label => 'Category'
			      );

    my $category_qm = $menu_bar_filter->cget(-menu);
    my $menu_bar_filter_category = $category_qm->Menu(-tearoff => 0);

    $menu_bar_filter->entryconfigure('Category',-menu => $menu_bar_filter_category,
				     -font => $FONTS{'MENU_FONT'});

    foreach $each ("user","work","both") {
	$menu_bar_filter_category->radiobutton(
					       -label    => "$each",
					       -variable => \$FILTER{'category'},
					       -value    => $each
					       );
    }


    # ***** Filter Panel *****

    $menu_bar_filter->command(-underline => 0,
			      -label => 'Panel (unattached)',
			      -command => \&create_filter_window,
			      -font    => $FONTS{'MENU_FONT'}			  
			      );

    # -----------------------------------------------------------------


    my $menu_bar_configure = $menu_bar->Menubutton(
						   -text => 'Configure',
						   -underline => 0
						   );

    my $menu_bar_configure_menu = $menu_bar_configure->Menu(-tearoff => 0);
    $menu_bar_configure->configure(-menu => $menu_bar_configure_menu,
				   -font => $FONTS{'MENU_FONT'});

    $menu_bar_configure->checkbutton(
				     -label => 'Colorize Requests',
				     -underline => 1,
				     -variable => \$CONFIGURE{'colorize'},
				     -state => 'disabled',
				     -font => $FONTS{'MENU_FONT'}
				 
				    );
    
    
    $menu_bar_configure->command(
				 -label => 'Colors...',
				 -underline => 0,
				 -command => \&color_editor,
				 -state => 'disabled',
				 -font => $FONTS{'MENU_FONT'}
			     
				);

    $menu_bar_configure->separator;

    $menu_bar_configure->checkbutton(
				     -label => 'Help Bar',
				     -underline => 1,
				     -state => 'disabled',
				     -variable => \$CONFIGURE{'helpbar'},
				     -font => $FONTS{'MENU_FONT'}
				    );
    $menu_bar_configure->checkbutton(
				     -label => 'Display Static Request',
				     -underline => 1,
				     -variable => \$CONFIGURE{'static_request'},
				     -command => \&pack_main_window,
				     -state => 'disabled',
				     -font => $FONTS{'MENU_FONT'}
				    );

    $menu_bar_configure->separator;
    
    $menu_bar_configure->command(-underline => 0,
	-label => 'Panel (unattached)',
	-command => \&create_configure_window,
	-font    => $FONTS{'MENU_FONT'}			  
    );

    $menu_bar_configure->separator;
				      
    $menu_bar_configure->command(
				 -label => 'Save Configuration',
				 -underline => 0,
				 -command => \&save_xrustrc,
				 -font => $FONTS{'MENU_FONT'}
				 );
				
 

    # -----------------------------------------------------------------

    my $menu_bar_help = $menu_bar->Menubutton(
					      -text => 'Help',
					      -underline => 0
					     );

    my $menu_bar_help_menu = $menu_bar_help->Menu(-tearoff => 0);
    $menu_bar_help->configure(-menu => $menu_bar_help_menu,
			      -font => $FONTS{'MENU_FONT'});
    
    $menu_bar_help->command(
			    -state => 'disabled',
			    -label => 'About X-Rust',
			    -underline => 0,
			    -font => $FONTS{'MENU_FONT'}
			   );

    # -----------------------------------------------------------------

    $menu_bar_file->pack(-side => 'left');
    $menu_bar_filter->pack(-side => 'left');
    $menu_bar_configure->pack(-side => 'left');
    $menu_bar_help->pack(-side => 'right');

    #
    # This one push sets us up for on-the-fly color editing.
    #
    push(@{$COLORS{'Menu'}->{'widgets'}}, $menu_bar, $menu_bar->Descendants); 

    return $menu_bar;

}

1;
