summaryrefslogtreecommitdiff
path: root/test/test-copy.c
blob: 520e929dde27e398e14ff253ad4ce0e84ae04ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
#include <libcaja-private/caja-file-operations.h>
#include <libcaja-private/caja-progress-info.h>

#include "test.h"

static void
copy_done (GHashTable *debuting_uris, gpointer data)
{
	g_print ("Copy done\n");
}

static void
changed_cb (CajaProgressInfo *info,
	    gpointer data)
{
	g_print ("Changed: %s -- %s\n",
		 caja_progress_info_get_status (info),
		 caja_progress_info_get_details (info));
}

static void
progress_changed_cb (CajaProgressInfo *info,
		     gpointer data)
{
	g_print ("Progress changed: %f\n",
		 caja_progress_info_get_progress (info));
}

static void
finished_cb (CajaProgressInfo *info,
	     gpointer data)
{
	g_print ("Finished\n");
	gtk_main_quit ();
}

int 
main (int argc, char* argv[])
{
	GtkWidget *window;
	GList *sources;
	GFile *dest;
	GFile *source;
	int i;
	GList *infos;
	CajaProgressInfo *progress_info;

	test_init (&argc, &argv);

	if (argc < 3) {
		g_print ("Usage test-copy <sources...> <dest dir>\n");
		return 1;
	}

	sources = NULL;
	for (i = 1; i < argc - 1; i++) {
		source = g_file_new_for_commandline_arg (argv[i]);
		sources = g_list_prepend (sources, source);
	}
	sources = g_list_reverse (sources);
	
	dest = g_file_new_for_commandline_arg (argv[i]);
	
	window = test_window_new ("copy test", 5);
	
	gtk_widget_show (window);

	caja_file_operations_copy (sources,
				       NULL /* GArray *relative_item_points */,
				       dest,
				       GTK_WINDOW (window),
				       copy_done, NULL);

	infos = caja_get_all_progress_info ();

	if (infos == NULL) {
		return 0;
	}

	progress_info = CAJA_PROGRESS_INFO (infos->data);

	g_signal_connect (progress_info, "changed", (GCallback)changed_cb, NULL);
	g_signal_connect (progress_info, "progress-changed", (GCallback)progress_changed_cb, NULL);
	g_signal_connect (progress_info, "finished", (GCallback)finished_cb, NULL);
	
	gtk_main ();
	
	return 0;
}