ecore_file_download() is BROKEN!!
authordavemds <davemds@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 27 Jan 2011 21:40:58 +0000 (21:40 +0000)
committerdavemds <davemds@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 27 Jan 2011 21:40:58 +0000 (21:40 +0000)
  Put in a super-simple example that should download a file
  and report the progress during the operation.

  See the ml for more info

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@56333 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

examples/ecore_file_download_example.c [new file with mode: 0644]

diff --git a/examples/ecore_file_download_example.c b/examples/ecore_file_download_example.c
new file mode 100644 (file)
index 0000000..bbfdbc2
--- /dev/null
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <Ecore.h>
+#include <Ecore_File.h>
+
+/* 
+ * ecore_file_download() example
+ *
+ * compile with:
+ * gcc ecore_file_download_example.c `pkg-config --libs --cflags ecore-file` \
+ *     -o ecore_file_download_example
+ *
+ */
+
+#define URL "http://cdimage.ubuntu.com/releases/10.10/release/ubuntu-10.10-dvd-i386.iso.zsync"
+#define DST "ubuntu.zsync"
+
+
+void
+completion_cb(void *data, const char *file, int status)
+{
+   printf("Done (status: %d)\n", status);
+   ecore_main_loop_quit();
+}
+
+int
+progress_cb(void *data, const char *file,
+            long int dltotal, long int dlnow,
+            long int ultotal, long int ulnow)
+{
+   printf("Progress: %ld/%ld\n", dlnow, dltotal);
+   return ECORE_CALLBACK_RENEW;
+}
+
+
+int main(void)
+{
+   double start;
+
+   eina_init();
+   ecore_init();
+   ecore_file_init();
+
+   if (ecore_file_exists(DST))
+     ecore_file_unlink(DST);
+
+   start = ecore_time_get();
+
+   if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL))
+   {
+      printf("Download started successfully:\n  URL: %s\n  DEST: %s\n", URL, DST);
+      ecore_main_loop_begin();
+      printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
+      printf("Downloaded %lld bytes\n", ecore_file_size(DST));
+   }
+   else
+   {
+       printf("Error, can't start download\n");
+       return 1;
+   }
+
+   ecore_file_shutdown();
+   ecore_shutdown();
+   eina_shutdown();
+   return 0;
+}