#include "background.h"
static GThreadPool *thread_pool = NULL;
+static gboolean stop_all_threads = FALSE;
static GtkWidget *bgwindow = NULL;
static GtkWidget *bgtreeview = NULL;
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] )
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 )
void a_background_uninit()
{
/* wait until all running threads stop */
+ stop_all_threads = TRUE;
g_thread_pool_free ( thread_pool, TRUE, TRUE );
}
/* 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 ();
#include <curl/curl.h>
+#include "background.h"
#include "file.h"
#include "globals.h"
#include "curl_download.h"
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;
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);