~ubuntu-branches/debian/stretch/downthemall/stretch

« back to all changes in this revision

Viewing changes to chrome/chrome.jar!/content/dta/manager/metaselect.js

  • Committer: Package Import Robot
  • Author(s): Michael Meskes
  • Date: 2016-09-21 13:33:55 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20160921133355-ylst3mzzo82mghyw
Tags: upstream-3.0.6
ImportĀ upstreamĀ versionĀ 3.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* You may find the license in the LICENSE file */
2
 
 
3
 
const METALINK_LOGO = 'chrome://dta/skin/icons/metalink48.png';
4
 
 
5
 
Cu.import("resource://dta/version.jsm");
6
 
 
7
 
const MetaSelect = {
8
 
        _insertDownload: function(d) {
9
 
                try {
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);
12
 
                        }
13
 
                        let e = document.createElement('richlistitem');
14
 
                        e.setAttribute("class", "item");
15
 
                        e.download = d;
16
 
                        $('downloads').appendChild(e);
17
 
                }
18
 
                catch (ex) {
19
 
                        Debug.log("Failed to add download from metalink", ex);
20
 
                }
21
 
        },
22
 
        load: function ML_load() {
23
 
                $('cancelbutton').label = _('button-cancel');
24
 
                
25
 
                try {
26
 
                        let downloads = window.arguments[0];
27
 
                        if (downloads.length) {
28
 
                                downloads.forEach(this._insertDownload, this);
29
 
                        }
30
 
                }
31
 
                catch(ex) {
32
 
                        Debug.log("Failed to load downloads from Metalink", ex);
33
 
                        // no-op
34
 
                }
35
 
                let info = {
36
 
                        'identity': _('mlidentity'),
37
 
                        'description': _('mldescription'),
38
 
                        'logo': null,
39
 
                        'publisher': null,
40
 
                        'license': null
41
 
                }
42
 
                try {
43
 
                        let oi = window.arguments[1];
44
 
                        for (x in info) {
45
 
                                if (x in oi && oi[x]) {
46
 
                                        info[x] = oi[x];
47
 
                                }
48
 
                        }
49
 
                }
50
 
                catch (ex) {
51
 
                        // no-op
52
 
                }
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');
58
 
                        try {
59
 
                                canvas.width = canvas.clientWidth;
60
 
                                canvas.height = canvas.clientHeight;
61
 
                                let ctx = canvas.getContext('2d');
62
 
                                
63
 
                                let w = logo.naturalWidth;
64
 
                                let h = logo.naturalHeight;
65
 
                                let d = Math.max(canvas.width, w, h);
66
 
                                
67
 
                                if (d != canvas.width) {
68
 
                                        ctx.scale(canvas.width / d, canvas.height / d);
69
 
                                }
70
 
                                
71
 
                                ctx.drawImage(logo, (d - w) /2, (d - h) / 2);                                                           
72
 
                        }
73
 
                        catch (ex) {
74
 
                                Debug.log("Cannot load logo", ex);
75
 
                                logo.src = METALINK_LOGO;
76
 
                        }
77
 
                };
78
 
                logo.onerror = function() {
79
 
                        logo.src = METALINK_LOGO;
80
 
                };
81
 
                logo.src = info.logo ? info.logo : METALINK_LOGO;
82
 
                if (info.publisher) {
83
 
                        let e = $('publisher');
84
 
                        e.value = info.publisher[0];
85
 
                        e.link = info.publisher[1];                     
86
 
                }
87
 
                else {
88
 
                        $('boxPublisher').hidden = true;
89
 
                }
90
 
                if (info.license) {
91
 
                        let e = $('license');
92
 
                        e.value = info.license[0];
93
 
                        e.link = info.license[1];                       
94
 
                }
95
 
                else {
96
 
                        $('boxLicense').hidden = true;
97
 
                }               
98
 
        },
99
 
        browseDir: function() {
100
 
                // get a new directory
101
 
                let newDir = Utils.askForDir(
102
 
                        $('directory').value, // initialize dialog with the current directory
103
 
                        _("validdestination")
104
 
                );
105
 
                // alright, we got something new, so lets set it.
106
 
                if (newDir) {
107
 
                        $('directory').value = newDir;
108
 
                }
109
 
        },      
110
 
        download: function ML_download(start) {
111
 
                let [notifications, directory, mask] = $('notifications', 'directory', 'renaming');
112
 
                notifications.removeAllNotifications(true);
113
 
                
114
 
                function err(msg) {
115
 
                        notifications.appendNotification(msg, 0, null, notifications.PRIORITY_CRITICAL_MEDIUM, null);
116
 
                }
117
 
                
118
 
                directory.value = directory.value.trim();
119
 
                mask.value = mask.value.trim();
120
 
                
121
 
                if (!mask.value) {
122
 
                        err(_('alertmask'));
123
 
                        return false;
124
 
                }
125
 
                if (!directory.value || !Utils.validateDir(directory.value)) {
126
 
                        err(_(directory.value ? 'alertinvaliddir' : 'alertnodir'));
127
 
                        return false;
128
 
                }
129
 
                
130
 
                let selected = false;
131
 
                Array.forEach(
132
 
                        document.getElementsByTagName('richlistitem'),
133
 
                        function(n) {
134
 
                                n.download.dirSave = directory.value;
135
 
                                n.download.mask = mask.value;           
136
 
                                n.download.selected = n.checked;
137
 
                                selected |= n.checked;
138
 
                        },
139
 
                        this
140
 
                );
141
 
                if (!selected) {
142
 
                        err(_('nolinks'));
143
 
                        return false;
144
 
                }
145
 
                window.arguments[1].start = start;
146
 
                self.close();
147
 
                return true;
148
 
        },
149
 
        cancel: function ML_cancel() {
150
 
                Array.forEach(
151
 
                        document.getElementsByTagName('richlistitem'),
152
 
                        function(n) {
153
 
                                n.download.selected = false;
154
 
                        },
155
 
                        this
156
 
                );
157
 
                self.close();
158
 
                return true;
159
 
        },
160
 
        openLink: function(e) {
161
 
                openUrl(e.link);
162
 
        },
163
 
        select: function(type) {
164
 
                let f;
165
 
                switch (type) {
166
 
                case 'all':
167
 
                        f = function(node) { return true; }
168
 
                break;
169
 
                case 'none':
170
 
                        f = function(node) { return false; }
171
 
                break;
172
 
                case 'invert':
173
 
                        f = function(node) { return !node.checked; }
174
 
                break;
175
 
                default:
176
 
                return;
177
 
                }
178
 
                let nodes = document.getElementsByTagName('richlistitem');
179
 
                for (let i = 0, e = nodes.length, node; i < e; ++i) {
180
 
                        node = nodes[i];
181
 
                        node.checked = f(node);
182
 
                }
183
 
        }
184
 
};
185
 
addEventListener('load', function() {
186
 
        removeEventListener('load', arguments.callee, false);
187
 
        try {
188
 
                MetaSelect.load();
189
 
        }
190
 
        catch (ex) {
191
 
                Debug.log("Failed to load", ex);
192
 
        }
193
 
}, false);
194
 
addEventListener('close', function() {
195
 
        removeEventListener('close', arguments.callee, false);
196
 
        MetaSelect.cancel();
197
 
}, false);