| | 445 | export: function T_export() { |
|---|
| | 446 | try { |
|---|
| | 447 | if (!this._export()) { |
|---|
| | 448 | throw new Exception("Cannot export"); |
|---|
| | 449 | } |
|---|
| | 450 | } |
|---|
| | 451 | catch (ex) { |
|---|
| | 452 | Debug.log("Cannot export downloads", ex); |
|---|
| | 453 | DTA_alert(_('exporttitle'), _('exportfailed')); |
|---|
| | 454 | } |
|---|
| | 455 | }, |
|---|
| | 456 | _export: function T_export() { |
|---|
| | 457 | let fp = new FilePicker(window, _('exporttitle'), Ci.nsIFilePicker.modeSave); |
|---|
| | 458 | fp.appendFilters(Ci.nsIFilePicker.filterHTML | Ci.nsIFilePicker.filterText); |
|---|
| | 459 | fp.appendFilter(_('exportfiltermetalink'), '*.metalink'); |
|---|
| | 460 | fp.defaultExtension = "metalink"; |
|---|
| | 461 | fp.filterIndex = 2; |
|---|
| | 462 | |
|---|
| | 463 | let rv = fp.show(); |
|---|
| | 464 | if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) { |
|---|
| | 465 | switch (fp.filterIndex) { |
|---|
| | 466 | case 0: return this._exportHTML(fp.file); |
|---|
| | 467 | case 1: return this._exportText(fp.file); |
|---|
| | 468 | case 2: return this._exportMetalink(fp.file); |
|---|
| | 469 | } |
|---|
| | 470 | } |
|---|
| | 471 | return false; |
|---|
| | 472 | }, |
|---|
| | 473 | // i.e. one url per line |
|---|
| | 474 | // exports hash fragments as well. |
|---|
| | 475 | _exportText: function T__exportText(file) { |
|---|
| | 476 | let cs = ConverterOutputStream( |
|---|
| | 477 | new FileOutputStream(file, 0x02 | 0x08 | 0x20, Prefs.permissions, 0), |
|---|
| | 478 | null, |
|---|
| | 479 | 0, |
|---|
| | 480 | null |
|---|
| | 481 | ); |
|---|
| | 482 | for (let d in this.selected) { |
|---|
| | 483 | let url = d.urlManager.url; |
|---|
| | 484 | if (d.hash) { |
|---|
| | 485 | url += '#hash(' + d.hash.type + ":" + d.hash.sum + ")"; |
|---|
| | 486 | } |
|---|
| | 487 | url += "\r\n"; |
|---|
| | 488 | cs.writeString(url); |
|---|
| | 489 | } |
|---|
| | 490 | cs.close(); |
|---|
| | 491 | return true; |
|---|
| | 492 | }, |
|---|
| | 493 | _exportMetalink: function T__exportMetalink(file) { |
|---|
| | 494 | let doc = document.implementation.createDocument(NS_METALINKER, 'metalink', null); |
|---|
| | 495 | let root = doc.documentElement; |
|---|
| | 496 | root.setAttribute('type', 'static'); |
|---|
| | 497 | root.setAttribute('version', '3.0'); |
|---|
| | 498 | root.setAttribute('generator', 'DownThemAll! ' + DTA_VERSION + ' <http://downthemall.net/>'); |
|---|
| | 499 | root.setAttributeNS(NS_DTA, 'version', DTA_VERSION); |
|---|
| | 500 | root.setAttribute('pubdate', new Date().toUTCString()); |
|---|
| | 501 | |
|---|
| | 502 | root.appendChild(doc.createComment("metalink as exported by DownThemAll!\r\nmay contain DownThemAll! specific information in the DownThemAll! namespace: " + NS_DTA)); |
|---|
| | 503 | |
|---|
| | 504 | let files = doc.createElement('files'); |
|---|
| | 505 | for (let d in this.selected) { |
|---|
| | 506 | let f = doc.createElement('file'); |
|---|
| | 507 | f.setAttribute('name', d.fileName); |
|---|
| | 508 | f.setAttributeNS(NS_DTA, 'num', d.numIstance); |
|---|
| | 509 | f.setAttributeNS(NS_DTA, 'startDate', d.startDate.getTime()); |
|---|
| | 510 | if (d.referrer) { |
|---|
| | 511 | f.setAttributeNS(NS_DTA, 'referrer', d.referrer.spec); |
|---|
| | 512 | } |
|---|
| | 513 | |
|---|
| | 514 | if (d.description) { |
|---|
| | 515 | let n = doc.createElement('description'); |
|---|
| | 516 | n.textContent = d.description; |
|---|
| | 517 | f.appendChild(n); |
|---|
| | 518 | } |
|---|
| | 519 | let r = doc.createElement('resources'); |
|---|
| | 520 | for (let u in d.urlManager.all) { |
|---|
| | 521 | let n = doc.createElement('url'); |
|---|
| | 522 | let t = u.url.match(/^(\w+):/); |
|---|
| | 523 | n.setAttribute('type', t[1]); |
|---|
| | 524 | n.setAttribute('preference', u.preference); |
|---|
| | 525 | n.setAttributeNS(NS_DTA, 'usable', u.usable); |
|---|
| | 526 | n.setAttributeNS(NS_DTA, 'charset', u.charset); |
|---|
| | 527 | n.textContent = u.url; |
|---|
| | 528 | r.appendChild(n); |
|---|
| | 529 | } |
|---|
| | 530 | if (d.hash) { |
|---|
| | 531 | let v = doc.createElement('verification'); |
|---|
| | 532 | let h = doc.createElement('hash'); |
|---|
| | 533 | h.setAttribute('type', d.hash.type.toLowerCase()); |
|---|
| | 534 | h.textContent = d.hash.sum.toLowerCase(); |
|---|
| | 535 | v.appendChild(h); |
|---|
| | 536 | f.appendChild(v); |
|---|
| | 537 | } |
|---|
| | 538 | f.appendChild(r); |
|---|
| | 539 | files.appendChild(f); |
|---|
| | 540 | } |
|---|
| | 541 | root.appendChild(files); |
|---|
| | 542 | |
|---|
| | 543 | let fs = new FileOutputStream(file, 0x02 | 0x08 | 0x20, Prefs.permissions, 0); |
|---|
| | 544 | let xml = '<?xml version="1.0"?>\r\n'; |
|---|
| | 545 | fs.write(xml, xml.length); |
|---|
| | 546 | new XMLSerializer().serializeToStream(doc, fs, 'utf-8'); |
|---|
| | 547 | fs.close(); |
|---|
| | 548 | |
|---|
| | 549 | return true; |
|---|
| | 550 | }, |
|---|