nautilus-3.6.3/test/test-nautilus-directory-async.c

No issues found

 1 #include <gtk/gtk.h>
 2 #include <libnautilus-private/nautilus-directory.h>
 3 #include <libnautilus-private/nautilus-search-directory.h>
 4 #include <libnautilus-private/nautilus-file.h>
 5 #include <unistd.h>
 6 
 7 void *client1, *client2;
 8 
 9 static void
10 files_added (NautilusDirectory *directory,
11 	     GList *added_files)
12 {
13 #if 0
14 	GList *list;
15 
16 	for (list = added_files; list != NULL; list = list->next) {
17 		NautilusFile *file = list->data;
18 
19 		g_print (" - %s\n", nautilus_file_get_uri (file));
20 	}
21 #endif
22 
23 	g_print ("files added: %d files\n",
24 		 g_list_length (added_files));
25 }
26 
27 static void
28 files_changed (NautilusDirectory *directory,
29 	       GList *changed_files)
30 {
31 #if 0
32 	GList *list;
33 
34 	for (list = changed_files; list != NULL; list = list->next) {
35 		NautilusFile *file = list->data;
36 
37 		g_print (" - %s\n", nautilus_file_get_uri (file));
38 	}
39 #endif
40 	g_print ("files changed: %d\n",
41 		 g_list_length (changed_files));
42 }
43 
44 static void
45 done_loading (NautilusDirectory *directory)
46 {
47 	g_print ("done loading\n");
48 	gtk_main_quit ();
49 }
50 
51 int
52 main (int argc, char **argv)
53 {
54 	NautilusDirectory *directory;
55 	NautilusFileAttributes attributes;
56 	const char *uri;
57 
58 	client1 = g_new0 (int, 1);
59 	client2 = g_new0 (int, 1);
60 
61 	gtk_init (&argc, &argv);
62 
63 	if (argv[1] == NULL) {
64 		uri = "file:///tmp";
65 	} else {
66 		uri = argv[1];
67 	}
68 	g_print ("loading %s", uri);
69 	directory = nautilus_directory_get_by_uri (uri);
70 
71 	g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL);
72 	g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL);
73 	g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL);
74 
75 	attributes =
76 		NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
77 		NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
78 		NAUTILUS_FILE_ATTRIBUTE_INFO |
79 		NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
80 		NAUTILUS_FILE_ATTRIBUTE_MOUNT |
81 		NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
82 
83 	nautilus_directory_file_monitor_add (directory, client1, TRUE,
84                                              attributes,
85 					     NULL, NULL);
86 
87 
88 	gtk_main ();
89 	return 0;
90 }