1
/* You may find the license in the LICENSE file */
3
const METALINK_LOGO = 'chrome://dta/skin/icons/metalink48.png';
5
Cu.import("resource://dta/version.jsm");
8
_insertDownload: function(d) {
10
if (d.lang && d.lang.search(/^\w{2}(?:-\w{2})?$/) != -1) {
11
d.selected = Version.LOCALE.slice(0,2) == d.lang.slice(0,2);
13
let e = document.createElement('richlistitem');
14
e.setAttribute("class", "item");
16
$('downloads').appendChild(e);
19
Debug.log("Failed to add download from metalink", ex);
22
load: function ML_load() {
23
$('cancelbutton').label = _('button-cancel');
26
let downloads = window.arguments[0];
27
if (downloads.length) {
28
downloads.forEach(this._insertDownload, this);
32
Debug.log("Failed to load downloads from Metalink", ex);
36
'identity': _('mlidentity'),
37
'description': _('mldescription'),
43
let oi = window.arguments[1];
45
if (x in oi && oi[x]) {
53
$('identity').value = info.identity;
54
$('desc').appendChild(document.createTextNode(info.description));
55
let logo = new Image();
56
logo.onload = function() {
57
let canvas = $('icon');
59
canvas.width = canvas.clientWidth;
60
canvas.height = canvas.clientHeight;
61
let ctx = canvas.getContext('2d');
63
let w = logo.naturalWidth;
64
let h = logo.naturalHeight;
65
let d = Math.max(canvas.width, w, h);
67
if (d != canvas.width) {
68
ctx.scale(canvas.width / d, canvas.height / d);
71
ctx.drawImage(logo, (d - w) /2, (d - h) / 2);
74
Debug.log("Cannot load logo", ex);
75
logo.src = METALINK_LOGO;
78
logo.onerror = function() {
79
logo.src = METALINK_LOGO;
81
logo.src = info.logo ? info.logo : METALINK_LOGO;
83
let e = $('publisher');
84
e.value = info.publisher[0];
85
e.link = info.publisher[1];
88
$('boxPublisher').hidden = true;
92
e.value = info.license[0];
93
e.link = info.license[1];
96
$('boxLicense').hidden = true;
99
browseDir: function() {
100
// get a new directory
101
let newDir = Utils.askForDir(
102
$('directory').value, // initialize dialog with the current directory
103
_("validdestination")
105
// alright, we got something new, so lets set it.
107
$('directory').value = newDir;
110
download: function ML_download(start) {
111
let [notifications, directory, mask] = $('notifications', 'directory', 'renaming');
112
notifications.removeAllNotifications(true);
115
notifications.appendNotification(msg, 0, null, notifications.PRIORITY_CRITICAL_MEDIUM, null);
118
directory.value = directory.value.trim();
119
mask.value = mask.value.trim();
125
if (!directory.value || !Utils.validateDir(directory.value)) {
126
err(_(directory.value ? 'alertinvaliddir' : 'alertnodir'));
130
let selected = false;
132
document.getElementsByTagName('richlistitem'),
134
n.download.dirSave = directory.value;
135
n.download.mask = mask.value;
136
n.download.selected = n.checked;
137
selected |= n.checked;
145
window.arguments[1].start = start;
149
cancel: function ML_cancel() {
151
document.getElementsByTagName('richlistitem'),
153
n.download.selected = false;
160
openLink: function(e) {
163
select: function(type) {
167
f = function(node) { return true; }
170
f = function(node) { return false; }
173
f = function(node) { return !node.checked; }
178
let nodes = document.getElementsByTagName('richlistitem');
179
for (let i = 0, e = nodes.length, node; i < e; ++i) {
181
node.checked = f(node);
185
addEventListener('load', function() {
186
removeEventListener('load', arguments.callee, false);
191
Debug.log("Failed to load", ex);
194
addEventListener('close', function() {
195
removeEventListener('close', arguments.callee, false);