~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to deluge/ui/webui/templates/ajax/static/js/deluge-details.js

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Script: deluge-details.js
3
 
    Contains the tabs for the torrent details.
4
 
 
5
 
 *
6
 
 * Copyright (C) Damien Churchill 2008 <damoxc@gmail.com>
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 3, or (at your option)
11
 
 * any later version.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program.  If not, write to:
20
 
 *     The Free Software Foundation, Inc.,
21
 
 *     51 Franklin Street, Fifth Floor
22
 
 *     Boston, MA  02110-1301, USA.
23
 
#
24
 
#    In addition, as a special exception, the copyright holders give
25
 
#    permission to link the code of portions of this program with the OpenSSL
26
 
#    library.
27
 
#    You must obey the GNU General Public License in all respects for all of
28
 
#    the code used other than OpenSSL. If you modify file(s) with this
29
 
#    exception, you may extend this exception to your version of the file(s),
30
 
#    but you are not obligated to do so. If you do not wish to do so, delete
31
 
#    this exception statement from your version. If you delete this exception
32
 
#    statement from all source files in the program, then also delete it here.
33
 
#
34
 
 
35
 
 *
36
 
*/
37
 
 
38
 
Deluge.Widgets.Details = new Class({
39
 
    Extends: Widgets.Tabs,
40
 
 
41
 
    initialize: function() {
42
 
        this.parent($$('#details .mooui-tabs')[0]);
43
 
 
44
 
        this.statistics = new Deluge.Widgets.StatisticsPage();
45
 
        this.details = new Deluge.Widgets.DetailsPage();
46
 
        this.files = new Deluge.Widgets.FilesPage();
47
 
        this.peers = new Deluge.Widgets.PeersPage();
48
 
        this.options = new Deluge.Widgets.OptionsPage();
49
 
 
50
 
        this.addPage(this.statistics);
51
 
        this.addPage(this.details);
52
 
        this.addPage(this.files);
53
 
        this.addPage(this.peers);
54
 
        this.addPage(this.options);
55
 
        this.addEvent('pageChanged', function(e) {
56
 
            this.update(this.torrentId);
57
 
        }.bindWithEvent(this));
58
 
        this.addEvent('resize', this.resized.bindWithEvent(this));
59
 
 
60
 
        this.files.addEvent('menuAction', function(e) {
61
 
            files = [];
62
 
            this.files.grid.getSelected().each(function(file) {
63
 
                files.push(file.fileIndex);
64
 
            });
65
 
            e.files = files;
66
 
            this.fireEvent('filesAction', e);
67
 
        }.bindWithEvent(this));
68
 
    },
69
 
 
70
 
    keys: {
71
 
        0: Deluge.Keys.Statistics,
72
 
        1: Deluge.Keys.Details,
73
 
        2: Deluge.Keys.Files,
74
 
        3: Deluge.Keys.Peers,
75
 
        4: Deluge.Keys.Options
76
 
    },
77
 
 
78
 
    clear: function() {
79
 
        this.pages.each(function(page) {
80
 
            page.element.getChildren().each(function(el) {
81
 
                el.set('opacity', 0.5);
82
 
            });
83
 
            if (page.clear) page.clear();
84
 
        });
85
 
    },
86
 
 
87
 
    update: function(torrentId) {
88
 
        this.torrentId = torrentId;
89
 
        if (!this.torrentId) {
90
 
            this.clear();
91
 
            return;
92
 
        };
93
 
        var keys = this.keys[this.currentPage], page = this.pages[this.currentPage];
94
 
        Deluge.Client.get_torrent_status(torrentId, keys, {
95
 
            onSuccess: function(torrent) {
96
 
                torrent.id = torrentId;
97
 
                if (page.update) page.update(torrent);
98
 
                page.element.getChildren().each(function(el) {
99
 
                    el.set('opacity', 1);
100
 
                });
101
 
            }.bindWithEvent(this)
102
 
        });
103
 
    },
104
 
 
105
 
    resized: function(event) {
106
 
        this.pages.each(function(page) {
107
 
            page.getSizeModifiers();
108
 
            page.sets({
109
 
                width: event.width - page.element.modifiers.x,
110
 
                height: event.height - page.element.modifiers.y - 28
111
 
            });
112
 
        });
113
 
    }
114
 
});
115
 
 
116
 
