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

static gboolean
time_handler(VncConnection *conn)
{
    printf("timer...\n");
    vnc_connection_open_host(conn, "localhost", "7777");

    return FALSE;
}

void disconnected(VncConnection *conn,
                        gpointer opaque G_GNUC_UNUSED)
{
    //vnc_connection_open_host(conn, "localhost", "7777");
    printf("reconnect...\n");
    g_timeout_add(10, (GSourceFunc) time_handler, conn);
}

int main( int argc, char *argv[])
{
  GtkWidget *window;
  VncConnection *conn;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);

  conn = vnc_connection_new();
  g_signal_connect(conn, "vnc-disconnected", G_CALLBACK(&disconnected), 0);

  vnc_connection_open_host(conn, "localhost", "7777");

  gtk_main();

  return 0;
}
