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 = {
|
|
|
|
priority_control: null,
|
|
|
|
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-09-03 04:33:04 +00:00
|
|
|
var e = elements.root,
|
2011-08-28 13:57:25 +00:00
|
|
|
c = [ e.classNameConst ];
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
if (!fields.isWanted) { c.push('skip'); }
|
|
|
|
if (isDone()) { c.push('complete'); }
|
2011-08-28 13:57:25 +00:00
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
refreshPriorityHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
{
|
2011-09-03 04:33:04 +00:00
|
|
|
var e = elements.priority_control,
|
2011-08-28 13:57:25 +00:00
|
|
|
c = [ e.classNameConst ];
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
switch(fields.priority) {
|
2011-08-28 13:57:25 +00:00
|
|
|
case -1 : c.push('low'); break;
|
|
|
|
case 1 : c.push('high'); break;
|
|
|
|
default : c.push('normal'); break;
|
|
|
|
}
|
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
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('');
|
2011-09-03 04:33:04 +00:00
|
|
|
setInnerHTML(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) {
|
|
|
|
var file = torrent.getFile(i),
|
2011-08-29 21:07:50 +00:00
|
|
|
name, root, wanted_div, pri_div, file_div, prog_div;
|
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-08-28 13:57:25 +00:00
|
|
|
root.classNameConst = 'inspector_torrent_file_list_entry ' + ((i%2)?'odd':'even');
|
|
|
|
root.className = root.classNameConst;
|
|
|
|
|
|
|
|
wanted_div = document.createElement('div');
|
|
|
|
wanted_div.className = "file_wanted_control";
|
2011-09-03 04:33:04 +00:00
|
|
|
$(wanted_div).click(function(){ fireWantedChanged(!fields.isWanted); });
|
2011-08-28 13:57:25 +00:00
|
|
|
|
|
|
|
pri_div = document.createElement('div');
|
|
|
|
pri_div.classNameConst = "file_priority_control";
|
|
|
|
pri_div.className = pri_div.classNameConst;
|
|
|
|
$(pri_div).bind('click',function(ev){
|
|
|
|
var prio,
|
|
|
|
x = ev.pageX,
|
|
|
|
e = ev.target;
|
2011-08-24 02:04:35 +00:00
|
|
|
while (e) {
|
2011-08-16 18:49:26 +00:00
|
|
|
x -= e.offsetLeft;
|
|
|
|
e = e.offsetParent;
|
|
|
|
}
|
2011-09-03 04:33:04 +00:00
|
|
|
// ugh.
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice) {
|
2011-08-24 02:04:35 +00:00
|
|
|
if (x < 8) prio = -1;
|
|
|
|
else if (x < 27) prio = 0;
|
2011-08-16 18:49:26 +00:00
|
|
|
else prio = 1;
|
|
|
|
} else {
|
2011-08-24 02:04:35 +00:00
|
|
|
if (x < 12) prio = -1;
|
|
|
|
else if (x < 23) prio = 0;
|
2011-08-16 18:49:26 +00:00
|
|
|
else prio = 1;
|
|
|
|
}
|
2011-09-03 04:33:04 +00:00
|
|
|
firePriorityChanged(prio);
|
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);
|
|
|
|
name = name.replace(/([\/_\.])/g, "$1​");
|
2011-08-28 13:57:25 +00:00
|
|
|
file_div = document.createElement('div');
|
|
|
|
file_div.className = "inspector_torrent_file_list_entry_name";
|
2011-08-29 21:07:50 +00:00
|
|
|
file_div.innerHTML = name;
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
prog_div = document.createElement('div');
|
|
|
|
prog_div.className = "inspector_torrent_file_list_entry_progress";
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
root.appendChild(wanted_div);
|
|
|
|
root.appendChild(pri_div);
|
|
|
|
root.appendChild(file_div);
|
|
|
|
root.appendChild(prog_div);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
elements.root = root;
|
|
|
|
elements.priority_control = pri_div;
|
|
|
|
elements.progress = prog_div;
|
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();
|
|
|
|
};
|
|
|
|
|
|
|
|
initialize(torrent, i);
|
2011-08-16 18:49:26 +00:00
|
|
|
};
|