// build by gcc -o test2 -g -O0 test2.c `pkg-config --libs --cflags gtk+-3.0`

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

GtkWidget *window;
GtkWidget *button;
GtkWidget *label;

void Done(GtkWidget* chooser, gint response)
{
  // A "response" signal won't be sent again but "destroy" will be.
  g_signal_handlers_disconnect_by_func(chooser, Done, NULL);
  gtk_widget_destroy(chooser);
}

gint test_callback(gpointer data)
{
  GtkWidget* chooser = gtk_app_chooser_dialog_new_for_content_type(GTK_WINDOW(window),
                       (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
                       "application/zip");
  gtk_app_chooser_dialog_set_heading(GTK_APP_CHOOSER_DIALOG(chooser), "Test");
  g_signal_connect(chooser, "response", G_CALLBACK(Done), NULL);
  g_signal_connect(chooser, "destroy", G_CALLBACK(Done), NULL);
  gtk_widget_show(chooser);

  return FALSE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

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

    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    button = gtk_button_new();
    label = gtk_label_new("Chooser");
    gtk_container_add(GTK_CONTAINER(button), label);
    gtk_container_add(GTK_CONTAINER(window), button);

    g_signal_connect (window, "destroy",
          G_CALLBACK (destroy), NULL);

    g_signal_connect (button, "clicked",
          G_CALLBACK (test_callback), NULL);

    gtk_widget_show_all (GTK_WIDGET(window));

    gtk_main ();

    return 0;
}
