improve the selective downloading adding support for directories and don't recreate treenodes

This commit is contained in:
Damien Churchill 2010-04-19 13:59:21 +01:00
parent c176ff900f
commit dd1716c240
2 changed files with 53 additions and 38 deletions

View File

@ -65,7 +65,7 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, {
dataIndex: 'download',
tpl: new Ext.XTemplate('{download:this.format}', {
format: function(v) {
return '<div class="x-grid3-check-col'+(v?'-on':'')+'"> </div>';
return '<div rel="chkbox" class="x-grid3-check-col'+(v?'-on':'')+'"> </div>';
}
})
}],
@ -84,23 +84,25 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, {
});
},
onNodeClick: function(node, e) {
node.attributes.download = !node.attributes.download;
var newNode = new Ext.tree.TreeNode(node.attributes);
node.parentNode.replaceChild(newNode, node);
this.fireEvent('filechecked', newNode, node.attributes.download, !node.attributes.download);
setDownload: function(node, value) {
node.attributes.download = value;
node.ui.updateColumns();
if (node.isLeaf()) {
return this.fireEvent('filechecked', node, value, !value);
} else {
node.cascade(function(n) {
n.attributes.download = value;
n.ui.updateColumns();
return this.fireEvent('filechecked', n, value, !value);
}, this);
}
},
onFolderCheck: function(node, checked) {
var priorities = this.optionsManager.get('file_priorities');
node.cascade(function(child) {
if (!child.ui.checkbox) {
child.attributes.checked = checked;
} else {
child.ui.checkbox.checked = checked;
}
priorities[child.attributes.fileindex] = checked;
}, this);
this.optionsManager.setDefault('file_priorities', priorities);
onNodeClick: function(node, e) {
var el = new Ext.Element(e.target);
if (el.getAttribute('rel') == 'chkbox') {
this.setDownload(node, !node.attributes.download);
}
}
});

View File

@ -97,27 +97,15 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
var priorities = this.form.optionsManager.get('file_priorities');
this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parentNode) {
if (type == 'dir') {
var folder = new Ext.tree.TreeNode({
filename: filename,
size: entry.length,
download: true
});
folder.on('checkchange', this.onFolderCheck, this);
parentNode.appendChild(folder);
return folder;
} else {
var node = new Ext.tree.TreeNode({
filename: filename,
fileindex: entry.index,
size: entry.length,
leaf: true,
download: priorities[entry.index],
uiProvider: Ext.tree.ColumnNodeUI
});
node.on('checkchange', this.onNodeCheck, this);
parentNode.appendChild(node);
}
var node = new Ext.tree.TreeNode({
download: (entry.index) ? priorities[entry.index] : true,
filename: filename,
fileindex: entry.index,
leaf: type != 'dir',
size: entry.length
});
parentNode.appendChild(node);
if (type == 'dir') return node;
}, this, root);
root.firstChild.expand();
},
@ -138,6 +126,31 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
},
onFileChecked: function(node, newValue, oldValue) {
if (!Ext.isNumber(node.attributes.fileindex)) return;
// if (this.form.optionsManager.get('compact_allocation')) {
// Ext.Msg.show({
// title: _('Unable to set file priority!'),
// msg: _('File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?'),
// buttons: Ext.Msg.YESNO,
// fn: function(result) {
// if (result == 'yes') {
// var priorities = this.form.optionsManager.get('file_priorities');
// priorities[node.attributes.fileindex] = (result) ? newValue : oldValue;
// this.form.optionsManager.update('file_priorities', priorities);
// } else {
// node.attributes.download = oldValue;
// node.ui.updateColumns();
// }
// },
// scope: this,
// icon: Ext.MessageBox.QUESTION
// });
// } else {
// var priorities = this.form.optionsManager.get('file_priorities');
// priorities[node.attributes.fileindex] = newValue;
// this.form.optionsManager.update('file_priorities', priorities);
// }
var priorities = this.form.optionsManager.get('file_priorities');
priorities[node.attributes.fileindex] = newValue;
this.form.optionsManager.update('file_priorities', priorities);