test-nautilus-directory-async.c 2.21 KB
Newer Older
1
#include <gtk/gtk.h>
2 3 4
#include <src/nautilus-directory.h>
#include <src/nautilus-search-directory.h>
#include <src/nautilus-file.h>
5 6 7 8 9 10
#include <unistd.h>

void *client1, *client2;

static void
files_added (NautilusDirectory *directory,
11
             GList             *added_files)
12 13
{
#if 0
14
    GList *list;
15

16 17 18
    for (list = added_files; list != NULL; list = list->next)
    {
        NautilusFile *file = list->data;
19

20 21
        g_print (" - %s\n", nautilus_file_get_uri (file));
    }
22 23
#endif

24 25
    g_print ("files added: %d files\n",
             g_list_length (added_files));
26 27 28 29
}

static void
files_changed (NautilusDirectory *directory,
30
               GList             *changed_files)
31 32
{
#if 0
33
    GList *list;
34

35 36 37
    for (list = changed_files; list != NULL; list = list->next)
    {
        NautilusFile *file = list->data;
38

39 40
        g_print (" - %s\n", nautilus_file_get_uri (file));
    }
41
#endif
42 43
    g_print ("files changed: %d\n",
             g_list_length (changed_files));
44 45 46 47 48
}

static void
done_loading (NautilusDirectory *directory)
{
49 50
    g_print ("done loading\n");
    gtk_main_quit ();
51 52 53
}

int
54 55
main (int    argc,
      char **argv)
56
{
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    NautilusDirectory *directory;
    NautilusFileAttributes attributes;
    const char *uri;

    client1 = g_new0 (int, 1);
    client2 = g_new0 (int, 1);

    gtk_init (&argc, &argv);

    if (argv[1] == NULL)
    {
        uri = "file:///tmp";
    }
    else
    {
        uri = argv[1];
    }
    g_print ("loading %s", uri);
    directory = nautilus_directory_get_by_uri (uri);

    g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL);
    g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL);
    g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL);

    attributes =
        NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
        NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
        NAUTILUS_FILE_ATTRIBUTE_INFO |
        NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
        NAUTILUS_FILE_ATTRIBUTE_MOUNT |
        NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;

    nautilus_directory_file_monitor_add (directory, client1, TRUE,
                                         attributes,
                                         NULL, NULL);


    gtk_main ();
    return 0;
96
}