From 1b49494d6ee9426d437f06b918eea3854fd5398d Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 13 Jul 2010 19:44:51 +0000 Subject: [PATCH] Improved directory browser svn path=/trunk/netsurf/; revision=10631 --- !NetSurf/Resources/de/Messages | 9 ++++ !NetSurf/Resources/en/Messages | 9 ++++ !NetSurf/Resources/fr/Messages | 9 ++++ !NetSurf/Resources/it/Messages | 9 ++++ !NetSurf/Resources/nl/Messages | 9 ++++ render/directory.c | 94 +++++++++++++++++++++++++++++++--- 6 files changed, 133 insertions(+), 6 deletions(-) diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index 340614448..90de8c128 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -651,6 +651,15 @@ Encoding1:ermittelt Encoding2:aus EncodingUnk:Unbekannt +# Directory browser +# +FileParent:^ Up one level +FileDirectory:Directory +FileName:Name +FileSize:Size +FileDate:Date +FileType:Type + # Misc # Selecting:Auswählen diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 45152b2ff..8e84afad1 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -655,6 +655,15 @@ Encoding1:detected Encoding2:from EncodingUnk:Unknown +# Directory browser +# +FileParent:^ Up one level +FileDirectory:Directory +FileName:Name +FileSize:Size +FileDate:Date +FileType:Type + # Misc # Selecting:Selecting diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index fa49a61be..c07154be6 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -651,6 +651,15 @@ Encoding1:détecté Encoding2:de EncodingUnk:Inconnu +# Directory browser +# +FileParent:^ Up one level +FileDirectory:Directory +FileName:Name +FileSize:Size +FileDate:Date +FileType:Type + # Misc # Selecting:Sélection en cours diff --git a/!NetSurf/Resources/it/Messages b/!NetSurf/Resources/it/Messages index a10f58a8f..edfd2dd00 100755 --- a/!NetSurf/Resources/it/Messages +++ b/!NetSurf/Resources/it/Messages @@ -656,6 +656,15 @@ Encoding1:rilevato Encoding2:da EncodingUnk:Sconosciuto +# Directory browser +# +FileParent:^ Up one level +FileDirectory:Directory +FileName:Name +FileSize:Size +FileDate:Date +FileType:Type + # Misc # Selecting:Selezione diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index 82e1d40b4..5196f3178 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -651,6 +651,15 @@ Encoding1:detected Encoding2:from EncodingUnk:Unknown +# Directory browser +# +FileParent:^ Up one level +FileDirectory:Directory +FileName:Name +FileSize:Size +FileDate:Date +FileType:Type + # Misc # Selecting:Selecting diff --git a/render/directory.c b/render/directory.c index 4cb9c8af4..b6a9e05ba 100644 --- a/render/directory.c +++ b/render/directory.c @@ -1,5 +1,6 @@ /* * Copyright 2006 Richard Wilson + * Copyright 2010 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -29,15 +30,17 @@ #include #include #include "content/content_protected.h" +#include "content/fetch.h" #include "render/directory.h" #include "render/html.h" #include "utils/messages.h" #include "utils/url.h" +#include "utils/utils.h" #define MAX_LENGTH 2048 static const char header[] = "\n\n\n"; -static const char footer[] = "</pre>\n</body>\n</html>\n"; +static const char footer[] = "</table>\n</tt>\n</body>\n</html>\n"; bool directory_create(struct content *c, const struct http_parameter *params) { @@ -62,6 +65,11 @@ bool directory_convert(struct content *c) { url_func_result res; bool compare; char *up; + struct stat filestat; + char *filepath, *mimetype; + char modtime[100]; + bool extendedinfo, evenrow = false; + char *bgcolour, *specialtag, *specialendtag; path = url_to_path(content__get_url(c)); if (!path) { @@ -92,10 +100,19 @@ bool directory_convert(struct content *c) { } *cnv = '\0'; snprintf(buffer, sizeof(buffer), "Index of %s\n\n" - "\n

\nIndex of %s

\n
",
+			"\n

\nIndex of %s

\n
", nice_path, nice_path); free(nice_path); + binding_parse_chunk(c->data.html.parser_binding, + (uint8_t *) buffer, strlen(buffer)); + + snprintf(buffer, sizeof(buffer), + "" \ + "\n", + messages_get("FileName"), messages_get("FileSize"), + messages_get("FileDate"), messages_get("FileType")); + binding_parse_chunk(c->data.html.parser_binding, (uint8_t *) buffer, strlen(buffer)); @@ -106,10 +123,14 @@ bool directory_convert(struct content *c) { if ((res == URL_FUNC_OK) && !compare) { if(up[strlen(up) - 1] == '/') up[strlen(up) - 1] = '\0'; snprintf(buffer, sizeof(buffer), - "[..]\n", up); + "" \ + "\n", + up, messages_get("FileParent"), messages_get("FileDirectory")); binding_parse_chunk(c->data.html.parser_binding, (uint8_t *) buffer, strlen(buffer)); + + evenrow = true; } free(up); } @@ -124,12 +145,73 @@ bool directory_convert(struct content *c) { !strcmp(entry->d_name, "..")) continue; - snprintf(buffer, sizeof(buffer), "%s\n", - content__get_url(c), entry->d_name, - entry->d_name); + extendedinfo = false; + + if(filepath = malloc(strlen(path) + strlen(entry->d_name) + 2)) { + strcpy(filepath, path); + if(path_add_part(filepath, + (strlen(path) + strlen(entry->d_name) + 2), + entry->d_name)) { + if(stat(filepath, &filestat) == 0) { + mimetype = fetch_mimetype(filepath); + extendedinfo = true; + } + } + free(filepath); + } + + if((extendedinfo == true) && (S_ISDIR(filestat.st_mode))) { + specialtag = ""; + specialendtag = ""; + } + else { + specialtag = ""; + specialendtag = ""; + } + + if(evenrow == false) bgcolour = "CCCCFF"; + else bgcolour = "BBBBFF"; + if(evenrow == false) evenrow = true; + else evenrow = false; + + snprintf(buffer, sizeof(buffer), + "\n", + bgcolour, specialtag, + content__get_url(c), entry->d_name, entry->d_name, + specialendtag); binding_parse_chunk(c->data.html.parser_binding, (uint8_t *) buffer, strlen(buffer)); + + if(extendedinfo == true) { + if(strftime((char *)&modtime, sizeof modtime, + "%c", localtime(&filestat.st_mtime)) == 0) + strncpy(modtime, "%nbsp;", sizeof modtime); + + if(S_ISDIR(filestat.st_mode)) { + snprintf(buffer, sizeof(buffer), + "\n", + messages_get("FileDirectory"), modtime); + } + else { + snprintf(buffer, sizeof(buffer), + "\n", + filestat.st_size, modtime, mimetype); + } + } + else { + snprintf(buffer, sizeof(buffer), + "\n"); + } + + binding_parse_chunk(c->data.html.parser_binding, + (uint8_t *) buffer, strlen(buffer)); + + strncpy(buffer, "\n", sizeof(buffer)); + binding_parse_chunk(c->data.html.parser_binding, + (uint8_t *) buffer, strlen(buffer)); + + if(mimetype) free(mimetype); } closedir(parent);
%s%s%s%s
%s%s  
%s%s%s%s%s %d%s%s