summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Hambley <lists@aether.demon.co.uk>2004-04-25 11:40:05 +0000
committerMatthew Hambley <lists@aether.demon.co.uk>2004-04-25 11:40:05 +0000
commitd44ab700d065a5ac859df24969a4d993cee122ec (patch)
treeeb67109f3052b0b5beb2b3da5116c55ec36ab954
parent7a06e57bb2a2495c3b3f1b8d63217aec4320de85 (diff)
downloadnetsurf-d44ab700d065a5ac859df24969a4d993cee122ec.tar.gz
netsurf-d44ab700d065a5ac859df24969a4d993cee122ec.tar.bz2
[project @ 2004-04-25 11:40:05 by matthewh]
A more human face to download bytecounts. Needs someone who can speak French to correct the fr messages file. svn path=/import/netsurf/; revision=803
-rw-r--r--!NetSurf/Resources/en/Messages13
-rw-r--r--!NetSurf/Resources/fr/Messages11
-rw-r--r--content/fetchcache.c8
-rw-r--r--riscos/download.c2
-rw-r--r--utils/utils.c51
-rw-r--r--utils/utils.h1
6 files changed, 75 insertions, 11 deletions
diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages
index 045605780..7c922a284 100644
--- a/!NetSurf/Resources/en/Messages
+++ b/!NetSurf/Resources/en/Messages
@@ -41,7 +41,7 @@ HelpInter:Interactive help
Themes:Themes
# Download window
-Downloaded:Download complete, %lu bytes
+Downloaded:Download complete, %s
# Forms
Form_Submit:Submit
@@ -61,9 +61,16 @@ NoMemory:NetSurf is running out of memory. Please free some memory and try again
FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this.
FontError:Failed to open font "Homerton.Medium" (%s).
+# Some general purpose words and phrases
+Bytes: B
+kBytes: kB
+MBytes: MB
+GBytes: GB
+
+# Progress
Loading:Opening page...
-RecPercent:Received %lu of %lu bytes (%u%%)
-Received:Received %lu bytes
+RecPercent:Received %s of %s (%u%%)
+Received:Received %s
Converting:Converting %lu bytes
BadRedirect:Bad redirect URL
FetchFailed:Unable to fetch document
diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages
index 3536bb234..008f67c41 100644
--- a/!NetSurf/Resources/fr/Messages
+++ b/!NetSurf/Resources/fr/Messages
@@ -32,7 +32,7 @@ ScaleView:Ajuster la vue
Themes:Thèmes
# Download window
-Downloaded:Téléchargement terminé, %lu octès
+Downloaded:Téléchargement terminé, %s
# Forms
Form_Submit:Soumettre
@@ -52,9 +52,14 @@ NoMemory:NetSurf a besoin de plus de mémoire. Veuillez libérer de la mémoire et
FontBadInst:An error occurred when initialising fonts due to the presence of obsolete copies of the ROM fonts on disc. NetSurf will exit and launch a program which will attempt to fix this.
FontError:Failed to open font "Homerton.Medium" (%s).
+Bytes: O
+kBytes: kO
+MBytes: MO
+GBytes: GO
+
Loading:Ouverture de la page...
-RecPercent:%lu reçus de %lu octès (%u%%)
-Received:%lu octès reçus
+RecPercent:%s reçus de %s (%u%%)
+Received:%s reçus
Converting:Convertion de %lu octès
BadRedirect:Mauvais URL de redirection
FetchFailed:Récupération du fichier impossible
diff --git a/content/fetchcache.c b/content/fetchcache.c
index c8c10db01..23f8fc19a 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -174,13 +174,13 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
if (c->total_size)
sprintf(c->status_message,
messages_get("RecPercent"),
- c->source_size + size, c->total_size,
- (unsigned int) ((c->source_size + size) *
- 100.0 / c->total_size));
+ human_friendly_bytesize(c->source_size + size),
+ human_friendly_bytesize(c->total_size),
+ (unsigned int) ((c->source_size + size) * 100.0 / c->total_size));
else
sprintf(c->status_message,
messages_get("Received"),
- c->source_size + size);
+ human_friendly_bytesize(c->source_size + size));
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
content_process_data(c, data, size);
break;
diff --git a/riscos/download.c b/riscos/download.c
index 28db3bb1f..7682ebd3c 100644
--- a/riscos/download.c
+++ b/riscos/download.c
@@ -180,7 +180,7 @@ void gui_download_window_error(gui_window *g, const char *error)
void gui_download_window_done(gui_window *g)
{
snprintf(g->status, 256, messages_get("Downloaded"),
- g->data.download.content->source_size);
+ human_friendly_bytesize(g->data.download.content->source_size));
wimp_set_icon_state(g->window,
ICON_DOWNLOAD_STATUS, 0, 0);
diff --git a/utils/utils.c b/utils/utils.c
index 1c080e8af..885b57ab7 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -294,3 +294,54 @@ void clean_cookiejar(void) {
xfree(cookies);
}
#endif
+
+/** We can have a fairly good estimate of how long the buffer needs to
+ * be. The unsigned long can store a value representing a maximum size
+ * of around 4 GB. Therefore the greatest space required is to
+ * represent 1023MB. Currently that would be represented as "1023MB" so 12
+ * including a null terminator.
+ * Ideally we would be able to know this value for sure, in the mean
+ * time the following should suffice.
+ **/
+
+#define BYTESIZE_BUFFER_SIZE 20
+
+/**
+ * Does a simple conversion which assumes the user speaks English. The buffer
+ * returned is one of two static ones so may change each time this call is
+ * made. Don't store the buffer for later use. It's done this way for
+ * convenience and to fight possible memory leaks, it is not necesarily pretty.
+ **/
+
+char *human_friendly_bytesize(unsigned long bytesize) {
+ static char buffer1[BYTESIZE_BUFFER_SIZE];
+ static char buffer2[BYTESIZE_BUFFER_SIZE];
+ static char *curbuffer = buffer2;
+
+ if (curbuffer == buffer1)
+ curbuffer = buffer2;
+ else
+ curbuffer = buffer1;
+
+ enum {bytes, kilobytes, megabytes, gigabytes} unit = bytes;
+ static char units[][7] = {"Bytes", "kBytes", "MBytes", "GBytes"};
+
+ if (bytesize > 1024) {
+ bytesize /= 1024;
+ unit = kilobytes;
+ }
+
+ if (bytesize > 1024) {
+ bytesize /= 1024;
+ unit = megabytes;
+ }
+
+ if (bytesize > 1024) {
+ bytesize /= 1024;
+ unit = gigabytes;
+ }
+
+ sprintf(curbuffer, "%lu%s", bytesize, messages_get(units[unit]));
+
+ return curbuffer;
+}
diff --git a/utils/utils.h b/utils/utils.h
index 1faef449d..b727b7ca8 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -30,5 +30,6 @@ bool is_dir(const char *path);
void regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
void clean_cookiejar(void);
void unicode_transliterate(unsigned int c, char **r);
+char *human_friendly_bytesize(unsigned long bytesize);
#endif