/*
 * DO NOT EDIT THIS FILE - it is generated by Glade.
 */

#include "config.h"
#include "ADM_toolkitGtk.h"
#include "ADM_audiofilter/audioprocess.hxx"
#include "ADM_audiofilter/audioeng_buildfilters.h"

extern uint32_t audioEncoderGetNumberOfEncoders(void);
extern const char  *audioEncoderGetDisplayName(uint32_t i);
extern uint8_t audioCodecSetByIndex(int i);

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
  g_object_set_data_full (G_OBJECT (component), name, \
    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
  g_object_set_data (G_OBJECT (component), name, widget)
  
static GtkWidget	*create_dialogAudioCodec (void);

 static int findCodec( void );
 static GtkWidget *dialog;
 static void okCallback(GtkButton * button, gpointer user_data);
 
  
 void okCallback(GtkButton * button, gpointer user_data)
{
	int cur;


		UNUSED_ARG(button);
		UNUSED_ARG(user_data);

		cur=findCodec();
		audioCodecSetByIndex(cur);
		audioCodecConfigure();

}

uint8_t DIA_audioCodec( int *codec )
{

	uint8_t ret=0;
	int old=*codec;
	
	dialog=create_dialogAudioCodec();
	gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),
										GTK_RESPONSE_OK,
										GTK_RESPONSE_CANCEL,
										-1);
	gtk_register_dialog(dialog);


	// now set the input one
    uint32_t nb=audioEncoderGetNumberOfEncoders();
	
   gtk_option_menu_set_history(GTK_OPTION_MENU(lookup_widget(dialog,"optionmenu_CodecList")), *codec);
	
	if(gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK)
	{
		
			*codec=findCodec();
			ret=1;
	
	}
	else
	{
		*codec=old;
	}

    gtk_unregister_dialog(dialog);
	gtk_widget_destroy(dialog);
	
	return ret;
} 

int findCodec( void )
{

int  j;
			j=getRangeInMenu(lookup_widget(dialog,"optionmenu_CodecList"));
            return j;
}
//-------------------------

GtkWidget	*create_dialogAudioCodec (void)
{
  GtkWidget *dialogAudioCodec;
  GtkWidget *dialog_vbox1;
  GtkWidget *vbox1;
  GtkWidget *optionmenu_CodecList;
  GtkWidget *menu1;
  GtkWidget *buttonConfigure;
  GtkWidget *dialog_action_area1;
  GtkWidget *cancelbutton1;
  GtkWidget *okbutton1;
uint32_t nbA=audioEncoderGetNumberOfEncoders();
  GtkWidget *acodec[nbA];
  int acodecNb=0;

  dialogAudioCodec = gtk_dialog_new ();
  gtk_window_set_title (GTK_WINDOW (dialogAudioCodec), QT_TR_NOOP("AudioCodec"));

  dialog_vbox1 = GTK_DIALOG (dialogAudioCodec)->vbox;
  gtk_widget_show (dialog_vbox1);

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox1);
  gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, TRUE, TRUE, 0);

  optionmenu_CodecList = gtk_option_menu_new ();
  gtk_widget_show (optionmenu_CodecList);
  gtk_box_pack_start (GTK_BOX (vbox1), optionmenu_CodecList, FALSE, FALSE, 0);

  menu1 = gtk_menu_new ();

 /***************/


        for(int i=0;i<nbA;i++)
        {
                acodec[i]=gtk_menu_item_new_with_mnemonic(audioEncoderGetDisplayName(i));
                gtk_widget_show(acodec[i]);
                gtk_container_add(GTK_CONTAINER(menu1),acodec[i]);
        }  

 /***************/ 
  gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu_CodecList), menu1);

  buttonConfigure = gtk_button_new_with_mnemonic (QT_TR_NOOP("Configure codec"));
  gtk_widget_show (buttonConfigure);
  gtk_box_pack_start (GTK_BOX (vbox1), buttonConfigure, FALSE, FALSE, 0);

  dialog_action_area1 = GTK_DIALOG (dialogAudioCodec)->action_area;
  gtk_widget_show (dialog_action_area1);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);

  cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
  gtk_widget_show (cancelbutton1);
  gtk_dialog_add_action_widget (GTK_DIALOG (dialogAudioCodec), cancelbutton1, GTK_RESPONSE_CANCEL);
  GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);

  okbutton1 = gtk_button_new_from_stock ("gtk-ok");
  gtk_widget_show (okbutton1);
  gtk_dialog_add_action_widget (GTK_DIALOG (dialogAudioCodec), okbutton1, GTK_RESPONSE_OK);
  GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);

  /* Store pointers to all widgets, for use by lookup_widget(). */
  GLADE_HOOKUP_OBJECT_NO_REF (dialogAudioCodec, dialogAudioCodec, "dialogAudioCodec");
  GLADE_HOOKUP_OBJECT_NO_REF (dialogAudioCodec, dialog_vbox1, "dialog_vbox1");
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, vbox1, "vbox1");
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, optionmenu_CodecList, "optionmenu_CodecList");
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, menu1, "menu1");
  for(int i=0;i<nbA;i++)
        {
             GLADE_HOOKUP_OBJECT (dialogAudioCodec, acodec[i],audioEncoderGetDisplayName(i));
        }  
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, buttonConfigure, "buttonConfigure");
  GLADE_HOOKUP_OBJECT_NO_REF (dialogAudioCodec, dialog_action_area1, "dialog_action_area1");
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, cancelbutton1, "cancelbutton1");
  GLADE_HOOKUP_OBJECT (dialogAudioCodec, okbutton1, "okbutton1");
	 gtk_signal_connect(GTK_OBJECT(buttonConfigure), "clicked",
                      GTK_SIGNAL_FUNC(okCallback),                   (void *) 0);
  return dialogAudioCodec;
}

