]> git.street.me.uk Git - andy/viking.git/commitdiff
Stop all curl downloads on quit
authorJocelyn Jaubert <jocelyn.jaubert@gmail.com>
Sat, 25 Apr 2009 13:08:59 +0000 (15:08 +0200)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Wed, 6 May 2009 20:05:43 +0000 (22:05 +0200)
Curl downloads now periodically checks a_background_testcancel() to see if
viking is quitting.

src/background.c
src/background.h
src/curl_download.c

index b9ca150a63549e507b9f5bb5b55bf37c2165d1ad..00540d1c722a715122a8f9b93f4e6907a48d40d5 100644 (file)
@@ -26,6 +26,7 @@
 #include "background.h"
 
 static GThreadPool *thread_pool = NULL;
+static gboolean stop_all_threads = FALSE;
 
 static GtkWidget *bgwindow = NULL;
 static GtkWidget *bgtreeview = NULL;
@@ -60,14 +61,15 @@ static void background_thread_update ()
 int a_background_thread_progress ( gpointer callbackdata, gdouble fraction )
 {
   gpointer *args = (gpointer *) callbackdata;
-  a_background_testcancel ( callbackdata );
+  int res = a_background_testcancel ( callbackdata );
   gdk_threads_enter();
   gtk_list_store_set( GTK_LIST_STORE(bgstore), (GtkTreeIter *) args[5], PROGRESS_COLUMN, fraction*100, -1 );
   gdk_threads_leave();
 
   args[6] = GINT_TO_POINTER(GPOINTER_TO_INT(args[6])-1);
   bgitemcount--;
-  return background_thread_update();
+  background_thread_update();
+  return res;
 }
 
 static void thread_die ( gpointer args[6] )
@@ -89,7 +91,9 @@ static void thread_die ( gpointer args[6] )
 int a_background_testcancel ( gpointer callbackdata )
 {
   gpointer *args = (gpointer *) callbackdata;
-  if ( args[0] )
+  if ( stop_all_threads ) 
+    return -1;
+  if ( args && args[0] )
   {
     vik_thr_free_func cleanup = args[4];
     if ( cleanup )
@@ -239,6 +243,7 @@ void a_background_init()
 void a_background_uninit()
 {
   /* wait until all running threads stop */
+  stop_all_threads = TRUE;
   g_thread_pool_free ( thread_pool, TRUE, TRUE );
 }
 
index 09af6b1f2c22dca1f3bcf53dacf6f08fa35112b3..e12734b331e0b9874a254b325a44d03b5fae215d 100644 (file)
@@ -32,8 +32,8 @@ typedef void(*vik_thr_func)(gpointer,gpointer);
 
 /* the new way */
 void a_background_thread ( GtkWindow *parent, const gchar *message, vik_thr_func func, gpointer userdata, vik_thr_free_func userdata_free_func, vik_thr_free_func userdata_cancel_cleanup_func, gint number_items );
-void a_background_thread_progress ( gpointer callbackdata, gdouble fraction );
-void a_background_testcancel ( gpointer callbackdata );
+int a_background_thread_progress ( gpointer callbackdata, gdouble fraction );
+int a_background_testcancel ( gpointer callbackdata );
 void a_background_show_window ();
 void a_background_init ();
 void a_background_uninit ();
index 8009557561de26cfdbb62c7f1ad2ae18f5c6ad28..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;
@@ -127,6 +133,9 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options )
       curl_easy_setopt ( curl, CURLOPT_URL, uri );
       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);