mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-19 22:58:30 +00:00
add a generic method for walking the file tree in the add window
This commit is contained in:
parent
c2e3f3d228
commit
4cefabe2db
@ -34,6 +34,8 @@ Copyright:
|
|||||||
|
|
||||||
Ext.namespace('Ext.deluge.add');
|
Ext.namespace('Ext.deluge.add');
|
||||||
Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||||
|
|
||||||
|
torrents: {},
|
||||||
|
|
||||||
constructor: function(config) {
|
constructor: function(config) {
|
||||||
config = Ext.apply({
|
config = Ext.apply({
|
||||||
@ -75,16 +77,17 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.optionsManager = new Deluge.OptionsManager({
|
this.optionsManager = new Deluge.OptionsManager({
|
||||||
defaults: {
|
defaults: {
|
||||||
'add_paused': false,
|
'add_paused': false,
|
||||||
'compact_allocation': false,
|
'compact_allocation': false,
|
||||||
'download_location': '~',
|
'download_location': '~',
|
||||||
'max_connections_per_torrent': -1,
|
'max_connections_per_torrent': -1,
|
||||||
'max_download_speed_per_torrent': -1,
|
'max_download_speed_per_torrent': -1,
|
||||||
'max_upload_slots_per_torrent': -1,
|
'max_upload_slots_per_torrent': -1,
|
||||||
'max_upload_speed_per_torrent': -1,
|
'max_upload_speed_per_torrent': -1,
|
||||||
'prioritize_first_last_pieces': false
|
'prioritize_first_last_pieces': false,
|
||||||
}
|
'file_priorities': []
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.form = this.add({
|
this.form = this.add({
|
||||||
@ -210,6 +213,11 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
this.optionsManager.changeId(null);
|
this.optionsManager.changeId(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addTorrent: function(torrent) {
|
||||||
|
this.torrents[torrent['info_hash']] = torrent;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
clear: function() {
|
clear: function() {
|
||||||
this.clearFiles();
|
this.clearFiles();
|
||||||
},
|
},
|
||||||
@ -255,42 +263,68 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setTorrent: function(torrent) {
|
getFilePriorities: function() {
|
||||||
var self = this;
|
var root = this.files.getRootNode();
|
||||||
function walk(files, parent) {
|
var priorities = {};
|
||||||
for (var file in files) {
|
|
||||||
var item = files[file];
|
function getCheckedState(node) {
|
||||||
|
if (node.ui.checkbox) {
|
||||||
if (Ext.type(item) == 'object') {
|
return node.ui.checkbox.checked;
|
||||||
var folder = new Ext.tree.TreeNode({
|
} else {
|
||||||
text: file,
|
return getCheckedState(node.parentNode);
|
||||||
checked: true
|
|
||||||
});
|
|
||||||
folder.on('checkchange', self.onFolderCheck, self);
|
|
||||||
parent.appendChild(folder);
|
|
||||||
walk(item, folder);
|
|
||||||
} else {
|
|
||||||
parent.appendChild(new Ext.tree.TreeNode({
|
|
||||||
filename: file,
|
|
||||||
text: file, // this needs to be here for sorting reasons
|
|
||||||
size: fsize(item[1]),
|
|
||||||
leaf: true,
|
|
||||||
checked: item[2],
|
|
||||||
iconCls: 'x-deluge-file',
|
|
||||||
uiProvider: Ext.tree.ColumnNodeUI
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root.cascade(function(node) {
|
||||||
|
if (!node.isLeaf()) return;
|
||||||
|
priorities[node.attributes.fileindex] = getCheckedState(node);
|
||||||
|
});
|
||||||
|
return priorities;
|
||||||
|
},
|
||||||
|
|
||||||
|
setTorrent: function(torrentId) {
|
||||||
|
var self = this;
|
||||||
this.clearFiles();
|
this.clearFiles();
|
||||||
var root = this.files.getRootNode();
|
var root = this.files.getRootNode();
|
||||||
walk(torrent['files_tree'], root);
|
this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parent) {
|
||||||
|
if (type == 'dir') {
|
||||||
|
var folder = new Ext.tree.TreeNode({
|
||||||
|
text: filename,
|
||||||
|
checked: true
|
||||||
|
});
|
||||||
|
folder.on('checkchange', self.onFolderCheck, self);
|
||||||
|
parent.appendChild(folder);
|
||||||
|
return folder;
|
||||||
|
} else {
|
||||||
|
parent.appendChild(new Ext.tree.TreeNode({
|
||||||
|
filename: filename,
|
||||||
|
fileindex: entry[0],
|
||||||
|
text: filename, // this needs to be here for sorting reasons
|
||||||
|
size: fsize(entry[1]),
|
||||||
|
leaf: true,
|
||||||
|
checked: entry[2],
|
||||||
|
iconCls: 'x-deluge-file',
|
||||||
|
uiProvider: Ext.tree.ColumnNodeUI
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, root);
|
||||||
root.firstChild.expand();
|
root.firstChild.expand();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
walkFileTree: function(files, callback, parent) {
|
||||||
|
for (var filename in files) {
|
||||||
|
var entry = files[filename];
|
||||||
|
var type = (Ext.type(entry) == 'object') ? 'dir' : 'file';
|
||||||
|
|
||||||
|
var ret = callback(filename, type, entry, parent)
|
||||||
|
parent = (ret) ? ret : parent;
|
||||||
|
if (type == 'dir') this.walkFileTree(entry, callback, parent);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onFolderCheck: function(node, checked) {
|
onFolderCheck: function(node, checked) {
|
||||||
node.cascade(function(child) {
|
node.cascade(function(child) {
|
||||||
|
if (!child.ui.checkbox) return;
|
||||||
child.ui.checkbox.checked = checked;
|
child.ui.checkbox.checked = checked;
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
@ -312,8 +346,6 @@ Ext.deluge.add.Window = Ext.extend(Ext.Window, {
|
|||||||
|
|
||||||
Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
||||||
|
|
||||||
torrents: {},
|
|
||||||
|
|
||||||
constructor: function(config) {
|
constructor: function(config) {
|
||||||
config = Ext.apply({
|
config = Ext.apply({
|
||||||
title: _('Add Torrents'),
|
title: _('Add Torrents'),
|
||||||
@ -418,6 +450,8 @@ Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function() {
|
onAdd: function() {
|
||||||
|
var priorities = this.optionsPanel.getFilePriorities();
|
||||||
|
return;
|
||||||
torrents = [];
|
torrents = [];
|
||||||
for (var id in this.torrents) {
|
for (var id in this.torrents) {
|
||||||
var info = this.torrents[id];
|
var info = this.torrents[id];
|
||||||
@ -454,7 +488,7 @@ Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onSelect: function(selModel, rowIndex, record) {
|
onSelect: function(selModel, rowIndex, record) {
|
||||||
this.optionsPanel.setTorrent(this.torrents[record.get('info_hash')]);
|
this.optionsPanel.setTorrent(record.get('info_hash'));
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
@ -493,7 +527,7 @@ Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
|
|||||||
r.set('info_hash', info['info_hash']);
|
r.set('info_hash', info['info_hash']);
|
||||||
r.set('text', info['name']);
|
r.set('text', info['name']);
|
||||||
this.grid.getStore().commitChanges();
|
this.grid.getStore().commitChanges();
|
||||||
this.torrents[info['info_hash']] = info;
|
this.optionsPanel.addTorrent(info);
|
||||||
},
|
},
|
||||||
|
|
||||||
onUrl: function(button, event) {
|
onUrl: function(button, event) {
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user