Deluge.Widgets.StatisticsPage = new Class({
117
 
    Extends: Widgets.TabPage,
118
 
 
119
 
    options: {
120
 
        url: '/template/render/html/tab_statistics.html'
121
 
    },
122
 
 
123
 
    initialize: function() {
124
 
        this.parent(_('Statistics'));
125
 
        this.addEvent('loaded', this.onLoad.bindWithEvent(this));
126
 
    },
127
 
 
128
 
    onLoad: function(e) {
129
 
        this.element.id = 'statistics';
130
 
        this.bar = new Widgets.ProgressBar();
131
 
        this.bar.element.inject(this.element, 'top');
132
 
        this.bar.set('width', this.getWidth() - 12);
133
 
        this.bar.update('', 0);
134
 
        this.addEvent('resize', this.onResize.bindWithEvent(this));
135
 
    },
136
 
 
137
 
    onResize: function(e) {
138
 
        if (!$defined(this.bar)) return;
139
 
        this.bar.set('width', this.getWidth() - 12);
140
 
    },
141
 
 
142
 
    clear: function() {
143
 
        if (this.bar) this.bar.update('', 0);
144
 
        this.element.getElements('dd').each(function(item) {
145
 
            item.set('text', '');
146
 
        }, this);
147
 
    },
148
 
 
149
 
    update: function(torrent) {
150
 
        var data = {
151
 
            downloaded: torrent.total_done.toBytes()+' ('+torrent.total_payload_download.toBytes()+')',
152
 
            uploaded: torrent.total_uploaded.toBytes()+' ('+torrent.total_payload_upload.toBytes()+')',
153
 
            share: torrent.ratio.toFixed(3),
154
 
            announce: torrent.next_announce.toTime(),
155
 
            tracker_status: torrent.tracker_status,
156
 
            downspeed: torrent.download_payload_rate.toSpeed(),
157
 
            upspeed: torrent.upload_payload_rate.toSpeed(),
158
 
            eta: torrent.eta.toTime(),
159
 
            pieces: torrent.num_pieces + ' (' + torrent.piece_length.toBytes() + ')',
160
 
            seeders: torrent.num_seeds + ' (' + torrent.total_seeds + ')',
161
 
            peers: torrent.num_peers + ' (' + torrent.total_peers + ')',
162
 
            avail: torrent.distributed_copies.toFixed(3),
163
 
            active_time: torrent.active_time.toTime(),
164
 
            seeding_time: torrent.seeding_time.toTime(),
165
 
            seed_rank: torrent.seed_rank
166
 
        }
167
 
        var text = torrent.state + ' ' + torrent.progress.toFixed(2) + '%';
168
 
        this.bar.update(text, torrent.progress);
169
 
 
170
 
        if (torrent.is_auto_managed) {data.auto_managed = 'True'}
171
 
        else {data.auto_managed = 'False'};
172
 
 
173
 
        this.element.getElements('dd').each(function(item) {
174
 
            item.set('text', data[item.getProperty('class')]);
175
 
        }, this);
176
 
    }
177
 
});
178
 
 
179
 
Deluge.Widgets.DetailsPage = new Class({
180
 
    Extends: Widgets.TabPage,
181
 
 
182
 
    options: {
183
 
        url: '/template/render/html/tab_details.html'
184
 
    },
185
 
 
186
 
    initialize: function() {
187
 
        this.parent(_('Details'));
188
 
    },
189
 
 
190
 
    clear: function() {
191
 
        this.element.getElements('dd').each(function(item) {
192
 
            item.set('text', '');
193
 
        }, this);
194
 
    },
195
 
 
196
 
    update: function(torrent) {
197
 
        var data = {
198
 
            torrent_name: torrent.name,
199
 
            hash: torrent.id,
200
 
            path: torrent.save_path,
201
 
            size: torrent.total_size.toBytes(),
202
 
            files: torrent.num_files,
203
 
            status: torrent.tracker_status,
204
 
            tracker: torrent.tracker
205
 
        };
206
 
        this.element.getElements('dd').each(function(item) {
207
 
            item.set('text', data[item.getProperty('class')])
208
 
        }, this);
209
 
    }
210
 
});
211
 
 
212
 
