summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-07-10 02:35:31 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-07-10 02:35:31 +0000
commitba22b4e753529ad33a204b3c215b354aeebbbd2a (patch)
treefec7c4c6cbb98a2cc1fe825387192bf14d1d710f
parentc273d17ae57b4b38478f64f53ff603d2afb08b0f (diff)
downloadnetsurf-ba22b4e753529ad33a204b3c215b354aeebbbd2a.tar.gz
netsurf-ba22b4e753529ad33a204b3c215b354aeebbbd2a.tar.bz2
[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
-rw-r--r--!NetSurf/Resources/en/Messages4
-rw-r--r--!NetSurf/Resources/fr/Messages4
-rw-r--r--content/fetch.c35
-rw-r--r--content/fetch.h1
-rw-r--r--content/fetchcache.c16
-rw-r--r--desktop/browser.c2
6 files changed, 58 insertions, 4 deletions
diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages
index 3bbf670d4..d34991b66 100644
--- a/!NetSurf/Resources/en/Messages
+++ b/!NetSurf/Resources/en/Messages
@@ -141,8 +141,10 @@ MBytes: MB
GBytes: GB
# Progress
+Progress:%s of %s
+ProgressU:%s
Loading:Opening page...
-RecPercent:Received %s of %s (%u%%)
+RecPercent:Received %s (%u%%)
Received:Received %s
Converting:Converting %lu bytes
BadRedirect:Bad redirect URL
diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages
index 1e156f39e..8c378e109 100644
--- a/!NetSurf/Resources/fr/Messages
+++ b/!NetSurf/Resources/fr/Messages
@@ -141,8 +141,10 @@ MBytes: MO
GBytes: GO
# Progress
+Progress:%s reçus de %s
+ProgressU:%s
Loading:Ouverture de la page...
-RecPercent:%s reçus de %s (%u%%)
+RecPercent:%s (%u%%)
Received:%s reçus
Converting:Conversion de %lu octets
BadRedirect:Mauvais URL de redirection
diff --git a/content/fetch.c b/content/fetch.c
index 184d78bcb..302dd6c66 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -79,11 +79,14 @@ static CURLM *curl_multi; /**< Global cURL multi handle. */
static CURL *fetch_blank_curl;
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_progress_buffer[256]; /**< Progress buffer for cURL */
static CURLcode fetch_set_options(struct fetch *f);
static void fetch_free(struct fetch *f);
static void fetch_stop(struct fetch *f);
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,
struct fetch *f);
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_WRITEFUNCTION, fetch_curl_data);
SETOPT(CURLOPT_HEADERFUNCTION, fetch_curl_header);
+ SETOPT(CURLOPT_PROGRESSFUNCTION, fetch_curl_progress);
+ SETOPT(CURLOPT_NOPROGRESS, 0);
SETOPT(CURLOPT_USERAGENT, user_agent);
SETOPT(CURLOPT_ENCODING, "gzip");
SETOPT(CURLOPT_LOW_SPEED_LIMIT, 1L);
@@ -357,6 +362,7 @@ CURLcode fetch_set_options(struct fetch *f)
SETOPT(CURLOPT_PRIVATE, f);
SETOPT(CURLOPT_WRITEDATA, f);
SETOPT(CURLOPT_WRITEHEADER, f);
+ SETOPT(CURLOPT_PROGRESSDATA, f);
SETOPT(CURLOPT_REFERER, f->referer);
SETOPT(CURLOPT_HTTPHEADER, f->headers);
if (f->post_urlenc) {
@@ -580,6 +586,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.
*/
diff --git a/content/fetch.h b/content/fetch.h
index 59767d255..eb2721b10 100644
--- a/content/fetch.h
+++ b/content/fetch.h
@@ -17,6 +17,7 @@
typedef enum {
FETCH_TYPE,
+ FETCH_PROGRESS,
FETCH_DATA,
FETCH_FINISHED,
FETCH_ERROR,
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 8d3272c94..62da13106 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -225,9 +225,21 @@ void fetchcache_callback(fetch_msg msg, void *p, const char *data,
}
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:
LOG(("FETCH_DATA"));
- if (c->total_size)
+/* if (c->total_size)
content_set_status(c,
messages_get("RecPercent"),
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"),
human_friendly_bytesize(c->source_size + size));
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);
c->fetch = 0;
}
diff --git a/desktop/browser.c b/desktop/browser.c
index 929b0a7ab..9aeaeaddd 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -507,6 +507,8 @@ void download_window_callback(fetch_msg msg, void *p, const char *data,
struct gui_download_window *download_window = p;
switch (msg) {
+ case FETCH_PROGRESS:
+ break;
case FETCH_DATA:
gui_download_window_data(download_window, data, size);
break;