2011-08-16 18:49:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright © Jordan Lee
|
|
|
|
* This code is licensed under the GPL version 2.
|
|
|
|
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
|
|
|
*/
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
function FileRow(torrent, i)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
this.initialize(torrent, i);
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileRow.prototype =
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
initialize: function(torrent, i)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
this._torrent = torrent;
|
|
|
|
this._index = i;
|
2011-08-24 02:04:35 +00:00
|
|
|
this.createRow(torrent, i);
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getTorrent: function()
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
return this._torrent;
|
|
|
|
},
|
2011-08-24 02:04:35 +00:00
|
|
|
getIndex: function()
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
return this._index;
|
|
|
|
},
|
|
|
|
|
|
|
|
readAttributes: function(file)
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
if (file.index !== undefined && file.index !== this._index) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._index = file.index;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
if (file.bytesCompleted !== undefined && file.bytesCompleted !== this._done) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._done = file.bytesCompleted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
if (file.length !== undefined && file.length !== this._size) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._size = file.length;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
if (file.priority !== undefined && file.priority !== this._prio) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._prio = file.priority;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
if (file.wanted !== undefined && file.wanted !== this._wanted) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._wanted = file.wanted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshWantedHTML: function() {
|
|
|
|
var e = this.getElement();
|
|
|
|
var c = [ e.classNameConst ];
|
2011-08-24 02:04:35 +00:00
|
|
|
if (!this._wanted) { c.push('skip'); }
|
|
|
|
if (this.isDone()) { c.push('complete'); }
|
2011-08-16 18:49:26 +00:00
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
|
|
|
refreshPriorityHTML: function() {
|
|
|
|
var e = this._priority_control;
|
|
|
|
var c = [ e.classNameConst ];
|
2011-08-24 02:04:35 +00:00
|
|
|
switch(this._prio) {
|
|
|
|
case -1 : c.push('low'); break;
|
|
|
|
case 1 : c.push('high'); break;
|
|
|
|
default : c.push('normal'); break;
|
2011-08-16 18:49:26 +00:00
|
|
|
}
|
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
|
|
|
refreshProgressHTML: function() {
|
2011-08-24 02:04:35 +00:00
|
|
|
var pct = 100 * (this._size ? (this._done / this._size) : 1.0);
|
2011-08-16 18:49:26 +00:00
|
|
|
var c = [ Transmission.fmt.size(this._done),
|
|
|
|
' of ',
|
|
|
|
Transmission.fmt.size(this._size),
|
|
|
|
' (',
|
|
|
|
Transmission.fmt.percentString(pct),
|
|
|
|
'%)' ].join('');
|
|
|
|
setInnerHTML(this._progress[0], c);
|
|
|
|
},
|
|
|
|
refreshHTML: function() {
|
2011-08-24 02:04:35 +00:00
|
|
|
if (this._dirty) {
|
2011-08-16 18:49:26 +00:00
|
|
|
this._dirty = false;
|
|
|
|
this.refreshProgressHTML();
|
|
|
|
this.refreshWantedHTML();
|
|
|
|
this.refreshPriorityHTML();
|
|
|
|
}
|
|
|
|
},
|
2011-08-24 02:04:35 +00:00
|
|
|
refresh: function()
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
var i = this.getIndex();
|
|
|
|
var t = this.getTorrent();
|
2011-08-25 23:06:41 +00:00
|
|
|
this.readAttributes(t.getFile(i));
|
2011-08-16 18:49:26 +00:00
|
|
|
this.refreshHTML();
|
|
|
|
},
|
|
|
|
|
|
|
|
isDone: function () {
|
|
|
|
return this._done >= this._size;
|
|
|
|
},
|
|
|
|
isEditable: function () {
|
2011-08-25 23:06:41 +00:00
|
|
|
return (this.getTorrent().getFileCount()>1) && !this.isDone();
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
createRow: function(torrent, i)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
var me = this;
|
2011-08-25 23:06:41 +00:00
|
|
|
var file = torrent.getFile(i);
|
2011-08-16 18:49:26 +00:00
|
|
|
var name = file.name.substring (file.name.lastIndexOf('/')+1);
|
|
|
|
|
|
|
|
var root = document.createElement('li');
|
2011-08-20 21:17:12 +00:00
|
|
|
root.id = 't' + this._torrent.getId() + 'f' + this._index;
|
2011-08-16 18:49:26 +00:00
|
|
|
root.classNameConst = 'inspector_torrent_file_list_entry ' + ((i%2)?'odd':'even');
|
|
|
|
root.className = root.classNameConst;
|
|
|
|
|
|
|
|
var wanted_div = document.createElement('div');
|
|
|
|
wanted_div.className = "file_wanted_control";
|
2011-08-24 02:04:35 +00:00
|
|
|
$(wanted_div).bind('click',function(){ me.fireWantedChanged(!me._wanted); });
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
var pri_div = document.createElement('div');
|
|
|
|
pri_div.classNameConst = "file_priority_control";
|
|
|
|
pri_div.className = pri_div.classNameConst;
|
|
|
|
$(pri_div).bind('click',function(ev){
|
|
|
|
var x = ev.pageX;
|
|
|
|
var 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;
|
|
|
|
}
|
|
|
|
var prio;
|
2011-08-24 02:04:35 +00:00
|
|
|
if (iPhone) {
|
|
|
|
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-08-24 02:04:35 +00:00
|
|
|
me.firePriorityChanged(prio);
|
2011-08-16 18:49:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var file_div = document.createElement('div');
|
|
|
|
file_div.className = "inspector_torrent_file_list_entry_name";
|
|
|
|
file_div.innerHTML = name.replace(/([\/_\.])/g, "$1​");
|
|
|
|
|
|
|
|
var prog_div = document.createElement('div');
|
|
|
|
prog_div.className = "inspector_torrent_file_list_entry_progress";
|
|
|
|
|
|
|
|
root.appendChild(wanted_div);
|
|
|
|
root.appendChild(pri_div);
|
|
|
|
root.appendChild(file_div);
|
|
|
|
root.appendChild(prog_div);
|
|
|
|
|
|
|
|
this._element = root;
|
|
|
|
this._priority_control = pri_div;
|
|
|
|
this._progress = $(prog_div);
|
|
|
|
|
|
|
|
this.refresh();
|
|
|
|
return root;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getElement: function()
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
return this._element;
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
fireWantedChanged: function(do_want)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
$(this).trigger('wantedToggled',[ this, do_want ]);
|
|
|
|
},
|
2011-08-24 02:04:35 +00:00
|
|
|
firePriorityChanged: function(priority)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
$(this).trigger('priorityToggled',[ this, priority ]);
|
|
|
|
}
|
|
|
|
};
|