[project @ 2004-07-10 02:35:30 by jmb]

Use libcurl's progress callback functionality to display fetch status.
This will update the status line once a second, more frequently requires hacking libcurl.

svn path=/import/netsurf/; revision=1066
This commit is contained in:
John Mark Bell 2004-07-10 02:35:31 +00:00
parent c273d17ae5
commit ba22b4e753
6 changed files with 58 additions and 4 deletions

View File

@ -141,8 +141,10 @@ MBytes: MB
GBytes: GB GBytes: GB
# Progress # Progress
Progress:%s of %s
ProgressU:%s
Loading:Opening page... Loading:Opening page...
RecPercent:Received %s of %s (%u%%) RecPercent:Received %s (%u%%)
Received:Received %s Received:Received %s
Converting:Converting %lu bytes Converting:Converting %lu bytes
BadRedirect:Bad redirect URL BadRedirect:Bad redirect URL

View File

@ -141,8 +141,10 @@ MBytes: MO
GBytes: GO GBytes: GO
# Progress # Progress
Progress:%s reçus de %s
ProgressU:%s
Loading:Ouverture de la page... Loading:Ouverture de la page...
RecPercent:%s reçus de %s (%u%%) RecPercent:%s (%u%%)
Received:%s reçus Received:%s reçus
Converting:Conversion de %lu octets Converting:Conversion de %lu octets
BadRedirect:Mauvais URL de redirection BadRedirect:Mauvais URL de redirection

View File