Deluge.Widgets.FilesGrid = new Class({
213
 
    Extends: Widgets.DataGrid,
214
 
 
215
 
    options: {
216
 
        columns: [
217
 
            {name: 'filename',text: 'Filename',type:'text',width: 350},
218
 
            {name: 'size',text: 'Size',type:'bytes',width: 80},
219
 
            {name: 'progress',text: 'Progress',type:'progress',width: 180},
220
 
            {name: 'priority',text: 'Priority',type:'icon',width: 150}
221
 
        ]
222
 
    },
223
 
 
224
 
    priority_texts: {
225
 
        0: 'Do Not Download',
226
 
        1: 'Normal Priority',
227
 
        2: 'High Priority',
228
 
        5: 'Highest Priority'
229
 
    },
230
 
 
231
 
    priority_icons: {
232
 
        0: '/static/images/16/process-stop.png',
233
 
        1: '/template/static/icons/16/gtk-yes.png',
234
 
        2: '/static/images/16/queue-down.png',
235
 
        5: '/static/images/16/go-bottom.png'
236
 
    },
237
 
 
238
 
    initialize: function(element, options) {
239
 
        this.parent(element, options);
240
 
        var menu = new Widgets.PopupMenu();
241
 
        $A([0,1,2,5]).each(function(index) {
242
 
            menu.add({
243
 
                type:'text',
244
 
                action: index,
245
 
                text: this.priority_texts[index],
246
 
                icon: this.priority_icons[index]
247
 
            });
248
 
        }, this);
249
 
 
250
 
        menu.addEvent('action', function(e) {
251
 
            e = {
252
 
                action: e.action,
253
 
                torrentId: menu.row.torrentId
254
 
            };
255
 
            this.fireEvent('menuAction', e);
256
 
        }.bind(this));
257
 
 
258
 
        this.addEvent('rowMenu', function(e) {
259
 
            e.stop();
260
 
            menu.row = e.row;
261
 
            menu.show(e);
262
 
        })
263
 
    },
264
 
 
265
 
    clear: function() {
266
 
        this.rows.empty();
267
 
        this.body.empty();
268
 
        this.render();
269
 
    },
270
 
 
271
 
    updateFiles: function(torrent) {
272
 
        torrent.files.each(function(file) {
273
 
            var p = torrent.file_priorities[file.index];
274
 
            var priority = {
275
 
                text:this.priority_texts[p],
276
 
                icon:this.priority_icons[p]
277
 
            };
278
 
 
279
 
            var percent = torrent.file_progress[file.index]*100.0;
280
 
            row = {
281
 
                id: torrent.id + '-' + file.index,
282
 
                data: {
283
 
                    filename: file.path,
284
 
                    size: file.size,
285
 
                    progress: {percent: percent, text: percent.toFixed(2) + '%'},
286
 
                    priority: priority
287
 
                },
288
 
                fileIndex: file.index,
289
 
                torrentId: torrent.id
290
 
 
291
 
            };
292
 
            if (this.has(row.id)) {
293
 
                this.updateRow(row, true);
294
 
            } else {
295
 
                this.addRow(row, true);
296
 
            };
297
 
        }, this);
298
 
        this.render();
299
 
    }
300
 
});
301
 
 
302
 
Deluge.Widgets.FilesPage = new Class({
303
 
    Extends: Widgets.TabPage,
304
 
 
305
 
    options: {
306
 
        url: '/template/render/html/tab_files.html'
307
 
    },
308
 
 
309
 
    initialize: function(el) {
310
 
        this.parent(_('Files'));
311
 
        this.torrentId = -1;
312
 
        this.addEvent('loaded', this.loaded.bindWithEvent(this));
313
 
        this.addEvent('resize', this.resized.bindWithEvent(this));
314
 
    },
315
 
 
316
 
    loaded: function(event) {
317
 
        this.grid = new Deluge.Widgets.FilesGrid('files');
318
 
        this.grid.addEvent('menuAction', this.menuAction.bindWithEvent(this));
319
 
 
320
 
        if (this.beenResized) {
321
 
            this.resized(this.beenResized);
322
 
            delete this.beenResized;
323
 
        };
324
 
    },
325
 
 
326
 
    clear: function() {
327
 
        if (this.grid) this.grid.clear();
328
 
    },
329
 
 
330
 
    resized: function(e) {
331
 
        if (!this.grid) {
332
 
            this.beenResized = e;
333
 
            return;
334
 
        };
335
 
 
336
 
        this.element.getPadding();
337
 
        this.grid.sets({
338
 
            width: e.width - this.element.padding.x,
339
 
            height: e.height - this.element.padding.y
340
 
        });
341
 
    },
342
 
 
343
 
    menuAction: function(e) {
344
 
        this.fireEvent('menuAction', e);
345
 
    },
346
 
 
347
 
    update: function(torrent) {
348
 
        if (this.torrentId != torrent.id) {
349
 
            this.torrentId = torrent.id;
350
 
            this.grid.rows.empty();
351
 
            this.grid.body.empty();
352
 
        }
353
 
        this.grid.updateFiles(torrent);
354
 
    }
355
 
});
356
 
 
357
 
