зеркало из https://github.com/mozilla/pjs.git
Adding new .dtd files; a=mcafee
This commit is contained in:
Родитель
92f5af7b31
Коммит
9504ccf7b0
|
@ -0,0 +1,93 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
var data;
|
||||
var dialog;
|
||||
|
||||
function initData() {
|
||||
// Create data object and initialize.
|
||||
data = new Object;
|
||||
data.location = window.arguments[0];
|
||||
data.contentType = window.arguments[1];
|
||||
}
|
||||
|
||||
function initDialog() {
|
||||
// Create dialog object and initialize.
|
||||
dialog = new Object;
|
||||
dialog.contentType = document.getElementById("dialog.contentType");
|
||||
dump("dialog.contentType="+dialog.contentType+"\n");
|
||||
dialog.more = document.getElementById("dialog.more");
|
||||
dialog.pick = document.getElementById("dialog.pick");
|
||||
dialog.save = document.getElementById("dialog.save");
|
||||
dialog.cancel = document.getElementById("dialog.cancel");
|
||||
}
|
||||
|
||||
function loadDialog() {
|
||||
// Set initial dialog field contents.
|
||||
dialog.contentType.childNodes[0].nodeValue = " " + data.contentType;
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
// Init data.
|
||||
initData();
|
||||
|
||||
// Init dialog.
|
||||
initDialog();
|
||||
|
||||
// Fill dialog.
|
||||
loadDialog();
|
||||
}
|
||||
|
||||
function onUnload() {
|
||||
// Nothing for now.
|
||||
}
|
||||
|
||||
function more() {
|
||||
// Have parent browser window go to appropriate web page.
|
||||
var moreInfo = "http://cgi.netscape.com/cgi-bin/plug-in_finder.cgi?";
|
||||
moreInfo += data.contentType;
|
||||
window.opener.content.location = moreInfo;
|
||||
}
|
||||
|
||||
function pick() {
|
||||
alert( "PickApp not implemented yet!" );
|
||||
}
|
||||
|
||||
function save() {
|
||||
// Use stream xfer component to prompt for destination and save.
|
||||
var xfer = Components.classes[ "component://netscape/appshell/component/xfer" ].getService();
|
||||
xfer = xfer.QueryInterface( Components.interfaces.nsIStreamTransfer );
|
||||
try {
|
||||
// When Necko lands, we need to receive the real nsIChannel and
|
||||
// do SelectFileAndTransferLocation!
|
||||
|
||||
// Use this for now...
|
||||
xfer.SelectFileAndTransferLocationSpec( data.location, window.opener );
|
||||
} catch( exception ) {
|
||||
// Failed (or cancelled), give them another chance.
|
||||
dump( "SelectFileAndTransferLocationSpec failed, rv=" + exception + "\n" );
|
||||
return;
|
||||
}
|
||||
// Save underway, close this dialog.
|
||||
window.close();
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
// Close the window.
|
||||
window.close();
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
var data; // nsIStreamTransferOperation object
|
||||
var dialog;
|
||||
|
||||
function loadDialog() {
|
||||
dialog.location.setAttribute( "value", data.source );
|
||||
dialog.fileName.setAttribute( "value", data.target );
|
||||
}
|
||||
|
||||
var progId = "component://netscape/appshell/component/xfer";
|
||||
var observer = {
|
||||
Observe: function( subject, topic, data ) {
|
||||
switch ( topic ) {
|
||||
case progId+";onProgress":
|
||||
var words = data.split( " " );
|
||||
onProgress( words[0], words[1] );
|
||||
break;
|
||||
case progId+";onStatus":
|
||||
onStatus( data );
|
||||
break;
|
||||
case progId+";onCompletion":
|
||||
onCompletion( data );
|
||||
break;
|
||||
default:
|
||||
dump( "Unknown topic: " + topic + "\n" );
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
// Set global variables.
|
||||
data = window.arguments[0];
|
||||
if ( !data ) {
|
||||
dump( "Invalid argument to downloadProgress.xul\n" );
|
||||
window.close()
|
||||
return;
|
||||
}
|
||||
|
||||
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");
|
||||
dialog.cancel = document.getElementById("dialog.cancel");
|
||||
|
||||
// Fill dialog.
|
||||
loadDialog();
|
||||
|
||||
// Commence transfer.
|
||||
data.observer = observer;
|
||||
data.Start();
|
||||
}
|
||||
|
||||
function onUnload() {
|
||||
// Unhook observer.
|
||||
data.observer = null;
|
||||
|
||||
// Terminate transfer.
|
||||
data.Stop();
|
||||
}
|
||||
|
||||
var started = false;
|
||||
var completed = false;
|
||||
var startTime;
|
||||
var elapsed;
|
||||
var interval = 1000; // Update every 1000 milliseconds.
|
||||
var lastUpdate = -interval; // Update initially.
|
||||
|
||||
function stop() {
|
||||
// Stop the transfer.
|
||||
data.Stop();
|
||||
|
||||
// Close the window.
|
||||
window.close();
|
||||
}
|
||||
|
||||
function onProgress( bytes, max ) {
|
||||
// Check for first time.
|
||||
if ( !started ) {
|
||||
// Initialize download start time.
|
||||
started = true;
|
||||
startTime = ( new Date() ).getTime();
|
||||
// Let the user stop, now.
|
||||
dialog.cancel.removeAttribute( "disabled" );
|
||||
}
|
||||
|
||||
// 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.
|
||||
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 );
|
||||
|
||||
// Check if download complete.
|
||||
if ( !completed ) {
|
||||
// Update status (nnn of mmm)
|
||||
var status = "( ";
|
||||
status += Math.round( bytes/1024 );
|
||||
status += "K of ";
|
||||
status += Math.round( max/1024 );
|
||||
status += "K bytes ";
|
||||
if ( rate ) {
|
||||
status += "at ";
|
||||
status += Math.round( (rate*10)/1024 ) / 10;
|
||||
status += "K bytes/sec )";
|
||||
} else {
|
||||
status += ")";
|
||||
}
|
||||
// Update status msg.
|
||||
onStatus( status );
|
||||
}
|
||||
|
||||
// Update percentage label on progress meter.
|
||||
dialog.progressPercent.childNodes[0].nodeValue = percent + "%";
|
||||
|
||||
if ( !completed ) {
|
||||
// Update time remaining.
|
||||
if ( rate ) {
|
||||
var rem = Math.round( ( max - bytes ) / rate ); // In seconds.
|
||||
dialog.timeLeft.childNodes[0].nodeValue = formatSeconds( rem );
|
||||
}
|
||||
} else {
|
||||
// Clear time remaining field.
|
||||
dialog.timeLeft.childNodes[0].nodeValue = "";
|
||||
}
|
||||
}
|
||||
|
||||
function formatSeconds( nSecs ) {
|
||||
status = "";
|
||||
if ( nSecs >= 3600 ) {
|
||||
status += Math.round( nSecs/3600 ) + " hours, ";
|
||||
nSecs = nSecs % 3600;
|
||||
}
|
||||
status += Math.round( nSecs/60 ) + " minutes and ";
|
||||
nSecs = nSecs % 60;
|
||||
status += nSecs + " seconds";
|
||||
return status;
|
||||
}
|
||||
|
||||
function onCompletion( status ) {
|
||||
// Note that we're done (and can ignore subsequent progress notifications).
|
||||
completed = true;
|
||||
// Indicate completion in status area.
|
||||
onStatus( "Download completed in " + formatSeconds( elapsed/1000 ) );
|
||||
// Close the window in 2 seconds (to ensure user sees we're done).
|
||||
window.setTimeout( "window.close();", 2000 );
|
||||
}
|
||||
|
||||
function onStatus( status ) {
|
||||
// Update status text in dialog.
|
||||
dialog.status.childNodes[0].nodeValue = status;
|
||||
}
|
Загрузка…
Ссылка в новой задаче