#include <iostream>
#include <gtk/gtk.h>
#include <gtk/gtkfilechooserdialog.h>

void
ClickCallback(GtkWidget *widget, GdkEventButton *event, gpointer callback_data)
{
    GtkWidget *dialog;
     
    dialog = gtk_file_chooser_dialog_new ("Open File",
     				      NULL,
     				      GTK_FILE_CHOOSER_ACTION_OPEN,
     				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     				      NULL);
     
	 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER (dialog), FALSE);
	 
    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
       {
         char *filename;
     
         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
         //open_file (filename);
         g_free (filename);
       }
     
    gtk_widget_destroy (dialog);
}

static gboolean
QuitCallback(GtkWidget *window, gpointer data)
{
  gtk_main_quit();
  return FALSE;
}

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

  // Create a window with a button.
  GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GtkWidget *vbox =  gtk_vbox_new(FALSE, 0);

  GtkWidget *gButton = gtk_button_new_with_label("Launch GTK+2 File Chooser");
  g_signal_connect(G_OBJECT(gButton), "button_press_event",
                     G_CALLBACK(ClickCallback), NULL);
  gtk_container_add(GTK_CONTAINER(vbox), gButton);

  gtk_container_add(GTK_CONTAINER(window), vbox);

  // Quit when our window closes
  g_signal_connect(G_OBJECT(window), "delete-event", 
		   G_CALLBACK(QuitCallback), NULL);

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