Deluge.Widgets.PeersPage = new Class({
358
 
    Extends: Widgets.TabPage,
359
 
 
360
 
    options: {
361
 
        url: '/template/render/html/tab_peers.html'
362
 
    },
363
 
 
364
 
    initialize: function(el) {
365
 
        this.parent(_('Peers'));
366
 
        this.addEvent('resize', this.resized.bindWithEvent(this));
367
 
        this.addEvent('loaded', this.loaded.bindWithEvent(this));
368
 
    },
369
 
 
370
 
    loaded: function(event) {
371
 
        this.grid = new Widgets.DataGrid($('peers'), {
372
 
            columns: [
373
 
                {name: 'country',type:'image',width: 20},
374
 
                {name: 'address',text: 'Address',type:'text',width: 80},
375
 
                {name: 'client',text: 'Client',type:'text',width: 180},
376
 
                {name: 'downspeed',text: 'Down Speed',type:'speed',width: 100},
377
 
                {name: 'upspeed',text: 'Up Speed',type:'speed',width: 100},
378
 
            ]});
379
 
        this.torrentId = -1;
380
 
        if (this.been_resized) {
381
 
            this.resized(this.been_resized);
382
 
            delete this.been_resized;
383
 
        };
384
 
    },
385
 
 
386
 
    resized: function(e) {
387
 
        if (!this.grid) {
388
 
            this.been_resized = e;
389
 
            return;
390
 
        };
391
 
 
392
 
        this.element.getPadding();
393
 
        this.grid.sets({
394
 
            width: e.width - this.element.padding.x,
395
 
            height: e.height - this.element.padding.y
396
 
        });
397
 
    },
398
 
 
399
 
    clear: function() {
400
 
        if (!this.grid) return;
401
 
        this.grid.rows.empty();
402
 
        this.grid.body.empty();
403
 
    },
404
 
 
405
 
    update: function(torrent) {
406
 
        if (this.torrentId != torrent.id) {
407
 
            this.torrentId = torrent.id;
408
 
            this.grid.rows.empty();
409
 
            this.grid.body.empty();
410
 
        }
411
 
        var peers = [];
412
 
        torrent.peers.each(function(peer) {
413
 
            if (peer.country.strip() != '') {
414
 
                peer.country = '/pixmaps/flags/' + peer.country.toLowerCase() + '.png'
415
 
            } else {
416
 
                peer.country = '/templates/static/images/spacer.gif'
417
 
            };
418
 
            row = {
419
 
                id: peer.ip,
420
 
                data: {
421
 
                    country: peer.country,
422
 
                    address: peer.ip,
423
 
                    client: peer.client,
424
 
                    downspeed: peer.down_speed,
425
 
                    upspeed: peer.up_speed
426
 
                    }
427
 
                }
428
 
            if (this.grid.has(row.id)) {
429
 
                this.grid.updateRow(row, true);
430
 
            } else {
431
 
                this.grid.addRow(row, true);
432
 
            }
433
 
            peers.include(peer.ip);
434
 
        }, this);
435
 
 
436
 
        this.grid.rows.each(function(row) {
437
 
            if (!peers.contains(row.id)) {
438
 
                row.element.destroy();
439
 
                this.grid.rows.erase(row);
440
 
            };
441
 
        }, this);
442
 
        this.grid.render();
443
 
    }
444
 
});
445
 
 
446
 
