#include <gtk/gtk.h>

static GtkWidget *dialog = NULL;

static void on_button_click(GtkButton *button, gpointer udata)
{
    if (!dialog) {
        dialog = gtk_file_chooser_dialog_new ("A dialog",
                                              NULL,
                                              (GtkFileChooserAction) udata,
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                              NULL);
    }

    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_hide (dialog);
    gtk_widget_destroy (dialog);
}

int main (int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    GtkWidget *window, *btnOpen, *btnSave, *vbox;

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Sample");

    btnOpen = gtk_button_new_with_label ("Open a file...");
    btnSave = gtk_button_new_with_label ("Save a file...");

    vbox = gtk_vbox_new (TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), btnOpen, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), btnSave, TRUE, TRUE, 0);

    gtk_container_add (GTK_CONTAINER (window), vbox);

    g_signal_connect (btnOpen, "clicked", G_CALLBACK (on_button_click), GTK_FILE_CHOOSER_ACTION_OPEN);
    g_signal_connect (btnSave, "clicked", G_CALLBACK (on_button_click), GTK_FILE_CHOOSER_ACTION_SAVE);

    gtk_widget_show_all (window);
    gtk_main();
    return 0;
}
