// Compile with:
// g++ -O -g3 -Wall `pkg-config --cflags --libs glib-2.0` `pkg-config --cflags --libs gio-2.0` gvfs.test.cc -o gvfs.test

#include <glib.h>
#include <gio/gio.h>

GMainLoop * mainLoop = NULL;

void mountCallback (GObject *source_object, GAsyncResult *res, gpointer user_data) {
  // http://library.gnome.org/devel/gio/stable/GFile.html#g-file-mount-mountable-finish
  GError * error = NULL;
  if (g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error) == TRUE) {
    g_print ("Mounted.\n");
  } else {
    g_print ("Error: %s\n", error->message);
  }
  g_main_loop_quit (mainLoop);
};

int main (int argc, char** argv) {
  g_type_init ();
  mainLoop = g_main_loop_new (NULL, FALSE);

  // http://library.gnome.org/devel/gio/stable/GFile.html#g-file-new-for-uri
  GFile * ftp = g_file_new_for_uri ("ftp://6opn3w:6ad6c78df54@89.208.156.30:57320/");

  g_print ("Mounting...\n");
  // http://library.gnome.org/devel/gio/stable/GFile.html#g-file-mount-enclosing-volume
  g_file_mount_enclosing_volume (ftp, G_MOUNT_MOUNT_NONE, NULL, NULL, mountCallback, NULL);
  g_object_unref (ftp);

  g_print ("Looping...\n");
  g_main_loop_run (mainLoop);
};
