14 _url_progress_cb(void *data, int type, void *event_info)
16 Ecore_Con_Event_Url_Progress *url_progress = event_info;
19 if (url_progress->down.total > 0)
21 struct _request *req = ecore_con_url_data_get(url_progress->url_con);
22 req->size = url_progress->down.now;
24 percent = (url_progress->down.now / url_progress->down.total) * 100;
25 printf("Total of download complete: %0.1f (%0.0f)%%\n",
26 percent, url_progress->down.now);
33 _url_complete_cb(void *data, int type, void *event_info)
35 Ecore_Con_Event_Url_Complete *url_complete = event_info;
37 struct _request *req = ecore_con_url_data_get(url_complete->url_con);
38 int nbytes = ecore_con_url_received_bytes_get(url_complete->url_con);
41 printf("download completed with status code: %d\n", url_complete->status);
42 printf("Total size of downloaded file: %ld bytes\n", req->size);
43 printf("Total size of downloaded file: %ld bytes "
44 "(from received_bytes_get)\n", nbytes);
45 ecore_main_loop_quit();
51 main(int argc, const char *argv[])
53 Ecore_Con_Url *ec_url = NULL;
56 const char *filename = "downloadedfile.dat";
60 printf("need one parameter: <url>\n");
64 fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
68 printf("error: could not open file for writing: \"%s\"\n",
77 ec_url = ecore_con_url_new(argv[1]);
80 printf("error when creating ecore con url object.\n");
84 req = malloc(sizeof(*req));
86 ecore_con_url_data_set(ec_url, req);
88 ecore_con_url_fd_set(ec_url, fd);
90 ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _url_progress_cb, NULL);
91 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
93 if (!ecore_con_url_get(ec_url))
95 printf("could not realize request.\n");
99 ecore_main_loop_begin();
103 ecore_con_url_free(ec_url);
107 ecore_con_url_shutdown();
108 ecore_con_shutdown();