/***************************************************************************
                          GUI_cutWiz.cpp  -  description
                             -------------------
    begin                : Sat Oct 5 2002
    copyright            : (C) 2002 by mean
    email                : fixounet@free.fr
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
  /*
 * DO NOT EDIT THIS FILE - it is generated by Glade.
 */
#if 0

#  include <config.h>

#include <stdio.h>
#include <stdlib.h>


#include <string.h>

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

#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "ADM_library/default.h"

static GtkWidget		*create_dialog1 (void);

static GtkWidget		*wdg;

static  GtkWidget *entry_size;
static  GtkWidget *entry_nbtrack;
static  GtkWidget *entry_bitrate;
static  GtkWidget *label_cut1;
static  GtkWidget *label_cut2;

static void gui_del(GtkButton * button, gpointer user_data);
static void gui_ok(GtkButton * button, gpointer user_data);
static void gui_compute(GtkButton * button, gpointer user_data);

static void setEntries(int size, int nb,int bitrate);
static int getEntries(int *size, int *nb,int *bitrate);
static void setEntriesOut(unsigned long int fr, unsigned long size);

extern void	computeIT(int size,int nb,int brate,uint32_t *frame,uint32_t *rsize);

static int lock;
static char string[500];

void gui_compute(GtkButton * button, gpointer user_data)
{
  UNUSED_ARG(button);
  UNUSED_ARG(user_data);
  
 int size,nb,brate;
 uint32_t frame,rsize;
 		// Retrieve info
   	
    if(!getEntries(&size,&nb,&brate)) return;
		
		// update fieds
		setEntries(size,nb,brate);
		
		rsize=size*1024*1024;
		// now compute
		computeIT(rsize,nb,brate,&frame,&rsize);
	  setEntriesOut(frame,rsize/(1024*1024));
}


void getCutPoints( int obr)
{

 	
    int ret=0;

    wdg = create_dialog1();
    lock = 0;
    
    setEntries(640,1,obr);
    gtk_widget_show(wdg);

    while (!lock)
      {
	  gtk_main_iteration();
      }
    if (lock == 1)
      {	
			 ret=1;
      }
      if(lock!=-2)     gtk_widget_destroy(wdg);
      wdg=NULL;
    return ;

}
void setEntries(int size, int nb,int bitrate)
{
int ret;

    gtk_editable_delete_text(GTK_EDITABLE(entry_size),
					 0, -1);
    gtk_editable_delete_text(GTK_EDITABLE(entry_nbtrack),
					 0, -1);
    gtk_editable_delete_text(GTK_EDITABLE(entry_bitrate),
					 0, -1);


		ret=0;
    sprintf(string, "%d", size);
		gtk_editable_insert_text(GTK_EDITABLE(entry_size),
					 string, strlen(string), &ret);
		ret=0;
					 
		sprintf(string, "%d", nb);
			gtk_editable_insert_text(GTK_EDITABLE(entry_nbtrack),
					 string, strlen(string), &ret);
		ret=0;
					 
		sprintf(string, "%d", bitrate);
				gtk_editable_insert_text(GTK_EDITABLE(entry_bitrate),
					 string, strlen(string), &ret);					 

}
void setEntriesOut(unsigned long int fr, unsigned long size)
{

    sprintf(string, "Frame : %lu , size %ld MB", fr,size);
    gtk_label_set_text(GTK_LABEL(label_cut1),string);
	
	
}

int getEntries(int *size, int *nb,int *bitrate)
{
//int ret;
char *str;

  str =   	  gtk_editable_get_chars(GTK_EDITABLE
						 (entry_size), 0, -1);						 
  *size = (int) atoi(str);
		     
    str =   	  gtk_editable_get_chars(GTK_EDITABLE
						 (entry_nbtrack), 0, -1);						 
  *nb = (int) atoi(str);
  
      str =   	  gtk_editable_get_chars(GTK_EDITABLE
						 (entry_bitrate), 0, -1);						 
  *bitrate = (int) atoi(str);
  
	return 1;
}

/*---------------------------------------*/
 void gui_del(GtkButton * button, gpointer user_data)
{
    UNUSED_ARG(button);
    UNUSED_ARG(user_data);
    gui_ok(NULL, (gpointer) -1);
}

void gui_ok(GtkButton * button, gpointer user_data)
{
    UNUSED_ARG(button);
    int res;

    res = (int) user_data;
    if (lock)
			return;			// second call back->ignore.
    switch (res)
      {
      case 1:
	  			lock = 1;
				  break;
      case 0:
				  lock = -1;
		  break;
  	    case -1:
    		 	lock=-2;
      	break;
       default:
       		ADM_assert(0);
      }
    return;

};

/*---------------------------------------*/

