]> git.street.me.uk Git - andy/viking.git/blobdiff - src/curl_download.c
Refactoring: use a GObject model to implement MapSource hierarchy tree
[andy/viking.git] / src / curl_download.c
index 4b078aaabbb0bd3a31407b740fe67e07c54905a2..f230dca0927c1826656c920f1534a4c87255a62f 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <curl/curl.h>
 
+#include "background.h"
 #include "file.h"
 #include "globals.h"
 #include "curl_download.h"
@@ -50,6 +51,11 @@ static size_t curl_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream
   return fwrite(ptr, size, nmemb, stream);
 }
 
+static int curl_progress_func(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+{
+  return a_background_testcancel(NULL);
+}
+
 static gchar *get_cookie_file(gboolean init)
 {
   static gchar *cookie_file = NULL;
@@ -80,7 +86,7 @@ static gchar *get_cookie_file(gboolean init)
     if (vik_verbose)
       curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );
     curl_easy_setopt(curl, CURLOPT_URL, "http://maps.google.com/"); /* google.com sets "PREF" cookie */
-    curl_easy_setopt ( curl, CURLOPT_FILE, out_file );
+    curl_easy_setopt ( curl, CURLOPT_WRITEDATA, out_file );
     curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
     curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_file);
     res = curl_easy_perform(curl);
@@ -125,8 +131,11 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options )
       if (vik_verbose)
         curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );
       curl_easy_setopt ( curl, CURLOPT_URL, uri );
-      curl_easy_setopt ( curl, CURLOPT_FILE, f );
+      curl_easy_setopt ( curl, CURLOPT_WRITEDATA, f );
       curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
+      curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, 0 );
+      curl_easy_setopt ( curl, CURLOPT_PROGRESSDATA, NULL );
+      curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func);
       if (options != NULL) {
         if(options->referer != NULL)
           curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);