#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget* button;

showme ()
{
        printf ("current folder just changed to %s\n", gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(button)));
        printf ("current filename is currently %s\n", gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(button)));
}

void
showmecf (GtkWidget* fc)
{
        printf ("current folder just changed to %s\n", gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(fc)));
        printf ("current filename is currently %s\n", gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(fc)));
}

void
showmefs (GtkWidget * fcb)
{
        printf ("file set, currently %s\n", gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(fcb)));
}

void
clicked ()
{
        GtkWidget* dialog;
        GtkWidget* dialog_vbox;
        int status;

        button = gtk_file_chooser_button_new ("Select a folder", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
        dialog = gtk_dialog_new ();

        dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG(dialog));
        gtk_box_pack_start (GTK_BOX(dialog_vbox), button, TRUE, TRUE, 0);
        gtk_dialog_add_button (GTK_DIALOG(dialog), "OK", GTK_RESPONSE_ACCEPT);

        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(button), "/home/paul");

        gtk_widget_show (GTK_WIDGET (button));

        g_signal_connect (G_OBJECT(button), "current-folder-changed", G_CALLBACK (showmecf), button);
        g_signal_connect (G_OBJECT(button), "file-set", G_CALLBACK (showmefs), button);

        status = gtk_dialog_run (GTK_DIALOG (dialog));
        printf ("Dialog returned %d\n", status);
        printf ("Current folder = %s\n", gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(button)));

        gtk_main_quit ();
}        

int
main (int argc, char* argv[])
{
        GtkWidget* win;
        GtkWidget* button;

        gtk_init (&argc, &argv);
        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        button = gtk_button_new_with_label ("Click me!");

        gtk_container_add (GTK_CONTAINER(win), button);
        g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(clicked), NULL);

        gtk_widget_show (GTK_WIDGET (button));
        gtk_widget_show (GTK_WIDGET (win));

        gtk_main ();
}
