home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!DOCTYPE bindings>
-
- <bindings xmlns="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:xbl="http://www.mozilla.org/xbl"
- xmlns:html="http://www.w3.org/1999/xhtml">
-
- <binding id="package-management"
- inheritstyle="false">
- <resources>
- <stylesheet src="package-management.css"/>
-
- <image src="head/exclamation.png"/>
- <image src="disclaimer/exclamation.png"/>
- <image src="placement/images/after.png"/>
- <image src="placement/images/before.png"/>
- <image src="placement/images/replace.png"/>
- </resources>
-
- <implementation>
- <field name="dialog">document.documentElement</field>
- <field name="parameters">window.parameters</field>
- <field name="_mode">this.parameters.mode</field>
- <field name="_application">this.parameters.application</field>
- <field name="_widgetLibrary">this._application.widgetLibrary</field>
- <field name="_packageManager">this._application.packageManager</field>
- <field name="_overlayProvider">this._application.overlayProvider</field>
- <field name="_XB">this._application.core.Lib.XB</field>
- <field name="_misc">this._application.core.Lib.misc</field>
- <field name="_errors">this._application.core.Lib.CustomErrors</field>
- <field name="_logger">this._application.core.Log4Moz.repository.getLogger(this._application.name + ".PackageManagementDialog")</field>
- <field name="_bundle">new this._misc.StringBundle("package-management/package-management.properties")</field>
- <field name="_comparator">this._Cc["@mozilla.org/xpcom/version-comparator;1"].getService(this._Ci.nsIVersionComparator)</field>
-
- <field name="flags">{}</field>
-
- <field name="_Cc">Components.classes</field>
- <field name="_Ci">Components.interfaces</field>
- <field name="_Cr">Components.results</field>
-
- <!-- nodes -->
- <field name="_nodeConfirmHead">document.getAnonymousElementByAttribute(this, "class", "confirm-head")</field>
- <field name="_nodeConfirmComponents">document.getAnonymousElementByAttribute(this, "class", "confirm-components")</field>
- <field name="_nodeDownloadHead">document.getAnonymousElementByAttribute(this, "class", "download-head")</field>
- <field name="_nodeDownloadProgressmeter">document.getAnonymousElementByAttribute(this, "class", "download-progressmeter")</field>
- <field name="_nodeConflictHead">document.getAnonymousElementByAttribute(this, "class", "conflict-head")</field>
- <field name="_nodeConflictDeleted">document.getAnonymousElementByAttribute(this, "class", "conflict-deleted")</field>
- <field name="_nodePlacementHead">document.getAnonymousElementByAttribute(this, "class", "placement-head")</field>
- <field name="_nodePlacementWidgets">document.getAnonymousElementByAttribute(this, "class", "placement-widgets")</field>
- <field name="_nodePlacementPlacement">document.getAnonymousElementByAttribute(this, "class", "placement-placement")</field>
-
- <field name="_nodeErrorHead">document.getAnonymousElementByAttribute(this, "class", "error-head")</field>
- <field name="_nodeErrorButtons">document.getAnonymousElementByAttribute(this, "anonid", "error-buttons")</field>
- <field name="_nodeErrorDetails">document.getAnonymousElementByAttribute(this, "class", "error-details")</field>
- <field name="_nodeErrorRepeat">document.getAnonymousElementByAttribute(this, "class", "error-repeat")</field>
- <field name="_nodeErrorMore">document.getAnonymousElementByAttribute(this, "class", "error-more")</field>
-
- <constructor><![CDATA[
- this.flags = {};
- ]]></constructor>
-
- <destructor><![CDATA[
- this._clean();
- ]]></destructor>
-
- <!-- steps -->
-
- <method name="_stepDownloadPackages">
- <body><![CDATA[
- var items = [];
- for each (let component in this.packages) {
- items.push({
- component: component,
- url: component.info.fileURL
- });
- }
-
- this.step("download");
-
- var context = this;
- this.queue = new this._misc.DownloadQueue(
- items,
- function (items) { context._stepPreinstall(items); },
- this._nodeDownloadProgressmeter
- );
- ]]></body>
- </method>
-
- <method name="_stepPreinstall">
- <parameter name="items"/>
- <body><![CDATA[
- var index = {};
- this.deleted = [];
- for each (let item in items) {
- if (item.status === this._Cr.NS_OK) {
- let component = item.component;
- try {
- let directory = item.file.clone();
- directory.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
- this._application.core.Lib.sysutils.extractZipArchive(item.file, directory);
- item.file.remove(true);
- component.file = directory;
- component.checked = false;
- component.pkg = new this._application.core.Lib.XB.WidgetPackage(directory, component.manifest.packageID);
- } catch (e) {
- try {
- directory.remove(true);
- }
- catch(e) {
- }
-
- this._clean();
-
- this._logger.error("Failed creating package object. " +
- this._application.core.Lib.misc.formatError(e));
- this._error(e);
- return;
- }
-
- let damage = false;
- for each (let widget in component.widgets) {
- let available = !!component.pkg.findFile(widget.unit.name + ".xml");
- widget.available = available;
- if (!available)
- damage = true;
- }
- if (damage) {
- component.type = "package-remove";
- this.deleted.push(component);
- }
- }
- else {
- this.flags.downloadError = true;
- }
- }
-
- this.queue.clean();
-
- if (this.flags.downloadError) {
- this._error("error.situation.network", {"accept": "_stepConflict();"});
- return;
- }
-
- this._stepConflict();
- ]]></body>
- </method>
-
- <method name="_stepConflict">
- <body><![CDATA[
- if (this.deleted.length == 0) {
- return this._stepConflictResolved();
- }
- else {
- this.step("conflict");
- this._nodeConflictDeleted.items = this.deleted;
- }
- ]]></body>
- </method>
-
- <method name="_stepConflictResolved">
- <body><![CDATA[
- this._filterComponent(this.packages, function(component) {
- component.type = "package";
- return !component.checked;
- });
-
- this._stepCreateWidgets();
- ]]></body>
- </method>
-
- <method name="_stepCreateWidgets">
- <body><![CDATA[
- this.widgets = [];
-
- var ids = {};
- try {
- for each (let preset in this.presets) {
- for each (let info in preset.widgetsInfo) {
- let id = info.protoID;
- if (id in ids)
- continue;
- ids[id] = 1;
-
- if (this.mode == "install" || !this._widgetLibrary.isKnownWidget(id)) {
- let prototype = this._getWidgetPrototypeById(id);
- if (prototype)
- this.widgets.push({
- type: "widget",
- checked: true,
- info: info,
- widget: prototype
- });
- else
- this.flags.widgetError = true;
- }
- }
- }
- }
- catch (e) {
- this._logger.error("Failed creating widget object. " + this._application.core.Lib.misc.formatError(e));
- this._error(e);
- return;
- }
-
- this._stepCheckErrors();
- ]]></body>
- </method>
-
- <!-- <method name="_stepCheckErrors"/> pure virtual -->
-
- <!-- <method name="_stepPlacement"/> pure virtual -->
-
- <method name="_stepApply">
- <body><![CDATA[
- if (this._stepInstall())
- this.dialog.close();
- ]]></body>
- </method>
-
- <method name="_stepInstall">
- <body><![CDATA[
- var packageIDs = [];
- var lostWidgetIds = [];
- for each (let package_ in this.packages) {
- packageIDs.push(package_.info.id);
-
- for each (let widget in package_.widgets)
- if (!widget.available)
- lostWidgetIds.push(widget.id);
- }
-
- var newKnownWidgetIds = [];
- var widgetInfos = [];
- for each (let widget in this.widgets) {
- newKnownWidgetIds.push(widget.info.protoID);
- if (widget.checked)
- widgetInfos.push(widget.info);
- }
-
- for each (let id in packageIDs)
- this._application.switchWidgets(id, false);
-
- try {
- this._widgetLibrary.forgetWidgets(lostWidgetIds);
-
- for each (let component in this.packages) {
- this._packageManager.installPackage(component.file.clone(), component.info);
- }
-
- this._widgetLibrary.acquaintWithWidgets(newKnownWidgetIds);
- this._application.forEachWindow(
- function(controller) {
- controller.updatePalette(packageIDs);
- controller.deleteObsoleteWidgetItems();
- }
- );
- }
- catch (e) {
- this._logger.error("Failed installing components. " + this._application.core.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- this._error(e);
- return false;
- }
- finally {
- for each (let id in packageIDs)
- this._application.switchWidgets(id, true);
- }
-
- try {
- var placement = this._nodePlacementPlacement.mode;
- this._application.forEachWindow(
- function(controller) {
- controller.setWidgets(widgetInfos, placement);
- }
- );
- }
- catch(e) {
- this._logger.error("Failed placing widgets. " + this._application.core.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- }
-
- for each (let preset in this.presets)
- this._savePreset(preset);
-
- return true;
- ]]></body>
- </method>
-
- <method name="_savePreset">
- <parameter name="preset"/>
- <body><![CDATA[
- try {
- var name = encodeURIComponent(preset.address);
- var file = this._application.directories.XBPresets;
- file.append(name);
- this._application.core.Lib.sysutils.writeTextFile(file, preset.content, 0755);
- }
- catch(e) {
- this._logger.error("Failed saving preset. " + this._application.core.Lib.misc.formatError(e));
- this._logger.debug(e.stack);
- }
- ]]></body>
- </method>
-
- <method name="step">
- <parameter name="name"/>
- <body><![CDATA[
- var nodes = document.getAnonymousNodes(this);
- for each (let node in nodes)
- if (node.nodeType == this.ELEMENT_NODE)
- node.style.display = ((node.getAttribute("step") == name) ? "-moz-box" : "none");
-
- this.dialog.sizeToContent();
- ]]></body>
- </method>
-
- <method name="_error">
- <parameter name="exception"/>
- <parameter name="buttons"/>
- <body><![CDATA[
- var bundle = new this._misc.StringBundle("errors.properties"),
- description = "";
-
- if (typeof exception == "string") {
- description = bundle.get(exception);
- exception = null;
- }
- if (exception)
- if (exception instanceof this._errors.EDownload)
- description = bundle.get("error.situation.network");
- else
- description = bundle.get("error.situation.install.generic");
-
- this._nodeErrorHead.description = description;
-
- this._nodeErrorMore.style.display = !!exception ? "" : "none";
- if (exception)
- this._nodeErrorDetails.textContent = this._application.core.Lib.misc.formatError(exception);
-
- buttons = buttons || {"close": "dialog.close();"};
- var node = this._nodeErrorButtons.firstChild;
- while(node) {
- if (node.nodeType == this.ELEMENT_NODE) {
- let action = node.getAttribute("action");
- if (action in buttons)
- node.removeAttribute("hidden");
- else
- node.setAttribute("hidden", true);
- let oncommand = buttons[action] || null;
- // Firefox can cache a oncommand property value, related @oncommand attribute. Supress this.
- node.removeAttribute("oncommand");
- if (oncommand)
- node.setAttribute("oncommand", oncommand);
- }
- node = node.nextSibling;
- }
-
- this.step("error");
- ]]></body>
- </method>
-
- <method name="_clean">
- <body><![CDATA[
- for each (let component in this.components)
- this._cleanComponent(component);
-
- if (this.queue)
- this.queue.clean();
- ]]></body>
- </method>
-
- <method name="_cleanComponent">
- <parameter name="component"/>
- <body><![CDATA[
- try {
- if (component.file)
- this._misc.removeFileSafe(component.file);
- } catch(e) {}
- try {
- if (component.pkg)
- component.pkg.finalize();
- } catch(e) {}
- ]]></body>
- </method>
-
- <method name="_filterComponent">
- <parameter name="components"/>
- <parameter name="check"/>
- <body><![CDATA[
- for(let i = components.length; i--;) {
- if (check(components[i]))
- continue;
- this._cleanComponent(components[i]);
- components.splice(i, 1);
- }
- ]]></body>
- </method>
-
- <method name="_compare">
- <parameter name="a"/>
- <parameter name="b"/>
- <body><![CDATA[
- return this._comparator.compare(a, b);
- ]]></body>
- </method>
-
-
- <method name="_knownWidgetsInPackage">
- <parameter name="packageId"/>
- <body><![CDATA[
- var prototypes = [];
- for each (let id in this._widgetLibrary.getWidgetProtoIDs()) {
- let [widgetPackageID, ] = this._widgetLibrary.parseWidgetProtoID(id);
- if (widgetPackageID == packageId)
- prototypes.push(this._widgetLibrary.getWidgetProto(id));
- }
- return prototypes;
- ]]></body>
- </method>
-
- <method name="_getWidgetPrototypeById">
- <parameter name="id"/>
- <body><![CDATA[
- var [packageId, widgetName] = this._widgetLibrary.parseWidgetProtoID(id);
- var prototype = null;
- for each (let component in this.packages)
- if (component.pkg.id == packageId) {
- if (component.pkg.findFile(widgetName + ".xml"))
- return component.pkg.getUnit(widgetName).widgetProto;
- break;
- }
-
- if (this._widgetLibrary.isKnownWidget(id))
- return this._widgetLibrary.getWidgetProto(id);
-
- try {
- let pkg = null;
- if (pkg = this._packageManager.getPackage(packageId))
- return pkg.getUnit(widgetName).widgetProto;
- } catch (e) {
- }
- return null;
- ]]></body>
- </method>
-
- </implementation>
- </binding>
- </bindings>
-