GtkWidget		*create_dialog1 (void)
{
  GtkWidget *dialog1;
  GtkWidget *dialog_vbox1;
  GtkWidget *table1;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *label3;
  GtkWidget *label4;
  GtkWidget *label5;
//  GtkWidget *entry_size;
//  GtkWidget *entry_nbtrack;
//  GtkWidget *entry_bitrate;
//  GtkWidget *label_cut1;
//  GtkWidget *label_cut2;
  GtkWidget *dialog_action_area1;
  GtkWidget *hbox1;
  GtkWidget *button_compute;
  GtkWidget *button_cancel;

  dialog1 = gtk_dialog_new ();
//  gtk_object_set_data (GTK_OBJECT (dialog1), "dialog1", dialog1);
  gtk_window_set_title (GTK_WINDOW (dialog1), ("Cut Wizard"));
  gtk_window_set_policy (GTK_WINDOW (dialog1), TRUE, TRUE, FALSE);

  //---
        
    gtk_object_set_data_full(GTK_OBJECT(dialog1),
			     "Cut Wizard",
			     dialog1,
			     (GtkDestroyNotify) gui_del);

      gtk_window_set_modal(GTK_WINDOW(dialog1), TRUE);

  //--
  
  
  dialog_vbox1 = GTK_DIALOG (dialog1)->vbox;
  gtk_object_set_data (GTK_OBJECT (dialog1), "dialog_vbox1", dialog_vbox1);
  gtk_widget_show (dialog_vbox1);

  table1 = gtk_table_new (5, 2, FALSE);
  gtk_widget_ref (table1);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "table1", table1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (table1);
  gtk_box_pack_start (GTK_BOX (dialog_vbox1), table1, TRUE, TRUE, 0);

  label1 = gtk_label_new (("Targetted size"));
  gtk_widget_ref (label1);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label1", label1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label1);
  gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);

  label2 = gtk_label_new (("# audio track"));
  gtk_widget_ref (label2);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label2", label2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label2);
  gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);

  label3 = gtk_label_new (("Audio bitrate"));
  gtk_widget_ref (label3);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label3", label3,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label3);
  gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);

  label4 = gtk_label_new (("Cutpoint 1"));
  gtk_widget_ref (label4);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label4", label4,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label4);
  gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);

  label5 = gtk_label_new (("CutPoint 2"));
  gtk_widget_ref (label5);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label5", label5,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label5);
  gtk_table_attach (GTK_TABLE (table1), label5, 0, 1, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);

  entry_size = gtk_entry_new ();
  gtk_widget_ref (entry_size);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "entry_size", entry_size,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (entry_size);
  gtk_table_attach (GTK_TABLE (table1), entry_size, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  entry_nbtrack = gtk_entry_new ();
  gtk_widget_ref (entry_nbtrack);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "entry_nbtrack", entry_nbtrack,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (entry_nbtrack);
  gtk_table_attach (GTK_TABLE (table1), entry_nbtrack, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  entry_bitrate = gtk_entry_new ();
  gtk_widget_ref (entry_bitrate);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "entry_bitrate", entry_bitrate,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (entry_bitrate);
  gtk_table_attach (GTK_TABLE (table1), entry_bitrate, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  label_cut1 = gtk_label_new ("");
  gtk_widget_ref (label_cut1);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label_cut1", label_cut1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label_cut1);
  gtk_table_attach (GTK_TABLE (table1), label_cut1, 1, 2, 3, 4,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label_cut1), 0, 0.5);

  label_cut2 = gtk_label_new ("");
  gtk_widget_ref (label_cut2);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "label_cut2", label_cut2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (label_cut2);
  gtk_table_attach (GTK_TABLE (table1), label_cut2, 1, 2, 4, 5,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label_cut2), 0, 0.5);

  dialog_action_area1 = GTK_DIALOG (dialog1)->action_area;
  gtk_object_set_data (GTK_OBJECT (dialog1), "dialog_action_area1", dialog_action_area1);
  gtk_widget_show (dialog_action_area1);
  gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 10);

  hbox1 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox1);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "hbox1", hbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox1);
  gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbox1, TRUE, TRUE, 0);

  button_compute = gtk_button_new_with_label (("Compute"));
  gtk_widget_ref (button_compute);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "button_compute", button_compute,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (button_compute);
  gtk_box_pack_start (GTK_BOX (hbox1), button_compute, FALSE, FALSE, 0);

  button_cancel = gtk_button_new_with_label (("Close"));
  gtk_widget_ref (button_cancel);
  gtk_object_set_data_full (GTK_OBJECT (dialog1), "button_cancel", button_cancel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (button_cancel);
  gtk_box_pack_start (GTK_BOX (hbox1), button_cancel, FALSE, FALSE, 0);

    gtk_signal_connect (GTK_OBJECT (button_cancel), "clicked",
                      GTK_SIGNAL_FUNC(gui_ok),
		       (void *) 0);
  gtk_signal_connect (GTK_OBJECT (button_compute), "clicked",
                      GTK_SIGNAL_FUNC(gui_compute),
		       (void *) 1);

  
  return dialog1;
}
#endif

