nautilus-3.6.3/test/test-copy.c

No issues found

 1 #include "test.h"
 2 
 3 #include <libnautilus-private/nautilus-file-operations.h>
 4 #include <libnautilus-private/nautilus-progress-info.h>
 5 #include <libnautilus-private/nautilus-progress-info-manager.h>
 6 
 7 static void
 8 copy_done (GHashTable *debuting_uris, 
 9            gboolean success,
10            gpointer data)
11 {
12 	g_print ("Copy done\n");
13 }
14 
15 static void
16 changed_cb (NautilusProgressInfo *info,
17 	    gpointer data)
18 {
19 	g_print ("Changed: %s -- %s\n",
20 		 nautilus_progress_info_get_status (info),
21 		 nautilus_progress_info_get_details (info));
22 }
23 
24 static void
25 progress_changed_cb (NautilusProgressInfo *info,
26 		     gpointer data)
27 {
28 	g_print ("Progress changed: %f\n",
29 		 nautilus_progress_info_get_progress (info));
30 }
31 
32 static void
33 finished_cb (NautilusProgressInfo *info,
34 	     gpointer data)
35 {
36 	g_print ("Finished\n");
37 	gtk_main_quit ();
38 }
39 
40 int 
41 main (int argc, char* argv[])
42 {
43 	GtkWidget *window;
44 	GList *sources;
45 	GFile *dest;
46 	GFile *source;
47 	int i;
48 	GList *infos;
49         NautilusProgressInfoManager *manager;
50 	NautilusProgressInfo *progress_info;
51 	
52 	test_init (&argc, &argv);
53 
54 	if (argc < 3) {
55 		g_print ("Usage test-copy <sources...> <dest dir>\n");
56 		return 1;
57 	}
58 
59 	sources = NULL;
60 	for (i = 1; i < argc - 1; i++) {
61 		source = g_file_new_for_commandline_arg (argv[i]);
62 		sources = g_list_prepend (sources, source);
63 	}
64 	sources = g_list_reverse (sources);
65 	
66 	dest = g_file_new_for_commandline_arg (argv[i]);
67 	
68 	window = test_window_new ("copy test", 5);
69 	
70 	gtk_widget_show (window);
71 
72         manager = nautilus_progress_info_manager_new ();
73 
74 	nautilus_file_operations_copy (sources,
75 				       NULL /* GArray *relative_item_points */,
76 				       dest,
77 				       GTK_WINDOW (window),
78 				       copy_done, NULL);
79         
80 	infos = nautilus_progress_info_manager_get_all_infos (manager);
81 
82 	if (infos == NULL) {
83 		g_object_unref (manager);
84 		return 0;
85 	}
86 
87 	progress_info = NAUTILUS_PROGRESS_INFO (infos->data);
88 
89 	g_signal_connect (progress_info, "changed", (GCallback)changed_cb, NULL);
90 	g_signal_connect (progress_info, "progress-changed", (GCallback)progress_changed_cb, NULL);
91 	g_signal_connect (progress_info, "finished", (GCallback)finished_cb, NULL);
92 	
93 	gtk_main ();
94 
95         g_object_unref (manager);
96 	
97 	return 0;
98 }