/*
 * Copyright (c) 2006 Brian Tarricone <bjt23@cornell.edu>
 *
 * Permission is hereby granted to the recipient to do whatever he or she
 * pleases with this code, including but not limited to modifying it,
 * redistributing it, redistributing modifications, etc., provided that this
 * copyright and license text remains intact.
 */

/* cc -o thunar-vfs-automounter thunar-vfs-automounter.c \
       `pkg-config thunar-vfs-1 --cflags --libs` */

#include <unistd.h>

#define EXO_API_SUBJECT_TO_CHANGE 1
#include <thunar-vfs/thunar-vfs.h>

static void
volumes_added(ThunarVfsVolumeManager *manager,
              GList *volumes,
              gpointer user_data)
{
    GList *l;
    
    for(l = volumes; l; l = l->next) {
        ThunarVfsVolume *volume = THUNAR_VFS_VOLUME(l->data);
        if(thunar_vfs_volume_is_removable(volume)
           && thunar_vfs_volume_is_present(volume))
        {
            thunar_vfs_volume_mount(volume, NULL, NULL);
        }
    }
}

int
main(int argc,
     char **argv)
{
    ThunarVfsVolumeManager *manager;
    GList *volumes, *l;
    
    daemon(1, 0);
    
    gtk_init(&argc, &argv);    
    thunar_vfs_init();
    
    manager = thunar_vfs_volume_manager_get_default();
    volumes = thunar_vfs_volume_manager_get_volumes(manager);
    volumes_added(manager, volumes, NULL);
    
    g_signal_connect(G_OBJECT(manager), "volumes-added",
                     G_CALLBACK(volumes_added), NULL);

    gtk_main();
    
    return 0;
}
