| 2575 | | $('loadingbox').hidden = false; |
|---|
| 2576 | | $('loading').value = _('adding'); |
|---|
| 2577 | | Components.utils.import('resource://dta/cothread.jsm'); |
|---|
| 2578 | | new CoThreadListWalker( |
|---|
| 2579 | | function startDownloads_cothread(e) { |
|---|
| 2580 | | let desc = ""; |
|---|
| 2581 | | DESCS.some( |
|---|
| 2582 | | function(i) { |
|---|
| 2583 | | if (typeof(e[i]) == 'string' && e[i].length) { |
|---|
| 2584 | | desc = e.description; |
|---|
| 2585 | | return true; |
|---|
| 2586 | | } |
|---|
| 2587 | | return false; |
|---|
| 2588 | | } |
|---|
| 2589 | | ); |
|---|
| 2590 | | |
|---|
| 2591 | | let qi = new QueueItem(); |
|---|
| 2592 | | let lnk = e.url; |
|---|
| 2593 | | if (typeof lnk == 'string') { |
|---|
| 2594 | | qi.urlManager = new UrlManager([new DTA_URL(IOService.newURI(lnk, null, null))]); |
|---|
| 2595 | | } |
|---|
| 2596 | | else if (lnk instanceof UrlManager) { |
|---|
| 2597 | | qi.urlManager = lnk; |
|---|
| 2598 | | } |
|---|
| 2599 | | else { |
|---|
| 2600 | | qi.urlManager = new UrlManager([lnk]); |
|---|
| 2601 | | } |
|---|
| 2602 | | qi.numIstance = e.numIstance; |
|---|
| | 2575 | for (let e in g) { |
|---|
| | 2576 | |
|---|
| | 2577 | var desc = ""; |
|---|
| | 2578 | DESCS.some( |
|---|
| | 2579 | function(i) { |
|---|
| | 2580 | if (typeof(e[i]) == 'string' && e[i].length) { |
|---|
| | 2581 | desc = e.description; |
|---|
| | 2582 | return true; |
|---|
| | 2583 | } |
|---|
| | 2584 | return false; |
|---|
| | 2585 | } |
|---|
| | 2586 | ); |
|---|
| 2604 | | if (e.referrer) { |
|---|
| 2605 | | try { |
|---|
| 2606 | | qi.referrer = e.referrer.toURL(); |
|---|
| 2607 | | } |
|---|
| 2608 | | catch (ex) { |
|---|
| 2609 | | // We might have been fed with about:blank or other crap. so ignore. |
|---|
| 2610 | | } |
|---|
| 2611 | | } |
|---|
| 2612 | | // only access the setter of the last so that we don't generate stuff trice. |
|---|
| 2613 | | qi._pathName = e.dirSave.addFinalSlash().toString(); |
|---|
| 2614 | | qi._description = desc ? desc : ''; |
|---|
| 2615 | | qi._mask = e.mask; |
|---|
| 2616 | | qi.fromMetalink = !!e.fromMetalink; |
|---|
| 2617 | | if (e.fileName) { |
|---|
| 2618 | | qi.fileName = e.fileName; |
|---|
| 2619 | | } |
|---|
| 2620 | | else { |
|---|
| 2621 | | qi.fileName = qi.urlManager.usable.getUsableFileName(); |
|---|
| 2622 | | } |
|---|
| 2623 | | if (e.startDate) { |
|---|
| 2624 | | qi.startDate = e.startDate; |
|---|
| 2625 | | } |
|---|
| 2626 | | if (e.url.hash) { |
|---|
| 2627 | | qi.hash = e.url.hash; |
|---|
| 2628 | | } |
|---|
| 2629 | | else if (e.hash) { |
|---|
| 2630 | | qi.hash = e.hash; |
|---|
| 2631 | | } |
|---|
| 2632 | | else { |
|---|
| 2633 | | qi.hash = null; // to initialize prettyHash |
|---|
| 2634 | | } |
|---|
| | 2588 | let qi = new QueueItem(); |
|---|
| | 2589 | let lnk = e.url; |
|---|
| | 2590 | if (typeof lnk == 'string') { |
|---|
| | 2591 | qi.urlManager = new UrlManager([new DTA_URL(IOService.newURI(lnk, null, null))]); |
|---|
| | 2592 | } |
|---|
| | 2593 | else if (lnk instanceof UrlManager) { |
|---|
| | 2594 | qi.urlManager = lnk; |
|---|
| | 2595 | } |
|---|
| | 2596 | else { |
|---|
| | 2597 | qi.urlManager = new UrlManager([lnk]); |
|---|
| | 2598 | } |
|---|
| | 2599 | qi.numIstance = e.numIstance; |
|---|
| 2636 | | let postData = ContentHandling.getPostDataFor(qi.urlManager.url); |
|---|
| 2637 | | if (e.url.postData) { |
|---|
| 2638 | | postData = e.url.postData; |
|---|
| 2639 | | } |
|---|
| 2640 | | if (postData) { |
|---|
| 2641 | | qi.postData = postData; |
|---|
| 2642 | | } |
|---|
| 2643 | | |
|---|
| 2644 | | qi.state = start ? QUEUED : PAUSED; |
|---|
| 2645 | | if (qi.is(QUEUED)) { |
|---|
| 2646 | | qi.status = TEXT_QUEUED; |
|---|
| 2647 | | } |
|---|
| 2648 | | else { |
|---|
| 2649 | | qi.status = TEXT_PAUSED; |
|---|
| 2650 | | } |
|---|
| 2651 | | qi.save(); |
|---|
| 2652 | | Tree.add(qi); |
|---|
| 2653 | | ++added; |
|---|
| 2654 | | |
|---|
| 2655 | | return true; |
|---|
| 2656 | | }, |
|---|
| 2657 | | g, |
|---|
| 2658 | | 100, |
|---|
| 2659 | | this, |
|---|
| 2660 | | function startDownloads_finish() { |
|---|
| 2661 | | SessionManager.endUpdate(); |
|---|
| 2662 | | Tree.endUpdate(); |
|---|
| 2663 | | |
|---|
| 2664 | | $('loadingbox').hidden = true; |
|---|
| 2665 | | |
|---|
| 2666 | | let bo = Tree.box.QueryInterface(Ci.nsITreeBoxObject); |
|---|
| 2667 | | if (added <= bo.getPageLength()) { |
|---|
| 2668 | | bo.scrollToRow(Tree.rowCount - bo.getPageLength()); |
|---|
| 2669 | | } |
|---|
| 2670 | | else { |
|---|
| 2671 | | bo.scrollToRow(numbefore); |
|---|
| 2672 | | } |
|---|
| 2673 | | |
|---|
| 2674 | | Dialog.startNext(); |
|---|
| 2675 | | } |
|---|
| 2676 | | ).run(); |
|---|
| | 2601 | if (e.referrer) { |
|---|
| | 2602 | try { |
|---|
| | 2603 | qi.referrer = e.referrer.toURL(); |
|---|
| | 2604 | } |
|---|
| | 2605 | catch (ex) { |
|---|
| | 2606 | // We might have been fed with about:blank or other crap. so ignore. |
|---|
| | 2607 | } |
|---|
| | 2608 | } |
|---|
| | 2609 | // only access the setter of the last so that we don't generate stuff trice. |
|---|
| | 2610 | qi._pathName = e.dirSave.addFinalSlash().toString(); |
|---|
| | 2611 | qi._description = desc ? desc : ''; |
|---|
| | 2612 | qi._mask = e.mask; |
|---|
| | 2613 | qi.fromMetalink = !!e.fromMetalink; |
|---|
| | 2614 | if (e.fileName) { |
|---|
| | 2615 | qi.fileName = e.fileName; |
|---|
| | 2616 | } |
|---|
| | 2617 | else { |
|---|
| | 2618 | qi.fileName = qi.urlManager.usable.getUsableFileName(); |
|---|
| | 2619 | } |
|---|
| | 2620 | if (e.startDate) { |
|---|
| | 2621 | qi.startDate = e.startDate; |
|---|
| | 2622 | } |
|---|
| | 2623 | if (e.url.hash) { |
|---|
| | 2624 | qi.hash = e.url.hash; |
|---|
| | 2625 | } |
|---|
| | 2626 | else if (e.hash) { |
|---|
| | 2627 | qi.hash = e.hash; |
|---|
| | 2628 | } |
|---|
| | 2629 | else { |
|---|
| | 2630 | qi.hash = null; // to initialize prettyHash |
|---|
| | 2631 | } |
|---|
| | 2632 | |
|---|
| | 2633 | let postData = ContentHandling.getPostDataFor(qi.urlManager.url); |
|---|
| | 2634 | if (e.url.postData) { |
|---|
| | 2635 | postData = e.url.postData; |
|---|
| | 2636 | } |
|---|
| | 2637 | if (postData) { |
|---|
| | 2638 | qi.postData = postData; |
|---|
| | 2639 | } |
|---|
| | 2640 | |
|---|
| | 2641 | qi.state = start ? QUEUED : PAUSED; |
|---|
| | 2642 | if (qi.is(QUEUED)) { |
|---|
| | 2643 | qi.status = TEXT_QUEUED; |
|---|
| | 2644 | } |
|---|
| | 2645 | else { |
|---|
| | 2646 | qi.status = TEXT_PAUSED; |
|---|
| | 2647 | } |
|---|
| | 2648 | qi.save(); |
|---|
| | 2649 | Tree.add(qi); |
|---|
| | 2650 | ++added; |
|---|
| | 2651 | } |
|---|
| | 2652 | SessionManager.endUpdate(); |
|---|
| | 2653 | Tree.endUpdate(); |
|---|
| | 2654 | |
|---|
| | 2655 | var boxobject = Tree._box; |
|---|
| | 2656 | boxobject.QueryInterface(Ci.nsITreeBoxObject); |
|---|
| | 2657 | if (added <= boxobject.getPageLength()) { |
|---|
| | 2658 | boxobject.scrollToRow(Tree.rowCount - boxobject.getPageLength()); |
|---|
| | 2659 | } |
|---|
| | 2660 | else { |
|---|
| | 2661 | boxobject.scrollToRow(numbefore); |
|---|
| | 2662 | } |
|---|