From 51f27af854b15478ea40eb567b0ece0d13beeac6 Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Sat, 3 Apr 1999 00:13:46 +0000 Subject: [PATCH] New for file download --- xpfe/browser/src/downloadProgress.css | 3 + xpfe/browser/src/downloadProgress.xul | 195 ++++++++++++++++++++++++++ xpfe/browser/src/makefile.win | 26 ++-- xpfe/browser/src/saveToDisk.xul | 89 ++++++++++++ 4 files changed, 304 insertions(+), 9 deletions(-) create mode 100644 xpfe/browser/src/downloadProgress.css create mode 100644 xpfe/browser/src/downloadProgress.xul create mode 100644 xpfe/browser/src/saveToDisk.xul diff --git a/xpfe/browser/src/downloadProgress.css b/xpfe/browser/src/downloadProgress.css new file mode 100644 index 000000000000..155f3c0692df --- /dev/null +++ b/xpfe/browser/src/downloadProgress.css @@ -0,0 +1,3 @@ +TD { + font: 10pt sans-serif; +} diff --git a/xpfe/browser/src/downloadProgress.xul b/xpfe/browser/src/downloadProgress.xul new file mode 100644 index 000000000000..7e2393538e4f --- /dev/null +++ b/xpfe/browser/src/downloadProgress.xul @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + var data; + var dialog; + + function loadDialog() { + dialog.location.setAttribute( "value", data.location.getAttribute( "value" ) ); + dialog.fileName.setAttribute( "value", data.fileName.getAttribute( "value" ) ); + } + + function onLoad() { + // Set global variables. + data = new Object; + data.location = document.getElementById("data.location"); + data.contentType = document.getElementById("data.contentType"); + data.fileName = document.getElementById("data.fileName"); + data.progress = document.getElementById("data.progress"); + data.status = document.getElementById("data.status"); + data.execute = document.getElementById("data.execute"); + dialog = new Object; + dialog.location = document.getElementById("dialog.location"); + dialog.contentType = document.getElementById("dialog.contentType"); + dialog.fileName = document.getElementById("dialog.fileName"); + dialog.status = document.getElementById("dialog.status"); + dialog.progress = document.getElementById("dialog.progress"); + dialog.progressPercent = document.getElementById("dialog.progressPercent"); + dialog.timeLeft = document.getElementById("dialog.timeLeft"); + + // Fill dialog. + loadDialog(); + } + + function cancel() { + data.execute.setAttribute("command","cancel"); + } + + var started = false; + var startTime; + var interval = 1000; // Update every 1000 milliseconds. + var lastUpdate = -interval; // Update initially. + + function onProgress() { + // Check for first time. + if ( !started ) { + // Initialize download start time. + started = true; + startTime = ( new Date() ).getTime(); + } + // Get stats. + var bytes = data.progress.getAttribute("value"); + var max = data.progress.getAttribute("max"); + + // Get current time. + var now = ( new Date() ).getTime(); + // If interval hasn't elapsed, ignore it. + if ( now - lastUpdate < interval && eval(bytes) < eval(max) ) { + return; + } + + // Update this time. + lastUpdate = now; + + // Update download rate. + var elapsed = now - startTime; + var rate; // bytes/sec + if ( elapsed ) { + rate = ( bytes * 1000 ) / elapsed; + } else { + rate = 0; + } + + // Calculate percentage. + var percent = Math.round( (bytes*100)/max ); + + // Advance progress meter. + dialog.progress.setAttribute( "value", percent ); + + // Update status (nnn of mmm) + var status = "( "; + status += Math.round( bytes/1000 ); + status += "K of "; + status += Math.round( max/1000 ); + status += "K bytes "; + if ( rate ) { + status += "at "; + status += Math.round( (rate*10)/1000 ) / 10; + status += "K bytes/sec )"; + } else { + status += ")"; + } + status += + dialog.status.childNodes[0].nodeValue = status; + + // Update percentage label on progress meter. + dialog.progressPercent.childNodes[0].nodeValue = percent + "%"; + + // Update time remaining. + if ( rate ) { + var rem = Math.round( ( max - bytes ) / rate ); // In seconds. + status = ""; + if ( rem >= 3600 ) { + status += Math.round( rem/3600 ) + " hours, "; + rem = rem % 3600; + } + status += Math.round( rem/60 ) + " minutes and "; + rem = rem % 60; + status += rem + " seconds"; + dialog.timeLeft.childNodes[0].nodeValue = status; + } + } + + + + + + + Location: + + + + + + + + + Saving: + + + + + + + + + Status: + + + + ( nn.nK of mm.mK bytes ) + + + + + + + Time Left: + + + + ? + + + + + + + + + 0% + + + + + + + Cancel + + + + + + diff --git a/xpfe/browser/src/makefile.win b/xpfe/browser/src/makefile.win index bc70d26cb221..4a676f03d02f 100644 --- a/xpfe/browser/src/makefile.win +++ b/xpfe/browser/src/makefile.win @@ -72,11 +72,14 @@ install:: $(DLL) $(MAKE_INSTALL) xul.css $(DIST)\bin\res\samples $(MAKE_INSTALL) navigator.css $(DIST)\bin\res\samples $(MAKE_INSTALL) navigator.xul $(DIST)\bin\res\samples + $(MAKE_INSTALL) saveToDisk.xul $(DIST)\bin\res\samples + $(MAKE_INSTALL) downloadProgress.xul $(DIST)\bin\res\samples + $(MAKE_INSTALL) downloadProgress.css $(DIST)\bin\res\samples $(MAKE_INSTALL) navigator-mozillazine0.css $(DIST)\bin\res\samples $(MAKE_INSTALL) navigator-test1.xul $(DIST)\bin\res\samples - $(MAKE_INSTALL) navigator-goofy.css $(DIST)\bin\res\samples - $(MAKE_INSTALL) navigator-shiny.css $(DIST)\bin\res\samples - $(MAKE_INSTALL) raindrops_light.gif $(DIST)\bin\res\samples + $(MAKE_INSTALL) navigator-goofy.css $(DIST)\bin\res\samples + $(MAKE_INSTALL) navigator-shiny.css $(DIST)\bin\res\samples + $(MAKE_INSTALL) raindrops_light.gif $(DIST)\bin\res\samples clobber:: rm -f $(DIST)\bin\$(DLLNAME).dll @@ -86,9 +89,14 @@ clobber:: rm -f $(DIST)\res\samples\BrowserInitPage.html rm -f $(DIST)\res\samples\sidebar.html rm -f $(DIST)\res\samples\xul.css - rm -f $(DIST)\res\samples\navigator.css - rm -f $(DIST)\res\samples\navigator-mozillazine0.css - rm -f $(DIST)\res\samples\navigator-test1.xul - rm -f $(DIST)\res\samples\navigator-goofy.css - rm -f $(DIST)\res\samples\navigator-shiny.css - rm -f $(DIST)\res\samples\raindrops_light.gif \ No newline at end of file + rm -f $(DIST)\res\samples\navigator.xul + rm -f $(DIST)\res\samples\saveToDisk.xul + rm -f $(DIST)\res\samples\downloadProgress.xul + rm -f $(DIST)\res\samples\downloadProgress.css + rm -f $(DIST)\res\samples\navigator.css + rm -f $(DIST)\res\samples\navigator-mozillazine0.css + rm -f $(DIST)\res\samples\navigator-test1.xul + rm -f $(DIST)\res\samples\navigator-goofy.css + rm -f $(DIST)\res\samples\navigator-shiny.css + rm -f $(DIST)\res\samples\raindrops_light.gif + diff --git a/xpfe/browser/src/saveToDisk.xul b/xpfe/browser/src/saveToDisk.xul new file mode 100644 index 000000000000..e77a9187fed1 --- /dev/null +++ b/xpfe/browser/src/saveToDisk.xul @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + var data; + var dialog; + + function loadDialog() { + dialog.location.setAttribute( "value", data.location.getAttribute( "value" ) ); + dialog.contentType.setAttribute( "value", data.contentType.getAttribute( "value" ) ); + dialog.fileName.setAttribute( "value", data.fileName.getAttribute( "value" ) ); + } + + function onLoad() { + // Set global variables. + data = new Object; + data.location = document.getElementById("data.location"); + data.contentType = document.getElementById("data.contentType"); + data.fileName = document.getElementById("data.fileName"); + data.execute = document.getElementById("data.execute"); + dialog = new Object; + dialog.location = document.getElementById("dialog.location"); + dialog.contentType = document.getElementById("dialog.contentType"); + dialog.fileName = document.getElementById("dialog.fileName"); + + // Fill dialog. + loadDialog(); + } + + function ok() { + data.execute.setAttribute("filename", dialog.fileName.value ); + data.execute.setAttribute("command","ok"); + } + + function cancel() { + data.execute.setAttribute("command","cancel"); + } + + + + + + URL: + + + + + + + + + content-type: + + + + + + + + + Enter file name: + + + + + + + + + Ok + Cancel + + + + +