summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-21 19:42:16 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-21 19:47:35 -0200
commit2e3aa2cf6c39cbe599fcf1adf8984e205960e125 (patch)
treea1951c7316a494a9c64d052e46a88d07fc6a5533
parent0c8c7ffacf2e7bb8d5f3874f1c919c6e5d499bbd (diff)
ecore_file_download_example: allow cancel.
If we ^C to cancel the main loop, then abort the download, this allows using one more API in the example and provides more correct code.
-rw-r--r--src/examples/ecore/ecore_file_download_example.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/examples/ecore/ecore_file_download_example.c b/src/examples/ecore/ecore_file_download_example.c
index d68dfc6289..7fb803043f 100644
--- a/src/examples/ecore/ecore_file_download_example.c
+++ b/src/examples/ecore/ecore_file_download_example.c
@@ -19,10 +19,13 @@
19#define DST "linux-1.0.tar.gz" 19#define DST "linux-1.0.tar.gz"
20#define DST_MIME "[x-gzip]linux-1.0.tar.gz" 20#define DST_MIME "[x-gzip]linux-1.0.tar.gz"
21 21
22static Ecore_File_Download_Job *job = NULL;
23
22void 24void
23completion_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED, int status) 25completion_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED, int status)
24{ 26{
25 printf("Done (status: %d)\n", status); 27 printf("Done (status: %d)\n", status);
28 job = NULL;
26 ecore_main_loop_quit(); 29 ecore_main_loop_quit();
27} 30}
28 31
@@ -53,12 +56,21 @@ main(void)
53 56
54 start = ecore_time_get(); 57 start = ecore_time_get();
55 58
56 if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL)) 59 if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, &job))
57 { 60 {
58 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST); 61 printf("Download started successfully:\n URL: %s\n DEST: %s\n JOB: %p\n", URL, DST, job);
59 ecore_main_loop_begin(); 62 ecore_main_loop_begin();
60 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); 63 if (job)
61 printf("Downloaded %lld bytes\n", ecore_file_size(DST)); 64 {
65 printf("\nMain loop aborted! Abort download!\n");
66 ecore_file_download_abort(job);
67 job = NULL;
68 }
69 else
70 {
71 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
72 printf("Downloaded %lld bytes\n", ecore_file_size(DST));
73 }
62 } 74 }
63 else 75 else
64 { 76 {
@@ -69,12 +81,21 @@ main(void)
69 headers = eina_hash_string_small_new(NULL); 81 headers = eina_hash_string_small_new(NULL);
70 eina_hash_add(headers, "Content-type", "application/x-gzip"); 82 eina_hash_add(headers, "Content-type", "application/x-gzip");
71 83
72 if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers)) 84 if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, &job, headers))
73 { 85 {
74 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST_MIME); 86 printf("Download started successfully:\n URL: %s\n DEST: %s\n JOB: %p\n", URL, DST_MIME, job);
75 ecore_main_loop_begin(); 87 ecore_main_loop_begin();
76 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); 88 if (job)
77 printf("Downloaded %lld bytes\n", ecore_file_size(DST_MIME)); 89 {
90 printf("\nMain loop aborted! Abort download!\n");
91 ecore_file_download_abort(job);
92 job = NULL;
93 }
94 else
95 {
96 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
97 printf("Downloaded %lld bytes\n", ecore_file_size(DST_MIME));
98 }
78 } 99 }
79 else 100 else
80 { 101 {