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-28 13:57:25 +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;
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
readAttributes: function(file)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-08-28 13:57:25 +00:00
|
|
|
if (file.index !== undefined && file.index !== this._index) {
|
|
|
|
this._index = file.index;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
if (file.bytesCompleted !== undefined && file.bytesCompleted !== this._done) {
|
|
|
|
this._done = file.bytesCompleted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
if (file.length !== undefined && file.length !== this._size) {
|
|
|
|
this._size = file.length;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
if (file.priority !== undefined && file.priority !== this._prio) {
|
|
|
|
this._prio = file.priority;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
if (file.wanted !== undefined && file.wanted !== this._wanted) {
|
|
|
|
this._wanted = file.wanted;
|
|
|
|
this._dirty = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshWantedHTML: function()
|
|
|
|
{
|
|
|
|
var e = this.getElement(),
|
|
|
|
c = [ e.classNameConst ];
|
|
|
|
|
|
|
|
if (!this._wanted) { c.push('skip'); }
|
|
|
|
if (this.isDone()) { c.push('complete'); }
|
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
|
|
|
refreshPriorityHTML: function()
|
|
|
|
{
|
|
|
|
var e = this._priority_control,
|
|
|
|
c = [ e.classNameConst ];
|
|
|
|
|
|
|
|
switch(this._prio) {
|
|
|
|
case -1 : c.push('low'); break;
|
|
|
|
case 1 : c.push('high'); break;
|
|
|
|
default : c.push('normal'); break;
|
|
|
|
}
|
|
|
|
e.className = c.join(' ');
|
|
|
|
},
|
|
|
|
refreshProgressHTML: function()
|
|
|
|
{
|
|
|
|
var pct = 100 * (this._size ? (this._done / this._size) : 1.0),
|
|
|
|
c = [ Transmission.fmt.size(this._done),
|
|
|
|
' of ',
|
|
|
|
Transmission.fmt.size(this._size),
|
|
|
|
' (',
|
|
|
|
Transmission.fmt.percentString(pct),
|
|
|
|
'%)' ].join('');
|
|
|
|
setInnerHTML(this._progress[0], c);
|
|
|
|
},
|
|
|
|
refreshHTML: function() {
|
|
|
|
if (this._dirty) {
|
|
|
|
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-28 13:57:25 +00:00
|
|
|
var i = this.getIndex(),
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
isDone: function () {
|
|
|
|
return this._done >= this._size;
|
|
|
|
},
|
|
|
|
isEditable: function () {
|
|
|
|
return (this.getTorrent().getFileCount()>1) && !this.isDone();
|
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
createRow: function(torrent, i)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-08-28 13:57:25 +00:00
|
|
|
var me = this,
|
|
|
|
file = torrent.getFile(i),
|
|
|
|
name = file.name.substring (file.name.lastIndexOf('/')+1),
|
|
|
|
root, wanted_div, pri_div, file_div, prog_div;
|
|
|
|
|
|
|
|
root = document.createElement('li');
|
|
|
|
root.id = 't' + this._torrent.getId() + 'f' + this._index;
|
|
|
|
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";
|
|
|
|
$(wanted_div).bind('click',function(){ me.fireWantedChanged(!me._wanted); });
|
|
|
|
|
|
|
|
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-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
|
|
|
});
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
file_div = document.createElement('div');
|
|
|
|
file_div.className = "inspector_torrent_file_list_entry_name";
|
|
|
|
file_div.innerHTML = name.replace(/([\/_\.])/g, "$1​");
|
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-08-28 13:57:25 +00:00
|
|
|
this._element = root;
|
|
|
|
this._priority_control = pri_div;
|
|
|
|
this._progress = $(prog_div);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
|
|
|
this.refresh();
|
|
|
|
return root;
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
getElement: function()
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
|
|
|
return this._element;
|
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
fireWantedChanged: function(do_want)
|
|
|
|
{
|
|
|
|
$(this).trigger('wantedToggled',[ this, do_want ]);
|
|
|
|
},
|
|
|
|
firePriorityChanged: function(priority)
|
|
|
|
{
|
|
|
|
$(this).trigger('priorityToggled',[ this, priority ]);
|
|
|
|
}
|
2011-08-16 18:49:26 +00:00
|
|
|
};
|