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


#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>


#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "config.h"
#include "callbacks.h"
#include "avi_vars.h"
#include "ADM_gui2/support.h"
#include "ADM_toolkit/toolkit_gtk.h"
#include "ADM_toolkit/toolkit_gtk_include.h"
#include "ADM_toolkit/filesel.h"


# include "prefs.h"

static GtkWidget	*create_dialog1 (void);
static GtkWidget 	*dialog;
static uint64_t		_init;
static uint32_t 	_audio;
static void callback( void );

uint8_t DIA_Requant(float *perce,uint32_t *quality,uint64_t init,uint32_t audio);
uint8_t DIA_Requant(float *perce,uint32_t *quality, uint64_t init,uint32_t audio)
{
uint8_t ret=0;
char string[1025];
	
	dialog=create_dialog1();
	gtk_transient(dialog);		
	sprintf(string,"%lu MB",init>>20);
	_init=init;
  	gtk_label_set_text(GTK_LABEL(WID(labelVideoIn)),string);
	
	sprintf(string,"%lu MB",audio>>20);
	_audio=audio;
	gtk_label_set_text(GTK_LABEL(WID(labelAudioIn)),string);
	
	gtk_signal_connect(GTK_OBJECT(WID(hscale1)),"value_changed",GTK_SIGNAL_FUNC(callback),0);
	



	if(gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK)
	{
		GtkAdjustment *sliderAdjustment;
		ret=1;
		// Read value & speed
		sliderAdjustment=gtk_range_get_adjustment (GTK_RANGE(WID(hscale1)));
		*perce=(float)GTK_ADJUSTMENT(sliderAdjustment)->value;
		*quality=0;		
	}

	gtk_widget_destroy(dialog);
	dialog=NULL;
	return ret;
}
void callback( void )
{
float per,current;
uint64_t final;
uint32_t mb;
char string[1024];

		GtkAdjustment *sliderAdjustment;		
		sliderAdjustment=gtk_range_get_adjustment (GTK_RANGE(WID(hscale1)));
		per=(float)GTK_ADJUSTMENT(sliderAdjustment)->value;
		if(per<1.0) per=1.0;
		current=_init;
		current/=per;
		
		final=(uint64_t)floor(current);
		final+=_audio;
		final>>=20;
		
		mb=(uint32_t )final;
		sprintf(string,"%lu MB",mb);		
  		gtk_label_set_text(GTK_LABEL(WID(labelTotal)),string);		
	
}

GtkWidget*
create_dialog1 (void)
{
  GtkWidget *dialog1;
  GtkWidget *dialog_vbox1;
  GtkWidget *vbox1;
  GtkWidget *label1;
  GtkWidget *hscale1;
  GtkWidget *table1;
  GtkWidget *label3;
  GtkWidget *label4;
  GtkWidget *label5;
  GtkWidget *labelVideoIn;
  GtkWidget *labelAudioIn;
  GtkWidget *labelTotal;
  GtkWidget *dialog_action_area1;
  GtkWidget *cancelbutton1;
  GtkWidget *okbutton1;

  dialog1 = gtk_dialog_new ();
  gtk_window_set_title (GTK_WINDOW (dialog1), _("Requantize Option"));

  dialog_vbox1 = GTK_DIALOG (dialog1)->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);

  label1 = gtk_label_new (_("Shrink factor"));
  gtk_widget_show (label1);
  gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, FALSE, 0);

  hscale1 = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (2, 1, 4, 0.2, 0.2, 0)));
  gtk_widget_show (hscale1);
  gtk_box_pack_start (GTK_BOX (vbox1), hscale1, FALSE, FALSE, 0);
  gtk_scale_set_digits (GTK_SCALE (hscale1), 2);

  table1 = gtk_table_new (3, 2, FALSE);
  gtk_widget_show (table1);
  gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, FALSE, 0);

  label3 = gtk_label_new (_("Initial Video size :"));
  gtk_widget_show (label3);
  gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);

  label4 = gtk_label_new (_("Audio size :"));
  gtk_widget_show (label4);
  gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);

  label5 = gtk_label_new (_("Final size (audio+video):"));
  gtk_widget_show (label5);
  gtk_table_attach (GTK_TABLE (table1), label5, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);

  labelVideoIn = gtk_label_new (_("0"));
  gtk_widget_show (labelVideoIn);
  gtk_table_attach (GTK_TABLE (table1), labelVideoIn, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (labelVideoIn), 0, 0.5);

  labelAudioIn = gtk_label_new (_("0"));
  gtk_widget_show (labelAudioIn);
  gtk_table_attach (GTK_TABLE (table1), labelAudioIn, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (labelAudioIn), 0, 0.5);

  labelTotal = gtk_label_new (_("0"));
  gtk_widget_show (labelTotal);
  gtk_table_attach (GTK_TABLE (table1), labelTotal, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (labelTotal), 0, 0.5);

  dialog_action_area1 = GTK_DIALOG (dialog1)->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 (dialog1), 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 (dialog1), 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 (dialog1, dialog1, "dialog1");
  GLADE_HOOKUP_OBJECT_NO_REF (dialog1, dialog_vbox1, "dialog_vbox1");
  GLADE_HOOKUP_OBJECT (dialog1, vbox1, "vbox1");
  GLADE_HOOKUP_OBJECT (dialog1, label1, "label1");
  GLADE_HOOKUP_OBJECT (dialog1, hscale1, "hscale1");
  GLADE_HOOKUP_OBJECT (dialog1, table1, "table1");
  GLADE_HOOKUP_OBJECT (dialog1, label3, "label3");
  GLADE_HOOKUP_OBJECT (dialog1, label4, "label4");
  GLADE_HOOKUP_OBJECT (dialog1, label5, "label5");
  GLADE_HOOKUP_OBJECT (dialog1, labelVideoIn, "labelVideoIn");
  GLADE_HOOKUP_OBJECT (dialog1, labelAudioIn, "labelAudioIn");
  GLADE_HOOKUP_OBJECT (dialog1, labelTotal, "labelTotal");
  GLADE_HOOKUP_OBJECT_NO_REF (dialog1, dialog_action_area1, "dialog_action_area1");
  GLADE_HOOKUP_OBJECT (dialog1, cancelbutton1, "cancelbutton1");
  GLADE_HOOKUP_OBJECT (dialog1, okbutton1, "okbutton1");

  return dialog1;
}