@ -79,11 +79,14 @@ static CURLM *curl_multi; /**< Global cURL multi handle. */
static CURL *fetch_blank_curl; static CURL *fetch_blank_curl;
static struct fetch *fetch_list = 0; /**< List of active fetches. */ static struct fetch *fetch_list = 0; /**< List of active fetches. */
static char fetch_error_buffer[CURL_ERROR_SIZE]; /**< Error buffer for cURL. */ static char fetch_error_buffer[CURL_ERROR_SIZE]; /**< Error buffer for cURL. */
static char fetch_progress_buffer[256]; /**< Progress buffer for cURL */
static CURLcode fetch_set_options(struct fetch *f); static CURLcode fetch_set_options(struct fetch *f);
static void fetch_free(struct fetch *f); static void fetch_free(struct fetch *f);
static void fetch_stop(struct fetch *f); static void fetch_stop(struct fetch *f);
static void fetch_done(CURL *curl_handle, CURLcode result); static void fetch_done(CURL *curl_handle, CURLcode result);
static int fetch_curl_progress(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow);
static size_t fetch_curl_data(void *data, size_t size, size_t nmemb, static size_t fetch_curl_data(void *data, size_t size, size_t nmemb,
struct fetch *f); struct fetch *f);
static size_t fetch_curl_header(char *data, size_t size, size_t nmemb, static size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
@ -142,6 +145,8 @@ void fetch_init(void)
SETOPT(CURLOPT_ERRORBUFFER, fetch_error_buffer); SETOPT(CURLOPT_ERRORBUFFER, fetch_error_buffer);
SETOPT(CURLOPT_WRITEFUNCTION, fetch_curl_data); SETOPT(CURLOPT_WRITEFUNCTION, fetch_curl_data);
SETOPT(CURLOPT_HEADERFUNCTION, fetch_curl_header); SETOPT(CURLOPT_HEADERFUNCTION, fetch_curl_header);
SETOPT(CURLOPT_PROGRESSFUNCTION, fetch_curl_progress);
SETOPT(CURLOPT_NOPROGRESS, 0);
SETOPT(CURLOPT_USERAGENT, user_agent); SETOPT(CURLOPT_USERAGENT, user_agent);
SETOPT(CURLOPT_ENCODING, "gzip"); SETOPT(CURLOPT_ENCODING, "gzip");
SETOPT(CURLOPT_LOW_SPEED_LIMIT, 1L); SETOPT(CURLOPT_LOW_SPEED_LIMIT, 1L);
@ -357,6 +362,7 @@ CURLcode fetch_set_options(struct fetch *f)
SETOPT(CURLOPT_PRIVATE, f); SETOPT(CURLOPT_PRIVATE, f);
SETOPT(CURLOPT_WRITEDATA, f); SETOPT(CURLOPT_WRITEDATA, f);
SETOPT(CURLOPT_WRITEHEADER, f); SETOPT(CURLOPT_WRITEHEADER, f);
SETOPT(CURLOPT_PROGRESSDATA, f);
SETOPT(CURLOPT_REFERER, f->referer); SETOPT(CURLOPT_REFERER, f->referer);
SETOPT(CURLOPT_HTTPHEADER, f->headers); SETOPT(CURLOPT_HTTPHEADER, f->headers);
if (f->post_urlenc) { if (f->post_urlenc) {
@ -579,6 +585,35 @@ void fetch_done(CURL *curl_handle, CURLcode result)
} }
/**
* Callback function for fetch progress
*/
int fetch_curl_progress(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow)
{
struct fetch *f = (struct fetch *)clientp;
double percent;
if (dltotal > 0) {
percent = dlnow * 100.0f / dltotal;
snprintf(fetch_progress_buffer, 255,
messages_get("Progress"),
human_friendly_bytesize(dlnow),
human_friendly_bytesize(dltotal));
f->callback(FETCH_PROGRESS, f->p, fetch_progress_buffer,
(unsigned long)percent);
}
else {
snprintf(fetch_progress_buffer, 255,
messages_get("ProgressU"),
human_friendly_bytesize(dlnow));
f->callback(FETCH_PROGRESS, f->p, fetch_progress_buffer, 0);
}
return 0;
}
/** /**
* Callback function for cURL. * Callback function for cURL.
*/ */

View File

@ -17,6 +17,7 @@
typedef enum { typedef enum {
FETCH_TYPE, FETCH_TYPE,
FETCH_PROGRESS,
FETCH_DATA, FETCH_DATA,
FETCH_FINISHED, FETCH_FINISHED,
FETCH_ERROR, FETCH_ERROR,

View File

@ -225,9 +225,21 @@ void fetchcache_callback(fetch_msg msg, void *p, const char *data,
} }
break; break;
case FETCH_PROGRESS:
if (size)
content_set_status(c,
messages_get("RecPercent"),
data, (unsigned int)size);
else
content_set_status(c,
messages_get("Received"),
data);
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
break;
case FETCH_DATA: case FETCH_DATA:
LOG(("FETCH_DATA")); LOG(("FETCH_DATA"));
if (c->total_size) /* if (c->total_size)
content_set_status(c, content_set_status(c,
messages_get("RecPercent"), messages_get("RecPercent"),
human_friendly_bytesize(c->source_size + size), human_friendly_bytesize(c->source_size + size),
@ -238,7 +250,7 @@ void fetchcache_callback(fetch_msg msg, void *p, const char *data,
messages_get("Received"), messages_get("Received"),
human_friendly_bytesize(c->source_size + size)); human_friendly_bytesize(c->source_size + size));
content_broadcast(c, CONTENT_MSG_STATUS, msg_data); content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
if (!content_process_data(c, data, size)) { */ if (!content_process_data(c, data, size)) {
fetch_abort(c->fetch); fetch_abort(c->fetch);
c->fetch = 0; c->fetch = 0;
} }

View File

@ -507,6 +507,8 @@ void download_window_callback(fetch_msg msg, void *p, const char *data,
struct gui_download_window *download_window = p; struct gui_download_window *download_window = p;
switch (msg) { switch (msg) {
case FETCH_PROGRESS:
break;
case FETCH_DATA: case FETCH_DATA:
gui_download_window_data(download_window, data, size); gui_download_window_data(download_window, data, size);
break; break;