2011-09-14 05:10:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copyright © Mnemosyne LLC
|
|
|
|
|
*
|
|
|
|
|
* This file is licensed under the GPLv2.
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2011-08-16 18:49:26 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
|
function FileRow(torrent, i)
|
2011-08-16 18:49:26 +00:00
|
|
|
|
{
|
2011-09-03 04:33:04 +00:00
|
|
|
|
var fields = {
|
|
|
|
|
have: 0,
|
|
|
|
|
index: 0,
|
|
|
|
|
isDirty: false,
|
|
|
|
|
isWanted: true,
|
|
|
|
|
priority: 0,
|
|
|
|
|
me: this,
|
|
|
|
|
size: 0,
|
|
|
|
|
torrent: null
|
2011-08-16 18:49:26 +00:00
|
|
|
|
},
|
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
elements = {
|
2011-10-21 02:58:19 +00:00
|
|
|
|
priority_low_button: null,
|
|
|
|
|
priority_normal_button: null,
|
|
|
|
|
priority_high_button: null,
|
2011-09-03 04:33:04 +00:00
|
|
|
|
progress: null,
|
|
|
|
|
root: null
|
2011-08-16 18:49:26 +00:00
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
|
|
|
|
|
initialize = function(torrent, i) {
|
|
|
|
|
fields.torrent = torrent;
|
|
|
|
|
fields.index = i;
|
|
|
|
|
createRow(torrent, i);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
},
|
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
readAttributes = function(file) {
|
|
|
|
|
if (fields.have !== file.bytesCompleted) {
|
|
|
|
|
fields.have = file.bytesCompleted;
|
|
|
|
|
fields.isDirty = true;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
}
|
2011-09-03 04:33:04 +00:00
|
|
|
|
if (fields.size !== file.length) {
|
|
|
|
|
fields.size = file.length;
|
|
|
|
|
fields.isDirty = true;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
}
|
2011-09-03 04:33:04 +00:00
|
|
|
|
if (fields.priority !== file.priority) {
|
|
|
|
|
fields.priority = file.priority;
|
|
|
|
|
fields.isDirty = true;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
}
|
2011-09-03 04:33:04 +00:00
|
|
|
|
if (fields.isWanted !== file.wanted) {
|
|
|
|
|
fields.isWanted = file.wanted;
|
|
|
|
|
fields.isDirty = true;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refreshWantedHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
|
{
|
2011-10-21 02:58:19 +00:00
|
|
|
|
var e = $(elements.root);
|
|
|
|
|
e.toggleClass('skip', !fields.isWanted);
|
|
|
|
|
e.toggleClass('complete', isDone());
|
2011-10-26 15:50:31 +00:00
|
|
|
|
$(e[0].checkbox).prop('checked', fields.isWanted);
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refreshPriorityHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
|
{
|
2011-10-21 02:58:19 +00:00
|
|
|
|
$(elements.priority_high_button ).toggleClass('selected', fields.priority === 1 );
|
|
|
|
|
$(elements.priority_normal_button).toggleClass('selected', fields.priority === 0 );
|
|
|
|
|
$(elements.priority_low_button ).toggleClass('selected', fields.priority === -1 );
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refreshProgressHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
|
{
|
2011-09-03 04:33:04 +00:00
|
|
|
|
var pct = 100 * (fields.size ? (fields.have / fields.size) : 1.0),
|
|
|
|
|
c = [ Transmission.fmt.size(fields.have),
|
2011-08-28 13:57:25 +00:00
|
|
|
|
' of ',
|
2011-09-03 04:33:04 +00:00
|
|
|
|
Transmission.fmt.size(fields.size),
|
2011-08-28 13:57:25 +00:00
|
|
|
|
' (',
|
|
|
|
|
Transmission.fmt.percentString(pct),
|
|
|
|
|
'%)' ].join('');
|
2012-07-20 17:37:50 +00:00
|
|
|
|
setTextContent(elements.progress, c);
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refreshHTML = function() {
|
|
|
|
|
if (fields.isDirty) {
|
|
|
|
|
fields.isDirty = false;
|
|
|
|
|
refreshProgressHTML();
|
|
|
|
|
refreshWantedHTML();
|
|
|
|
|
refreshPriorityHTML();
|
2011-08-28 13:57:25 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refresh = function() {
|
|
|
|
|
readAttributes(fields.torrent.getFile(fields.index));
|
|
|
|
|
refreshHTML();
|
2011-08-16 18:49:26 +00:00
|
|
|
|
},
|
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
isDone = function () {
|
|
|
|
|
return fields.have >= fields.size;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
createRow = function(torrent, i) {
|
2011-10-21 02:58:19 +00:00
|
|
|
|
var file = torrent.getFile(i), e, name, root, box;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
|
|
|
|
|
root = document.createElement('li');
|
2011-09-03 04:33:04 +00:00
|
|
|
|
root.id = 't' + fields.torrent.getId() + 'f' + fields.index;
|
2011-10-21 02:58:19 +00:00
|
|
|
|
root.className = 'inspector_torrent_file_list_entry ' + ((i%2)?'odd':'even');
|
|
|
|
|
elements.root = root;
|
|
|
|
|
|
2011-10-26 15:50:31 +00:00
|
|
|
|
e = document.createElement('input');
|
|
|
|
|
e.type = 'checkbox';
|
2011-10-21 02:58:19 +00:00
|
|
|
|
e.className = "file_wanted_control";
|
2011-10-26 15:50:31 +00:00
|
|
|
|
e.title = 'Download file';
|
|
|
|
|
$(e).change(function(ev){ fireWantedChanged( $(ev.currentTarget).prop('checked')); });
|
|
|
|
|
root.checkbox = e;
|
2011-10-21 02:58:19 +00:00
|
|
|
|
root.appendChild(e);
|
|
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.className = 'file-priority-radiobox';
|
|
|
|
|
box = e;
|
|
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.className = 'low';
|
|
|
|
|
e.title = 'Low Priority';
|
|
|
|
|
$(e).click(function(){ firePriorityChanged(-1); });
|
|
|
|
|
elements.priority_low_button = e;
|
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.className = 'normal';
|
|
|
|
|
e.title = 'Normal Priority';
|
|
|
|
|
$(e).click(function(){ firePriorityChanged(0); });
|
|
|
|
|
elements.priority_normal_button = e;
|
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.title = 'High Priority';
|
|
|
|
|
e.className = 'high';
|
|
|
|
|
$(e).click(function(){ firePriorityChanged(1); });
|
|
|
|
|
elements.priority_high_button = e;
|
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
|
|
root.appendChild(box);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
2011-08-29 21:07:50 +00:00
|
|
|
|
name = file.name || 'Unknown';
|
|
|
|
|
name = name.substring(name.lastIndexOf('/')+1);
|
2012-08-18 14:59:09 +00:00
|
|
|
|
name = name.replace(/([\/_\.])/g, "$1");
|
2011-10-21 02:58:19 +00:00
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.className = "inspector_torrent_file_list_entry_name";
|
2012-07-20 17:37:50 +00:00
|
|
|
|
setTextContent(e, name);
|
2011-10-21 02:58:19 +00:00
|
|
|
|
root.appendChild(e);
|
|
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
|
e.className = "inspector_torrent_file_list_entry_progress";
|
|
|
|
|
root.appendChild(e);
|
|
|
|
|
elements.progress = e;
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
refresh();
|
2011-08-16 18:49:26 +00:00
|
|
|
|
return root;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
|
fireWantedChanged = function(do_want) {
|
|
|
|
|
$(fields.me).trigger('wantedToggled',[ fields.me, do_want ]);
|
2011-08-28 13:57:25 +00:00
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
firePriorityChanged = function(priority) {
|
|
|
|
|
$(fields.me).trigger('priorityToggled',[ fields.me, priority ]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
**** PUBLIC
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
this.getElement = function() {
|
|
|
|
|
return elements.root;
|
|
|
|
|
};
|
|
|
|
|
this.getIndex = function() {
|
|
|
|
|
return fields.index;
|
|
|
|
|
};
|
|
|
|
|
this.isEditable = function () {
|
|
|
|
|
return (fields.torrent.getFileCount()>1) && !isDone();
|
|
|
|
|
};
|
2012-08-18 15:04:06 +00:00
|
|
|
|
this.getPath = function () {
|
|
|
|
|
var file = torrent.getFile(i);
|
2012-09-23 17:21:19 +00:00
|
|
|
|
var path = file.name.replace(/\/\/+/g,'/');
|
|
|
|
|
path = path.split('/').slice(0,-1);
|
|
|
|
|
path.push('t' + fields.torrent.getId() + 'f' + fields.index);
|
|
|
|
|
return path;
|
2012-08-18 15:04:06 +00:00
|
|
|
|
};
|
2011-09-03 04:33:04 +00:00
|
|
|
|
|
|
|
|
|
initialize(torrent, i);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
};
|