/* gtk file chooser bug test */
#include <stdio.h>
#include <gtk/gtk.h>

#define eprintf(txt) fprintf (stderr, "%s\n", txt);
#define error(txt) { eprintf (txt); exit (1); }

/*

This is my Makefile:

CFLAGS = -Wall

all: test
	cp test ~
	~/test

test: test.o
	gcc -o test test.o `pkg-config --libs gtk+-2.0`

test.o: test.c
	gcc -c $(CFLAGS) test.c `pkg-config --cflags gtk+-2.0`

I have the source on my USB memory, which is mounted noexec

*/
void open_dialog()
{
	GtkWidget *dialog;
	char *filename;

	dialog = gtk_file_chooser_dialog_new ("Open File",
										0,
										GTK_FILE_CHOOSER_ACTION_OPEN,
										GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
										GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
										NULL);
	
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
	{
		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		eprintf (filename);
		g_free (filename);
	}
	
	gtk_widget_destroy (dialog);
}

void save_dialog(int new_document)
{
	GtkWidget *dialog ;
/*	int new_document;

	dialog = gtk_dialog_new_with_buttons ("New Document?", NULL, 0, GTK_STOCK_YES, GTK_RESPONSE_YES, GTK_STOCK_NO, GTK_RESPONSE_NO, 0);

	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
		new_document = TRUE;
	else
		new_document = FALSE;

	gtk_widget_destroy (dialog);
*/
	/******/

	dialog = gtk_file_chooser_dialog_new ("Save File",
										0,
										GTK_FILE_CHOOSER_ACTION_SAVE,
										GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
										GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
										NULL);
	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
	
	if (new_document)
	{
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), "/home/olle");
		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
	}
	else
		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), "/home/olle/minirc.exe");
	
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
	{
		char *filename;
	
		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		eprintf (filename);
		g_free (filename);
	}
	
	gtk_widget_destroy (dialog);
}

int main(int argc, char **argv)
{
	gtk_init(&argc, &argv);

	open_dialog();

	save_dialog(0);

	save_dialog(1);

	return 0;
}