Deluge.Widgets.OptionsPage = new Class({
447
 
    Extends: Widgets.TabPage,
448
 
 
449
 
    options: {
450
 
        url: '/template/render/html/tab_options.html'
451
 
    },
452
 
 
453
 
    initialize: function() {
454
 
        if (!this.element)
455
 
            this.parent(_('Options'));
456
 
        this.addEvent('loaded', function(event) {
457
 
            this.loaded(event);
458
 
        }.bindWithEvent(this));
459
 
    },
460
 
 
461
 
    loaded: function(event) {
462
 
        this.bound = {
463
 
            apply: this.apply.bindWithEvent(this),
464
 
            reset: this.reset.bindWithEvent(this)
465
 
        };
466
 
        this.form = this.element.getElement('form');
467
 
        this.changed = new Hash();
468
 
        this.form.getElements('input').each(function(el) {
469
 
            if (el.type == 'button') return;
470
 
            el.focused = false;
471
 
            el.addEvent('change', function(e) {
472
 
                if (!this.changed[this.torrentId])
473
 
                    this.changed[this.torrentId] = {};
474
 
                if (el.type == 'checkbox')
475
 
                    this.changed[this.torrentId][el.name] = el.checked;
476
 
                else
477
 
                    this.changed[this.torrentId][el.name] = el.value;
478
 
            }.bindWithEvent(this));
479
 
            el.addEvent('focus', function(e) {
480
 
                el.focused = true;
481
 
            });
482
 
            el.addEvent('blur', function(e) {
483
 
                el.focused = false;
484
 
            });
485
 
        }, this);
486
 
 
487
 
        new Widgets.Spinner(this.form.max_download_speed, {
488
 
            step: 10,
489
 
            precision: 1,
490
 
            limit: {
491
 
                high: null,
492
 
                low: -1
493
 
            }
494
 
        });
495
 
        new Widgets.Spinner(this.form.max_upload_speed, {
496
 
            step: 10,
497
 
            precision: 1,
498
 
            limit: {
499
 
                high: null,
500
 
                low: -1
501
 
            }
502
 
        });
503
 
        new Widgets.Spinner(this.form.max_connections, {
504
 
            step: 1,
505
 
            precision: 0,
506
 
            limit: {
507
 
                high: null,
508
 
                low: -1
509
 
            }
510
 
        });
511
 
        new Widgets.Spinner(this.form.max_upload_slots, {
512
 
            step: 1,
513
 
            precision: 0,
514
 
            limit: {
515
 
                high: null,
516
 
                low: -1
517
 
            }
518
 
        });
519
 
        new Widgets.Spinner(this.form.stop_ratio, {
520
 
            step: 1,
521
 
            precision: 1,
522
 
            limit: {
523
 
                high: null,
524
 
                low: -1
525
 
            }
526
 
        });
527
 
 
528
 
        this.form.apply_options.addEvent('click', this.bound.apply);
529
 
        this.form.reset_options.addEvent('click', this.bound.reset);
530
 
    },
531
 
 
532
 
    apply: function(event) {
533
 
        if (!this.torrentId) return;
534
 
        var changed = this.changed[this.torrentId];
535
 
        if ($defined(changed['is_auto_managed'])) {
536
 
            changed['auto_managed'] = changed['is_auto_managed'];
537
 
            delete changed['is_auto_managed'];
538
 
        };
539
 
        Deluge.Client.set_torrent_options(this.torrentId, changed, {
540
 
            onSuccess: function(event) {
541
 
                delete this.changed[this.torrentId];
542
 
            }.bindWithEvent(this)
543
 
        });
544
 
    },
545
 
 
546
 
    clear: function() {
547
 
        if (!this.form) return;
548
 
        $$W(this.form.max_download_speed).setValue(0);
549
 
        $$W(this.form.max_upload_speed).setValue(0);
550
 
        $$W(this.form.max_connections).setValue(0);
551
 
        $$W(this.form.max_upload_slots).setValue(0);
552
 
        $$W(this.form.stop_ratio).setValue(2);
553
 
        this.form.is_auto_managed.checked = false;
554
 
        this.form.stop_at_ratio.checked = false;
555
 
        this.form.remove_at_ratio.checked = false;
556
 
        this.form.private.checked = false;
557
 
        this.form.private.disabled = false;
558
 
        this.form.prioritize_first_last.checked = false;
559
 
    },
560
 
 
561
 
    reset: function(event) {
562
 
        if (this.torrentId) {
563
 
            delete this.changed[this.torrentId];
564
 
        }
565
 
        Deluge.Client.get_torrent_status(this.torrentId, Deluge.Keys.Options, {
566
 
            onSuccess: function(torrent) {
567
 
                torrent.id = this.torrentId;
568
 
                this.update(torrent);
569
 
            }.bindWithEvent(this)
570
 
        });
571
 
    },
572
 
 
573
 
    update: function(torrent) {
574
 
        this.torrentId = torrent.id;
575
 
        $each(torrent, function(value, key) {
576
 
            var changed = this.changed[this.torrentId];
577
 
            if (changed && $defined(changed[key])) return;
578
 
            var type = $type(value);
579
 
            if (type == 'boolean') {
580
 
                this.form[key].checked = value;
581
 
            } else {
582
 
                if (!this.form[key].focused) {
583
 
                    widget = $$W(this.form[key]);
584
 
                    if (widget) {
585
 
                        widget.setValue(value);
586
 
                    } else {
587
 
                        this.form[key].value = value;
588
 
                    };
589
 
                };
590
 
            };
591
 
            if (key == 'private' && value == 0) {
592
 
                this.form[key].disabled = true;
593
 
                this.form[key].getParent().addClass('opt-disabled');
594
 
            };
595
 
        }, this);
596
 
    }
597
 
});