1 #include "test.h"
2 
3 #include <src/nautilus-file-operations.h>
4 #include <src/nautilus-progress-info.h>
5 #include <src/nautilus-progress-info-manager.h>
6 
7 static void
copy_done(GHashTable * debuting_uris,gboolean success,gpointer data)8 copy_done (GHashTable *debuting_uris,
9            gboolean    success,
10            gpointer    data)
11 {
12     g_print ("Copy done\n");
13 }
14 
15 static void
changed_cb(NautilusProgressInfo * info,gpointer data)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
progress_changed_cb(NautilusProgressInfo * info,gpointer data)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
finished_cb(NautilusProgressInfo * info,gpointer data)33 finished_cb (NautilusProgressInfo *info,
34              gpointer              data)
35 {
36     g_print ("Finished\n");
37     gtk_main_quit ();
38 }
39 
40 int
main(int argc,char * argv[])41 main (int   argc,
42       char *argv[])
43 {
44     GtkWidget *window;
45     GList *sources;
46     GFile *dest;
47     GFile *source;
48     int i;
49     GList *infos;
50     NautilusProgressInfoManager *manager;
51     NautilusProgressInfo *progress_info;
52 
53     test_init (&argc, &argv);
54 
55     if (argc < 3)
56     {
57         g_print ("Usage test-copy <sources...> <dest dir>\n");
58         return 1;
59     }
60 
61     sources = NULL;
62     for (i = 1; i < argc - 1; i++)
63     {
64         source = g_file_new_for_commandline_arg (argv[i]);
65         sources = g_list_prepend (sources, source);
66     }
67     sources = g_list_reverse (sources);
68 
69     dest = g_file_new_for_commandline_arg (argv[i]);
70 
71     window = test_window_new ("copy test", 5);
72 
73     gtk_widget_show (window);
74 
75     manager = nautilus_progress_info_manager_dup_singleton ();
76 
77     nautilus_file_operations_copy_async (sources,
78                                          dest,
79                                          GTK_WINDOW (window),
80                                          NULL,
81                                          copy_done, NULL);
82 
83     infos = nautilus_progress_info_manager_get_all_infos (manager);
84 
85     if (infos == NULL)
86     {
87         g_object_unref (manager);
88         return 0;
89     }
90 
91     progress_info = NAUTILUS_PROGRESS_INFO (infos->data);
92 
93     g_signal_connect (progress_info, "changed", (GCallback) changed_cb, NULL);
94     g_signal_connect (progress_info, "progress-changed", (GCallback) progress_changed_cb, NULL);
95     g_signal_connect (progress_info, "finished", (GCallback) finished_cb, NULL);
96 
97     gtk_main ();
98 
99     g_object_unref (manager);
100 
101     return 0;
102 }
103