/* compile with
 *	gcc try17.c `pkg-config gtk+-2.0 --cflags --libs`
 */

#include <gtk/gtk.h>

static void
click_cb (GtkWidget * button, GtkWidget * chooser)
{
  static const char *tmp = "/tmp";
  char *name;

  printf ("gtk_file_chooser_set_filename(\"%s\");\n", tmp);
  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser), tmp);
  name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
  printf ("gtk_file_chooser_get_filename() == \"%s\"\n", name);
  g_free (name);

  printf ("while (g_main_context_iteration (NULL, FALSE))\n\t;\n");
  while (g_main_context_iteration (NULL, FALSE))
    ;

  name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
  printf ("gtk_file_chooser_get_filename() == \"%s\"\n", name);
  g_free (name);
}

int
main (int argc, char **argv)
{
  GtkWidget *chooser;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  chooser = gtk_file_chooser_dialog_new ("choose a file", NULL,
					 GTK_FILE_CHOOSER_ACTION_OPEN,
					 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
					 NULL);

  button = gtk_button_new_with_label ("click me");
  g_signal_connect (G_OBJECT (button),
		    "clicked", G_CALLBACK (click_cb), chooser);

  gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (chooser), button);

  gtk_dialog_run (GTK_DIALOG (chooser));

  return (0);
}
