show progress properly, begin to make pause/resume work

This commit is contained in:
ben%bengoodger.com 2005-06-15 23:17:53 +00:00
Родитель 137846db2e
Коммит 082097cd00
2 изменённых файлов: 57 добавлений и 15 удалений

Просмотреть файл

@ -310,7 +310,6 @@ var gDownloadingPage = {
_paused: false,
onPause: function() {
LOG("PAUSE/RESUME DOWNLOAD");
var updates =
Components.classes["@mozilla.org/updates/update-service;1"].
getService(Components.interfaces.nsIApplicationUpdateService);
@ -318,6 +317,7 @@ var gDownloadingPage = {
updates.downloadUpdate(gUpdates.update, false);
else
updates.pauseDownload();
this._paused = !this._paused;
},
onClose: function() {
@ -341,10 +341,12 @@ var gDownloadingPage = {
onProgress: function(request, context, progress, maxProgress) {
request.QueryInterface(nsIIncrementalDownload);
LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
// LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
var active = document.getElementById("activeDownloadItem");
active.setAttribute("progress", Math.floor(100 * (progress/maxProgress)));
active.startDownload();
active.state = STATE_DOWNLOADING;
active.progress = Math.floor(100 * (progress/maxProgress));
},
onStatus: function(request, context, status, statusText) {
@ -356,12 +358,17 @@ var gDownloadingPage = {
request.QueryInterface(nsIIncrementalDownload);
LOG("gDownloadingPage.onStopRequest: " + request.URI.spec + ", status = " + status);
// Flip the progressmeter back to "undetermined" mode in case we need to
// download a new (complete) update patch.
var active = document.getElementById("activeDownloadItem");
active.stopDownload();
var state = STATE_FAILED;
const NS_BINDING_ABORTED = 0x804b0002;
var updates =
Components.classes["@mozilla.org/updates/update-service;1"]
.getService(Components.interfaces.nsIApplicationUpdateService);
if (status == Components.results.NS_ERROR_UNEXPECTED) {
var state = STATE_FAILED;
if (!gUpdates.update.isCompleteUpdate) {
// If we were downloading a patch and the patch verification phase
// failed, log this and then commence downloading the complete update.
@ -375,8 +382,10 @@ var gDownloadingPage = {
return;
}
else if (status == NS_BINDING_ABORTED) {
LOG("Download PAUSED");
state = gUpdates.update.state;
LOG("gDownloadingPage.onStopRequest: Pausing Download");
}
active.state = state;
updates.removeDownloadListener(this);
},
@ -384,7 +393,7 @@ var gDownloadingPage = {
var brandName = gUpdates.brandStrings.getString("brandShortName");
var verificationError = gUpdates.updateStrings.getFormattedString("verificationError", [brandName]);
var downloadingPage = document.getElementById("downloading");
// gUpdates.advanceToErrorPage(downloadingPage, verificationError);
gUpdates.advanceToErrorPage(downloadingPage, verificationError);
},
/**

Просмотреть файл

@ -60,14 +60,14 @@
<xul:link class="update-item-details" xbl:inherits="href=detailsURL">&details.link;</xul:link>
</xul:hbox>
<xul:deck anonid="modeDeck">
<xul:label class="update-item-status" xbl:inherits="xbl:text=status" flex="1"/>
<xul:label class="update-item-status" xbl:inherits="value=status" flex="1"/>
<xul:vbox>
<xul:progressmeter class="update-item-progress" xbl:inherits="value=progress" mode="undetermined"/>
<xul:progressmeter class="update-item-progress" anonid="progress"
mode="undetermined"/>
<xul:hbox align="center">
<xul:label class="update-item-status" xbl:inherits="value=status" flex="1" crop="right"/>
<xul:button class="update-item-pause"
label="&pause.label;" accesskey="&pause.accesskey;"
oncommand="this.parentNode.parentNode.fireEvent('pause');"/>
<xul:button class="update-item-pause" anonid="pause-button"
label="&pause.label;" accesskey="&pause.accesskey;"/>
</xul:hbox>
</xul:vbox>
</xul:deck>
@ -79,6 +79,9 @@
<field name="_strings">
document.getAnonymousElementByAttribute(this, "anonid", "strings");
</field>
<field name="_progressBar">
document.getAnonymousElementByAttribute(this, "anonid", "progress");
</field>
<field name="_modeDeck">
document.getAnonymousElementByAttribute(this, "anonid", "modeDeck");
</field>
@ -93,6 +96,34 @@
]]></body>
</method>
<property name="progress">
<getter><![CDATA[
return parseInt(this._progressBar.getAttribute("value"));
]]></getter>
<setter><![CDATA[
this._progressBar.setAttribute("value", val);
]]></setter>
</property>
<field name="_started">false</field>
<method name="startDownload">
<body><![CDATA[
if (!this._started) {
this._progressBar.setAttribute("mode", "normal");
this._started = true;
}
]]></body>
</method>
<method name="stopDownload">
<body><![CDATA[
if (this._started) {
this._progressBar.setAttribute("mode", "undetermined");
this._started = false;
}
]]></body>
</method>
<property name="state">
<getter><![CDATA[
return this.getAttribute("state");
@ -100,7 +131,6 @@
<setter><![CDATA[
this.setAttribute("state", val);
this._modeDeck.setAttribute("selectedIndex", val == "downloading" ? 1 : 0);
if (val == "failed") {
var failed = this._strings.getString("statusFailed");
this.setAttribute("status", failed);
@ -126,10 +156,13 @@
]]></setter>
</property>
<field name="eventPrefix">"update-"</field>
<property name="state"
onset="this.setAttribute('state', val); return val;"
onget="return this.getAttribute('state');"/>
</implementation>
<handlers>
<handler event="command"><![CDATA[
if (event.originalTarget.getAttribute("anonid") == "pause-button")
this.fireEvent("pause");
]]></handler>
</handlers>
</binding>
<binding id="license">