/* gcc -Wall -o set_file set_file.c `pkg-config --cflags --libs gtk+-2.0` */

#include <gtk/gtk.h>

static void onFileSet(GtkWidget *file)
{
    gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file));

    printf("Received 'file-set', filename: '%s'\n", filename);
    g_free(filename);
}

int main(int argc, char **argv)
{
    GtkWidget *win, *file;

    gtk_init(&argc, &argv);

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(win), "File button test");

    file = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
    /* enlarge the widget a bit */
    gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(file), 20);
    g_signal_connect(file, "file-set", G_CALLBACK(onFileSet), NULL);
    gtk_container_add(GTK_CONTAINER(win), file);

    gtk_widget_show_all(win);

    gtk_main();

    return 0;
}

